From 474575cdd819918997701ef2f9be63219600d152 Mon Sep 17 00:00:00 2001 From: bthmc Date: Fri, 22 Aug 2025 19:21:32 +0200 Subject: [PATCH] feat: Format nickel --- README.md | 4 +++- docs/format.md | 5 +++-- example/MODULE.bazel | 9 +++++++++ example/WORKSPACE.bazel | 9 +++++++++ example/src/BUILD.bazel | 6 ++++++ example/src/hello.ncl | 3 +++ example/tools/format/BUILD.bazel | 1 + format/multitool.lock.json | 25 +++++++++++++++++++++++++ format/private/filter.jq | 1 + format/private/format.sh | 1 + format/private/formatter_binary.bzl | 3 +++ format/test/BUILD.bazel | 1 + format/test/format_test.bats | 7 +++++++ 13 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 example/src/hello.ncl diff --git a/README.md b/README.md index a40485a8..b76f5f59 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ Linters which are not language-specific: | Jsonnet | [jsonnetfmt] | | | Kotlin | [ktfmt] | [ktlint] | | Markdown | [Prettier] | [Vale] | +| Nickel | [nickel] | | | Protocol Buffer | [buf] | [buf lint] | | Python | [ruff] | [flake8], [ruff] | | Rust | [rustfmt] | | @@ -84,13 +85,14 @@ Linters which are not language-specific: [ruff]: https://docs.astral.sh/ruff/ [shellcheck]: https://www.shellcheck.net/ [shfmt]: https://github.com/mvdan/sh -[taplo] : https://taplo.tamasfe.dev/ +[taplo]: https://taplo.tamasfe.dev/ [clang-format]: https://clang.llvm.org/docs/ClangFormat.html [clang-tidy]: https://clang.llvm.org/extra/clang-tidy/ [vale]: https://vale.sh/ [yamlfmt]: https://github.com/google/yamlfmt [rustfmt]: https://rust-lang.github.io/rustfmt [stylelint]: https://stylelint.io +[nickel]: https://github.com/tweag/nickel 1. Non-hermetic: requires that a swift toolchain is installed on the machine. See https://github.com/bazelbuild/rules_swift#1-install-swift diff --git a/docs/format.md b/docs/format.md index 38644398..cdd37877 100644 --- a/docs/format.md +++ b/docs/format.md @@ -23,8 +23,8 @@ 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, gherkin, go, graphql, html, java, javascript, jsonnet, kotlin, - markdown, protocol_buffer, python, rust, scala, shell, sql, starlark, swift, terraform, - toml, xml, yaml) + markdown, nickel, protocol_buffer, python, rust, scala, shell, sql, starlark, swift, + terraform, toml, xml, yaml) Language attributes that may be passed to [format_multirun](#format_multirun) or [format_test](#format_test). @@ -58,6 +58,7 @@ Some languages have dialects: | jsonnet | a `jsonnetfmt` binary, or any other tool that has a matching command-line interface. Use `@aspect_rules_lint//format:jsonnetfmt` to choose the built-in tool. | Label | optional | `None` | | kotlin | a `ktfmt` binary, or any other tool that has a matching command-line interface. | Label | optional | `None` | | markdown | a `prettier` binary, or any other tool that has a matching command-line interface. | Label | optional | `None` | +| nickel | a `nickel` binary, or any other tool that has a matching command-line interface. | Label | optional | `None` | | protocol_buffer | a `buf` binary, or any other tool that has a matching command-line interface. | Label | optional | `None` | | python | a `ruff` binary, or any other tool that has a matching command-line interface. Use `@aspect_rules_lint//format:ruff` to choose the built-in tool. | Label | optional | `None` | | rust | a `rustfmt` binary, or any other tool that has a matching command-line interface. | Label | optional | `None` | diff --git a/example/MODULE.bazel b/example/MODULE.bazel index e3ca29a5..e724cecf 100644 --- a/example/MODULE.bazel +++ b/example/MODULE.bazel @@ -38,6 +38,15 @@ http_file( ], ) +http_file( + name = "nickel", + executable = True, + sha256 = "825657c5139d3b3c0da37da073493e18ef32cbe74afbf726a7dd643a39b4fd8b", + urls = [ + "https://github.com/tweag/nickel/releases/download/1.13.0/nickel-x86_64-linux", + ], +) + rules_ts_ext = use_extension("@aspect_rules_ts//ts:extensions.bzl", "ext") rules_ts_ext.deps() use_repo(rules_ts_ext, "npm_typescript") diff --git a/example/WORKSPACE.bazel b/example/WORKSPACE.bazel index 837fa114..78371c50 100644 --- a/example/WORKSPACE.bazel +++ b/example/WORKSPACE.bazel @@ -21,6 +21,15 @@ http_file( ], ) +http_file( + name = "nickel", + executable = True, + sha256 = "825657c5139d3b3c0da37da073493e18ef32cbe74afbf726a7dd643a39b4fd8b", + urls = [ + "https://github.com/tweag/nickel/releases/download/1.13.0/nickel-x86_64-linux", + ], +) + load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains") py_repositories() diff --git a/example/src/BUILD.bazel b/example/src/BUILD.bazel index 98805da1..244b91d8 100644 --- a/example/src/BUILD.bazel +++ b/example/src/BUILD.bazel @@ -121,6 +121,12 @@ kt_jvm_library( srcs = ["hello.kt"], ) +filegroup( + name = "nickel", + srcs = ["hello.ncl"], + tags = ["nickel"], +) + # Cause a test failure when files are not formatted. # This is useful when you have no other way to check formatting on CI; see documentation. format_test( diff --git a/example/src/hello.ncl b/example/src/hello.ncl new file mode 100644 index 00000000..a9987318 --- /dev/null +++ b/example/src/hello.ncl @@ -0,0 +1,3 @@ +foo { + bar +} diff --git a/example/tools/format/BUILD.bazel b/example/tools/format/BUILD.bazel index e77ca7bb..d55d55a2 100644 --- a/example/tools/format/BUILD.bazel +++ b/example/tools/format/BUILD.bazel @@ -101,6 +101,7 @@ format_multirun( jsonnet = "@aspect_rules_lint//format:jsonnetfmt", kotlin = ":ktfmt", markdown = ":prettier", + nickel = "@nickel//file", protocol_buffer = "//tools/lint:buf", python = "@aspect_rules_lint//format:ruff", # Note, older rules_rust versions may need diff --git a/format/multitool.lock.json b/format/multitool.lock.json index 5453b4e6..c85253e9 100644 --- a/format/multitool.lock.json +++ b/format/multitool.lock.json @@ -171,5 +171,30 @@ "cpu": "x86_64" } ] + }, + "nickel": { + "binaries": [ + { + "kind": "file", + "url": "https://github.com/tweag/nickel/releases/download/1.13.0/nickel-arm64-linux", + "sha256": "6c8b2d9a4bfa24761356302ba21bf9b2f107062bac7c514dc31f40198c40edc0", + "os": "linux", + "cpu": "arm64" + }, + { + "kind": "file", + "url": "https://github.com/tweag/nickel/releases/download/1.13.0/nickel-arm64-macos", + "sha256": "30aafb99e4deaf511ea8b2e93e507a9c0ba8bd25b9c116412fb3e6d3e7426e46", + "os": "macos", + "cpu": "arm64" + }, + { + "kind": "file", + "url": "https://github.com/tweag/nickel/releases/download/1.13.0/nickel-x86_64-linux", + "sha256": "825657c5139d3b3c0da37da073493e18ef32cbe74afbf726a7dd643a39b4fd8b", + "os": "linux", + "cpu": "x86_64" + } + ] } } diff --git a/format/private/filter.jq b/format/private/filter.jq index b8996a59..aee932f1 100644 --- a/format/private/filter.jq +++ b/format/private/filter.jq @@ -4,6 +4,7 @@ with_entries(select(.key | IN( "CSS", "Cuda", "Markdown", + "Nickel", "Go", "Gherkin", "GraphQL", diff --git a/format/private/format.sh b/format/private/format.sh index 6f9350c9..ff23c2da 100755 --- a/format/private/format.sh +++ b/format/private/format.sh @@ -153,6 +153,7 @@ function ls-files { # which does support the entire HCL language FWICT 'Terraform') patterns=('*.tf' '*.tfvars') ;; 'TOML') patterns=('*.toml') ;; + 'Nickel') patterns=('*.ncl') ;; *) echo >&2 "Internal error: unknown language $language" diff --git a/format/private/formatter_binary.bzl b/format/private/formatter_binary.bzl index c16b7e73..f6b6952a 100644 --- a/format/private/formatter_binary.bzl +++ b/format/private/formatter_binary.bzl @@ -29,6 +29,7 @@ TOOLS = { "Rust": "rustfmt", "XML": "prettier", "Gherkin": "prettier", + "Nickel": "nickel", } # Provided to make install more convenient @@ -59,6 +60,7 @@ CHECK_FLAGS = { "clang-format": "--style=file --fallback-style=none --dry-run -Werror", "yamlfmt": "-lint", "rustfmt": "--check", + "nickel": "format --check", } # Flags to pass each tool when running in default mode @@ -86,6 +88,7 @@ FIX_FLAGS = { "clang-format": "-style=file --fallback-style=none -i", "yamlfmt": "", "rustfmt": "", + "nickel": "format", } def to_attribute_name(lang): diff --git a/format/test/BUILD.bazel b/format/test/BUILD.bazel index ff5597d3..7062cd57 100644 --- a/format/test/BUILD.bazel +++ b/format/test/BUILD.bazel @@ -50,6 +50,7 @@ format_multirun( jsonnet = ":mock_jsonnetfmt.sh", kotlin = ":mock_ktfmt.sh", markdown = ":mock_prettier.sh", + nickel = ":mock_nickel.sh", protocol_buffer = ":mock_buf.sh", python = ":mock_ruff.sh", rust = ":mock_rustfmt.sh", diff --git a/format/test/format_test.bats b/format/test/format_test.bats index 07290c35..c6e94c97 100644 --- a/format/test/format_test.bats +++ b/format/test/format_test.bats @@ -190,3 +190,10 @@ bats_load_library "bats-assert" assert_output --partial "+ prettier --write example/src/hello.feature" } + +@test "should run nickel on ncl" { + run bazel run //format/test:format_Nickel_with_nickel + assert_success + + assert_output --partial '+ nickel format example/src/hello.ncl' +}