aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorVille Skyttä <ville.skytta@iki.fi>2023-12-15 04:30:35 +0200
committerGitHub <noreply@github.com>2023-12-14 18:30:35 -0800
commit53c0389b5ed23f0ead92d782e4f14d8780fb18e7 (patch)
treeecbab66248295a59fb41849ed02f4c230822d456 /test
parentf3cbdbcae88d17c5f3b7d3de53c9251bb77892cb (diff)
Add support for `dprint` (#249)
https://dprint.dev --------- Co-authored-by: Radon Rosborough <radon@intuitiveexplanations.com>
Diffstat (limited to 'test')
-rwxr-xr-xtest/formatters/apheleia-ft.el34
-rw-r--r--test/formatters/installers/dprint.bash19
-rw-r--r--test/formatters/samplecode/dprint/in.dockerfile1
l---------test/formatters/samplecode/dprint/in.js1
l---------test/formatters/samplecode/dprint/in.json1
l---------test/formatters/samplecode/dprint/in.md1
l---------test/formatters/samplecode/dprint/in.py1
-rw-r--r--test/formatters/samplecode/dprint/in.toml1
l---------test/formatters/samplecode/dprint/in.ts1
-rw-r--r--test/formatters/samplecode/dprint/out.dockerfile1
-rw-r--r--test/formatters/samplecode/dprint/out.js3
-rw-r--r--test/formatters/samplecode/dprint/out.json19
-rw-r--r--test/formatters/samplecode/dprint/out.md4
-rw-r--r--test/formatters/samplecode/dprint/out.py3
-rw-r--r--test/formatters/samplecode/dprint/out.toml1
-rw-r--r--test/formatters/samplecode/dprint/out.ts6
16 files changed, 84 insertions, 13 deletions
diff --git a/test/formatters/apheleia-ft.el b/test/formatters/apheleia-ft.el
index a8ac9d4..1e1f4ce 100755
--- a/test/formatters/apheleia-ft.el
+++ b/test/formatters/apheleia-ft.el
@@ -269,8 +269,10 @@ environment variable, defaulting to all formatters."
(dolist (in-file (apheleia-ft--input-files formatter))
(let ((extension (file-name-extension in-file))
(in-text (apheleia-ft--read-file in-file))
+ ;; The `in-temp-real-file' variable is set to whatever
+ ;; temporary file the formatter will run on (in case it
+ ;; uses the `file' or `filepath' symbol or is a function).
(in-temp-real-file nil)
- (in-temp-file nil)
(out-temp-file nil)
(command (alist-get (intern formatter) apheleia-formatters))
(syms nil)
@@ -292,15 +294,15 @@ environment variable, defaulting to all formatters."
;; Some formatters use the current file-name or buffer-name to interpret the
;; type of file that is being formatted. Some may not be able to determine
;; this from the contents of the file so we set this to force it.
- (rename-buffer in-file)
+ (rename-buffer (file-name-nondirectory in-file))
(setq stdout-buffer (get-buffer-create
(format "*apheleia-ft-stdout-%S%s" formatter extension)))
(with-current-buffer stdout-buffer
(erase-buffer))
(if (functionp command)
- (progn
- (setq in-temp-file (apheleia-ft--write-temp-file
- in-text extension))
+ (let ((in-temp-file (apheleia-ft--write-temp-file
+ in-text extension)))
+ (setq in-temp-real-file in-temp-file)
(with-current-buffer (find-file-noselect in-temp-file)
(funcall command
:buffer (current-buffer)
@@ -308,14 +310,20 @@ environment variable, defaulting to all formatters."
:formatter formatter
:callback (lambda ()))
(copy-to-buffer stdout-buffer (point-min) (point-max))))
- (progn
-
- (let ((ctx (apheleia--formatter-context
- (intern formatter) command nil nil)))
- (setq command `(,(apheleia-formatter--arg1 ctx)
- ,@(apheleia-formatter--argv ctx))
- in-temp-real-file (apheleia-formatter--input-fname ctx)
- out-temp-file (apheleia-formatter--output-fname ctx)))
+ (let ((in-temp-file (apheleia-ft--write-temp-file
+ in-text extension)))
+ (with-current-buffer (find-file-noselect in-temp-file)
+ (let ((ctx (apheleia--formatter-context
+ (intern formatter) command nil nil)))
+ (setq command `(,(apheleia-formatter--arg1 ctx)
+ ,@(apheleia-formatter--argv ctx))
+ ;; In this case the real temp file might be
+ ;; different from the one we generated, because
+ ;; the context creator might generate another
+ ;; temporary file to avoid touching our existing
+ ;; one.
+ in-temp-real-file (apheleia-formatter--input-fname ctx)
+ out-temp-file (apheleia-formatter--output-fname ctx))))
(with-current-buffer stdout-buffer
(erase-buffer))
diff --git a/test/formatters/installers/dprint.bash b/test/formatters/installers/dprint.bash
new file mode 100644
index 0000000..929c4b9
--- /dev/null
+++ b/test/formatters/installers/dprint.bash
@@ -0,0 +1,19 @@
+npm install -g dprint
+
+# Included: WASM plugins, preferring first over 3rd party wrappers
+# where redundant (e.g. -typescript and -json instead of -biome)
+cat <<\EOF >/tmp/dprint.json
+{
+ "excludes": [],
+ "plugins": [
+ "https://plugins.dprint.dev/dockerfile-0.3.0.wasm",
+ "https://plugins.dprint.dev/json-0.19.1.wasm",
+ "https://plugins.dprint.dev/markdown-0.16.3.wasm",
+ "https://plugins.dprint.dev/ruff-0.0.2.wasm",
+ "https://plugins.dprint.dev/toml-0.5.4.wasm",
+ "https://plugins.dprint.dev/typescript-0.88.7.wasm"
+ ]
+}
+EOF
+
+# dprint config update # not done to keep formatting stable
diff --git a/test/formatters/samplecode/dprint/in.dockerfile b/test/formatters/samplecode/dprint/in.dockerfile
new file mode 100644
index 0000000..444eb9e
--- /dev/null
+++ b/test/formatters/samplecode/dprint/in.dockerfile
@@ -0,0 +1 @@
+FROM scratch
diff --git a/test/formatters/samplecode/dprint/in.js b/test/formatters/samplecode/dprint/in.js
new file mode 120000
index 0000000..da49303
--- /dev/null
+++ b/test/formatters/samplecode/dprint/in.js
@@ -0,0 +1 @@
+../prettier-javascript/in.js \ No newline at end of file
diff --git a/test/formatters/samplecode/dprint/in.json b/test/formatters/samplecode/dprint/in.json
new file mode 120000
index 0000000..599a1e2
--- /dev/null
+++ b/test/formatters/samplecode/dprint/in.json
@@ -0,0 +1 @@
+../prettier-json/in.json \ No newline at end of file
diff --git a/test/formatters/samplecode/dprint/in.md b/test/formatters/samplecode/dprint/in.md
new file mode 120000
index 0000000..99482b8
--- /dev/null
+++ b/test/formatters/samplecode/dprint/in.md
@@ -0,0 +1 @@
+../prettier-markdown/in.md \ No newline at end of file
diff --git a/test/formatters/samplecode/dprint/in.py b/test/formatters/samplecode/dprint/in.py
new file mode 120000
index 0000000..ebc1034
--- /dev/null
+++ b/test/formatters/samplecode/dprint/in.py
@@ -0,0 +1 @@
+../ruff/in.py \ No newline at end of file
diff --git a/test/formatters/samplecode/dprint/in.toml b/test/formatters/samplecode/dprint/in.toml
new file mode 100644
index 0000000..1f05503
--- /dev/null
+++ b/test/formatters/samplecode/dprint/in.toml
@@ -0,0 +1 @@
+title = "Apheleia dprint TOML test"
diff --git a/test/formatters/samplecode/dprint/in.ts b/test/formatters/samplecode/dprint/in.ts
new file mode 120000
index 0000000..1b5f9d6
--- /dev/null
+++ b/test/formatters/samplecode/dprint/in.ts
@@ -0,0 +1 @@
+../prettier-typescript/in.ts \ No newline at end of file
diff --git a/test/formatters/samplecode/dprint/out.dockerfile b/test/formatters/samplecode/dprint/out.dockerfile
new file mode 100644
index 0000000..c35f1b5
--- /dev/null
+++ b/test/formatters/samplecode/dprint/out.dockerfile
@@ -0,0 +1 @@
+FROM scratch
diff --git a/test/formatters/samplecode/dprint/out.js b/test/formatters/samplecode/dprint/out.js
new file mode 100644
index 0000000..c0c58c0
--- /dev/null
+++ b/test/formatters/samplecode/dprint/out.js
@@ -0,0 +1,3 @@
+function HelloWorld({ greeting = "hello", greeted = "\"World\"", silent = false, onMouseOver }) {
+ if (!greeting) return null;
+}
diff --git a/test/formatters/samplecode/dprint/out.json b/test/formatters/samplecode/dprint/out.json
new file mode 100644
index 0000000..59bb3b4
--- /dev/null
+++ b/test/formatters/samplecode/dprint/out.json
@@ -0,0 +1,19 @@
+{
+ "arrowParens": "always",
+ "bracketSpacing": true,
+ "embeddedLanguageFormatting": "auto",
+ "htmlWhitespaceSensitivity": "css",
+ "insertPragma": false,
+ "jsxBracketSameLine": false,
+ "jsxSingleQuote": false,
+ "printWidth": 80,
+ "proseWrap": "preserve",
+ "quoteProps": "as-needed",
+ "requirePragma": false,
+ "semi": true,
+ "singleQuote": false,
+ "tabWidth": 2,
+ "trailingComma": "es5",
+ "useTabs": false,
+ "vueIndentScriptAndStyle": false
+}
diff --git a/test/formatters/samplecode/dprint/out.md b/test/formatters/samplecode/dprint/out.md
new file mode 100644
index 0000000..4d08fcd
--- /dev/null
+++ b/test/formatters/samplecode/dprint/out.md
@@ -0,0 +1,4 @@
+| col1 | col 2 |
+| ------ | ---------- |
+| nice | fits |
+| oh no! | it's ugly! |
diff --git a/test/formatters/samplecode/dprint/out.py b/test/formatters/samplecode/dprint/out.py
new file mode 100644
index 0000000..0a63d13
--- /dev/null
+++ b/test/formatters/samplecode/dprint/out.py
@@ -0,0 +1,3 @@
+def asdjf(l, a):
+ 3
+ +4
diff --git a/test/formatters/samplecode/dprint/out.toml b/test/formatters/samplecode/dprint/out.toml
new file mode 100644
index 0000000..091bd6b
--- /dev/null
+++ b/test/formatters/samplecode/dprint/out.toml
@@ -0,0 +1 @@
+title = "Apheleia dprint TOML test"
diff --git a/test/formatters/samplecode/dprint/out.ts b/test/formatters/samplecode/dprint/out.ts
new file mode 100644
index 0000000..143b5a7
--- /dev/null
+++ b/test/formatters/samplecode/dprint/out.ts
@@ -0,0 +1,6 @@
+interface GreetingSettings {
+ greeting: string;
+ duration?: number;
+ color?: string;
+}
+declare function greet(setting: GreetingSettings): void;