Skip to content

Commit ecbe562

Browse files
committed
Preview guard changes to file-level RUF100
1 parent 7ab4d6c commit ecbe562

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

crates/ruff_linter/src/checkers/noqa.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,25 @@ pub(crate) fn check_noqa(
110110
&& !exemption.includes(Rule::UnusedNOQA)
111111
&& !per_file_ignores.contains(Rule::UnusedNOQA)
112112
{
113-
let directives = noqa_directives
114-
.lines()
115-
.iter()
116-
.map(|line| (&line.directive, &line.matches, false))
117-
.chain(
118-
file_noqa_directives
119-
.lines()
120-
.iter()
121-
.map(|line| (&line.parsed_file_exemption, &line.matches, true)),
122-
);
113+
let directives: Vec<_> = if settings.preview.is_enabled() {
114+
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+
)
124+
.collect()
125+
} else {
126+
noqa_directives
127+
.lines()
128+
.iter()
129+
.map(|line| (&line.directive, &line.matches, false))
130+
.collect()
131+
};
123132
for (directive, matches, is_file_level) in directives {
124133
match directive {
125134
Directive::All(directive) => {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,10 @@ mod tests {
318318
fn ruff_noqa_filedirective_unused() -> Result<()> {
319319
let diagnostics = test_path(
320320
Path::new("ruff/RUF100_6.py"),
321-
&settings::LinterSettings::for_rules(vec![Rule::UnusedNOQA]),
321+
&settings::LinterSettings {
322+
preview: PreviewMode::Enabled,
323+
..settings::LinterSettings::for_rules(vec![Rule::UnusedNOQA])
324+
},
322325
)?;
323326
assert_messages!(diagnostics);
324327
Ok(())

0 commit comments

Comments
 (0)