Skip to content

Commit 7c872e6

Browse files
authored
Only run executable rules when they are enabled (#13298)
1 parent 5ef6979 commit 7c872e6

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

crates/ruff_linter/src/checkers/tokens.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,13 @@ pub(crate) fn check_tokens(
154154
Rule::ShebangNotFirstLine,
155155
Rule::ShebangMissingPython,
156156
]) {
157-
flake8_executable::rules::from_tokens(&mut diagnostics, path, locator, comment_ranges);
157+
flake8_executable::rules::from_tokens(
158+
&mut diagnostics,
159+
path,
160+
locator,
161+
comment_ranges,
162+
settings,
163+
);
158164
}
159165

160166
if settings.rules.any_enabled(&[

crates/ruff_linter/src/rules/flake8_executable/rules/mod.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use std::path::Path;
22

3+
use crate::codes::Rule;
4+
use crate::comments::shebang::ShebangDirective;
5+
use crate::settings::LinterSettings;
36
use ruff_diagnostics::Diagnostic;
47
use ruff_python_trivia::CommentRanges;
58
use ruff_source_file::Locator;
@@ -9,8 +12,6 @@ pub(crate) use shebang_missing_python::*;
912
pub(crate) use shebang_not_executable::*;
1013
pub(crate) use shebang_not_first_line::*;
1114

12-
use crate::comments::shebang::ShebangDirective;
13-
1415
mod shebang_leading_whitespace;
1516
mod shebang_missing_executable_file;
1617
mod shebang_missing_python;
@@ -22,6 +23,7 @@ pub(crate) fn from_tokens(
2223
path: &Path,
2324
locator: &Locator,
2425
comment_ranges: &CommentRanges,
26+
settings: &LinterSettings,
2527
) {
2628
let mut has_any_shebang = false;
2729
for range in comment_ranges {
@@ -33,8 +35,10 @@ pub(crate) fn from_tokens(
3335
diagnostics.push(diagnostic);
3436
}
3537

36-
if let Some(diagnostic) = shebang_not_executable(path, range) {
37-
diagnostics.push(diagnostic);
38+
if settings.rules.enabled(Rule::ShebangNotExecutable) {
39+
if let Some(diagnostic) = shebang_not_executable(path, range) {
40+
diagnostics.push(diagnostic);
41+
}
3842
}
3943

4044
if let Some(diagnostic) = shebang_leading_whitespace(range, locator) {
@@ -48,8 +52,10 @@ pub(crate) fn from_tokens(
4852
}
4953

5054
if !has_any_shebang {
51-
if let Some(diagnostic) = shebang_missing_executable_file(path) {
52-
diagnostics.push(diagnostic);
55+
if settings.rules.enabled(Rule::ShebangMissingExecutableFile) {
56+
if let Some(diagnostic) = shebang_missing_executable_file(path) {
57+
diagnostics.push(diagnostic);
58+
}
5359
}
5460
}
5561
}

0 commit comments

Comments
 (0)