diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d10a8b..587fd6b 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 66b0e0c..2660297 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 0000000..9316c89 --- /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 0000000..9316c89 --- /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 0000000..9316c89 --- /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 0000000..9316c89 --- /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 0000000..9316c89 --- /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 0000000..0f36849 --- /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 0000000..81a3661 --- /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 0000000..9916239 --- /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 0000000..599a1e2 --- /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 0000000..59bb3b4 --- /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 0000000..74d0a43 --- /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 0000000..d5dd18c --- /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 0000000..c659c72 --- /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 0000000..6acb9d1 --- /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 0000000..3338af2 --- /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 0000000..b4e8ae3 --- /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 0000000..bdbc9aa --- /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 0000000..8b4f56d --- /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