Skip to content

Commit ada8aa2

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 ee24ede commit ada8aa2

File tree

8 files changed

+42
-5
lines changed

8 files changed

+42
-5
lines changed

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/.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/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("console is not allowed, but this file is ignored");

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("console is not allowed, but this file is ignored");

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

0 commit comments

Comments
 (0)