Skip to content

Commit 3bd775f

Browse files
dylwil3ntBre
andauthored
[ruff] Stabilize checking for file-level directives in unused-noqa (RUF100) (#18497)
Note that the preview behavior was not documented (shame on us!) so the documentation was not modified. --------- Co-authored-by: Brent Westbrook <[email protected]>
1 parent 3ba59e2 commit 3bd775f

File tree

3 files changed

+17
-38
lines changed

3 files changed

+17
-38
lines changed

crates/ruff_linter/src/checkers/noqa.rs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use crate::fix::edits::delete_comment;
1212
use crate::noqa::{
1313
Code, Directive, FileExemption, FileNoqaDirectives, NoqaDirectives, NoqaMapping,
1414
};
15-
use crate::preview::is_check_file_level_directives_enabled;
1615
use crate::registry::{AsRule, Rule, RuleSet};
1716
use crate::rule_redirects::get_redirect_target;
1817
use crate::rules::pygrep_hooks;
@@ -112,25 +111,16 @@ pub(crate) fn check_noqa(
112111
&& !exemption.includes(Rule::UnusedNOQA)
113112
&& !per_file_ignores.contains(Rule::UnusedNOQA)
114113
{
115-
let directives: Vec<_> = if is_check_file_level_directives_enabled(settings) {
116-
noqa_directives
117-
.lines()
118-
.iter()
119-
.map(|line| (&line.directive, &line.matches, false))
120-
.chain(
121-
file_noqa_directives
122-
.lines()
123-
.iter()
124-
.map(|line| (&line.parsed_file_exemption, &line.matches, true)),
125-
)
126-
.collect()
127-
} else {
128-
noqa_directives
129-
.lines()
130-
.iter()
131-
.map(|line| (&line.directive, &line.matches, false))
132-
.collect()
133-
};
114+
let directives = noqa_directives
115+
.lines()
116+
.iter()
117+
.map(|line| (&line.directive, &line.matches, false))
118+
.chain(
119+
file_noqa_directives
120+
.lines()
121+
.iter()
122+
.map(|line| (&line.parsed_file_exemption, &line.matches, true)),
123+
);
134124
for (directive, matches, is_file_level) in directives {
135125
match directive {
136126
Directive::All(directive) => {

crates/ruff_linter/src/preview.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,6 @@ pub(crate) const fn is_allow_nested_roots_enabled(settings: &LinterSettings) ->
109109
settings.preview.is_enabled()
110110
}
111111

112-
// https://github.com/astral-sh/ruff/pull/17061
113-
pub(crate) const fn is_check_file_level_directives_enabled(settings: &LinterSettings) -> bool {
114-
settings.preview.is_enabled()
115-
}
116-
117112
// https://github.com/astral-sh/ruff/pull/18208
118113
pub(crate) const fn is_multiple_with_statements_fix_safe_enabled(
119114
settings: &LinterSettings,

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,7 @@ mod tests {
324324
fn ruff_noqa_filedirective_unused() -> Result<()> {
325325
let diagnostics = test_path(
326326
Path::new("ruff/RUF100_6.py"),
327-
&settings::LinterSettings {
328-
preview: PreviewMode::Enabled,
329-
..settings::LinterSettings::for_rules(vec![Rule::UnusedNOQA])
330-
},
327+
&settings::LinterSettings::for_rules(vec![Rule::UnusedNOQA]),
331328
)?;
332329
assert_messages!(diagnostics);
333330
Ok(())
@@ -337,15 +334,12 @@ mod tests {
337334
fn ruff_noqa_filedirective_unused_last_of_many() -> Result<()> {
338335
let diagnostics = test_path(
339336
Path::new("ruff/RUF100_7.py"),
340-
&settings::LinterSettings {
341-
preview: PreviewMode::Enabled,
342-
..settings::LinterSettings::for_rules(vec![
343-
Rule::UnusedNOQA,
344-
Rule::FStringMissingPlaceholders,
345-
Rule::LineTooLong,
346-
Rule::UnusedVariable,
347-
])
348-
},
337+
&settings::LinterSettings::for_rules(vec![
338+
Rule::UnusedNOQA,
339+
Rule::FStringMissingPlaceholders,
340+
Rule::LineTooLong,
341+
Rule::UnusedVariable,
342+
]),
349343
)?;
350344
assert_messages!(diagnostics);
351345
Ok(())

0 commit comments

Comments
 (0)