Skip to content

Commit ae39f61

Browse files
committed
remove unreachable branch in PGH004 implementation
1 parent d48bb11 commit ae39f61

1 file changed

Lines changed: 3 additions & 28 deletions

File tree

crates/ruff_linter/src/rules/pygrep_hooks/rules/blanket_noqa.rs

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ use crate::Locator;
4646
#[derive(ViolationMetadata)]
4747
pub(crate) struct BlanketNOQA {
4848
missing_colon: bool,
49-
space_before_colon: bool,
5049
file_exemption: bool,
5150
}
5251

@@ -57,27 +56,22 @@ impl Violation for BlanketNOQA {
5756
fn message(&self) -> String {
5857
let BlanketNOQA {
5958
missing_colon,
60-
space_before_colon,
6159
file_exemption,
6260
} = self;
6361
// This awkward branching is necessary to ensure that the generic message is picked up by
6462
// `derive_message_formats`.
65-
if !missing_colon && !space_before_colon && !file_exemption {
63+
if !missing_colon && !file_exemption {
6664
"Use specific rule codes when using `noqa`".to_string()
6765
} else if *file_exemption {
6866
"Use specific rule codes when using `ruff: noqa`".to_string()
69-
} else if *missing_colon {
70-
"Use a colon when specifying `noqa` rule codes".to_string()
7167
} else {
72-
"Do not add spaces between `noqa` and its colon".to_string()
68+
"Use a colon when specifying `noqa` rule codes".to_string()
7369
}
7470
}
7571

7672
fn fix_title(&self) -> Option<String> {
7773
if self.missing_colon {
7874
Some("Add missing colon".to_string())
79-
} else if self.space_before_colon {
80-
Some("Remove space(s) before colon".to_string())
8175
} else {
8276
None
8377
}
@@ -98,7 +92,6 @@ pub(crate) fn blanket_noqa(
9892
diagnostics.push(Diagnostic::new(
9993
BlanketNOQA {
10094
missing_colon: false,
101-
space_before_colon: false,
10295
file_exemption: true,
10396
},
10497
line.range(),
@@ -116,31 +109,14 @@ pub(crate) fn blanket_noqa(
116109
let mut cursor = Cursor::new(&line[noqa_end.to_usize()..]);
117110
cursor.eat_while(char::is_whitespace);
118111

119-
// Check for extraneous spaces before the colon.
120-
// Ex) `# noqa : F401`
121-
if cursor.first() == ':' {
122-
let start = all.end();
123-
let end = start + cursor.token_len();
124-
let mut diagnostic = Diagnostic::new(
125-
BlanketNOQA {
126-
missing_colon: false,
127-
space_before_colon: true,
128-
file_exemption: false,
129-
},
130-
TextRange::new(all.start(), end),
131-
);
132-
diagnostic.set_fix(Fix::unsafe_edit(Edit::deletion(start, end)));
133-
diagnostics.push(diagnostic);
134-
} else if noqa::lex_codes(cursor.chars().as_str()).is_ok_and(|codes| !codes.is_empty())
135-
{
112+
if noqa::lex_codes(cursor.chars().as_str()).is_ok_and(|codes| !codes.is_empty()) {
136113
// Check for a missing colon.
137114
// Ex) `# noqa F401`
138115
let start = all.end();
139116
let end = start + cursor.token_len();
140117
let mut diagnostic = Diagnostic::new(
141118
BlanketNOQA {
142119
missing_colon: true,
143-
space_before_colon: false,
144120
file_exemption: false,
145121
},
146122
TextRange::new(all.start(), end),
@@ -152,7 +128,6 @@ pub(crate) fn blanket_noqa(
152128
diagnostics.push(Diagnostic::new(
153129
BlanketNOQA {
154130
missing_colon: false,
155-
space_before_colon: false,
156131
file_exemption: false,
157132
},
158133
all.range(),

0 commit comments

Comments
 (0)