mirror of
https://github.com/vale981/apheleia
synced 2025-03-04 17:11:40 -05:00
Add support for dprint
(#249)
https://dprint.dev --------- Co-authored-by: Radon Rosborough <radon@intuitiveexplanations.com>
This commit is contained in:
parent
f3cbdbcae8
commit
53c0389b5e
18 changed files with 90 additions and 13 deletions
|
@ -10,6 +10,8 @@ The format is based on [Keep a Changelog].
|
||||||
settings ([#261]).
|
settings ([#261]).
|
||||||
|
|
||||||
### Formatters
|
### Formatters
|
||||||
|
* [`dprint`](https://dprint.dev) for various (depending on
|
||||||
|
[installed plugins](https://dprint.dev/plugins/)) ([#209]).
|
||||||
* [`js-beautify`](https://github.com/beautify-web/js-beautify) for
|
* [`js-beautify`](https://github.com/beautify-web/js-beautify) for
|
||||||
[JavaScript](https://www.javascript.com/),
|
[JavaScript](https://www.javascript.com/),
|
||||||
[JSON](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/JSON),
|
[JSON](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/JSON),
|
||||||
|
@ -25,6 +27,7 @@ The format is based on [Keep a Changelog].
|
||||||
* [cljfmt](https://github.com/weavejester/cljfmt) for clojure,
|
* [cljfmt](https://github.com/weavejester/cljfmt) for clojure,
|
||||||
clojurescript, edn files. ([#271])
|
clojurescript, edn files. ([#271])
|
||||||
|
|
||||||
|
[#209]: https://github.com/radian-software/apheleia/pull/209
|
||||||
[#229]: https://github.com/radian-software/apheleia/pull/229
|
[#229]: https://github.com/radian-software/apheleia/pull/229
|
||||||
[#257]: https://github.com/radian-software/apheleia/pull/257
|
[#257]: https://github.com/radian-software/apheleia/pull/257
|
||||||
[#260]: https://github.com/radian-software/apheleia/pull/260
|
[#260]: https://github.com/radian-software/apheleia/pull/260
|
||||||
|
|
|
@ -56,6 +56,7 @@
|
||||||
(denofmt-md . ("deno" "fmt" "-" "--ext" "md"))
|
(denofmt-md . ("deno" "fmt" "-" "--ext" "md"))
|
||||||
(denofmt-ts . ("deno" "fmt" "-" "--ext" "ts"))
|
(denofmt-ts . ("deno" "fmt" "-" "--ext" "ts"))
|
||||||
(denofmt-tsx . ("deno" "fmt" "-" "--ext" "tsx"))
|
(denofmt-tsx . ("deno" "fmt" "-" "--ext" "tsx"))
|
||||||
|
(dprint . ("dprint" "fmt" "--stdin" filepath))
|
||||||
(elm-format . ("elm-format" "--yes" "--stdin"))
|
(elm-format . ("elm-format" "--yes" "--stdin"))
|
||||||
(fish-indent . ("fish_indent"))
|
(fish-indent . ("fish_indent"))
|
||||||
(fourmolu . ("fourmolu"))
|
(fourmolu . ("fourmolu"))
|
||||||
|
@ -291,12 +292,14 @@ rather than using this system."
|
||||||
(cmake-mode . cmake-format)
|
(cmake-mode . cmake-format)
|
||||||
(cmake-ts-mode . cmake-format)
|
(cmake-ts-mode . cmake-format)
|
||||||
(common-lisp-mode . lisp-indent)
|
(common-lisp-mode . lisp-indent)
|
||||||
|
(conf-toml-mode . dprint)
|
||||||
(cperl-mode . perltidy)
|
(cperl-mode . perltidy)
|
||||||
(crystal-mode . crystal-tool-format)
|
(crystal-mode . crystal-tool-format)
|
||||||
(css-mode . prettier-css)
|
(css-mode . prettier-css)
|
||||||
(css-ts-mode . prettier-css)
|
(css-ts-mode . prettier-css)
|
||||||
(dart-mode . dart-format)
|
(dart-mode . dart-format)
|
||||||
(dart-ts-mode . dart-format)
|
(dart-ts-mode . dart-format)
|
||||||
|
(dockerfile-mode . dprint)
|
||||||
(elixir-mode . mix-format)
|
(elixir-mode . mix-format)
|
||||||
(elixir-ts-mode . mix-format)
|
(elixir-ts-mode . mix-format)
|
||||||
(elm-mode . elm-format)
|
(elm-mode . elm-format)
|
||||||
|
|
|
@ -269,8 +269,10 @@ environment variable, defaulting to all formatters."
|
||||||
(dolist (in-file (apheleia-ft--input-files formatter))
|
(dolist (in-file (apheleia-ft--input-files formatter))
|
||||||
(let ((extension (file-name-extension in-file))
|
(let ((extension (file-name-extension in-file))
|
||||||
(in-text (apheleia-ft--read-file 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-real-file nil)
|
||||||
(in-temp-file nil)
|
|
||||||
(out-temp-file nil)
|
(out-temp-file nil)
|
||||||
(command (alist-get (intern formatter) apheleia-formatters))
|
(command (alist-get (intern formatter) apheleia-formatters))
|
||||||
(syms nil)
|
(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
|
;; 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
|
;; 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.
|
;; 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
|
(setq stdout-buffer (get-buffer-create
|
||||||
(format "*apheleia-ft-stdout-%S%s" formatter extension)))
|
(format "*apheleia-ft-stdout-%S%s" formatter extension)))
|
||||||
(with-current-buffer stdout-buffer
|
(with-current-buffer stdout-buffer
|
||||||
(erase-buffer))
|
(erase-buffer))
|
||||||
(if (functionp command)
|
(if (functionp command)
|
||||||
(progn
|
(let ((in-temp-file (apheleia-ft--write-temp-file
|
||||||
(setq in-temp-file (apheleia-ft--write-temp-file
|
in-text extension)))
|
||||||
in-text extension))
|
(setq in-temp-real-file in-temp-file)
|
||||||
(with-current-buffer (find-file-noselect in-temp-file)
|
(with-current-buffer (find-file-noselect in-temp-file)
|
||||||
(funcall command
|
(funcall command
|
||||||
:buffer (current-buffer)
|
:buffer (current-buffer)
|
||||||
|
@ -308,14 +310,20 @@ environment variable, defaulting to all formatters."
|
||||||
:formatter formatter
|
:formatter formatter
|
||||||
:callback (lambda ()))
|
:callback (lambda ()))
|
||||||
(copy-to-buffer stdout-buffer (point-min) (point-max))))
|
(copy-to-buffer stdout-buffer (point-min) (point-max))))
|
||||||
(progn
|
(let ((in-temp-file (apheleia-ft--write-temp-file
|
||||||
|
in-text extension)))
|
||||||
(let ((ctx (apheleia--formatter-context
|
(with-current-buffer (find-file-noselect in-temp-file)
|
||||||
(intern formatter) command nil nil)))
|
(let ((ctx (apheleia--formatter-context
|
||||||
(setq command `(,(apheleia-formatter--arg1 ctx)
|
(intern formatter) command nil nil)))
|
||||||
,@(apheleia-formatter--argv ctx))
|
(setq command `(,(apheleia-formatter--arg1 ctx)
|
||||||
in-temp-real-file (apheleia-formatter--input-fname ctx)
|
,@(apheleia-formatter--argv ctx))
|
||||||
out-temp-file (apheleia-formatter--output-fname 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
|
(with-current-buffer stdout-buffer
|
||||||
(erase-buffer))
|
(erase-buffer))
|
||||||
|
|
19
test/formatters/installers/dprint.bash
Normal file
19
test/formatters/installers/dprint.bash
Normal file
|
@ -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
|
1
test/formatters/samplecode/dprint/in.dockerfile
Normal file
1
test/formatters/samplecode/dprint/in.dockerfile
Normal file
|
@ -0,0 +1 @@
|
||||||
|
FROM scratch
|
1
test/formatters/samplecode/dprint/in.js
Symbolic link
1
test/formatters/samplecode/dprint/in.js
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../prettier-javascript/in.js
|
1
test/formatters/samplecode/dprint/in.json
Symbolic link
1
test/formatters/samplecode/dprint/in.json
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../prettier-json/in.json
|
1
test/formatters/samplecode/dprint/in.md
Symbolic link
1
test/formatters/samplecode/dprint/in.md
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../prettier-markdown/in.md
|
1
test/formatters/samplecode/dprint/in.py
Symbolic link
1
test/formatters/samplecode/dprint/in.py
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../ruff/in.py
|
1
test/formatters/samplecode/dprint/in.toml
Normal file
1
test/formatters/samplecode/dprint/in.toml
Normal file
|
@ -0,0 +1 @@
|
||||||
|
title = "Apheleia dprint TOML test"
|
1
test/formatters/samplecode/dprint/in.ts
Symbolic link
1
test/formatters/samplecode/dprint/in.ts
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../prettier-typescript/in.ts
|
1
test/formatters/samplecode/dprint/out.dockerfile
Normal file
1
test/formatters/samplecode/dprint/out.dockerfile
Normal file
|
@ -0,0 +1 @@
|
||||||
|
FROM scratch
|
3
test/formatters/samplecode/dprint/out.js
Normal file
3
test/formatters/samplecode/dprint/out.js
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
function HelloWorld({ greeting = "hello", greeted = "\"World\"", silent = false, onMouseOver }) {
|
||||||
|
if (!greeting) return null;
|
||||||
|
}
|
19
test/formatters/samplecode/dprint/out.json
Normal file
19
test/formatters/samplecode/dprint/out.json
Normal file
|
@ -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
|
||||||
|
}
|
4
test/formatters/samplecode/dprint/out.md
Normal file
4
test/formatters/samplecode/dprint/out.md
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
| col1 | col 2 |
|
||||||
|
| ------ | ---------- |
|
||||||
|
| nice | fits |
|
||||||
|
| oh no! | it's ugly! |
|
3
test/formatters/samplecode/dprint/out.py
Normal file
3
test/formatters/samplecode/dprint/out.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
def asdjf(l, a):
|
||||||
|
3
|
||||||
|
+4
|
1
test/formatters/samplecode/dprint/out.toml
Normal file
1
test/formatters/samplecode/dprint/out.toml
Normal file
|
@ -0,0 +1 @@
|
||||||
|
title = "Apheleia dprint TOML test"
|
6
test/formatters/samplecode/dprint/out.ts
Normal file
6
test/formatters/samplecode/dprint/out.ts
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
interface GreetingSettings {
|
||||||
|
greeting: string;
|
||||||
|
duration?: number;
|
||||||
|
color?: string;
|
||||||
|
}
|
||||||
|
declare function greet(setting: GreetingSettings): void;
|
Loading…
Add table
Reference in a new issue