Skip to content

Commit c17ff6f

Browse files
b0inbotalexeagle
andauthored
feat: add XML format via prettier (#474)
* feat: add XML format via prettier * fixes --------- Co-authored-by: Alex Eagle <[email protected]>
1 parent 8a8cc86 commit c17ff6f

File tree

9 files changed

+22
-1
lines changed

9 files changed

+22
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Linters which are not language-specific:
5151
| TSX | [Prettier] | [ESLint] |
5252
| TypeScript | [Prettier] | [ESLint] |
5353
| YAML | [yamlfmt] | |
54+
| XML | [prettier/plugin-xml] | |
5455

5556
[prettier]: https://prettier.io
5657
[google-java-format]: https://github.com/google/google-java-format
@@ -68,6 +69,7 @@ Linters which are not language-specific:
6869
[ktlint]: https://github.com/pinterest/ktlint
6970
[buildifier]: https://github.com/keith/buildifier-prebuilt
7071
[prettier-plugin-sql]: https://github.com/un-ts/prettier
72+
[prettier/plugin-xml]: https://github.com/prettier/plugin-xml
7173
[gofmt]: https://pkg.go.dev/cmd/gofmt
7274
[gofumpt]: https://github.com/mvdan/gofumpt
7375
[jsonnetfmt]: https://github.com/google/go-jsonnet

docs/format.md

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"eslint": "^9.16.0",
1010
"prettier": "^2.8.7",
1111
"prettier-plugin-sql": "^0.14.0",
12+
"@prettier/plugin-xml": "^0.10.0",
1213
"stylelint": "^16",
1314
"stylelint-config-standard": "^36.0.1",
1415
"typescript": "4.9.5",

example/src/hello.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<hello>
2+
<world>
3+
todo</world>
4+
</hello>

example/tools/format/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ format_multirun(
9393
swift = ":swiftformat",
9494
terraform = "@aspect_rules_lint//format:terraform",
9595
visibility = ["//:__subpackages__"],
96+
xml = ":prettier",
9697
yaml = "@aspect_rules_lint//format:yamlfmt",
9798
)
9899

format/private/format.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ function ls-files {
142142
'TypeScript') patterns=('*.ts' '*.cts' '*.mts') ;;
143143
'Vue') patterns=('*.vue') ;;
144144
'YAML') patterns=('*.yml' '*.yaml' '.clang-format' '.clang-tidy' '.gemrc') ;;
145+
# Note: https://github.com/github-linguist/linguist/blob/559a6426942abcae16b6d6b328147476432bf6cb/lib/linguist/languages.yml#L7767-L7882
146+
# has a giant list of patterns. We arbitrarily choose some "common" ones.
147+
'XML') patterns=('*.xml' '*.xsd') ;;
145148

146149
# Note: terraform fmt cannot handle all HCL files such as .terraform.lock
147150
# "Only .tf and .tfvars files can be processed with terraform fmt"

format/private/formatter_binary.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ TOOLS = {
2626
"Cuda": "clang-format",
2727
"YAML": "yamlfmt",
2828
"Rust": "rustfmt",
29+
"XML": "prettier",
2930
}
3031

3132
# Provided to make install more convenient

format/test/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,6 @@ format_multirun(
5757
swift = ":mock_swiftformat.sh",
5858
# TODO: this attribute should be renamed to hcl
5959
terraform = ":mock_terraform-fmt.sh",
60+
xml = ":mock_prettier.sh",
6061
yaml = ":mock_yamlfmt.sh",
6162
)

format/test/format_test.bats

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ bats_load_library "bats-assert"
4040
assert_output --partial "+ prettier --write .bcr/README.md CONTRIBUTING.md README.md"
4141
}
4242

43+
@test "should run prettier on XML" {
44+
run bazel run //format/test:format_XML_with_prettier
45+
assert_success
46+
47+
assert_output --partial "+ prettier --write example/checkstyle-suppressions.xml"
48+
}
49+
4350
@test "should run prettier on CSS" {
4451
run bazel run //format/test:format_CSS_with_prettier
4552
assert_success

0 commit comments

Comments
 (0)