aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVille Skyttä <ville.skytta@iki.fi>2023-12-15 04:04:19 +0200
committerGitHub <noreply@github.com>2023-12-14 18:04:19 -0800
commit41dff902fb56cc011d1e694045755796d5e3e27d (patch)
tree48a81fbf30bcefdf59ceef324439cee587473501
parenta38279566a82c39253973e49a2a56634ded50212 (diff)
Add support for JSON with `python3 -m json.tool` (#257)
https://docs.python.org/3/library/json.html#module-json.tool
-rw-r--r--CHANGELOG.md3
-rw-r--r--apheleia-formatters.el3
-rw-r--r--apheleia-utils.el1
-rw-r--r--test/formatters/installers/python3-json.bash1
l---------test/formatters/samplecode/python3-json/in.json1
-rw-r--r--test/formatters/samplecode/python3-json/out.json19
6 files changed, 28 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a6fef33..40c9460 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,8 @@ The format is based on [Keep a Changelog].
[HTML](https://en.wikipedia.org/wiki/HTML) and
[CSS](https://www.google.com/search?q=css)
([#229])
+* [`python3-json`](https://docs.python.org/3/library/json.html#module-json.tool)
+ for JSON ([#257]).
* [`robotidy`](https://robotidy.readthedocs.io) for Robot Framework files
([#263]).
* [denofmt](https://docs.deno.com/runtime/manual/tools/formatter) for
@@ -24,6 +26,7 @@ The format is based on [Keep a Changelog].
clojurescript, edn files. ([#271])
[#229]: https://github.com/radian-software/apheleia/pull/229
+[#257]: https://github.com/radian-software/apheleia/pull/257
[#260]: https://github.com/radian-software/apheleia/pull/260
[#261]: https://github.com/radian-software/apheleia/pull/261
[#263]: https://github.com/radian-software/apheleia/pull/263
diff --git a/apheleia-formatters.el b/apheleia-formatters.el
index 2446b0e..26c0a07 100644
--- a/apheleia-formatters.el
+++ b/apheleia-formatters.el
@@ -150,6 +150,9 @@
(robotidy . ("robotidy" "--no-color" "-"
(apheleia-formatters-indent nil "--indent")
(apheleia-formatters-fill-column "--line-length")))
+ (python3-json
+ . ("python3" "-m" "json.tool"
+ (apheleia-formatters-indent "--tab" "--indent")))
(rubocop . ("rubocop" "--stdin" filepath "--auto-correct"
"--stderr" "--format" "quiet" "--fail-level" "fatal"))
(ruby-standard . ("standardrb" "--stdin" filepath "--fix" "--stderr"
diff --git a/apheleia-utils.el b/apheleia-utils.el
index 5e8b364..07a358b 100644
--- a/apheleia-utils.el
+++ b/apheleia-utils.el
@@ -49,6 +49,7 @@ always returns nil to defer to the formatter."
(nxml-mode 'nxml-child-indent)
(robot-mode 'robot-mode-basic-offset)
(perl-mode 'perl-indent-level)
+ (python-mode 'python-indent-offset)
(scss-mode 'css-indent-offset)
(web-mode 'web-mode-indent-style)
(tsx-ts-mode 'typescript-ts-mode-indent-offset)
diff --git a/test/formatters/installers/python3-json.bash b/test/formatters/installers/python3-json.bash
new file mode 100644
index 0000000..da920e3
--- /dev/null
+++ b/test/formatters/installers/python3-json.bash
@@ -0,0 +1 @@
+apt-get install -y python3
diff --git a/test/formatters/samplecode/python3-json/in.json b/test/formatters/samplecode/python3-json/in.json
new file mode 120000
index 0000000..599a1e2
--- /dev/null
+++ b/test/formatters/samplecode/python3-json/in.json
@@ -0,0 +1 @@
+../prettier-json/in.json \ No newline at end of file
diff --git a/test/formatters/samplecode/python3-json/out.json b/test/formatters/samplecode/python3-json/out.json
new file mode 100644
index 0000000..6af7b82
--- /dev/null
+++ b/test/formatters/samplecode/python3-json/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
+}