mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 12:55:05 +00:00
refactor: Add Copy implementation to Rule (#3556)
This commit is contained in:
parent
aa51ecedc5
commit
eff84442bc
59 changed files with 835 additions and 965 deletions
|
|
@ -16,7 +16,7 @@ struct Explanation<'a> {
|
|||
}
|
||||
|
||||
/// Explain a `Rule` to the user.
|
||||
pub fn rule(rule: &Rule, format: HelpFormat) -> Result<()> {
|
||||
pub fn rule(rule: Rule, format: HelpFormat) -> Result<()> {
|
||||
let (linter, _) = Linter::parse_code(&rule.noqa_code().to_string()).unwrap();
|
||||
let mut stdout = BufWriter::new(io::stdout().lock());
|
||||
let mut output = String::new();
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ pub fn run(
|
|||
":".bold()
|
||||
);
|
||||
let settings = resolver.resolve(path, pyproject_strategy);
|
||||
if settings.rules.enabled(&Rule::IOError) {
|
||||
if settings.rules.enabled(Rule::IOError) {
|
||||
Diagnostics::new(vec![Message::from_diagnostic(
|
||||
Diagnostic::new(
|
||||
IOError { message },
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ quoting the executed command, along with the relevant file contents and `pyproje
|
|||
set_up_logging(&log_level)?;
|
||||
|
||||
match command {
|
||||
Command::Rule { rule, format } => commands::rule::rule(&rule, format)?,
|
||||
Command::Rule { rule, format } => commands::rule::rule(rule, format)?,
|
||||
Command::Config { option } => return Ok(commands::config::config(option.as_deref())),
|
||||
Command::Linter { format } => commands::linter::linter(format)?,
|
||||
Command::Clean => commands::clean::clean(log_level)?,
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ struct ExpandedFix<'a> {
|
|||
|
||||
#[derive(Serialize)]
|
||||
struct ExpandedMessage<'a> {
|
||||
code: SerializeRuleAsCode<'a>,
|
||||
code: SerializeRuleAsCode,
|
||||
message: String,
|
||||
fix: Option<ExpandedFix<'a>>,
|
||||
location: Location,
|
||||
|
|
@ -63,9 +63,9 @@ struct ExpandedStatistics {
|
|||
fixable: bool,
|
||||
}
|
||||
|
||||
struct SerializeRuleAsCode<'a>(&'a Rule);
|
||||
struct SerializeRuleAsCode(Rule);
|
||||
|
||||
impl Serialize for SerializeRuleAsCode<'_> {
|
||||
impl Serialize for SerializeRuleAsCode {
|
||||
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
|
|
@ -74,8 +74,8 @@ impl Serialize for SerializeRuleAsCode<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a Rule> for SerializeRuleAsCode<'a> {
|
||||
fn from(rule: &'a Rule) -> Self {
|
||||
impl From<Rule> for SerializeRuleAsCode {
|
||||
fn from(rule: Rule) -> Self {
|
||||
Self(rule)
|
||||
}
|
||||
}
|
||||
|
|
@ -405,13 +405,13 @@ impl Printer {
|
|||
}
|
||||
|
||||
pub fn write_statistics(&self, diagnostics: &Diagnostics) -> Result<()> {
|
||||
let violations: Vec<&Rule> = diagnostics
|
||||
let violations: Vec<Rule> = diagnostics
|
||||
.messages
|
||||
.iter()
|
||||
.map(|message| message.kind.rule())
|
||||
.sorted()
|
||||
.dedup()
|
||||
.collect::<Vec<_>>();
|
||||
.collect();
|
||||
if violations.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
|
|
@ -537,11 +537,11 @@ impl Printer {
|
|||
}
|
||||
}
|
||||
|
||||
fn group_messages_by_filename(messages: &[Message]) -> BTreeMap<&String, Vec<&Message>> {
|
||||
fn group_messages_by_filename(messages: &[Message]) -> BTreeMap<&str, Vec<&Message>> {
|
||||
let mut grouped_messages = BTreeMap::default();
|
||||
for message in messages {
|
||||
grouped_messages
|
||||
.entry(&message.filename)
|
||||
.entry(message.filename.as_str())
|
||||
.or_insert_with(Vec::new)
|
||||
.push(message);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue