Skip to content

Commit

Permalink
refactor: Rename ParseCode trait to RuleNamespace
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
not-my-profile authored and charliermarsh committed Jan 22, 2023
1 parent 87443e6 commit c3dd1b0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion ruff_cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use ruff::cache::CACHE_DIR_NAME;
use ruff::linter::add_noqa_to_path;
use ruff::logging::LogLevel;
use ruff::message::{Location, Message};
use ruff::registry::{Linter, ParseCode, Rule};
use ruff::registry::{Linter, Rule, RuleNamespace};
use ruff::resolver::{FileDiscovery, PyprojectDiscovery};
use ruff::settings::flags;
use ruff::settings::types::SerializationFormat;
Expand Down
8 changes: 4 additions & 4 deletions ruff_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use syn::{parse_macro_input, DeriveInput, ItemFn};
mod config;
mod define_rule_mapping;
mod derive_message_formats;
mod parse_code;
mod rule_code_prefix;
mod rule_namespace;

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

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

parse_code::derive_impl(input)
rule_namespace::derive_impl(input)
.unwrap_or_else(syn::Error::into_compile_error)
.into()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn derive_impl(input: DeriveInput) -> syn::Result<proc_macro2::TokenStream>
}

Ok(quote! {
impl crate::registry::ParseCode for #ident {
impl crate::registry::RuleNamespace for #ident {
fn parse_code(code: &str) -> Option<(Self, &str)> {
#if_statements
None
Expand Down
8 changes: 4 additions & 4 deletions src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use itertools::Itertools;
use once_cell::sync::Lazy;
use ruff_macros::ParseCode;
use ruff_macros::RuleNamespace;
use rustc_hash::FxHashMap;
use rustpython_parser::ast::Location;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -439,7 +439,7 @@ ruff_macros::define_rule_mapping!(
RUF100 => violations::UnusedNOQA,
);

#[derive(EnumIter, Debug, PartialEq, Eq, ParseCode)]
#[derive(EnumIter, Debug, PartialEq, Eq, RuleNamespace)]
pub enum Linter {
#[prefix = "F"]
Pyflakes,
Expand Down Expand Up @@ -520,7 +520,7 @@ pub enum Linter {
Ruff,
}

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

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

use super::{Linter, ParseCode, Rule};
use super::{Linter, Rule, RuleNamespace};

#[test]
fn check_code_serialization() {
Expand Down

0 comments on commit c3dd1b0

Please sign in to comment.