diff --git a/README.md b/README.md index 6b2c978c3..b73c04509 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ trunk check enable {linter} | Textproto | [txtpbfmt] | | TOML | [taplo] | | Typescript | [deno], [eslint], [prettier], [rome], [semgrep] | -| YAML | [prettier], [semgrep], [yamllint] | +| YAML | [prettier], [semgrep], [yamlfmt], [yamllint] | [actionlint]: https://trunk.io/linters/infra/actionlint [ansible-lint]: https://github.com/ansible/ansible-lint#readme @@ -197,6 +197,7 @@ trunk check enable {linter} [txtpbfmt]: https://github.com/protocolbuffers/txtpbfmt#readme [ty]: https://github.com/astral-sh/ty#readme [vale]: https://vale.sh/docs/ +[yamlfmt]: https://github.com/google/yamlfmt#readme [yamllint]: https://trunk.io/linters/yaml/yamllint [yapf]: https://github.com/google/yapf#readme diff --git a/linters/yamlfmt/plugin.yaml b/linters/yamlfmt/plugin.yaml new file mode 100644 index 000000000..0989899c1 --- /dev/null +++ b/linters/yamlfmt/plugin.yaml @@ -0,0 +1,45 @@ +version: 0.1 +downloads: + - name: yamlfmt + downloads: + - os: + linux: Linux + macos: Darwin + windows: Windows + cpu: + x86_64: x86_64 + arm_64: arm64 + url: https://github.com/google/yamlfmt/releases/download/v${version}/yamlfmt_${version}_${os}_${cpu}.tar.gz +tools: + definitions: + - name: yamlfmt + download: yamlfmt + known_good_version: 0.1.0 + shims: [yamlfmt] +lint: + definitions: + - name: yamlfmt + files: [yaml] + description: Formats yaml files + commands: + - name: format + output: rewrite + run: yamlfmt ${target} + run_from: ${parent} + success_codes: [0, 1] + cache_results: true + formatter: true + in_place: true + batch: true + tools: [yamlfmt] + direct_configs: + - .yamlfmt + - .yamlfmt.yaml + - .yamlfmt.yml + - yamlfmt.yaml + - yamlfmt.yml + suggest_if: config_present + version_command: + parse_regex: ${semver} + run: yamlfmt -version + known_good_version: 0.1.0 diff --git a/linters/yamlfmt/test_data/basic.in.yaml b/linters/yamlfmt/test_data/basic.in.yaml new file mode 100644 index 000000000..88c1b4568 --- /dev/null +++ b/linters/yamlfmt/test_data/basic.in.yaml @@ -0,0 +1,3 @@ +yaml: + array: + - item \ No newline at end of file diff --git a/linters/yamlfmt/test_data/yamlfmt_v0.1.0_basic.fmt.shot b/linters/yamlfmt/test_data/yamlfmt_v0.1.0_basic.fmt.shot new file mode 100644 index 000000000..42c058492 --- /dev/null +++ b/linters/yamlfmt/test_data/yamlfmt_v0.1.0_basic.fmt.shot @@ -0,0 +1,8 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Testing formatter yamlfmt test basic 1`] = ` +"yaml: + array: + - item +" +`; diff --git a/linters/yamlfmt/yamlfmt.test.ts b/linters/yamlfmt/yamlfmt.test.ts new file mode 100644 index 000000000..405a4d1af --- /dev/null +++ b/linters/yamlfmt/yamlfmt.test.ts @@ -0,0 +1,9 @@ +import { linterCheckTest, linterFmtTest } from "tests"; +import { osTimeoutMultiplier } from "tests/utils"; + +// This install is quite slow on some Linux machines. +jest.setTimeout(600000 * osTimeoutMultiplier); + +linterCheckTest({ linterName: "yamlfmt", namedTestPrefixes: ["empty"] }); + +linterFmtTest({ linterName: "yamlfmt", namedTestPrefixes: ["basic"] });