Skip to content

Commit 8a8cc86

Browse files
authored
fix(ruff): honor exclusions when linting (#483)
* fix(ruff): honor exclusions when linting Without this flag, it will lint files that are excluded by the config file since we pass explicit flags * chore: repro problem with ruff excludes
1 parent 38c0c15 commit 8a8cc86

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

example/.ruff.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exclude = ['test/excluded.py']

example/test/BUILD.bazel

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ py_library(
5252
srcs = ["generated.py"],
5353
)
5454

55+
py_library(
56+
name = "excluded_py",
57+
srcs = ["excluded.py"],
58+
)
59+
5560
java_library(
5661
name = "generated_java",
5762
srcs = ["generated.java"],
@@ -73,6 +78,11 @@ ruff_test(
7378
srcs = [":generated_py"],
7479
)
7580

81+
ruff_test(
82+
name = "ruff_should_ignore_excluded",
83+
srcs = ["excluded_py"],
84+
)
85+
7686
pmd_test(
7787
name = "pmd_should_ignore_generated",
7888
srcs = [":generated_java"],

example/test/excluded.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import os

lint/ruff.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ def ruff_action(ctx, executable, srcs, config, stdout, exit_code = None, env = {
9191
# `ruff help check` to see available options
9292
args = ctx.actions.args()
9393
args.add("check")
94+
# Honor exclusions in pyproject.toml even though we pass explicit list of files
95+
args.add("--force-exclude")
9496
args.add_all(srcs)
9597

9698
if exit_code:
@@ -130,7 +132,7 @@ def ruff_fix(ctx, executable, srcs, config, patch, stdout, exit_code, env = {}):
130132
output = patch_cfg,
131133
content = json.encode({
132134
"linter": executable._ruff.path,
133-
"args": ["check", "--fix"] + [s.path for s in srcs],
135+
"args": ["check", "--fix", "--force-exclude"] + [s.path for s in srcs],
134136
"files_to_diff": [s.path for s in srcs],
135137
"output": patch.path,
136138
}),

0 commit comments

Comments
 (0)