Make noqa parsing consistent and more robust (#16483)

# Summary
The goal of this PR is to address various issues around parsing
suppression comments by

1. Unifying the logic used to parse in-line (`# noqa`) and file-level
(`# ruff: noqa`) noqa comments
2. Recovering from certain errors and surfacing warnings in these cases

Closes #15682 
Supersedes #12811 
Addresses
https://github.com/astral-sh/ruff/pull/14229#discussion_r1835481018
Related: #14229 , #12809
This commit is contained in:
Dylan 2025-03-11 14:50:32 -05:00 committed by Micha Reiser
parent a04347b7a3
commit 8bd140c99d
57 changed files with 1547 additions and 829 deletions

View File

@ -19,5 +19,6 @@ def f():
def f(): def f():
# Only `E741` should be ignored by the `noqa`. # Neither of these are ignored and warning is
# logged to user
I = 1 # noqa: E741.F841 I = 1 # noqa: E741.F841

View File

@ -293,7 +293,14 @@ impl<'a> Checker<'a> {
if !self.noqa.is_enabled() { if !self.noqa.is_enabled() {
return false; return false;
} }
noqa::rule_is_ignored(code, offset, self.noqa_line_for, self.locator)
noqa::rule_is_ignored(
code,
offset,
self.noqa_line_for,
self.comment_ranges(),
self.locator,
)
} }
/// Create a [`Generator`] to generate source code based on the current AST state. /// Create a [`Generator`] to generate source code based on the current AST state.

View File

@ -38,7 +38,8 @@ pub(crate) fn check_noqa(
let exemption = FileExemption::from(&file_noqa_directives); let exemption = FileExemption::from(&file_noqa_directives);
// Extract all `noqa` directives. // Extract all `noqa` directives.
let mut noqa_directives = NoqaDirectives::from_commented_ranges(comment_ranges, path, locator); let mut noqa_directives =
NoqaDirectives::from_commented_ranges(comment_ranges, &settings.external, path, locator);
// Indices of diagnostics that were ignored by a `noqa` directive. // Indices of diagnostics that were ignored by a `noqa` directive.
let mut ignored_diagnostics = vec![]; let mut ignored_diagnostics = vec![];

File diff suppressed because it is too large Load Diff

View File

@ -3,7 +3,7 @@ use ruff_macros::{derive_message_formats, ViolationMetadata};
use ruff_python_trivia::Cursor; use ruff_python_trivia::Cursor;
use ruff_text_size::{Ranged, TextRange}; use ruff_text_size::{Ranged, TextRange};
use crate::noqa::{Directive, FileNoqaDirectives, NoqaDirectives, ParsedFileExemption}; use crate::noqa::{self, Directive, FileNoqaDirectives, NoqaDirectives};
use crate::settings::types::PreviewMode; use crate::settings::types::PreviewMode;
use crate::Locator; use crate::Locator;
@ -46,7 +46,6 @@ use crate::Locator;
#[derive(ViolationMetadata)] #[derive(ViolationMetadata)]
pub(crate) struct BlanketNOQA { pub(crate) struct BlanketNOQA {
missing_colon: bool, missing_colon: bool,
space_before_colon: bool,
file_exemption: bool, file_exemption: bool,
} }
@ -57,27 +56,22 @@ impl Violation for BlanketNOQA {
fn message(&self) -> String { fn message(&self) -> String {
let BlanketNOQA { let BlanketNOQA {
missing_colon, missing_colon,
space_before_colon,
file_exemption, file_exemption,
} = self; } = self;
// This awkward branching is necessary to ensure that the generic message is picked up by // This awkward branching is necessary to ensure that the generic message is picked up by
// `derive_message_formats`. // `derive_message_formats`.
if !missing_colon && !space_before_colon && !file_exemption { if !missing_colon && !file_exemption {
"Use specific rule codes when using `noqa`".to_string() "Use specific rule codes when using `noqa`".to_string()
} else if *file_exemption { } else if *file_exemption {
"Use specific rule codes when using `ruff: noqa`".to_string() "Use specific rule codes when using `ruff: noqa`".to_string()
} else if *missing_colon {
"Use a colon when specifying `noqa` rule codes".to_string()
} else { } else {
"Do not add spaces between `noqa` and its colon".to_string() "Use a colon when specifying `noqa` rule codes".to_string()
} }
} }
fn fix_title(&self) -> Option<String> { fn fix_title(&self) -> Option<String> {
if self.missing_colon { if self.missing_colon {
Some("Add missing colon".to_string()) Some("Add missing colon".to_string())
} else if self.space_before_colon {
Some("Remove space(s) before colon".to_string())
} else { } else {
None None
} }
@ -94,11 +88,10 @@ pub(crate) fn blanket_noqa(
) { ) {
if preview.is_enabled() { if preview.is_enabled() {
for line in file_noqa_directives.lines() { for line in file_noqa_directives.lines() {
if let ParsedFileExemption::All = line.parsed_file_exemption { if let Directive::All(_) = line.parsed_file_exemption {
diagnostics.push(Diagnostic::new( diagnostics.push(Diagnostic::new(
BlanketNOQA { BlanketNOQA {
missing_colon: false, missing_colon: false,
space_before_colon: false,
file_exemption: true, file_exemption: true,
}, },
line.range(), line.range(),
@ -116,22 +109,7 @@ pub(crate) fn blanket_noqa(
let mut cursor = Cursor::new(&line[noqa_end.to_usize()..]); let mut cursor = Cursor::new(&line[noqa_end.to_usize()..]);
cursor.eat_while(char::is_whitespace); cursor.eat_while(char::is_whitespace);
// Check for extraneous spaces before the colon. if noqa::lex_codes(cursor.chars().as_str()).is_ok_and(|codes| !codes.is_empty()) {
// Ex) `# noqa : F401`
if cursor.first() == ':' {
let start = all.end();
let end = start + cursor.token_len();
let mut diagnostic = Diagnostic::new(
BlanketNOQA {
missing_colon: false,
space_before_colon: true,
file_exemption: false,
},
TextRange::new(all.start(), end),
);
diagnostic.set_fix(Fix::unsafe_edit(Edit::deletion(start, end)));
diagnostics.push(diagnostic);
} else if Directive::lex_code(cursor.chars().as_str()).is_some() {
// Check for a missing colon. // Check for a missing colon.
// Ex) `# noqa F401` // Ex) `# noqa F401`
let start = all.end(); let start = all.end();
@ -139,7 +117,6 @@ pub(crate) fn blanket_noqa(
let mut diagnostic = Diagnostic::new( let mut diagnostic = Diagnostic::new(
BlanketNOQA { BlanketNOQA {
missing_colon: true, missing_colon: true,
space_before_colon: false,
file_exemption: false, file_exemption: false,
}, },
TextRange::new(all.start(), end), TextRange::new(all.start(), end),
@ -151,7 +128,6 @@ pub(crate) fn blanket_noqa(
diagnostics.push(Diagnostic::new( diagnostics.push(Diagnostic::new(
BlanketNOQA { BlanketNOQA {
missing_colon: false, missing_colon: false,
space_before_colon: false,
file_exemption: false, file_exemption: false,
}, },
all.range(), all.range(),

View File

@ -68,58 +68,3 @@ PGH004_0.py:21:8: PGH004 [*] Use a colon when specifying `noqa` rule codes
22 22 | 22 22 |
23 23 | # PGH004 23 23 | # PGH004
24 24 | x = 2 # noqa : X300 24 24 | x = 2 # noqa : X300
PGH004_0.py:24:8: PGH004 [*] Do not add spaces between `noqa` and its colon
|
23 | # PGH004
24 | x = 2 # noqa : X300
| ^^^^^^^ PGH004
25 |
26 | # PGH004
|
= help: Remove space(s) before colon
Unsafe fix
21 21 | x = 2 # noqa X100, X200
22 22 |
23 23 | # PGH004
24 |-x = 2 # noqa : X300
24 |+x = 2 # noqa: X300
25 25 |
26 26 | # PGH004
27 27 | x = 2 # noqa : X400
PGH004_0.py:27:8: PGH004 [*] Do not add spaces between `noqa` and its colon
|
26 | # PGH004
27 | x = 2 # noqa : X400
| ^^^^^^^^ PGH004
28 |
29 | # PGH004
|
= help: Remove space(s) before colon
Unsafe fix
24 24 | x = 2 # noqa : X300
25 25 |
26 26 | # PGH004
27 |-x = 2 # noqa : X400
27 |+x = 2 # noqa: X400
28 28 |
29 29 | # PGH004
30 30 | x = 2 # noqa :X500
PGH004_0.py:30:8: PGH004 [*] Do not add spaces between `noqa` and its colon
|
29 | # PGH004
30 | x = 2 # noqa :X500
| ^^^^^^^ PGH004
|
= help: Remove space(s) before colon
Unsafe fix
27 27 | x = 2 # noqa : X400
28 28 |
29 29 | # PGH004
30 |-x = 2 # noqa :X500
30 |+x = 2 # noqa:X500

View File

@ -2,7 +2,7 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix};
use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_macros::{derive_message_formats, ViolationMetadata};
use ruff_text_size::Ranged; use ruff_text_size::Ranged;
use crate::noqa::{Codes, Directive, FileNoqaDirectives, NoqaDirectives, ParsedFileExemption}; use crate::noqa::{Codes, Directive, FileNoqaDirectives, NoqaDirectives};
use crate::rule_redirects::get_redirect_target; use crate::rule_redirects::get_redirect_target;
/// ## What it does /// ## What it does
@ -59,7 +59,7 @@ pub(crate) fn redirected_file_noqa(
noqa_directives: &FileNoqaDirectives, noqa_directives: &FileNoqaDirectives,
) { ) {
for line in noqa_directives.lines() { for line in noqa_directives.lines() {
let ParsedFileExemption::Codes(codes) = &line.parsed_file_exemption else { let Directive::Codes(codes) = &line.parsed_file_exemption else {
continue; continue;
}; };

View File

@ -1,19 +1,26 @@
--- ---
source: crates/ruff_linter/src/rules/ruff/mod.rs source: crates/ruff_linter/src/rules/ruff/mod.rs
snapshot_kind: text
--- ---
noqa.py:23:5: F841 [*] Local variable `I` is assigned to but never used noqa.py:24:5: E741 Ambiguous variable name: `I`
| |
21 | def f(): 22 | # Neither of these are ignored and warning is
22 | # Only `E741` should be ignored by the `noqa`. 23 | # logged to user
23 | I = 1 # noqa: E741.F841 24 | I = 1 # noqa: E741.F841
| ^ E741
|
noqa.py:24:5: F841 [*] Local variable `I` is assigned to but never used
|
22 | # Neither of these are ignored and warning is
23 | # logged to user
24 | I = 1 # noqa: E741.F841
| ^ F841 | ^ F841
| |
= help: Remove assignment to unused variable `I` = help: Remove assignment to unused variable `I`
Unsafe fix Unsafe fix
20 20 |
21 21 | def f(): 21 21 | def f():
22 22 | # Only `E741` should be ignored by the `noqa`. 22 22 | # Neither of these are ignored and warning is
23 |- I = 1 # noqa: E741.F841 23 23 | # logged to user
23 |+ pass # noqa: E741.F841 24 |- I = 1 # noqa: E741.F841
24 |+ pass # noqa: E741.F841

View File

@ -1,10 +1,16 @@
--- ---
source: crates/ruff_linter/src/noqa.rs source: crates/ruff_linter/src/noqa.rs
expression: "ParsedFileExemption::try_extract(TextRange::up_to(source.text_len()), source,)" expression: exemption
snapshot_kind: text
--- ---
Ok( Ok(
Some( Some(
All, NoqaLexerOutput {
warnings: [],
directive: All(
All {
range: 0..14,
},
),
},
), ),
) )

View File

@ -1,10 +1,16 @@
--- ---
source: crates/ruff_linter/src/noqa.rs source: crates/ruff_linter/src/noqa.rs
expression: "ParsedFileExemption::try_extract(TextRange::up_to(source.text_len()), source,)" expression: exemption
snapshot_kind: text
--- ---
Ok( Ok(
Some( Some(
All, NoqaLexerOutput {
warnings: [],
directive: All(
All {
range: 0..14,
},
),
},
), ),
) )

View File

@ -1,10 +1,16 @@
--- ---
source: crates/ruff_linter/src/noqa.rs source: crates/ruff_linter/src/noqa.rs
expression: "ParsedFileExemption::try_extract(TextRange::up_to(source.text_len()), source,)" expression: exemption
snapshot_kind: text
--- ---
Ok( Ok(
Some( Some(
All, NoqaLexerOutput {
warnings: [],
directive: All(
All {
range: 0..12,
},
),
},
), ),
) )

View File

@ -1,24 +1,26 @@
--- ---
source: crates/ruff_linter/src/noqa.rs source: crates/ruff_linter/src/noqa.rs
expression: "ParsedFileExemption::try_extract(TextRange::up_to(source.text_len()), source,)" expression: exemption
snapshot_kind: text
--- ---
Ok( Ok(
Some( Some(
Codes( NoqaLexerOutput {
Codes { warnings: [],
range: 0..26, directive: Codes(
codes: [ Codes {
Code { range: 0..26,
code: "F401", codes: [
range: 16..20, Code {
}, code: "F401",
Code { range: 16..20,
code: "F841", },
range: 22..26, Code {
}, code: "F841",
], range: 22..26,
}, },
), ],
},
),
},
), ),
) )

View File

@ -1,14 +1,16 @@
--- ---
source: crates/ruff_linter/src/noqa.rs source: crates/ruff_linter/src/noqa.rs
expression: "Directive::try_extract(source, TextSize::default())" expression: directive
snapshot_kind: text
--- ---
Ok( Ok(
Some( Some(
All( NoqaLexerOutput {
All { warnings: [],
range: 0..6, directive: All(
}, All {
), range: 0..6,
},
),
},
), ),
) )

View File

@ -1,14 +1,16 @@
--- ---
source: crates/ruff_linter/src/noqa.rs source: crates/ruff_linter/src/noqa.rs
expression: "Directive::try_extract(source, TextSize::default())" expression: directive
snapshot_kind: text
--- ---
Ok( Ok(
Some( Some(
All( NoqaLexerOutput {
All { warnings: [],
range: 0..6, directive: All(
}, All {
), range: 0..6,
},
),
},
), ),
) )

View File

@ -1,14 +1,16 @@
--- ---
source: crates/ruff_linter/src/noqa.rs source: crates/ruff_linter/src/noqa.rs
expression: "Directive::try_extract(source, TextSize::default())" expression: directive
snapshot_kind: text
--- ---
Ok( Ok(
Some( Some(
All( NoqaLexerOutput {
All { warnings: [],
range: 35..41, directive: All(
}, All {
), range: 35..41,
},
),
},
), ),
) )

View File

@ -1,14 +1,16 @@
--- ---
source: crates/ruff_linter/src/noqa.rs source: crates/ruff_linter/src/noqa.rs
expression: "Directive::try_extract(source, TextSize::default())" expression: directive
snapshot_kind: text
--- ---
Ok( Ok(
Some( Some(
All( NoqaLexerOutput {
All { warnings: [],
range: 0..7, directive: All(
}, All {
), range: 0..7,
},
),
},
), ),
) )

View File

@ -1,14 +1,16 @@
--- ---
source: crates/ruff_linter/src/noqa.rs source: crates/ruff_linter/src/noqa.rs
expression: "Directive::try_extract(source, TextSize::default())" expression: directive
snapshot_kind: text
--- ---
Ok( Ok(
Some( Some(
All( NoqaLexerOutput {
All { warnings: [],
range: 0..5, directive: All(
}, All {
), range: 0..5,
},
),
},
), ),
) )

View File

@ -1,14 +1,16 @@
--- ---
source: crates/ruff_linter/src/noqa.rs source: crates/ruff_linter/src/noqa.rs
expression: "Directive::try_extract(source, TextSize::default())" expression: directive
snapshot_kind: text
--- ---
Ok( Ok(
Some( Some(
All( NoqaLexerOutput {
All { warnings: [],
range: 0..6, directive: All(
}, All {
), range: 0..6,
},
),
},
), ),
) )

View File

@ -1,20 +1,22 @@
--- ---
source: crates/ruff_linter/src/noqa.rs source: crates/ruff_linter/src/noqa.rs
expression: "Directive::try_extract(source, TextSize::default())" expression: directive
snapshot_kind: text
--- ---
Ok( Ok(
Some( Some(
Codes( NoqaLexerOutput {
Codes { warnings: [],
range: 0..12, directive: Codes(
codes: [ Codes {
Code { range: 0..12,
code: "F401", codes: [
range: 8..12, Code {
}, code: "F401",
], range: 8..12,
}, },
), ],
},
),
},
), ),
) )

View File

@ -1,20 +1,22 @@
--- ---
source: crates/ruff_linter/src/noqa.rs source: crates/ruff_linter/src/noqa.rs
expression: "Directive::try_extract(source, TextSize::default())" expression: directive
snapshot_kind: text
--- ---
Ok( Ok(
Some( Some(
Codes( NoqaLexerOutput {
Codes { warnings: [],
range: 0..12, directive: Codes(
codes: [ Codes {
Code { range: 0..12,
code: "F401", codes: [
range: 8..12, Code {
}, code: "F401",
], range: 8..12,
}, },
), ],
},
),
},
), ),
) )

View File

@ -0,0 +1,7 @@
---
source: crates/ruff_linter/src/noqa.rs
expression: directive
---
Err(
InvalidCodeSuffix,
)

View File

@ -1,20 +1,22 @@
--- ---
source: crates/ruff_linter/src/noqa.rs source: crates/ruff_linter/src/noqa.rs
expression: "Directive::try_extract(source, TextSize::default())" expression: directive
snapshot_kind: text
--- ---
Ok( Ok(
Some( Some(
Codes( NoqaLexerOutput {
Codes { warnings: [],
range: 35..47, directive: Codes(
codes: [ Codes {
Code { range: 35..47,
code: "F401", codes: [
range: 43..47, Code {
}, code: "F401",
], range: 43..47,
}, },
), ],
},
),
},
), ),
) )

View File

@ -0,0 +1,22 @@
---
source: crates/ruff_linter/src/noqa.rs
expression: directive
---
Ok(
Some(
NoqaLexerOutput {
warnings: [],
directive: Codes(
Codes {
range: 2..13,
codes: [
Code {
code: "F401",
range: 9..13,
},
],
},
),
},
),
)

View File

@ -0,0 +1,22 @@
---
source: crates/ruff_linter/src/noqa.rs
expression: directive
---
Ok(
Some(
NoqaLexerOutput {
warnings: [],
directive: Codes(
Codes {
range: 6..18,
codes: [
Code {
code: "F401",
range: 14..18,
},
],
},
),
},
),
)

View File

@ -1,20 +1,22 @@
--- ---
source: crates/ruff_linter/src/noqa.rs source: crates/ruff_linter/src/noqa.rs
expression: "Directive::try_extract(source, TextSize::default())" expression: directive
snapshot_kind: text
--- ---
Ok( Ok(
Some( Some(
Codes( NoqaLexerOutput {
Codes { warnings: [],
range: 0..13, directive: Codes(
codes: [ Codes {
Code { range: 0..13,
code: "F401", codes: [
range: 9..13, Code {
}, code: "F401",
], range: 9..13,
}, },
), ],
},
),
},
), ),
) )

View File

@ -1,20 +1,22 @@
--- ---
source: crates/ruff_linter/src/noqa.rs source: crates/ruff_linter/src/noqa.rs
expression: "Directive::try_extract(source, TextSize::default())" expression: directive
snapshot_kind: text
--- ---
Ok( Ok(
Some( Some(
Codes( NoqaLexerOutput {
Codes { warnings: [],
range: 0..10, directive: Codes(
codes: [ Codes {
Code { range: 0..10,
code: "F401", codes: [
range: 6..10, Code {
}, code: "F401",
], range: 6..10,
}, },
), ],
},
),
},
), ),
) )

View File

@ -1,20 +1,22 @@
--- ---
source: crates/ruff_linter/src/noqa.rs source: crates/ruff_linter/src/noqa.rs
expression: "Directive::try_extract(source, TextSize::default())" expression: directive
snapshot_kind: text
--- ---
Ok( Ok(
Some( Some(
Codes( NoqaLexerOutput {
Codes { warnings: [],
range: 0..12, directive: Codes(
codes: [ Codes {
Code { range: 0..12,
code: "F401", codes: [
range: 8..12, Code {
}, code: "F401",
], range: 8..12,
}, },
), ],
},
),
},
), ),
) )

View File

@ -1,24 +1,26 @@
--- ---
source: crates/ruff_linter/src/noqa.rs source: crates/ruff_linter/src/noqa.rs
expression: "Directive::try_extract(source, TextSize::default())" expression: directive
snapshot_kind: text
--- ---
Ok( Ok(
Some( Some(
Codes( NoqaLexerOutput {
Codes { warnings: [],
range: 0..18, directive: Codes(
codes: [ Codes {
Code { range: 0..18,
code: "F401", codes: [
range: 8..12, Code {
}, code: "F401",
Code { range: 8..12,
code: "F841", },
range: 14..18, Code {
}, code: "F841",
], range: 14..18,
}, },
), ],
},
),
},
), ),
) )

View File

@ -1,24 +1,26 @@
--- ---
source: crates/ruff_linter/src/noqa.rs source: crates/ruff_linter/src/noqa.rs
expression: "Directive::try_extract(source, TextSize::default())" expression: directive
snapshot_kind: text
--- ---
Ok( Ok(
Some( Some(
Codes( NoqaLexerOutput {
Codes { warnings: [],
range: 0..18, directive: Codes(
codes: [ Codes {
Code { range: 0..18,
code: "F401", codes: [
range: 8..12, Code {
}, code: "F401",
Code { range: 8..12,
code: "F841", },
range: 14..18, Code {
}, code: "F841",
], range: 14..18,
}, },
), ],
},
),
},
), ),
) )

View File

@ -1,24 +1,26 @@
--- ---
source: crates/ruff_linter/src/noqa.rs source: crates/ruff_linter/src/noqa.rs
expression: "Directive::try_extract(source, TextSize::default())" expression: directive
snapshot_kind: text
--- ---
Ok( Ok(
Some( Some(
Codes( NoqaLexerOutput {
Codes { warnings: [],
range: 35..53, directive: Codes(
codes: [ Codes {
Code { range: 35..53,
code: "F401", codes: [
range: 43..47, Code {
}, code: "F401",
Code { range: 43..47,
code: "F841", },
range: 49..53, Code {
}, code: "F841",
], range: 49..53,
}, },
), ],
},
),
},
), ),
) )

View File

@ -1,24 +1,26 @@
--- ---
source: crates/ruff_linter/src/noqa.rs source: crates/ruff_linter/src/noqa.rs
expression: "Directive::try_extract(source, TextSize::default())" expression: directive
snapshot_kind: text
--- ---
Ok( Ok(
Some( Some(
Codes( NoqaLexerOutput {
Codes { warnings: [],
range: 0..20, directive: Codes(
codes: [ Codes {
Code { range: 0..20,
code: "F401", codes: [
range: 9..13, Code {
}, code: "F401",
Code { range: 9..13,
code: "F841", },
range: 16..20, Code {
}, code: "F841",
], range: 16..20,
}, },
), ],
},
),
},
), ),
) )

View File

@ -1,24 +1,26 @@
--- ---
source: crates/ruff_linter/src/noqa.rs source: crates/ruff_linter/src/noqa.rs
expression: "Directive::try_extract(source, TextSize::default())" expression: directive
snapshot_kind: text
--- ---
Ok( Ok(
Some( Some(
Codes( NoqaLexerOutput {
Codes { warnings: [],
range: 0..15, directive: Codes(
codes: [ Codes {
Code { range: 0..15,
code: "F401", codes: [
range: 6..10, Code {
}, code: "F401",
Code { range: 6..10,
code: "F841", },
range: 11..15, Code {
}, code: "F841",
], range: 11..15,
}, },
), ],
},
),
},
), ),
) )

View File

@ -1,24 +1,26 @@
--- ---
source: crates/ruff_linter/src/noqa.rs source: crates/ruff_linter/src/noqa.rs
expression: "Directive::try_extract(source, TextSize::default())" expression: directive
snapshot_kind: text
--- ---
Ok( Ok(
Some( Some(
Codes( NoqaLexerOutput {
Codes { warnings: [],
range: 0..18, directive: Codes(
codes: [ Codes {
Code { range: 0..18,
code: "F401", codes: [
range: 8..12, Code {
}, code: "F401",
Code { range: 8..12,
code: "F841", },
range: 14..18, Code {
}, code: "F841",
], range: 14..18,
}, },
), ],
},
),
},
), ),
) )

View File

@ -1,24 +1,30 @@
--- ---
source: crates/ruff_linter/src/noqa.rs source: crates/ruff_linter/src/noqa.rs
expression: "Directive::try_extract(source, TextSize::default())" expression: directive
snapshot_kind: text
--- ---
Ok( Ok(
Some( Some(
Codes( NoqaLexerOutput {
Codes { warnings: [
range: 0..18, MissingItem(
codes: [ 13..13,
Code { ),
code: "F401", ],
range: 8..12, directive: Codes(
}, Codes {
Code { range: 0..18,
code: "F841", codes: [
range: 14..18, Code {
}, code: "F401",
], range: 8..12,
}, },
), Code {
code: "F841",
range: 14..18,
},
],
},
),
},
), ),
) )

View File

@ -1,24 +1,30 @@
--- ---
source: crates/ruff_linter/src/noqa.rs source: crates/ruff_linter/src/noqa.rs
expression: "Directive::try_extract(source, TextSize::default())" expression: directive
snapshot_kind: text
--- ---
Ok( Ok(
Some( Some(
Codes( NoqaLexerOutput {
Codes { warnings: [
range: 0..19, MissingItem(
codes: [ 13..14,
Code { ),
code: "F401", ],
range: 8..12, directive: Codes(
}, Codes {
Code { range: 0..19,
code: "F841", codes: [
range: 15..19, Code {
}, code: "F401",
], range: 8..12,
}, },
), Code {
code: "F841",
range: 15..19,
},
],
},
),
},
), ),
) )

View File

@ -1,20 +1,22 @@
--- ---
source: crates/ruff_linter/src/noqa.rs source: crates/ruff_linter/src/noqa.rs
expression: "Directive::try_extract(source, TextSize::default())" expression: directive
snapshot_kind: text
--- ---
Ok( Ok(
Some( Some(
Codes( NoqaLexerOutput {
Codes { warnings: [],
range: 4..16, directive: Codes(
codes: [ Codes {
Code { range: 4..16,
code: "F401", codes: [
range: 12..16, Code {
}, code: "F401",
], range: 12..16,
}, },
), ],
},
),
},
), ),
) )

View File

@ -0,0 +1,20 @@
---
source: crates/ruff_linter/src/noqa.rs
expression: lex_codes(&source)
---
Ok(
[
Code {
code: "F401",
range: 1..5,
},
Code {
code: "F402",
range: 7..11,
},
Code {
code: "F403",
range: 11..15,
},
],
)

View File

@ -1,20 +1,22 @@
--- ---
source: crates/ruff_linter/src/noqa.rs source: crates/ruff_linter/src/noqa.rs
expression: "Directive::try_extract(source, TextSize::default())" expression: directive
snapshot_kind: text
--- ---
Ok( Ok(
Some( Some(
Codes( NoqaLexerOutput {
Codes { warnings: [],
range: 0..12, directive: Codes(
codes: [ Codes {
Code { range: 0..12,
code: "F401", codes: [
range: 8..12, Code {
}, code: "F401",
], range: 8..12,
}, },
), ],
},
),
},
), ),
) )

View File

@ -1,24 +1,30 @@
--- ---
source: crates/ruff_linter/src/noqa.rs source: crates/ruff_linter/src/noqa.rs
expression: "Directive::try_extract(source, TextSize::default())" expression: directive
snapshot_kind: text
--- ---
Ok( Ok(
Some( Some(
Codes( NoqaLexerOutput {
Codes { warnings: [
range: 0..16, MissingDelimiter(
codes: [ 12..12,
Code { ),
code: "F401", ],
range: 8..12, directive: Codes(
}, Codes {
Code { range: 0..16,
code: "F841", codes: [
range: 12..16, Code {
}, code: "F401",
], range: 8..12,
}, },
), Code {
code: "F841",
range: 12..16,
},
],
},
),
},
), ),
) )

View File

@ -1,20 +1,22 @@
--- ---
source: crates/ruff_linter/src/noqa.rs source: crates/ruff_linter/src/noqa.rs
expression: "Directive::try_extract(source, TextSize::default())" expression: directive
snapshot_kind: text
--- ---
Ok( Ok(
Some( Some(
Codes( NoqaLexerOutput {
Codes { warnings: [],
range: 0..12, directive: Codes(
codes: [ Codes {
Code { range: 0..12,
code: "F401", codes: [
range: 8..12, Code {
}, code: "F401",
], range: 8..12,
}, },
), ],
},
),
},
), ),
) )

View File

@ -1,10 +1,16 @@
--- ---
source: crates/ruff_linter/src/noqa.rs source: crates/ruff_linter/src/noqa.rs
expression: "ParsedFileExemption::try_extract(TextRange::up_to(source.text_len()), source,)" expression: exemption
snapshot_kind: text
--- ---
Ok( Ok(
Some( Some(
All, NoqaLexerOutput {
warnings: [],
directive: All(
All {
range: 0..12,
},
),
},
), ),
) )

View File

@ -1,10 +1,16 @@
--- ---
source: crates/ruff_linter/src/noqa.rs source: crates/ruff_linter/src/noqa.rs
expression: "ParsedFileExemption::try_extract(TextRange::up_to(source.text_len()), source,)" expression: exemption
snapshot_kind: text
--- ---
Ok( Ok(
Some( Some(
All, NoqaLexerOutput {
warnings: [],
directive: All(
All {
range: 0..12,
},
),
},
), ),
) )

View File

@ -0,0 +1,16 @@
---
source: crates/ruff_linter/src/noqa.rs
expression: exemption
---
Ok(
Some(
NoqaLexerOutput {
warnings: [],
directive: All(
All {
range: 18..30,
},
),
},
),
)

View File

@ -1,10 +1,16 @@
--- ---
source: crates/ruff_linter/src/noqa.rs source: crates/ruff_linter/src/noqa.rs
expression: "ParsedFileExemption::try_extract(TextRange::up_to(source.text_len()), source,)" expression: exemption
snapshot_kind: text
--- ---
Ok( Ok(
Some( Some(
All, NoqaLexerOutput {
warnings: [],
directive: All(
All {
range: 0..10,
},
),
},
), ),
) )

View File

@ -0,0 +1,16 @@
---
source: crates/ruff_linter/src/noqa.rs
expression: exemption
---
Ok(
Some(
NoqaLexerOutput {
warnings: [],
directive: All(
All {
range: 0..12,
},
),
},
),
)

View File

@ -0,0 +1,16 @@
---
source: crates/ruff_linter/src/noqa.rs
expression: exemption
---
Ok(
Some(
NoqaLexerOutput {
warnings: [],
directive: All(
All {
range: 0..12,
},
),
},
),
)

View File

@ -0,0 +1,16 @@
---
source: crates/ruff_linter/src/noqa.rs
expression: exemption
---
Ok(
Some(
NoqaLexerOutput {
warnings: [],
directive: All(
All {
range: 0..12,
},
),
},
),
)

View File

@ -0,0 +1,22 @@
---
source: crates/ruff_linter/src/noqa.rs
expression: exemption
---
Ok(
Some(
NoqaLexerOutput {
warnings: [],
directive: Codes(
Codes {
range: 18..36,
codes: [
Code {
code: "F401",
range: 32..36,
},
],
},
),
},
),
)

View File

@ -0,0 +1,22 @@
---
source: crates/ruff_linter/src/noqa.rs
expression: exemption
---
Ok(
Some(
NoqaLexerOutput {
warnings: [],
directive: Codes(
Codes {
range: 0..18,
codes: [
Code {
code: "F401",
range: 14..18,
},
],
},
),
},
),
)

View File

@ -0,0 +1,22 @@
---
source: crates/ruff_linter/src/noqa.rs
expression: exemption
---
Ok(
Some(
NoqaLexerOutput {
warnings: [],
directive: Codes(
Codes {
range: 0..18,
codes: [
Code {
code: "F401",
range: 14..18,
},
],
},
),
},
),
)

View File

@ -0,0 +1,22 @@
---
source: crates/ruff_linter/src/noqa.rs
expression: exemption
---
Ok(
Some(
NoqaLexerOutput {
warnings: [],
directive: Codes(
Codes {
range: 0..18,
codes: [
Code {
code: "F401",
range: 14..18,
},
],
},
),
},
),
)

View File

@ -1,24 +1,26 @@
--- ---
source: crates/ruff_linter/src/noqa.rs source: crates/ruff_linter/src/noqa.rs
expression: "ParsedFileExemption::try_extract(TextRange::up_to(source.text_len()), source,)" expression: exemption
snapshot_kind: text
--- ---
Ok( Ok(
Some( Some(
Codes( NoqaLexerOutput {
Codes { warnings: [],
range: 0..24, directive: Codes(
codes: [ Codes {
Code { range: 0..24,
code: "F401", codes: [
range: 14..18, Code {
}, code: "F401",
Code { range: 14..18,
code: "F841", },
range: 20..24, Code {
}, code: "F841",
], range: 20..24,
}, },
), ],
},
),
},
), ),
) )

View File

@ -0,0 +1,26 @@
---
source: crates/ruff_linter/src/noqa.rs
expression: exemption
---
Ok(
Some(
NoqaLexerOutput {
warnings: [],
directive: Codes(
Codes {
range: 3..27,
codes: [
Code {
code: "F401",
range: 17..21,
},
Code {
code: "F841",
range: 23..27,
},
],
},
),
},
),
)

View File

@ -0,0 +1,30 @@
---
source: crates/ruff_linter/src/noqa.rs
expression: exemption
---
Ok(
Some(
NoqaLexerOutput {
warnings: [
MissingItem(
19..19,
),
],
directive: Codes(
Codes {
range: 0..24,
codes: [
Code {
code: "F401",
range: 14..18,
},
Code {
code: "F841",
range: 20..24,
},
],
},
),
},
),
)

View File

@ -0,0 +1,30 @@
---
source: crates/ruff_linter/src/noqa.rs
expression: exemption
---
Ok(
Some(
NoqaLexerOutput {
warnings: [
MissingItem(
19..20,
),
],
directive: Codes(
Codes {
range: 0..25,
codes: [
Code {
code: "F401",
range: 14..18,
},
Code {
code: "F841",
range: 21..25,
},
],
},
),
},
),
)

View File

@ -0,0 +1,7 @@
---
source: crates/ruff_linter/src/noqa.rs
expression: exemption
---
Err(
InvalidCodeSuffix,
)

View File

@ -0,0 +1,30 @@
---
source: crates/ruff_linter/src/noqa.rs
expression: exemption
---
Ok(
Some(
NoqaLexerOutput {
warnings: [
MissingDelimiter(
18..18,
),
],
directive: Codes(
Codes {
range: 0..22,
codes: [
Code {
code: "F401",
range: 14..18,
},
Code {
code: "F841",
range: 18..22,
},
],
},
),
},
),
)