Skip to content

Commit 12e4da0

Browse files
committed
use Vec<NoqaCode> directly instead of constructing a RuleSet
1 parent 098cf09 commit 12e4da0

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

crates/ruff/src/printer.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,8 @@ fn print_fix_summary(writer: &mut dyn Write, fixed: &FixMap) -> Result<()> {
501501
for (rule, count) in table.iter().sorted_by_key(|(.., count)| Reverse(*count)) {
502502
writeln!(
503503
writer,
504-
" {count:>num_digits$} × {} ({})",
505-
rule.noqa_code().to_string().red().bold(),
506-
rule.as_ref(),
504+
" {count:>num_digits$} × {}",
505+
rule.to_string().red().bold(),
507506
)?;
508507
}
509508
}

crates/ruff_linter/src/noqa.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::Locator;
1818
use crate::codes::NoqaCode;
1919
use crate::fs::relativize_path;
2020
use crate::message::OldDiagnostic;
21-
use crate::registry::{Rule, RuleSet};
21+
use crate::registry::Rule;
2222
use crate::rule_redirects::get_redirect_target;
2323

2424
/// Generates an array of edits that matches the length of `messages`.
@@ -780,7 +780,7 @@ fn build_noqa_edits_by_diagnostic(
780780
if let Some(noqa_edit) = generate_noqa_edit(
781781
comment.directive,
782782
comment.line,
783-
RuleSet::from_rule(comment.rule),
783+
vec![comment.rule],
784784
locator,
785785
line_ending,
786786
) {
@@ -829,7 +829,7 @@ fn build_noqa_edits_by_line<'a>(
829829

830830
struct NoqaComment<'a> {
831831
line: TextSize,
832-
rule: Rule,
832+
rule: NoqaCode,
833833
directive: Option<&'a Directive<'a>>,
834834
}
835835

@@ -845,13 +845,11 @@ fn find_noqa_comments<'a>(
845845

846846
// Mark any non-ignored diagnostics.
847847
for message in diagnostics {
848-
let Some(rule) = message.to_rule() else {
848+
let Some(rule) = message.to_noqa_code() else {
849849
comments_by_line.push(None);
850850
continue;
851851
};
852852

853-
let code = rule.noqa_code();
854-
855853
match &exemption {
856854
FileExemption::All(_) => {
857855
// If the file is exempted, don't add any noqa directives.
@@ -860,7 +858,7 @@ fn find_noqa_comments<'a>(
860858
}
861859
FileExemption::Codes(codes) => {
862860
// If the diagnostic is ignored by a global exemption, don't add a noqa directive.
863-
if codes.contains(&&code) {
861+
if codes.contains(&&rule) {
864862
comments_by_line.push(None);
865863
continue;
866864
}
@@ -878,7 +876,7 @@ fn find_noqa_comments<'a>(
878876
continue;
879877
}
880878
Directive::Codes(codes) => {
881-
if codes.includes(code) {
879+
if codes.includes(rule) {
882880
comments_by_line.push(None);
883881
continue;
884882
}
@@ -897,7 +895,7 @@ fn find_noqa_comments<'a>(
897895
continue;
898896
}
899897
directive @ Directive::Codes(codes) => {
900-
if !codes.includes(code) {
898+
if !codes.includes(rule) {
901899
comments_by_line.push(Some(NoqaComment {
902900
line: directive_line.start(),
903901
rule,
@@ -922,7 +920,7 @@ fn find_noqa_comments<'a>(
922920

923921
struct NoqaEdit<'a> {
924922
edit_range: TextRange,
925-
rules: RuleSet,
923+
rules: Vec<NoqaCode>,
926924
codes: Option<&'a Codes<'a>>,
927925
line_ending: LineEnding,
928926
}
@@ -943,16 +941,13 @@ impl NoqaEdit<'_> {
943941
writer,
944942
self.rules
945943
.iter()
946-
.map(|rule| rule.noqa_code().to_string())
944+
.map(ToString::to_string)
947945
.chain(codes.iter().map(ToString::to_string))
948946
.sorted_unstable(),
949947
);
950948
}
951949
None => {
952-
push_codes(
953-
writer,
954-
self.rules.iter().map(|rule| rule.noqa_code().to_string()),
955-
);
950+
push_codes(writer, self.rules.iter().map(ToString::to_string));
956951
}
957952
}
958953
write!(writer, "{}", self.line_ending.as_str()).unwrap();
@@ -968,7 +963,7 @@ impl Ranged for NoqaEdit<'_> {
968963
fn generate_noqa_edit<'a>(
969964
directive: Option<&'a Directive>,
970965
offset: TextSize,
971-
rules: RuleSet,
966+
rules: Vec<NoqaCode>,
972967
locator: &Locator,
973968
line_ending: LineEnding,
974969
) -> Option<NoqaEdit<'a>> {

0 commit comments

Comments
 (0)