Skip to content

Commit c3dd1b0

Browse files
not-my-profilecharliermarsh
authored andcommitted
refactor: Rename ParseCode trait to RuleNamespace
ParseCode was a fitting name since the trait only contained a single parse_code method ... since we now however want to introduce an additional `prefixes` method RuleNamespace is more fitting.
1 parent 87443e6 commit c3dd1b0

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

ruff_cli/src/commands.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use ruff::cache::CACHE_DIR_NAME;
1515
use ruff::linter::add_noqa_to_path;
1616
use ruff::logging::LogLevel;
1717
use ruff::message::{Location, Message};
18-
use ruff::registry::{Linter, ParseCode, Rule};
18+
use ruff::registry::{Linter, Rule, RuleNamespace};
1919
use ruff::resolver::{FileDiscovery, PyprojectDiscovery};
2020
use ruff::settings::flags;
2121
use ruff::settings::types::SerializationFormat;

ruff_macros/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use syn::{parse_macro_input, DeriveInput, ItemFn};
1919
mod config;
2020
mod define_rule_mapping;
2121
mod derive_message_formats;
22-
mod parse_code;
2322
mod rule_code_prefix;
23+
mod rule_namespace;
2424

2525
#[proc_macro_derive(ConfigurationOptions, attributes(option, doc, option_group))]
2626
pub fn derive_config(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
@@ -37,11 +37,11 @@ pub fn define_rule_mapping(item: proc_macro::TokenStream) -> proc_macro::TokenSt
3737
define_rule_mapping::define_rule_mapping(&mapping).into()
3838
}
3939

40-
#[proc_macro_derive(ParseCode, attributes(prefix))]
41-
pub fn derive_rule_code_prefix(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
40+
#[proc_macro_derive(RuleNamespace, attributes(prefix))]
41+
pub fn derive_rule_namespace(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
4242
let input = parse_macro_input!(input as DeriveInput);
4343

44-
parse_code::derive_impl(input)
44+
rule_namespace::derive_impl(input)
4545
.unwrap_or_else(syn::Error::into_compile_error)
4646
.into()
4747
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub fn derive_impl(input: DeriveInput) -> syn::Result<proc_macro2::TokenStream>
4444
}
4545

4646
Ok(quote! {
47-
impl crate::registry::ParseCode for #ident {
47+
impl crate::registry::RuleNamespace for #ident {
4848
fn parse_code(code: &str) -> Option<(Self, &str)> {
4949
#if_statements
5050
None

src/registry.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use itertools::Itertools;
44
use once_cell::sync::Lazy;
5-
use ruff_macros::ParseCode;
5+
use ruff_macros::RuleNamespace;
66
use rustc_hash::FxHashMap;
77
use rustpython_parser::ast::Location;
88
use serde::{Deserialize, Serialize};
@@ -439,7 +439,7 @@ ruff_macros::define_rule_mapping!(
439439
RUF100 => violations::UnusedNOQA,
440440
);
441441

442-
#[derive(EnumIter, Debug, PartialEq, Eq, ParseCode)]
442+
#[derive(EnumIter, Debug, PartialEq, Eq, RuleNamespace)]
443443
pub enum Linter {
444444
#[prefix = "F"]
445445
Pyflakes,
@@ -520,7 +520,7 @@ pub enum Linter {
520520
Ruff,
521521
}
522522

523-
pub trait ParseCode: Sized {
523+
pub trait RuleNamespace: Sized {
524524
fn parse_code(code: &str) -> Option<(Self, &str)>;
525525
}
526526

@@ -742,7 +742,7 @@ pub static CODE_REDIRECTS: Lazy<FxHashMap<&'static str, Rule>> = Lazy::new(|| {
742742
mod tests {
743743
use strum::IntoEnumIterator;
744744

745-
use super::{Linter, ParseCode, Rule};
745+
use super::{Linter, Rule, RuleNamespace};
746746

747747
#[test]
748748
fn check_code_serialization() {

0 commit comments

Comments
 (0)