Skip to content

Commit b2b65e7

Browse files
committed
revert RuleNamespace and NoqaCode::rule changes
from 08a227e in #18391
1 parent b47daff commit b2b65e7

File tree

5 files changed

+13
-32
lines changed

5 files changed

+13
-32
lines changed

crates/ruff_linter/src/registry.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@ pub enum Linter {
215215
}
216216

217217
pub trait RuleNamespace: Sized {
218+
/// Returns the prefix that every single code that ruff uses to identify
219+
/// rules from this linter starts with. In the case that multiple
220+
/// `#[prefix]`es are configured for the variant in the `Linter` enum
221+
/// definition this is the empty string.
222+
fn common_prefix(&self) -> &'static str;
223+
218224
/// Attempts to parse the given rule code. If the prefix is recognized
219225
/// returns the respective variant along with the code with the common
220226
/// prefix stripped.

crates/ruff_linter/src/rule_selector.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ mod schema {
265265
use strum::IntoEnumIterator;
266266

267267
use crate::RuleSelector;
268+
use crate::registry::RuleNamespace;
268269
use crate::rule_selector::{Linter, RuleCodePrefix};
269270

270271
impl JsonSchema for RuleSelector {

crates/ruff_macros/src/map_codes.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,9 @@ fn generate_rule_to_code(linter_to_rules: &BTreeMap<Ident, BTreeMap<String, Rule
254254
}
255255

256256
let mut rule_noqa_code_match_arms = quote!();
257-
let mut noqa_code_rule_match_arms = quote!();
258257
let mut rule_group_match_arms = quote!();
259-
let mut noqa_code_consts = quote!();
260258

261-
for (i, (rule, codes)) in rule_to_codes.into_iter().enumerate() {
259+
for (rule, codes) in rule_to_codes {
262260
let rule_name = rule.segments.last().unwrap();
263261
assert_eq!(
264262
codes.len(),
@@ -294,14 +292,6 @@ See also https://github.com/astral-sh/ruff/issues/2186.
294292
#(#attrs)* Rule::#rule_name => NoqaCode(crate::registry::Linter::#linter.common_prefix(), #code),
295293
});
296294

297-
let const_ident = quote::format_ident!("NOQA_PREFIX_{}", i);
298-
noqa_code_consts.extend(quote! {
299-
const #const_ident: &str = crate::registry::Linter::#linter.common_prefix();
300-
});
301-
noqa_code_rule_match_arms.extend(quote! {
302-
#(#attrs)* NoqaCode(#const_ident, #code) => Some(Rule::#rule_name),
303-
});
304-
305295
rule_group_match_arms.extend(quote! {
306296
#(#attrs)* Rule::#rule_name => #group,
307297
});
@@ -350,16 +340,6 @@ See also https://github.com/astral-sh/ruff/issues/2186.
350340
}
351341
}
352342
}
353-
354-
impl NoqaCode {
355-
pub fn rule(&self) -> Option<Rule> {
356-
#noqa_code_consts
357-
match self {
358-
#noqa_code_rule_match_arms
359-
_ => None
360-
}
361-
}
362-
}
363343
};
364344
rule_to_code
365345
}

crates/ruff_macros/src/rule_namespace.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ pub(crate) fn derive_impl(input: DeriveInput) -> syn::Result<proc_macro2::TokenS
118118
None
119119
}
120120

121+
fn common_prefix(&self) -> &'static str {
122+
match self { #common_prefix_match_arms }
123+
}
124+
121125
fn name(&self) -> &'static str {
122126
match self { #name_match_arms }
123127
}
@@ -126,16 +130,6 @@ pub(crate) fn derive_impl(input: DeriveInput) -> syn::Result<proc_macro2::TokenS
126130
match self { #url_match_arms }
127131
}
128132
}
129-
130-
impl #ident {
131-
/// Returns the prefix that every single code that ruff uses to identify
132-
/// rules from this linter starts with. In the case that multiple
133-
/// `#[prefix]`es are configured for the variant in the `Linter` enum
134-
/// definition this is the empty string.
135-
pub const fn common_prefix(&self) -> &'static str {
136-
match self { #common_prefix_match_arms }
137-
}
138-
}
139133
})
140134
}
141135

crates/ruff_workspace/src/configuration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use ruff_cache::cache_dir;
2222
use ruff_formatter::IndentStyle;
2323
use ruff_graph::{AnalyzeSettings, Direction};
2424
use ruff_linter::line_width::{IndentWidth, LineLength};
25-
use ruff_linter::registry::{INCOMPATIBLE_CODES, Rule, RuleSet};
25+
use ruff_linter::registry::{INCOMPATIBLE_CODES, Rule, RuleNamespace, RuleSet};
2626
use ruff_linter::rule_selector::{PreviewOptions, Specificity};
2727
use ruff_linter::rules::{flake8_import_conventions, isort, pycodestyle};
2828
use ruff_linter::settings::fix_safety_table::FixSafetyTable;

0 commit comments

Comments
 (0)