Giter VIP home page Giter VIP logo

rules_lint's Introduction

Run linters and formatters under Bazel

This ruleset integrates linting and formatting as first-class concepts under Bazel.

Features:

  • No changes needed to rulesets. Works with the Bazel rules you already use.
  • No changes needed to BUILD files. You don't need to add lint wrapper macros, and lint doesn't appear in bazel query output. Instead, users simply lint their existing *_library targets.
  • Incremental. Lint checks (including producing fixes) are run as normal Bazel actions, which means they support Remote Execution and the outputs are stored in the Remote Cache.
  • Lint results can be presented in various ways, such as Code Review comments or failing tests. See Usage.
  • Can lint changes only. It's fine if your repository has a lot of existing issues. It's not necessary to fix or suppress all of them to start linting new changes. This is sometimes called the "Water Leak Principle": you should always fix a leak before mopping the spill.
  • Can format files not known to Bazel. Formatting just runs directly on the file tree. No need to create sh_library targets for your shell scripts, for example.
  • Honors the same configuration files you use for these tools outside Bazel (e.g. in the editor)

Supported tools

New tools are being added frequently, so check this page again!

Language Formatter Linter(s)
C / C++ clang-format clang-tidy
Cuda clang-format
CSS, Less, Sass Prettier Stylelint
Go gofmt or gofumpt
GraphQL Prettier
HCL (Hashicorp Config) terraform fmt
HTML Prettier
JSON Prettier
Java google-java-format pmd
JavaScript Prettier ESLint
Jsonnet jsonnetfmt
Kotlin ktfmt ktlint
Markdown Prettier Vale
Protocol Buffer buf buf lint
Python ruff flake8, ruff
Rust rustfmt
SQL prettier-plugin-sql
Scala scalafmt
Shell shfmt shellcheck
Starlark Buildifier
Swift SwiftFormat (1)
TSX Prettier ESLint
TypeScript Prettier ESLint
YAML yamlfmt
  1. Non-hermetic: requires that a swift toolchain is installed on the machine. See https://github.com/bazelbuild/rules_swift#1-install-swift

To add a tool, please follow the steps in lint/README.md or format/README.md and then send us a PR. Thanks!!

Installation

Follow instructions from the release you wish to use: https://github.com/aspect-build/rules_lint/releases

Usage

Formatting and Linting are inherently different, which leads to differences in how they are used in rules_lint.

Formatter Linter
Only one per language, since they could conflict with each other. Many per language is fine; results compose.
Invariant: program's behavior is never changed. Suggested fixes may change behavior.
Developer has no choices. Always blindly accept result. Fix may be manual, or select from multiple auto-fixes.
Changes must be applied. Violations can be suppressed.
Operates on a single file at a time. Can require the dependency graph.
Can always format just changed files / regions New violations might be introduced in unchanged files.
Fast enough to put in a pre-commit workflow. Some are slow.

Format

To format files, run the target you create when you install rules_lint.

We recommend using a Git pre-commit hook to format changed files, and Aspect Workflows to provide the check on CI.

asciicast

See Formatting for more ways to use the formatter.

Lint

To lint code, we recommend using the Aspect CLI to get the missing lint command, and Aspect Workflows to provide first-class support for "linters as code reviewers".

For example, running bazel lint //src:all prints lint warnings to the terminal for all targets in the //src package:

asciicast

See Linting for more ways to use the linter.

Ignoring files

The linters only visit files that are part of the Bazel dependency graph (listed as srcs to some library target).

The formatter honors the .gitignore and .gitattributes files. Otherwise use the affordance provided by the tool, for example .prettierignore for files to be ignored by Prettier.

Sometimes engineers want to ignore a file with a certain extension because the content isn't actually valid syntax for the corresponding language. For example, you might write a template for YAML and name it my-template.yaml even though it needs to have some interpolated values inserted before it's syntactically valid. We recommend instead fixing the file extension. In this example, my.yaml.tmpl or my-template.yaml_ might be better.

Using with your editor

We believe that existing editor plugins should just work as-is. They may download or bundle their own copy of the tools, which can lead to some version skew in lint/format rules.

For formatting, we believe it's a waste of time to configure these in the editor, because developers should just rely on formatting happening when they commit and not care what the code looks like before that point. But we're not trying to stop anyone, either!

You could probably configure the editor to always run the same Bazel command, any time a file is changed. Instructions to do this are out-of-scope for this repo, particularly since they have to be formulated and updated for so many editors.

FAQ

What about type-checking?

We consider type-checkers as a build tool, not as a linter. This is for a few reasons:

  • They are commonly distributed along with compilers. In compiled languages like Java, types are required in order for the compiler to emit executable bytecode at all. In interpreted languages they're still often linked, e.g. TypeScript does both "compiling" to JavaScript and also type-checking. This suggests that rules for a language should include the type-checker, e.g. we expect Sorbet to be integrated with rules_ruby and mypy/pyright to be integrated with rules_python or Aspect's rules_py.
  • We think most developers want "build error" semantics for type-checks: the whole repository should successfully type-check or you cannot commit the change. rules_lint is optimized for "warning" semantics, where we produce report files and it's up to the Dev Infra team how to present those, for example only on changed files.
  • You can only type-check a library if its dependencies were checkable, which means short-circuiting execution. rules_lint currently runs linters on every node in the dependency graph, including any whose dependencies have lint warnings.

rules_lint's People

Contributors

agoessling avatar alexeagle avatar codrin-lanterne avatar daewok avatar ewhauser avatar github-actions[bot] avatar gregmagolan avatar honnix avatar hunshcn avatar jbedard avatar jelmer avatar jgao54 avatar jmeekhof avatar jsharpe avatar laurencetews avatar lpulley avatar mattem avatar mattnworb avatar mortenmj avatar mrmeku avatar peakschris avatar pjjw avatar plobsing avatar psalaberria002 avatar sallustfire avatar smocherla-brex avatar spencerc avatar srabraham avatar tokongs avatar tomgr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

rules_lint's Issues

[Bug]: markdown support doesn't seem to be implemented

What happened?

Tried using markdown in the multi_formatter_binary and got an error

Version

Development (host) and target OS/architectures:

Output of bazel --version: `bazel 6.4.0

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file:

Language(s) and/or frameworks involved:

How to reproduce

multi_formatter_binary(
    name = "format",

    markdown = ":prettier"
)

throws

ERROR: <REDACTED>/BUILD:54:23: //:format: no such attribute 'markdown' in 'multi_formatter_binary' rule

Any other information?

The docs clearly state markdown is supported using Prettier but the rule doesn't expose that option

[FR]: Create a way to ignore checked in files

What is the current behavior?

Currently, the only way to ignore files is for use with the prettier extension since it is a binary that has its own ignoring logic using .prettierignore or other means particular to that binary

For other languages, such as go, there is no way to not have a file be formattted. This poses many problems for checked in generated code, vendored in libraries and other situations in which formatting is simply not desired for particular use cases. The only lever available is to turn off formatting for the entire language itself

We cannot rely on each formatter that bazel-super-formatter uses to have its own ignore logic.

Describe the feature

We need to introduce a file which bazel-super-formatter can parse for .gitignore like patterns for exclusion. The file can be a standardized location (such as .prettierignore at the root of the repo) but generally, it would be better us to expose a parameter that is configurable in a bazelrc file.

run --@aspect_rules_format//ignore="path/to/file"

In general, I believe the best way to faciliate this is to replace the file identification step of format.sh with a binary

IE replace

if [ "$#" -eq 0 ]; then
  files=$(git ls-files '*.py' '*.pyi')
else
  files=$(find "$@" -name '*.py' -or -name '*.pyi')
fi

with

bin=$(rlocation aspect_rules_format/find_files_binary)
files=$(bin '*.py' '*.pyi')

As to which language this binary should be written in, that's up for debate. It would be nice to do this only in bash, but I doubt that there is a bash utility installed on all systems that has this use case built in. That being the case, it seems logical
to use a language whose toolchain we already install for formatting. This leaves us with Go or Javascript as primary candidates.

Fund our work

[Bug]: 0.14 release broke formatter accepting file arguments

What happened?

Due to keith/rules_multirun#44
(and obviously missing integration testing in this repo)

Version

0.14.0 and 0.14.1

How to reproduce

INFO: Running command line: bazel-bin/tools/format/format.bash lint.sh
Traceback (most recent call last):
  File "/private/var/tmp/_bazel_alexeagle/3eecd93732ac7c6f4f360a54a468da50/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/tools/format/format.bash.runfiles/_main/../rules_multirun~0.7.0/internal/multirun.py", line 91, in <module>
    _main(sys.argv[-1])
  File "/private/var/tmp/_bazel_alexeagle/3eecd93732ac7c6f4f360a54a468da50/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/tools/format/format.bash.runfiles/_main/../rules_multirun~0.7.0/internal/multirun.py", line 73, in _main
    with open(path) as f:
FileNotFoundError: [Errno 2] No such file or directory: 'lint.sh'

[Bug]: Lints reported on generated files

What happened?

Haven't verified, but we think we currently run linters on all srcs of a *_library including those in bazel-out which means we're reporting lint violations on generated code. This is not desirable, we should probably filter them out.

Follow-up from #62

Version

HEAD

How to reproduce

No response

Any other information?

No response

[FR]: Add support for specifying formatter config files?

What is the current behavior?

I am running ruff for Python following the examples in this repository. I configured the multi_formatter_binary just as in the examples, but it doesn't pick up the ruff.toml file located in the repo root. It seems that running a formatter via multi_formatter_binary does not respect config files in the repo, even after using the ruff_aspect as shown in the examples folder.

It looks like the aspects for linting allow you to specify configurations, but this doesn't seem to transfer over to the formatters?

Describe the feature

There should be a way for this to be specified for formatting, and not just linting. And if there is already a way to do this, please expand the documentation to make it clear how this is done.

[Bug]: Clarify severity warning vs. error

What happened?

In the README I don't talk about warnings vs errors yet. It's kinda implied in the "Usage" section for lint where I give five ways to use it.

However we also don't honor what the tool settings say. For example https://eslint.org/docs/latest/use/configure/rules#rule-severities is pretty clear about the exit code you get when something is an error vs. a warning.

We should probably have our "warning" semantics apply only when you have configured a check to be a warning. Needs some thoughtfulness about how to do it.

Version

HEAD

How to reproduce

No response

Any other information?

No response

[Bug]: Lint.sh from examples can fail on long-lived CI workers

What happened?

If I make a PR adding some new component to our repository, this will cause a linting report to be written to bazel-out. If the same agent later builds some other branch, where this new component is not present in the source tree, the report will still be present in bazel-out. If the PR has a linting failure, this will also cause other branches to fail.

Version

Development (host) and target OS/architectures:

linux/amd64

Output of bazel --version:

bazel 6.4.0

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file:

bazel_dep(name = "aspect_bazel_lib", version = "2.0.0-rc0")
bazel_dep(name = "aspect_rules_lint", version = "0.0.0")

git_override(
module_name = "aspect_rules_lint",
commit = "699cd2c9719bfb3bfc3a9f8c6a7006f0a058c067",
remote = "https://github.com/aspect-build/rules_lint.git",
)

Language(s) and/or frameworks involved:

Python

How to reproduce

Create a branch which adds some file with a linting failure. Run the /examples/lint.sh on this branch. Then run on some other branch which doesn't have the same file.

Any other information?

No response

[Bug]: Restore HCL language

What happened?

Switched from hcl to terraform because terraform-fmt doesn't cover everything

See comment:

# Note: terraform fmt cannot handle all HCL files such as .terraform.lock
# "Only .tf and .tfvars files can be processed with terraform fmt"
# so we define a custom language here instead of 'HCL' from github-linguist definition for the language.
# TODO: we should probably use https://terragrunt.gruntwork.io/docs/reference/cli-options/#hclfmt instead
# which does support the entire HCL language FWICT
'Terraform') patterns=('*.tf' '*.tfvars') ;;

1.0 api review

Some raw notes


diff --git a/MODULE.bazel b/MODULE.bazel
index 9114d1f..32c9f9d 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -16,13 +16,13 @@ bazel_dep(name = "bazel_skylib", version = "1.4.2")
 bazel_dep(name = "platforms", version = "0.0.7")
 
 # Needed in the root because we dereference ProtoInfo in our aspect impl
-bazel_dep(name = "rules_proto", version = "5.3.0-21.7")
+bazel_dep(name = "rules_proto", version = "6.0.0-rc1")
 
 # Needed in the root because we dereference the toolchain in our aspect impl
 bazel_dep(name = "rules_buf", version = "0.1.1")
 
 # Needed due to rules_proto leaking the dependency
-bazel_dep(name = "protobuf", version = "21.7", repo_name = "com_google_protobuf")
+# bazel_dep(name = "protobuf", version = "21.7", repo_name = "com_google_protobuf")
 
 # Needed to get the 'go_context' symbol, to invoke golangci-lint
 bazel_dep(name = "rules_go", version = "0.39.1", repo_name = "io_bazel_rules_go")
diff --git a/docs/formatting.md b/docs/formatting.md
index d7ee0ef..366e993 100644
--- a/docs/formatting.md
+++ b/docs/formatting.md
@@ -30,6 +30,9 @@ alias(
 
 ## Usage
 
+### With Aspect Workflows
+Maybe point to live examples
+
 ### One-time re-format all files
 
 Assuming you installed with the typical layout:
diff --git a/docs/lint_test.md b/docs/lint_test.md
index 78caf2b..16ba1b2 100644
--- a/docs/lint_test.md
+++ b/docs/lint_test.md
@@ -42,7 +42,7 @@ flake8_test(
 ## make_lint_test
 
 <pre>
-make_lint_test(<a href="#make_lint_test-aspect">aspect</a>)
+lint_make_test(<a href="#make_lint_test-aspect">aspect</a>)
 </pre>
 
 
diff --git a/example/WORKSPACE.bzlmod b/example/WORKSPACE.bzlmod
index 69c372c..aeebaa0 100644
--- a/example/WORKSPACE.bzlmod
+++ b/example/WORKSPACE.bzlmod
@@ -17,6 +17,7 @@ load(
 )
 load("@aspect_rules_lint//lint:ruff.bzl", "fetch_ruff")
 
+# CAN THIS be an extension that calls http_archive
 fetch_gofumpt()
 
 fetch_pmd()
diff --git a/example/tools/BUILD b/example/tools/BUILD
index 5e788c3..2574d20 100644
--- a/example/tools/BUILD
+++ b/example/tools/BUILD
@@ -110,6 +110,8 @@ java_binary(
     runtime_deps = ["@maven//:org_scalameta_scalafmt_cli_2_13"],
 )
 
+# REDUCE THE BOILERPLATE
+# research the ARM thing?
 native_binary(
     name = "yamlfmt",
     src = select(
@@ -119,6 +121,7 @@ native_binary(
             "@bazel_tools//src/conditions:darwin_x86_64": "@yamlfmt_Darwin_x86_64//:yamlfmt",
             "@bazel_tools//src/conditions:darwin_arm64": "@yamlfmt_Darwin_arm64//:yamlfmt",
         },
+        error-no-match = "windows",
     ),
     out = "yamlfmt",
 )
@@ -180,7 +183,7 @@ copy_to_directory(
 # bazel run :shellcheck -- --help
 shellcheck_binary(name = "shellcheck")
 
-multi_formatter_binary(
+format_multi_binary(
     name = "format",
     cc = "@llvm_toolchain_llvm//:bin/clang-format",
     # Or ":gofumpt" if you want to use gofumpt instead of gofmt
diff --git a/format/defs.bzl b/format/defs.bzl
index cabde8e..487f017 100644
--- a/format/defs.bzl
+++ b/format/defs.bzl
@@ -32,4 +32,5 @@ multi_formatter_binary(
 
 load("//format/private:formatter_binary.bzl", _fmt = "multi_formatter_binary")
 
+# Macro could expand to one per language as well
 multi_formatter_binary = _fmt
diff --git a/lint/eslint.bzl b/lint/eslint.bzl
index 7d4683f..f7eb2e5 100644
--- a/lint/eslint.bzl
+++ b/lint/eslint.bzl
@@ -151,7 +151,7 @@ def _eslint_aspect_impl(target, ctx):
     eslint_fix(ctx, ctx.executable, files_to_lint, patch)
     return [info]
 
-def eslint_aspect(binary, configs):
+def lint_eslint_aspect(binary, configs):
     """A factory function to create a linter aspect.
 
     Args:
diff --git a/lint/ruff.bzl b/lint/ruff.bzl
index bcf2a3b..609cb5f 100644
--- a/lint/ruff.bzl
+++ b/lint/ruff.bzl
@@ -147,6 +147,7 @@ def ruff_aspect(binary, configs):
         # Needed for linters that need semantic information like transitive type declarations.
         # attr_aspects = ["deps"],
         attrs = {
+            # KILL THIS and try a custom flag
             "fail_on_violation": attr.bool(),
             "_ruff": attr.label(
                 default = binary,
diff --git a/lint/vale.bzl b/lint/vale.bzl
index 873cd44..61bd768 100644
--- a/lint/vale.bzl
+++ b/lint/vale.bzl
@@ -175,7 +175,7 @@ def fetch_vale(tag = VALE_VERSIONS.keys()[0]):
 
         maybe(
             http_archive,
-            name = "vale_" + plat,
+            name = "aspect_rules_lint.vale_" + plat,
             url = url.format(
                 tag = tag,
                 plat = plat,

[Bug]: eslint may walk to ancestors and find duplicate plugins

What happened?

ESLint couldn't determine the plugin "@typescript-eslint" uniquely.

- /private/var/tmp/_bazel_jao/a28f07b7c13871bba430d7ed055ab5dd/execroot/bazel-out/darwin_arm64-fastbuild/bin/web/lint.sh.runfiles/figma/node_modules/.aspect_rules_js/@[email protected]_-873932014/node_modules/@typescript-eslint/eslint-plugin/dist/index.js (loaded in "--config")
- /private/var/tmp/_bazel_jao/a28f07b7c13871bba430d7ed055ab5dd/execroot/bazel-out/darwin_arm64-fastbuild/bin/node_modules/.aspect_rules_js/@[email protected]_-873932014/node_modules/@typescript-eslint/eslint-plugin/dist/index.js (loaded in "../../../.eslintrc.js")

Version

N/A

How to reproduce

Don't have a repro with rules_lint yet, but a client found their custom eslint_binary was hitting this.

Any other information?

setting root: true prevents eslint from traversing the ancestors.

Assuming this is reproducible with rules_lint, then maybe we should set root:true or maybe we should recommend that users put that in their config.

[FR]: make formatter's --mode check to be a test rule

What is the current behavior?

bazel run //:format -- --mode check

we can only use bazel run to run check. why not make it to be a test.

Cooperating with #97 will be very helpful in ci.

Describe the feature

bazel test //:format_test
format_multirun_test(
    name = "format_test",
    go = "@cc_mvdan_gofumpt//:gofumpt",
    starlark = "@com_github_bazelbuild_buildtools//buildifier",
)

[Bug]: ruff failing on my M1 Mac

What happened?

bazel run tools:format fails.

Running ruff...
/private/var/tmp/_bazel_alexeagle/3eecd93732ac7c6f4f360a54a468da50/external/ruff_aarch64-apple-darwin/ruff: line 1: 4: command not found
/private/var/tmp/_bazel_alexeagle/3eecd93732ac7c6f4f360a54a468da50/external/ruff_aarch64-apple-darwin/ruff: line 2: 0: command not found
/private/var/tmp/_bazel_alexeagle/3eecd93732ac7c6f4f360a54a468da50/external/ruff_aarch64-apple-darwin/ruff: line 3: 4096: command not found
/private/var/tmp/_bazel_alexeagle/3eecd93732ac7c6f4f360a54a468da50/external/ruff_aarch64-apple-darwin/ruff: line 4: 8192: command not found
/private/var/tmp/_bazel_alexeagle/3eecd93732ac7c6f4f360a54a468da50/external/ruff_aarch64-apple-darwin/ruff: line 5: 12877824: command not found
/private/var/tmp/_bazel_alexeagle/3eecd93732ac7c6f4f360a54a468da50/external/ruff_aarch64-apple-darwin/ruff: line 6: 12894208: command not found

Version

HEAD

How to reproduce

No response

Any other information?

I fetch the tool outside of Bazel:

alexeagle@MacBook-Pro-8 example % wget https://github.com/astral-sh/ruff/releases/download/v0.1.1/ruff-aarch64-apple-darwin.tar.gz
--2023-10-31 16:12:10--  https://github.com/astral-sh/ruff/releases/download/v0.1.1/ruff-aarch64-apple-darwin.tar.gz
Resolving github.com (github.com)... 192.30.255.113
Connecting to github.com (github.com)|192.30.255.113|:443... connected.
HTTP request sent, awaiting response... 302 Found
Connecting to objects.githubusercontent.com (objects.githubusercontent.com)|185.199.108.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5568233 (5.3M) [application/octet-stream]
Saving to: ‘ruff-aarch64-apple-darwin.tar.gz.2’

ruff-aarch64-apple-darwin.tar.gz.2      100%[=============================================================================>]   5.31M  5.07MB/s    in 1.0s    

2023-10-31 16:12:12 (5.07 MB/s) - ‘ruff-aarch64-apple-darwin.tar.gz.2’ saved [5568233/5568233]

Then let's check the content:

alexeagle@MacBook-Pro-8 example % shasum -a 256 ruff-aarch64-apple-darwin.tar.gz
e2444e4c7bda7133a0c47a368993be55f7bbe3c3a68d14be83dca480fe624c5e  ruff-aarch64-apple-darwin.tar.gz

alexeagle@MacBook-Pro-8 example % tar -tvf ruff-aarch64-apple-darwin.tar.gz 
-rwxr-xr-x  0 runner staff 13085794 Oct 19 14:08 ruff
alexeagle@MacBook-Pro-8 example % tar -xvf !$
tar -xvf ruff-aarch64-apple-darwin.tar.gz
x ruff
alexeagle@MacBook-Pro-8 example % shasum -a 256 ruff
c7fe90b95a9e26bea01583b05f883a7b29eefe2fa628f752e5e37f7aab979785  ruff

Now we take those identical hashes and try to fetch with Bazel:

maybe(
            http_archive,
            name = "ruff_" + plat,
            url = "https://github.com/astral-sh/ruff/releases/download/v0.1.1/ruff-aarch64-apple-darwin.tar.gz",
            sha256 = "e2444e4c7bda7133a0c47a368993be55f7bbe3c3a68d14be83dca480fe624c5e",
            patch_cmds = [
                # On MacOS, `xattr -c` clears the "Unknown developer" warning when executing a fetched binary
                #"if command -v xattr > /dev/null; then xattr -c ruff; fi",
                #"chmod u+x ruff",
                "echo 'c7fe90b95a9e26bea01583b05f883a7b29eefe2fa628f752e5e37f7aab979785  ruff' | shasum -a 256 --check",
            ],
            build_file_content = """exports_files(["ruff"])""",
        )

And somehow we don't get the same checksum of the ruff binary??

% bazel fetch @ruff_aarch64-apple-darwin//:ruff                                                   
INFO: Repository ruff_aarch64-apple-darwin instantiated at:
  /Users/alexeagle/Projects/rules_lint/example/WORKSPACE.bazel:175:11: in <toplevel>
  /private/var/tmp/_bazel_alexeagle/3eecd93732ac7c6f4f360a54a468da50/external/aspect_rules_lint/lint/ruff.bzl:149:14: in fetch_ruff
  /private/var/tmp/_bazel_alexeagle/3eecd93732ac7c6f4f360a54a468da50/external/bazel_tools/tools/build_defs/repo/utils.bzl:233:18: in maybe
Repository rule http_archive defined at:
  /private/var/tmp/_bazel_alexeagle/3eecd93732ac7c6f4f360a54a468da50/external/bazel_tools/tools/build_defs/repo/http.bzl:372:31: in <toplevel>
INFO: repository @ruff_aarch64-apple-darwin' used the following cache hits instead of downloading the corresponding file.
 * Hash 'e2444e4c7bda7133a0c47a368993be55f7bbe3c3a68d14be83dca480fe624c5e' for https://github.com/astral-sh/ruff/releases/download/v0.1.1/ruff-aarch64-apple-darwin.tar.gz
If the definition of 'repository @ruff_aarch64-apple-darwin' was updated, verify that the hashes were also updated.
ERROR: An error occurred during the fetch of repository 'ruff_aarch64-apple-darwin':
   Traceback (most recent call last):
        File "/private/var/tmp/_bazel_alexeagle/3eecd93732ac7c6f4f360a54a468da50/external/bazel_tools/tools/build_defs/repo/http.bzl", line 143, column 10, in _http_archive_impl
                patch(ctx, auth = auth)
        File "/private/var/tmp/_bazel_alexeagle/3eecd93732ac7c6f4f360a54a468da50/external/bazel_tools/tools/build_defs/repo/utils.bzl", line 193, column 21, in patch
                fail("Error applying patch command %s:\n%s%s" %
Error in fail: Error applying patch command echo 'c7fe90b95a9e26bea01583b05f883a7b29eefe2fa628f752e5e37f7aab979785  ruff' | shasum -a 256 --check:
ruff: FAILED
shasum: WARNING: 1 computed checksum did NOT match

[Bug]: golangci-lint doesn't pull in dependencies

What happened?

golangci-lint doesn't just look at the .go file specified on the command-line, it also needs to pull in metadata about e.g. types from other files that are referenced from the file that is being linted. Without this, it complains about missing files.

The lint target should inherit all dependencies of the original target, as well as dependencies on any generated files in srcs as those are currently being filtered out (since they don't newed to be linted).

Version

Development (host) and target OS/architectures:

Output of bazel --version:

bazel 7.0.2

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file:

N/A, reproducible using example from rules_lint

Language(s) and/or frameworks involved:

Go / golang-ci

How to reproduce

I'll attach a PR to this bug that demonstrates the issue with the example in the rules_lint repo.

Any other information?

No response

[Bug]: lint.sh stops on first issue on Windows

What happened?

Trying to get this working on Windows, I've added select statements for some things in linters.bzl, and an echo statement to lint.sh. It's now working in example except it stops on first issue, and prints a different issue each time:

d:\workdir\rules_lint\example>bash lint.sh --keep_going src:all
bazel build --aspects=//tools/lint:linters.bzl%buf,//tools/lint:linters.bzl%eslint,//tools/lint:linters.bzl%flake8,//tools/lint:linters.bzl%pmd,//tools/lint:linters.bzl%ruff,//tools/lint:linters.bzl%shellcheck,//tools/lint:linters.bzl%golangci_lint,//tools/lint:linters.bzl%vale --build_event_json_file=/tmp/tmp.3z2v30BWf8 --output_groups=rules_lint_report --remote_download_regex='.*aspect_rules_lint.report' --keep_going src:all
WARNING: Running Bazel server needs to be killed, because the startup options are different.
Starting local Bazel server and connecting to it...
WARNING: For repository 'rules_java', the root module requires module version [email protected], but got [email protected] in the resolved dependency graph.
WARNING: For repository 'platforms', the root module requires module version [email protected], but got [email protected] in the resolved dependency graph.
DEBUG: C:/users/browchri/_bazel_browchri/ipvyj7f4/external/aspect_rules_ts~1.3.3/ts/private/ts_project.bzl:74:14:
WARNING: disabling ts_project workers which are not currently support on Windows hosts.
See https://github.com/aspect-build/rules_ts/issues/228 for more details.
INFO: Analyzed 10 targets (251 packages loaded, 16879 targets configured).
INFO: Found 10 targets...
INFO: Elapsed time: 31.865s, Critical Path: 2.25s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Build Event Protocol files produced successfully.
From bazel-out/x64_windows-fastbuild/bin/src/ESLint.ts.aspect_rules_lint.report:
src\file.ts: line 2, col 7, Error - Type string trivially inferred from a string literal, remove type annotation. (@typescript-eslint/no-inferrable-types)

1 problem

Version

Development (host) and target OS/architectures:
Windows

Output of bazel --version:
bazel 7.0.0

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file:
as latest example repo

Language(s) and/or frameworks involved:

How to reproduce

clone rules_lint
cd examples
bash lint.sh --keep_going src:all

Any other information?

No response

[Bug]: all formatters appear to run on all files

What happened?

Since switching to multirun in 46e190e we have a new behavior.

Previously, format.sh was run a single time. Any tool for which zero files needed formatting (based on the mapping of file extensions) was not run at all.

Now, there's one execution of format.sh for each tool, so that they may be in parallel. Each execution still short-circuits if no changed files match the file extensions. However, it's still not desirable to print the progress messages, like

Formatting JavaScript with prettier...
workflows/rosetta/src/tasks/branch-freshness.task.ts 142ms
Formatted TypeScript in 0m0.440s
Formatting Jsonnet with jsonnetfmt...
Formatting Terraform with terraform-fmt...
Formatting Go with gofmt...
Formatting Shell with shfmt...
Formatted Shell in 0m0.004s

when there was nothing to do.

Version

Latest

How to reproduce

No response

Any other information?

No response

[Bug]: golangci-lint blows away cache

What happened?

golangci-lint heavily relies on a cache to speed up repeat runs; the way the golangci_lint action works today (

GOLANGCI_LINT_CACHE=$(pwd)/.cache {golangci_lint} run --config={config} $@"""
) means the cache gets blown away in between runs

Version

Development (host) and target OS/architectures: Debian Linux amd64

Output of bazel --version: 5.2.2

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file: HEAD

Language(s) and/or frameworks involved: go

How to reproduce

No response

Any other information?

No response

[FR]: formatter's --mode check shouldn't bail on the first error

What is the current behavior?

I've defined //:format as a multi_formatter_binary that supports Go, Starlark, and Java. I have a Go file and a Java file which are both incorrectly formatted. Running bazel run //:format -- --mode check prints the following output:

Formatting Starlark with Buildifier...
Formatting Java with java-format...
java/com/.../SomeJavaFile.java
java/com/.../SomeJavaFile.java
FAILED: A formatter tool exited with code 123
Try running 'bazel run @@//bazel/lint:format' to fix this.

Notice that the check didn't reach the Go file, it bailed after the first error.

Describe the feature

It would be helpful for usability reasons if the --mode check invocation of the formatter checked all the file types and reported an exhaustive list of unformatted files.

[Bug]: Starlark formatter no longer touches BUILD files

What happened?

Looks like when format.sh was overhauled, rules_lint stopped getting BUILD/BUILD.bazel etc files outside of the root. the patterns for starlark at least are incomplete, and probably for other languages, too:

$ git ls-files --cached --modified --other --exclude-standard BUILD.bazel
BUILD.bazel
$ find . -name BUILD.bazel | wc -l
737

looks like a little additional processing is needed from linguist to add '**/' for any pattern that has no wildcards in it already

Version

Development (host) and target OS/architectures: all

Output of bazel --version: bazel 7.0.0

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file:

Language(s) and/or frameworks involved: all

How to reproduce

make an edit to a BUILD.bazel file in a subdirectory that would be corrected by buildifier. Run the formatter. Note it was not corrected.

Any other information?

additionally, if you trace execution of ls-files in format.sh it looks like we're getting some unexpected wildcard handling:

...
++ case "$language" in
++ patterns=('BUCK' 'BUILD' 'BUILD.bazel' 'MODULE.bazel' 'Tiltfile' 'WORKSPACE' 'WORKSPACE.bazel' '*.bzl' '*.star')
++ '[' 0 -eq 0 ']'
++ git ls-files --cached --modified --other --exclude-standard BUCK BUILD BUILD.bazel MODULE.bazel Tiltfile WORKSPACE WORKSPACE.bazel extensions.bzl repositories.bzl '*.star'
...

notable here is the expansion of *.bzl into the two matching files in the root of my repository. it looks like this is because of an unquoted bash array expansion- might want to turn on shellcheck from rules_lint in rules_lint :)

[FR]: Expose lint actions as tests

What is the current behavior?

You have to use --keep_going if you want a bazel build to print all the lint violations and also exit non-zero.

Describe the feature

A lot of users wire up linters today as tests, so we should let them continue to do that.

[Bug]: Error: In js_library rule @@aspect_rules_lint~//lint:eslint.bazel-formatter, toolchain type @@aspect_bazel_lib~//lib:coreutils_toolchain_type was requested but only types [] are configured

What happened?

Linting to happen with no errors.

Version

Development (host) and target OS/architectures:

Output of bazel --version:
bazel 7.1.1

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file:
bazel_dep(name = "aspect_rules_lint", version = "0.15.0")

Language(s) and/or frameworks involved:
Typescript + eslint.

How to reproduce

  1. Check out this commit: zemn-me/monorepo@240f92b
  2. Run bazel test //ts/math/...

Any other information?

Error:

WARNING: Option 'experimental_remote_build_event_upload' is deprecated: Use --remote_build_event_upload instead
INFO: Invocation ID: 54ecfcd1-fc0c-4485-9fba-98d5e9e9b454
INFO: Streaming build results to: https://app.buildbuddy.io/invocation/54ecfcd1-fc0c-4485-9fba-98d5e9e9b454
WARNING: Option 'experimental_remote_build_event_upload' is deprecated: Use --remote_build_event_upload instead
ERROR: /home/thomas/.cache/bazel/_bazel_thomas/a41610ee02ad9c69b13020a7f1cf3deb/external/aspect_rules_lint~/lint/BUILD.bazel:56:11: in js_library rule @@aspect_rules_lint~//lint:eslint.bazel-formatter: 
Traceback (most recent call last):
        File "/home/thomas/.cache/bazel/_bazel_thomas/a41610ee02ad9c69b13020a7f1cf3deb/external/aspect_rules_js~/js/private/js_library.bzl", line 167, column 61, in _js_library_impl
                sources, declarations = _gather_sources_and_declarations(
        File "/home/thomas/.cache/bazel/_bazel_thomas/a41610ee02ad9c69b13020a7f1cf3deb/external/aspect_rules_js~/js/private/js_library.bzl", line 127, column 46, in _gather_sources_and_declarations
                file = copy_js_file_to_bin_action(ctx, file)
        File "/home/thomas/.cache/bazel/_bazel_thomas/a41610ee02ad9c69b13020a7f1cf3deb/external/aspect_rules_js~/js/private/js_helpers.bzl", line 175, column 35, in copy_js_file_to_bin_action
                return copy_file_to_bin_action(ctx, file)
        File "/home/thomas/.cache/bazel/_bazel_thomas/a41610ee02ad9c69b13020a7f1cf3deb/external/aspect_bazel_lib~/lib/private/copy_to_bin.bzl", line 84, column 21, in copy_file_to_bin_action
                copy_file_action(ctx, file, dst)
        File "/home/thomas/.cache/bazel/_bazel_thomas/a41610ee02ad9c69b13020a7f1cf3deb/external/aspect_bazel_lib~/lib/private/copy_file.bzl", line 84, column 31, in copy_file_action
                coreutils = ctx.toolchains[_COREUTILS_TOOLCHAIN].coreutils_info
Error: In js_library rule @@aspect_rules_lint~//lint:eslint.bazel-formatter, toolchain type @@aspect_bazel_lib~//lib:coreutils_toolchain_type was requested but only types [] are configured
ERROR: /home/thomas/.cache/bazel/_bazel_thomas/a41610ee02ad9c69b13020a7f1cf3deb/external/aspect_rules_lint~/lint/BUILD.bazel:56:11: Analysis of target '@@aspect_rules_lint~//lint:eslint.bazel-formatter' failed
ERROR: Loading failed
Use --verbose_failures to see the command lines of failed build steps.
ERROR: Analysis of target '//ts/math/canvas:canvas_lint' failed; build aborted
INFO: Elapsed time: 0.216s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
ERROR: Build did NOT complete successfully
ERROR: No test targets were found, yet testing was requested
INFO: Streaming build results to: https://app.buildbuddy.io/invocation/54ecfcd1-fc0c-4485-9fba-98d5e9e9b454

[Bug]: lint.sh does not work if --symlink_prefix is set in .bazelrc

What happened?

We have --symlink_prefix set in our .bazelrc. The rules_lint_report generated by lint.sh does not respect this, so all of the report filenames are invalid and lint.sh is therefore unable to show any results.

Version

Development (host) and target OS/architectures: ARM Ubuntu running in Docker on macOS

Output of bazel --version: bazel 6.4.0

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file: 0.14.2

Language(s) and/or frameworks involved: rules_python

How to reproduce

  1. bazel clean
  2. Apply the patch below to the rules_lint repository
  3. ./lint.sh //...
diff --git a/example/.bazelrc b/example/.bazelrc
index 6c429f0..f647e76 100644
--- a/example/.bazelrc
+++ b/example/.bazelrc
@@ -8,3 +8,5 @@ build --repo_env=JAVA_HOME=../bazel_tools/jdk
 common --lockfile_mode=off
 
 startup --host_jvm_args=-DBAZEL_TRACK_SOURCE_DIRECTORIES=1
+
+common --symlink_prefix=.bazel/
\ No newline at end of file

Any other information?

Nope

[Bug]: The bash escaping in format.sh will stop recursing if matched at root level

What happened?

I am using the markdown formatter and I have many markdown files in my repo. However, when I run bazel run //:format it will only find the markdown files in the top level.

# This formats only README_TOP_LEVEL.md
WORKSPACE
README_TOP_LEVEL.md
subfolder1/
  README_NOT_FORMATTED1.md
subfolder2/
  README_NOT_FORMATTED2.md

Interestingly, when I delete README_TOP_LEVEL.md (shown below) the formatter works.

# This formats all files
WORKSPACE
subfolder1/
  README_NOT_FORMATTED1.md
subfolder2/
  README_NOT_FORMATTED2.md

Version

Development (host) and target OS/architectures:

Output of bazel --version: bazel 6.3.2

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file: git version 2.41.0

Language(s) and/or frameworks involved:
git version 2.41.0

How to reproduce

Run the formatter with a repo that looks like this

# This formats only README_TOP_LEVEL.md
WORKSPACE
README_TOP_LEVEL.md
subfolder1/
  README_NOT_FORMATTED1.md
subfolder2/
  README_NOT_FORMATTED2.md

Any other information?

I was able to narrow it down to some bash expansions. Here is a minimal reproducer.

patterns=('contents.lr' '*.md' '*.livemd' '*.markdown')
git ls-files --cached --modified --other --exclude-standard ${patterns[@]} | {
  grep -vE "^$(git ls-files --deleted)$" || true;
}

By adding some echos I think I narrowed it down to some bash magic where the single quotes are escaped.

patterns=('contents.lr' '*.md' '*.livemd' '*.markdown')
echo "git ls-files --cached --modified --other --exclude-standard ${patterns[@]}"
#Prints
#git ls-files --cached --modified --other --exclude-standard contents.lr *.md *.livemd *.markdown
git ls-files --cached --modified --other --exclude-standard ${patterns[@]} | {
  grep -vE "^$(git ls-files --deleted)$" || true;
}

I assume that should have some single quotes separating '.md' '.livemd' '*.markdown'

Finally I tried

patterns=('contents.lr' '*.md' '*.livemd' '*.markdown')
test=$(printf "'%s' " "${patterns[@]}")
echo "$test"
echo "git ls-files --cached --modified --other --exclude-standard ${test}"
git ls-files --cached --modified --other --exclude-standard ${test} | {
  grep -vE "^$(git ls-files --deleted)$" || true;
}

That returned nothing. I hit my bash knowledge limit. If you can give me a hint on the bash wisdom here I can submit a PR with the fix.

[Bug]: ruff failing on Mac x86

What happened?

try to load ruff binary, it failed with the following error

% bazel run //:ruff    
bazel::login succeed
Starting local Bazel server and connecting to it...
INFO: Invocation ID: a203b7e2-c67c-459c-a6f0-a6ea586fcba8
INFO: Analyzed target //:ruff (6 packages loaded, 15 targets configured).
INFO: Found 1 target...
Target @ruff_x86_64-apple-darwin//:ruff up-to-date (nothing to build)
INFO: Elapsed time: 11.382s, Critical Path: 0.05s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Running command line: /private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/external/ruff_x86_64-apple-darwin/ruff
/private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/external/ruff_x86_64-apple-darwin/ruff: line 1: 3: command not found
/private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/external/ruff_x86_64-apple-darwin/ruff: line 2: 0: command not found
/private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/external/ruff_x86_64-apple-darwin/ruff: line 3: 4096: command not found
/private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/external/ruff_x86_64-apple-darwin/ruff: line 4: 16384: command not found
/private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/external/ruff_x86_64-apple-darwin/ruff: line 5: 14503936: command not found
/private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/external/ruff_x86_64-apple-darwin/ruff: line 6: 14532608: command not found
/private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/external/ruff_x86_64-apple-darwin/ruff: line 7: 83144: command not found
/private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/external/ruff_x86_64-apple-darwin/ruff: line 8: ????X: command not found
/private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/external/ruff_x86_64-apple-darwin/ruff: line 9: syntax error near unexpected token `)'
/private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/external/ruff_x86_64-apple-darwin/ruff: line 9: `???H__PAGEZERO?__TEXT???__text__TEXT?F?*??F?__stubs__TEXT?q?q?__stub_helper__TEXT?u???u??__const__TEXT?|??%?|?__gcc_except_tab__TEXTX??}X??__cstring__TEXTp??)(p??__unwind_info__TEXT?%?\??%?__eh_frame__TEXT??????__DATA???(??
                                                                                                                                                         __program_vars__DATA??(??__nl_symbol_ptr__DATA(?(???__got__DATA0??`0???__la_symbol_ptr__DATA???`????__mod_init_func__DATA?????	__const__DATA??????__thread_vars__DATA?w???w?__data__DATA {? {?__thread_data__DATA ??@ ??__thread_bss__DATA`??h__common__DATA??(? __bss__DATA0.??H__LINKEDIT@?????D"?0??x(x???@H???8???'0????>
                                                                                                                  P???p??e 
                                                                                                                           /usr/lib/dyld??k&?<?̓"WD1g$'
Error: bazel exited with exit code: 2

Version

Development (host) and target OS/architectures: macOS x86

Output of bazel --version: Build label: 6.4.0

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file:

http_archive(
    name = "aspect_rules_lint",
    sha256 = "ddc21b1399c03708f82e5a46d6c747bf23d55484bad1efdaa92a22d5fee20ea1",
    strip_prefix = "rules_lint-0.5.0",
    url = "https://github.com/aspect-build/rules_lint/releases/download/v0.5.0/rules_lint-v0.5.0.tar.gz",
)
load("@aspect_rules_lint//lint:ruff.bzl", "fetch_ruff")
fetch_ruff()

Language(s) and/or frameworks involved:
python

How to reproduce

Configure the WORKSPACE file as above. 

In BUILD.bazel: 
alias(
    name = "ruff",
    actual = select({
        "@bazel_tools//src/conditions:linux_x86_64": "@ruff_x86_64-unknown-linux-gnu//:ruff",
        "@bazel_tools//src/conditions:linux_aarch64": "@ruff_aarch64-unknown-linux-gnu//:ruff",
        "@bazel_tools//src/conditions:darwin_arm64": "@ruff_aarch64-apple-darwin//:ruff",
        "@bazel_tools//src/conditions:darwin_x86_64": "@ruff_x86_64-apple-darwin//:ruff",
    }),
)

bazel run //:ruff

Any other information?

No response

[Bug]: custom buildifier with flags doesn't seem to work

What happened?

Here's my setup:

load("@aspect_rules_lint//format:defs.bzl", "multi_formatter_binary")
load("@buildifier_prebuilt//:rules.bzl", "buildifier")
load("@npm//:prettier/package_json.bzl", prettier = "bin")
buildifier(
    name = "buildifier",
    exclude_patterns = ["./node_modules/*"],
    lint_mode = "fix",
    lint_warnings = [
        "attr-cfg",
        "attr-license",
        "attr-non-empty",
        "attr-output-default",
        "attr-single-file",
        "constant-glob",
        "ctx-actions",
        "ctx-args",
        "depset-iteration",
        "depset-union",
        "dict-concatenation",
        "duplicated-name",
        "filetype",
        "git-repository",
        "http-archive",
        "integer-division",
        "load",
        "load-on-top",
        "native-build",
        "native-package",
        "out-of-order-load",
        "output-group",
        "package-name",
        "package-on-top",
        "positional-args",
        "redefined-variable",
        "repository-name",
        "same-origin-load",
        "string-iteration",
        "unsorted-dict-items",
        "unused-variable",
    ],
    verbose = True,
)

multi_formatter_binary(
    name = "format",
    javascript = ":prettier",
    # TODO: This seems to break
    starlark = ":buildifier",
    visibility = ["//visibility:public"],
)

The buildifier target as you can see has a bunch of flags presets. When I try to run the format target it bombs out:

Running Buildifier...
FAILED: A formatter tool exited with code 1
Try running 'bazel run //:format' to fix this.

Version

Development (host) and target OS/architectures:

Output of bazel --version: aspect 5.3.4

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file:

Language(s) and/or frameworks involved:

How to reproduce

No response

Any other information?

No response

[Bug]: Visibility argument to format_multirun causes error

What happened?

When adding visibility = [...] to format_multirun this causes format_multirun to error.

Version

Development (host) and target OS/architectures:

Output of bazel --version:
bazel 6.4.0

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file:
v.15

Language(s) and/or frameworks involved:

How to reproduce

Add a visibility argument to `format_multirun`

Any other information?

No response

[Bug]: JSON format does not seem to be supported

What happened?

There is no way to format json files using this tool. It looks like there is scaffolding for it in format.sh but then it is never called.

Version

Development (host) and target OS/architectures:

Output of bazel --version: bazel 6.3.2

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file: rules_lint-0.10.0

Language(s) and/or frameworks involved: json

How to reproduce

No response

Any other information?

I will hopefully get to submitting a PR myself but in case I do not I wanted to put this issues out there in case another contributor beat me to it.

[Bug]: terraform broke

What happened?

@gregmagolan writes: something in rules_lint 0.10.0 broke terraform format:

$ br //:format
INFO: Analyzed target //:format (2 packages loaded, 5 targets configured).
INFO: Found 1 target...
Target //tools/format:format up-to-date:
  bazel-bin/tools/format/format.sh
INFO: Elapsed time: 1.377s, Critical Path: 0.01s
INFO: 5 processes: 5 internal.
INFO: Build completed successfully, 5 total actions
INFO: Running command line: bazel-bin/tools/format/format.sh
Formatting Starlark with Buildifier...
Formatting Hashicorp Config Language with terraform fmt...
╷
│ Error: Only .tf and .tfvars files can be processed with terraform fmt
│ 
│ 
╵

FAILED: A formatter tool exited with code 1
Try running 'bazel run @//tools/format:format' to fix this.
Error: bazel exited with exit code: 1
Error: bazel exited with exit code: 1

Works fine with 0.9.1

Version

0.10.0

How to reproduce

No response

Any other information?

No response

[FR]: Apply fixes

What is the current behavior?

Linters offer to fix problems they find, but we don't offer a convenient workflow under Bazel to accept those.

Describe the feature

Likely aspect-build/aspect-cli#409 is the nicest developer experience.

For developers who don't want to use Aspect CLI we can follow the model of example/lint.sh and just show them how to write a fixup.sh that does approx. the same thing.

[Bug]: generated code will be format. (.go)

What happened?

gofumpt will not format generated code mvdan/gofumpt#150.
but due to mvdan/gofumpt#195 , the behavior of gofumpt dir and gofumpt file is different.

rules_lint find all .go files, and execute with gofumpt file. It will cause generated code formatted.

There seems to be no solution at present (also we can't ignore generated file)

Version

Development (host) and target OS/architectures:

Output of bazel --version: 7.1.1

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file: 0.18.0

Language(s) and/or frameworks involved: go

How to reproduce

No response

Any other information?

No response

[Bug]: Format fails when there are deleted files

What happened?

The format script uses git ls-files, which includes deleted files if the changes aren't committed.

If we used the following command deleted files would be excluded from the output.
$ git ls-files "*.bazel" | grep -vE "^$(git ls-files -d | paste -sd "|" -)$"

Version

Development (host) and target OS/architectures:

Output of bazel --version: aspect 5.8.5

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file:

Language(s) and/or frameworks involved:

How to reproduce

$ git clone [email protected]:aspect-build/rules_lint.git
$ cd rules_lint/example
$ mv src/hello.jsonnet src/hello2.jsonnet
$ bazel run format
Opening input file: src/hello.jsonnet: no such file or directory

[Bug]: shfmt doesn't respect editorconfig-defined ignored files

What happened?

I have a file in my vendor'd third_party directory. There's a shell script in that directory that's not correctly formatted. Normally, I'd be able to instruct the shfmt tool to ignore that directory by setting up an .editorconfig file that looks like this:

# Ignore the entire "third_party" directory.
[third_party/**]
ignore = true

This is described in the shfmt documentation.

Unfortunately, the shfmt tool only applies this ignore setting when it's being passed a directory to walk. When passed a list of filenames directly, shfmt formats the files with no regard to the ignore setting. This is an open issue on the shfmt's bug tracker, but the author feels that the tool's behavior is correct.

Version

Development (host) and target OS/architectures:

Linux / amd64

Output of bazel --version:

6.2.1

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file:

v0.7.0

Language(s) and/or frameworks involved:

shfmt

How to reproduce

  1. Create a misformatted shell file in third_party/bad.sh:
#!/usr/bin/env bash

      function     badly_formatted()    {
  true
}
  1. Ask shfmt to ignore it by adding an .editorconfig file:
# .editorconfig
[third_party/**]
ignore = true
  1. Run the //:format target

Expected results: third_party/bad.sh isn't changed

Actual results: third_party/bad.sh is reformatted

Any other information?

No response

[Bug]: how do prettier plugins work?

(It is entirely possible that I'm just Holding It Wrong; guidance welcome and appreciated. ❤️)

What happened?

I've got prettier set up as described in the docs, with a handful of plugins specified in BUILD as well as the .prettierrc file:

prettier.prettier_binary(
    name = "prettier",
    data = [
        "//:prettierrc",
        "//:node_modules/@trivago/prettier-plugin-sort-imports",
        "//:node_modules/prettier-plugin-tailwindcss",
    ],
    # Allow the binary to be run outside bazel
    env = {"BAZEL_BINDIR": "."},
)

multi_formatter_binary(
    name = "format",
    javascript = ":prettier",
)

Unfortunately, no force on earth can compel these plugins to work:

Formatting JavaScript with Prettier...
[error] Cannot find package '@trivago/prettier-plugin-sort-imports' imported from /cloud/noop.js
FAILED: A formatter tool exited with code 123

I've been trying permutations for hours. Things I've tried that have not worked:

At this point, I am fresh out of ideas and would love a nudge in the right direction. 🙏

Version

Development (host) and target OS/architectures: Ubuntu running in Docker on a M1 Mac

Output of bazel --version: bazel 6.4.0

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file: 0.9.1

Language(s) and/or frameworks involved: JS

How to reproduce

No response

Any other information?

No response

[FR]: Buildifier `add_tables` not supported

What is the current behavior?

Currently there does not seem to be a way to add custom overrides to buildifier and am stuck with the default linting / sorting standards.

Describe the feature

Should be able to specify the add_tables configuration arg to include any custom sorting enforced by the repo

{
  "IsLabelArg": {},
  "LabelBlacklist": {},
  "IsSortableListArg": {},
  "SortableAllowlist": {},
  "NamePriority": {}
}

[FR]: Run buildifier lint as a formatter

What is the current behavior?

buildifier runs as a formatter currently, but bulidfier lint doesn't run. Because rules_lint uses aspects to run lint mode, it wouldn't make sense to try to run buildifier as a linter.

Describe the feature

Suggestion: add an optional buildifer_lint to the multi formatter. Even though it is technically a linter vs a formatter, this seems reasonable sense it is opt in. Happy to submit a PR for this.

[Bug]: Ruff ignores excluded files/dirs when running //:format in the check mode

What happened?

Hi!

For some reason, Ruff formatter ignores excluded files/dirs when running bazel run //:format -- --mode check in the check mode only. Everything works well in fix mode -- --mode fix.

Screenshot 2024-03-12 at 11 17 09 PM

Version

Development (host) and target OS/architectures: Darwin MacBook-Pro.local 22.6.0 Darwin Kernel Version 22.6.0: Wed Jul 5 22:22:05 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6000 arm64

Output of bazel --version: bazel 6.5.0

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file:

Other context (I use rules_lint-0.13.0 version):

http_archive(
    name = "aspect_rules_lint",
    sha256 = "c0824de8400f1e271c5568fc47581e165b2132f9d21691fcfefe8bf89ad413bd",
    strip_prefix = "rules_lint-0.13.0",
    url = "https://github.com/aspect-build/rules_lint/releases/download/v0.13.0/rules_lint-v0.13.0.tar.gz",
)

# Python dependencies
load("@aspect_rules_lint//lint:ruff.bzl", "fetch_ruff")

fetch_ruff()

Language(s) and/or frameworks involved:

Python/Ruff formatter

How to reproduce

  1. I recently added multi_formatter_binary where specified python = "//tools/format:ruff", so far only.
multi_formatter_binary(
    name = "format",
    python = "//tools/format:ruff",
    # Add more languaged here...
    visibility = ["//visibility:public"],
)
  1. In the ruff.toml (settings config), has exclude = ["main.py", "<path to /dir when main.py file located>"] properly defined
  2. Expected behavior: when I run bazel run //:format -- --mode check, it should show nothing since all py files were excluded in ruff.toml config
  3. Actual behavior: when I run bazel run //:format -- --mode check it still shows 1 file that "would re-format".

[Bug]: eslint test doesn't work when passing transpiler to ts_project

What happened?

We're using ts_project from Aspect's rules_ts, and passing in swc as a transpiler:

ts_project(
    name = name,
    srcs = srcs,
    transpiler = partial.make(
        swc,
        source_maps = "true",
        swcrc = swcrc,
    ),
    source_map = True,
    resolve_json_module = True,
    allow_js = False,
    incremental = True,
    declaration = True,
    tsconfig = tsconfig,
    deps = deps,
    **kwargs
)

Creating a lint target based on this name, results in linting the .js and .js.map files generated by SWC. If instead we pass in the :<name>_transpile target that rules_ts generates for SWC, we get the following error:

ERROR: <snip>/BUILD.bazel:10:26: in _eslint_test rule //foo/bar:baz.lint:
Traceback (most recent call last):
        File "<sandbox>/external/aspect_rules_lint/lint/lint_test.bzl", line 43, column 43, in _test_impl
                for report in src[OutputGroupInfo].rules_lint_report.to_list():
Error: 'OutputGroupInfo' value has no field or method 'rules_lint_report'
Available attributes: _hidden_top_level_INTERNAL_

Version

Development (host) and target OS/architectures:

Output of bazel --version: bazel 6.3.1-0c22e4f

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file:

  • rules_lint: 0.6.1
  • rules_ts: 2.0.1

Language(s) and/or frameworks involved:

  • Typescript

How to reproduce

No response

Any other information?

No response

[Bug]: When formatting with this rule, Record and other modern Java constructs fail

What happened?

Added a Record file in a java project

When the google java formatter is run directly against the file via a java_binary target, it succeeds

When run via the multi_formatter_binary that consumes that target, we see error: class interface or enum expected

Version

Development (host) and target OS/architectures: Mac

Output of bazel --version: bazel 7.0.2

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file:
bazel_dep(name = "aspect_rules_lint", version = "0.10.0")
(Also tried 11.0)

Language(s) and/or frameworks involved:
java

How to reproduce

java_binary(
    name = "java-format",
    jvm_flags = [
        "--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
        "--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
        "--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
        "--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
        "--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
    ],
    main_class = "com.google.googlejavaformat.java.Main",
    runtime_deps = ["@google-java-format//jar"],
)

multi_formatter_binary(
    name = "format",
    java = ":java-format",
    visibility = ["//visibility:public"],
)

com.my.package

public record MyRecord(String field1, String field2) {

}

running bazel run :java-format -- /path/from/root/to/MyRecord.java, it succeeds without error

running bazel run :format, we receive that error

Any other information?

No response

[FR]: should linters apply to `*_binary` sources too?

What is the current behavior?

A number of this library's linters only check the srcs of *_library targets. PMD filters out all targets save for java_library; Ruff, py_library; ShellCheck, sh_library.

Each of these has a corresponding *_binary rule that also accepts srcs directly. These sources will not be linted.

Describe the feature

My intuition would be that all source files, or at least all source files blaze query can find, should get lint applied.

[FR]: Split Javascript and SQL formatting

What is the current behavior?

While the default tool for both SQL and Javascript formatting is prettier, they should be split out as options.

Describe the feature

This feature will allow people to define alternative Javascript (i.e. biome) or SQL formatters

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.