Skip to content

Commit 9cfc08a

Browse files
alexeaglemrmeku
authored andcommitted
feat: remove golangci-lint (aspect-build#207)
In preparation for 1.0, we want all linters to work correctly. In the discussion for aspect-build#129 we decided that is a fatal bug, and no one is able to fix it in the short term. We're happy to add Go linting back to rules_lint when someone has a correct implementation that handles transitive srcs. The code will still be here in the git history when it's time to revive it. Closes aspect-build#129
1 parent 129a609 commit 9cfc08a

21 files changed

+44
-263
lines changed

MODULE.bazel

-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ bazel_dep(name = "rules_proto", version = "6.0.0-rc2")
2424
bazel_dep(name = "rules_buf", version = "0.1.1")
2525
bazel_dep(name = "toolchains_protoc", version = "0.2.1")
2626

27-
# Needed to get the 'go_context' symbol, to invoke golangci-lint
28-
bazel_dep(name = "rules_go", version = "0.39.1", repo_name = "io_bazel_rules_go")
29-
3027
multitool = use_extension("@rules_multitool//multitool:extension.bzl", "multitool")
3128
multitool.hub(lockfile = "//format:multitool.lock.json")
3229
multitool.hub(lockfile = "//lint:multitool.lock.json")

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ New tools are being added frequently, so check this page again!
2424
| ---------------------- | --------------------- | ---------------- |
2525
| C / C++ | [clang-format] | ([#112]) |
2626
| CSS | [Prettier] | |
27-
| Go | [gofmt] or [gofumpt] | [golangci-lint] |
27+
| Go | [gofmt] or [gofumpt] | |
2828
| HCL (Hashicorp Config) | [terraform] fmt | |
2929
| HTML | [Prettier] | |
3030
| JSON | [Prettier] | |
@@ -63,7 +63,6 @@ New tools are being added frequently, so check this page again!
6363
[ruff]: https://docs.astral.sh/ruff/
6464
[shellcheck]: https://www.shellcheck.net/
6565
[shfmt]: https://github.com/mvdan/sh
66-
[golangci-lint]: https://github.com/golangci/golangci-lint
6766
[clang-format]: https://clang.llvm.org/docs/ClangFormat.html
6867
[#112]: https://github.com/aspect-build/rules_lint/issues/112
6968
[vale]: https://vale.sh/

docs/BUILD.bazel

-5
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ stardoc_with_diff_test(
3737
bzl_library_target = "//lint:ruff",
3838
)
3939

40-
stardoc_with_diff_test(
41-
name = "golangci-lint",
42-
bzl_library_target = "//lint:golangci-lint",
43-
)
44-
4540
stardoc_with_diff_test(
4641
name = "shellcheck",
4742
bzl_library_target = "//lint:shellcheck",

docs/golangci-lint.md

-63
This file was deleted.

docs/linting.md

+11
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,17 @@ By default, we filter out generated files from linting.
9292

9393
To bypass this filter, add `tags=["lint-genfiles"]` to a target to force all the `srcs` to be linted.
9494

95+
## Ignoring files explicitly
96+
97+
Commonly, the underlying linters that rules_lint invokes provide their own methods of excluding files from linting (.prettierignore for example). At times when that is not the case, rules_lint provides its
98+
own escape hatch to exclude files from linting using attributes specified via [`.gitattributes` files](https://git-scm.com/docs/gitattributes).
99+
100+
If any of following attributes are set on a file it will be excluded from linting:
101+
102+
- `rules_lint_ignored`
103+
- `gitlab-generated`
104+
- `linguist-generated`
105+
95106
## Debugging
96107

97108
Some linters honor the debug flag in this repo. To enable it, add a Bazel flag:

example/.aspect/cli/config.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ lint:
33
- //tools/lint:linters.bzl%eslint
44
- //tools/lint:linters.bzl%buf
55
- //tools/lint:linters.bzl%flake8
6-
- //tools/lint:linters.bzl%golangci_lint
76
- //tools/lint:linters.bzl%pmd
87
- //tools/lint:linters.bzl%ruff
98
- //tools/lint:linters.bzl%vale

example/.gitattributes

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Do not try and format generated code
2+
pnpm-lock.yaml linguist-generated
3+
4+
# Any of the below attributes can be set to ignore a file
5+
src/subdir/rules_lint_ignored.js rules_lint_ignored
6+
src/subdir/gitlab-generated.js gitlab-generated
7+
src/subdir/linguist-generated.js linguist-generated

example/.golangci.yaml

-21
This file was deleted.

example/BUILD.bazel

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ exports_files(
1919
".ruff.toml",
2020
".shellcheckrc",
2121
".scalafmt.conf",
22-
".golangci.yaml",
2322
".vale.ini",
2423
],
2524
visibility = ["//visibility:public"],

example/lint.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ filter='.namedSetOfFiles | values | .files[] | ((.pathPrefix | join("/")) + "/"
2424

2525
# NB: perhaps --remote_download_toplevel is needed as well with remote execution?
2626
args=(
27-
"--aspects=$(echo //tools/lint:linters.bzl%{buf,eslint,flake8,pmd,ruff,shellcheck,golangci_lint,vale} | tr ' ' ',')"
27+
"--aspects=$(echo //tools/lint:linters.bzl%{buf,eslint,flake8,pmd,ruff,shellcheck,vale} | tr ' ' ',')"
2828
"--build_event_json_file=$buildevents"
2929
)
3030
report_args=(

example/src/subdir/.eslintrc.cjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/* eslint-env node */
22
const base = require("../../.eslintrc.cjs");
3-
base["rules"] = { "no-debugger": 0 };
3+
base["rules"] = { "no-debugger": 0, "no-console": 1 };
44
module.exports = base;

example/src/subdir/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ js_library(
1616

1717
js_library(
1818
name = "eslint-override",
19-
srcs = ["index.js"],
19+
srcs = glob(["*.js"]),
2020
)
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Ignored by https://github.com/aspect-build/rules_lint/blob/example/.gitattributes
2+
console.log("This is an intentional lint error");

example/src/subdir/linguist-generated.js

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Ignored by https://github.com/aspect-build/rules_lint/blob/example/.gitattributes
2+
console.log("This is an intentional lint error");

example/test/lint_test.bats

-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ EOF
2828
# Buf
2929
assert_output --partial 'src/file.proto:1:1:Import "src/unused.proto" is unused.'
3030

31-
# Golangci-lint
32-
assert_output --partial 'src/hello.go:13:2: SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck)'
33-
3431
# Vale
3532
assert_output --partial "src/README.md:3:47:Google.We:Try to avoid using first-person plural like 'We'."
3633
}

example/tools/lint/linters.bzl

-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
load("@aspect_rules_lint//lint:buf.bzl", "lint_buf_aspect")
44
load("@aspect_rules_lint//lint:eslint.bzl", "lint_eslint_aspect")
55
load("@aspect_rules_lint//lint:flake8.bzl", "lint_flake8_aspect")
6-
load("@aspect_rules_lint//lint:golangci-lint.bzl", "lint_golangci_aspect")
76
load("@aspect_rules_lint//lint:lint_test.bzl", "lint_test")
87
load("@aspect_rules_lint//lint:pmd.bzl", "lint_pmd_aspect")
98
load("@aspect_rules_lint//lint:ruff.bzl", "lint_ruff_aspect")
@@ -57,13 +56,6 @@ shellcheck = lint_shellcheck_aspect(
5756

5857
shellcheck_test = lint_test(aspect = shellcheck)
5958

60-
golangci_lint = lint_golangci_aspect(
61-
binary = "@multitool//tools/golangci-lint",
62-
config = "@@//:.golangci.yaml",
63-
)
64-
65-
golangci_lint_test = lint_test(aspect = golangci_lint)
66-
6759
vale = lint_vale_aspect(
6860
binary = "@@//tools/lint:vale",
6961
config = "@@//:.vale.ini",

format/private/format.sh

+16-3
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,22 @@ function ls-files {
9494

9595
# TODO: determine which staged changes we should format; avoid formatting unstaged changes
9696
# TODO: try to format only modified regions of the file (where supported)
97-
git ls-files --cached --modified --other --exclude-standard "${patterns[@]}" "${patterns[@]/#/*/}" | {
98-
grep -vE "^$(git ls-files --deleted)$" || true;
99-
}
97+
files=$(git ls-files --cached --modified --other --exclude-standard "${patterns[@]}" "${patterns[@]/#/*/}" | {
98+
grep -vE \
99+
"^$(git ls-files --deleted)$" \
100+
|| true;
101+
})
102+
git_attributes=$(git check-attr -a -- $files)
103+
non_ignored_files=()
104+
for file in $files; do
105+
# Check if any of the attributes we ignore are set for this file.
106+
if ! grep -qE "(^| )$file: (rules_lint_ignored|linguist-generated|gitlab-generated): set($| )" <<< $git_attributes; then
107+
non_ignored_files+=("$file")
108+
fi
109+
done
110+
if [ ${#non_ignored_files[@]} -gt 0 ]; then
111+
echo "${non_ignored_files[@]}"
112+
fi
100113
else
101114
# When given arguments, they are glob patterns of the superset of files to format.
102115
# We just need to filter those so we only select files for this language

lint/BUILD.bazel

-10
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,6 @@ bzl_library(
118118
],
119119
)
120120

121-
bzl_library(
122-
name = "golangci-lint",
123-
srcs = ["golangci-lint.bzl"],
124-
visibility = ["//visibility:public"],
125-
deps = [
126-
"//lint/private:lint_aspect",
127-
"@io_bazel_rules_go//go:def",
128-
],
129-
)
130-
131121
bzl_library(
132122
name = "shellcheck",
133123
srcs = ["shellcheck.bzl"],

lint/golangci-lint.bzl

-104
This file was deleted.

0 commit comments

Comments
 (0)