From 2b354f405bf4c8cd13f364811efafa175d22afe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Thu, 23 Nov 2023 22:19:04 +0200 Subject: [PATCH 1/4] Add support for `yq` (#250) --- CHANGELOG.md | 1 + apheleia-formatters.el | 14 +++++++++++++- test/formatters/installers/yq-csv.bash | 1 + test/formatters/installers/yq-json.bash | 1 + test/formatters/installers/yq-properties.bash | 1 + test/formatters/installers/yq-tsv.bash | 1 + test/formatters/installers/yq-xml.bash | 1 + test/formatters/installers/yq-yaml.bash | 1 + test/formatters/samplecode/yq-csv/in.csv | 2 ++ test/formatters/samplecode/yq-csv/out.csv | 2 ++ test/formatters/samplecode/yq-json/in.json | 1 + test/formatters/samplecode/yq-json/out.json | 19 +++++++++++++++++++ .../samplecode/yq-properties/in.properties | 1 + .../samplecode/yq-properties/out.properties | 1 + test/formatters/samplecode/yq-tsv/in.tsv | 2 ++ test/formatters/samplecode/yq-tsv/out.tsv | 2 ++ test/formatters/samplecode/yq-xml/in.xml | 1 + test/formatters/samplecode/yq-xml/out.xml | 1 + test/formatters/samplecode/yq-yaml/in.yml | 1 + test/formatters/samplecode/yq-yaml/out.yml | 7 +++++++ 20 files changed, 60 insertions(+), 1 deletion(-) create mode 120000 test/formatters/installers/yq-csv.bash create mode 120000 test/formatters/installers/yq-json.bash create mode 120000 test/formatters/installers/yq-properties.bash create mode 120000 test/formatters/installers/yq-tsv.bash create mode 120000 test/formatters/installers/yq-xml.bash create mode 100644 test/formatters/installers/yq-yaml.bash create mode 100644 test/formatters/samplecode/yq-csv/in.csv create mode 100644 test/formatters/samplecode/yq-csv/out.csv create mode 120000 test/formatters/samplecode/yq-json/in.json create mode 100644 test/formatters/samplecode/yq-json/out.json create mode 100644 test/formatters/samplecode/yq-properties/in.properties create mode 100644 test/formatters/samplecode/yq-properties/out.properties create mode 100644 test/formatters/samplecode/yq-tsv/in.tsv create mode 100644 test/formatters/samplecode/yq-tsv/out.tsv create mode 100644 test/formatters/samplecode/yq-xml/in.xml create mode 100644 test/formatters/samplecode/yq-xml/out.xml create mode 120000 test/formatters/samplecode/yq-yaml/in.yml create mode 100644 test/formatters/samplecode/yq-yaml/out.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d10a8b0..587fd6b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,7 @@ The format is based on [Keep a Changelog]. ### Formatters +* [`yq`](https://mikefarah.gitbook.io/yq/) for YAML, JSON, CSV, TSV, XML and [.properties](https://en.wikipedia.org/wiki/.properties) ([#250]). * [purs-tidy](https://github.com/natefaubion/purescript-tidy) for PureScript ([#182]). * [`jq`](https://stedolan.github.io/jq/) for [JSON](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/JSON) diff --git a/apheleia-formatters.el b/apheleia-formatters.el index 66b0e0c6..26602978 100644 --- a/apheleia-formatters.el +++ b/apheleia-formatters.el @@ -149,7 +149,19 @@ (stylua . ("stylua" "-")) (rustfmt . ("rustfmt" "--quiet" "--emit" "stdout")) (terraform . ("terraform" "fmt" "-")) - (yapf . ("yapf"))) + (yapf . ("yapf")) + (yq-csv . ("yq" "--prettyPrint" "--no-colors" + "--input-format" "csv" "--output-format" "csv")) + (yq-json . ("yq" "--prettyPrint" "--no-colors" + "--input-format" "json" "--output-format" "json")) + (yq-properties . ("yq" "--prettyPrint" "--no-colors" + "--input-format" "props" "--output-format" "props")) + (yq-tsv . ("yq" "--prettyPrint" "--no-colors" + "--input-format" "tsv" "--output-format" "tsv")) + (yq-xml . ("yq" "--prettyPrint" "--no-colors" + "--input-format" "xml" "--output-format" "xml")) + (yq-yaml . ("yq" "--prettyPrint" "--no-colors" "--no-doc" + "--input-format" "yaml" "--output-format" "yaml"))) "Alist of code formatting commands. The keys may be any symbols you want, and the values are shell commands, lists of strings and symbols, or a function symbol. diff --git a/test/formatters/installers/yq-csv.bash b/test/formatters/installers/yq-csv.bash new file mode 120000 index 00000000..9316c89d --- /dev/null +++ b/test/formatters/installers/yq-csv.bash @@ -0,0 +1 @@ +yq-yaml.bash \ No newline at end of file diff --git a/test/formatters/installers/yq-json.bash b/test/formatters/installers/yq-json.bash new file mode 120000 index 00000000..9316c89d --- /dev/null +++ b/test/formatters/installers/yq-json.bash @@ -0,0 +1 @@ +yq-yaml.bash \ No newline at end of file diff --git a/test/formatters/installers/yq-properties.bash b/test/formatters/installers/yq-properties.bash new file mode 120000 index 00000000..9316c89d --- /dev/null +++ b/test/formatters/installers/yq-properties.bash @@ -0,0 +1 @@ +yq-yaml.bash \ No newline at end of file diff --git a/test/formatters/installers/yq-tsv.bash b/test/formatters/installers/yq-tsv.bash new file mode 120000 index 00000000..9316c89d --- /dev/null +++ b/test/formatters/installers/yq-tsv.bash @@ -0,0 +1 @@ +yq-yaml.bash \ No newline at end of file diff --git a/test/formatters/installers/yq-xml.bash b/test/formatters/installers/yq-xml.bash new file mode 120000 index 00000000..9316c89d --- /dev/null +++ b/test/formatters/installers/yq-xml.bash @@ -0,0 +1 @@ +yq-yaml.bash \ No newline at end of file diff --git a/test/formatters/installers/yq-yaml.bash b/test/formatters/installers/yq-yaml.bash new file mode 100644 index 00000000..0f368497 --- /dev/null +++ b/test/formatters/installers/yq-yaml.bash @@ -0,0 +1 @@ +curl -fsSLo /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 && chmod +x /usr/local/bin/yq diff --git a/test/formatters/samplecode/yq-csv/in.csv b/test/formatters/samplecode/yq-csv/in.csv new file mode 100644 index 00000000..81a3661f --- /dev/null +++ b/test/formatters/samplecode/yq-csv/in.csv @@ -0,0 +1,2 @@ +hello,"world" +a,"1,2" diff --git a/test/formatters/samplecode/yq-csv/out.csv b/test/formatters/samplecode/yq-csv/out.csv new file mode 100644 index 00000000..99162393 --- /dev/null +++ b/test/formatters/samplecode/yq-csv/out.csv @@ -0,0 +1,2 @@ +hello,world +a,"1,2" diff --git a/test/formatters/samplecode/yq-json/in.json b/test/formatters/samplecode/yq-json/in.json new file mode 120000 index 00000000..599a1e23 --- /dev/null +++ b/test/formatters/samplecode/yq-json/in.json @@ -0,0 +1 @@ +../prettier-json/in.json \ No newline at end of file diff --git a/test/formatters/samplecode/yq-json/out.json b/test/formatters/samplecode/yq-json/out.json new file mode 100644 index 00000000..59bb3b44 --- /dev/null +++ b/test/formatters/samplecode/yq-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 +} diff --git a/test/formatters/samplecode/yq-properties/in.properties b/test/formatters/samplecode/yq-properties/in.properties new file mode 100644 index 00000000..74d0a43f --- /dev/null +++ b/test/formatters/samplecode/yq-properties/in.properties @@ -0,0 +1 @@ +foo=bar diff --git a/test/formatters/samplecode/yq-properties/out.properties b/test/formatters/samplecode/yq-properties/out.properties new file mode 100644 index 00000000..d5dd18c1 --- /dev/null +++ b/test/formatters/samplecode/yq-properties/out.properties @@ -0,0 +1 @@ +foo = bar diff --git a/test/formatters/samplecode/yq-tsv/in.tsv b/test/formatters/samplecode/yq-tsv/in.tsv new file mode 100644 index 00000000..c659c726 --- /dev/null +++ b/test/formatters/samplecode/yq-tsv/in.tsv @@ -0,0 +1,2 @@ +hello "world" +a "1 2" diff --git a/test/formatters/samplecode/yq-tsv/out.tsv b/test/formatters/samplecode/yq-tsv/out.tsv new file mode 100644 index 00000000..6acb9d1b --- /dev/null +++ b/test/formatters/samplecode/yq-tsv/out.tsv @@ -0,0 +1,2 @@ +hello world +a "1 2" diff --git a/test/formatters/samplecode/yq-xml/in.xml b/test/formatters/samplecode/yq-xml/in.xml new file mode 100644 index 00000000..3338af29 --- /dev/null +++ b/test/formatters/samplecode/yq-xml/in.xml @@ -0,0 +1 @@ + diff --git a/test/formatters/samplecode/yq-xml/out.xml b/test/formatters/samplecode/yq-xml/out.xml new file mode 100644 index 00000000..b4e8ae3e --- /dev/null +++ b/test/formatters/samplecode/yq-xml/out.xml @@ -0,0 +1 @@ + diff --git a/test/formatters/samplecode/yq-yaml/in.yml b/test/formatters/samplecode/yq-yaml/in.yml new file mode 120000 index 00000000..bdbc9aaf --- /dev/null +++ b/test/formatters/samplecode/yq-yaml/in.yml @@ -0,0 +1 @@ +../prettier-yaml/in.yml \ No newline at end of file diff --git a/test/formatters/samplecode/yq-yaml/out.yml b/test/formatters/samplecode/yq-yaml/out.yml new file mode 100644 index 00000000..8b4f56dc --- /dev/null +++ b/test/formatters/samplecode/yq-yaml/out.yml @@ -0,0 +1,7 @@ +- hosts: all + tasks: + - name: Get software for apt repository management. + apt: + state: present + name: + - python3-pycurl From 14e88bfde8d2c42051d0b707614780ac1c3408df Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Thu, 23 Nov 2023 12:28:50 -0800 Subject: [PATCH 2/4] Respect `typescript-indent-level`, `typescript-ts-mode-indent-offset` (#252) https://github.com/emacs-typescript/typescript.el/blob/v0.4/typescript-mode.el#L635-L639 https://github.com/emacs-mirror/emacs/blob/emacs-29.1/lisp/progmodes/typescript-ts-mode.el#L38-L43 --------- Signed-off-by: Anders Kaseorg --- apheleia-utils.el | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apheleia-utils.el b/apheleia-utils.el index 9407cd2f..7ca30bb1 100644 --- a/apheleia-utils.el +++ b/apheleia-utils.el @@ -45,9 +45,13 @@ INDENT-FLAG." (json-ts-mode 'json-ts-mode-indent-offset) (js-mode 'js-indent-level) (js-jsx-mode 'js-indent-level) + (js-ts-mode 'js-indent-level) (js2-mode 'js2-basic-offset) (js2-jsx-mode 'js2-basic-offset) - (js3-mode 'js3-indent-level)))) + (js3-mode 'js3-indent-level) + (tsx-ts-mode 'typescript-ts-mode-indent-offset) + (typescript-mode 'typescript-indent-level) + (typescript-ts-mode 'typescript-ts-mode-indent-offset)))) (defcustom apheleia-formatters-respect-fill-column nil "Whether formatters should set `fill-column' related flags." From d966a2411558c552db0871fdd4bfcfd3cdb71ad5 Mon Sep 17 00:00:00 2001 From: Radon Rosborough Date: Thu, 23 Nov 2023 12:29:10 -0800 Subject: [PATCH 3/4] Add missing changelog entry (#254) --- CHANGELOG.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 587fd6b4..b7a77884 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,12 +15,11 @@ The format is based on [Keep a Changelog]. * Disable formatting of go module files with gofmt. This was never supported ([#214]). * Remove support for Emacs 26 ([#215]). - -### Features -* New user option `apheleia-formatters-respect-indent-level`, - defaulting to `t`. You can set this to `nil` to disable Apheleia - configuring formatters to use the same indent settings as the Emacs - major mode is using ([#208]). +* Emacs will infer indentation configuration from your major mode and, + by default, supply this configuration to formatters, to ensure + consistency between how you have Emacs configured and how your + formatter is configured. You can disable this by setting + `apheleia-formatters-respect-indent-level` to nil ([#167], [#208]). ### Enhancements * Use the `prettier-json` formatter for `js-json-mode` ([#209]). @@ -94,6 +93,7 @@ The format is based on [Keep a Changelog]. * [`yapf`](https://github.com/google/yapf) for [Python](https://www.python.org/) ([#196]) * [`hclfmt`](https://github.com/hashicorp/hcl/tree/main/cmd/hclfmt) for [HCL](https://github.com/hashicorp/hcl) ([#231]) +[#167]: https://github.com/radian-software/apheleia/pull/167 [#168]: https://github.com/radian-software/apheleia/pull/168 [#169]: https://github.com/radian-software/apheleia/pull/169 [#170]: https://github.com/radian-software/apheleia/pull/170 From 317fe75906e85bfcf9ca481b4804a79c25ab3b9c Mon Sep 17 00:00:00 2001 From: Radon Rosborough Date: Thu, 23 Nov 2023 12:30:41 -0800 Subject: [PATCH 4/4] Test against Emacs 29 instead of master (#255) --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 5bda9d56..6a3c3ce1 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - emacs_version: [27, 28, "master"] + emacs_version: [27, 28, 29] steps: - name: Checkout uses: actions/checkout@v4