diff --git a/README.md b/README.md index 461ea52f..92d730b8 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ Linters which are not language-specific: | TSX | [Prettier] | [ESLint] | | TypeScript | [Prettier] | [ESLint] | | YAML | [yamlfmt] | | +| XML | [prettier/plugin-xml] | | [prettier]: https://prettier.io [google-java-format]: https://github.com/google/google-java-format @@ -68,6 +69,7 @@ Linters which are not language-specific: [ktlint]: https://github.com/pinterest/ktlint [buildifier]: https://github.com/keith/buildifier-prebuilt [prettier-plugin-sql]: https://github.com/un-ts/prettier +[prettier/plugin-xml]: https://github.com/prettier/plugin-xml [gofmt]: https://pkg.go.dev/cmd/gofmt [gofumpt]: https://github.com/mvdan/gofumpt [jsonnetfmt]: https://github.com/google/go-jsonnet diff --git a/docs/format.md b/docs/format.md index 7fa8a759..beb3dc87 100644 --- a/docs/format.md +++ b/docs/format.md @@ -23,7 +23,7 @@ See the example/tools/format/BUILD file in this repo for full examples of declar load("@aspect_rules_lint//format:defs.bzl", "languages") languages(name, c, cc, css, cuda, go, graphql, html, java, javascript, jsonnet, kotlin, markdown, - protocol_buffer, python, rust, scala, shell, sql, starlark, swift, terraform, yaml) + protocol_buffer, python, rust, scala, shell, sql, starlark, swift, terraform, xml, yaml) Language attributes that may be passed to [format_multirun](#format_multirun) or [format_test](#format_test). @@ -65,6 +65,7 @@ Some languages have dialects: | starlark | a `buildifier` binary, or any other tool that has a matching command-line interface. | Label | optional | `None` | | swift | a `swiftformat` binary, or any other tool that has a matching command-line interface. | Label | optional | `None` | | terraform | a `terraform-fmt` binary, or any other tool that has a matching command-line interface. Use `@aspect_rules_lint//format:terraform` to choose the built-in tool. | Label | optional | `None` | +| xml | a `prettier` binary, or any other tool that has a matching command-line interface. | Label | optional | `None` | | yaml | a `yamlfmt` binary, or any other tool that has a matching command-line interface. Use `@aspect_rules_lint//format:yamlfmt` to choose the built-in tool. | Label | optional | `None` | diff --git a/example/package.json b/example/package.json index ce81cc21..0522d5de 100644 --- a/example/package.json +++ b/example/package.json @@ -9,6 +9,7 @@ "eslint": "^9.16.0", "prettier": "^2.8.7", "prettier-plugin-sql": "^0.14.0", + "@prettier/plugin-xml": "^0.10.0", "stylelint": "^16", "stylelint-config-standard": "^36.0.1", "typescript": "4.9.5", diff --git a/example/src/hello.xml b/example/src/hello.xml new file mode 100644 index 00000000..7ab400f6 --- /dev/null +++ b/example/src/hello.xml @@ -0,0 +1,4 @@ + + + todo + diff --git a/example/tools/format/BUILD.bazel b/example/tools/format/BUILD.bazel index ea03d4ab..fad3f062 100644 --- a/example/tools/format/BUILD.bazel +++ b/example/tools/format/BUILD.bazel @@ -93,6 +93,7 @@ format_multirun( swift = ":swiftformat", terraform = "@aspect_rules_lint//format:terraform", visibility = ["//:__subpackages__"], + xml = ":prettier", yaml = "@aspect_rules_lint//format:yamlfmt", ) diff --git a/format/private/format.sh b/format/private/format.sh index 7008b0f7..7264e010 100755 --- a/format/private/format.sh +++ b/format/private/format.sh @@ -142,6 +142,9 @@ function ls-files { 'TypeScript') patterns=('*.ts' '*.cts' '*.mts') ;; 'Vue') patterns=('*.vue') ;; 'YAML') patterns=('*.yml' '*.yaml' '.clang-format' '.clang-tidy' '.gemrc') ;; + # Note: https://github.com/github-linguist/linguist/blob/559a6426942abcae16b6d6b328147476432bf6cb/lib/linguist/languages.yml#L7767-L7882 + # has a giant list of patterns. We arbitrarily choose some "common" ones. + 'XML') patterns=('*.xml' '*.xsd') ;; # Note: terraform fmt cannot handle all HCL files such as .terraform.lock # "Only .tf and .tfvars files can be processed with terraform fmt" diff --git a/format/private/formatter_binary.bzl b/format/private/formatter_binary.bzl index cbb20fad..baa3c081 100644 --- a/format/private/formatter_binary.bzl +++ b/format/private/formatter_binary.bzl @@ -26,6 +26,7 @@ TOOLS = { "Cuda": "clang-format", "YAML": "yamlfmt", "Rust": "rustfmt", + "XML": "prettier", } # Provided to make install more convenient diff --git a/format/test/BUILD.bazel b/format/test/BUILD.bazel index a508b554..9a08339f 100644 --- a/format/test/BUILD.bazel +++ b/format/test/BUILD.bazel @@ -57,5 +57,6 @@ format_multirun( swift = ":mock_swiftformat.sh", # TODO: this attribute should be renamed to hcl terraform = ":mock_terraform-fmt.sh", + xml = ":mock_prettier.sh", yaml = ":mock_yamlfmt.sh", ) diff --git a/format/test/format_test.bats b/format/test/format_test.bats index f4416185..0c979a53 100644 --- a/format/test/format_test.bats +++ b/format/test/format_test.bats @@ -40,6 +40,13 @@ bats_load_library "bats-assert" assert_output --partial "+ prettier --write .bcr/README.md CONTRIBUTING.md README.md" } +@test "should run prettier on XML" { + run bazel run //format/test:format_XML_with_prettier + assert_success + + assert_output --partial "+ prettier --write example/checkstyle-suppressions.xml" +} + @test "should run prettier on CSS" { run bazel run //format/test:format_CSS_with_prettier assert_success