Skip to content

Commit 2c3f091

Browse files
authored
Rename ruff_linter::Diagnostic to OldDiagnostic (#18355)
Summary -- It's a bit late in the refactoring process, but I think there are still a couple of PRs left before getting rid of this type entirely, so I thought it would still be worth doing. This PR is just a quick rename with no other changes. Test Plan -- Existing tests
1 parent 9d3cad9 commit 2c3f091

File tree

67 files changed

+316
-304
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+316
-304
lines changed

crates/ruff/src/commands/check.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rayon::prelude::*;
1212
use rustc_hash::FxHashMap;
1313

1414
use ruff_db::panic::catch_unwind;
15-
use ruff_linter::Diagnostic;
15+
use ruff_linter::OldDiagnostic;
1616
use ruff_linter::message::Message;
1717
use ruff_linter::package::PackageRoot;
1818
use ruff_linter::registry::Rule;
@@ -131,7 +131,7 @@ pub(crate) fn check(
131131

132132
Diagnostics::new(
133133
vec![Message::from_diagnostic(
134-
Diagnostic::new(IOError { message }, TextRange::default()),
134+
OldDiagnostic::new(IOError { message }, TextRange::default()),
135135
dummy,
136136
None,
137137
)],

crates/ruff/src/diagnostics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use colored::Colorize;
1212
use log::{debug, warn};
1313
use rustc_hash::FxHashMap;
1414

15-
use ruff_linter::Diagnostic;
15+
use ruff_linter::OldDiagnostic;
1616
use ruff_linter::codes::Rule;
1717
use ruff_linter::linter::{FixTable, FixerResult, LinterResult, ParseSource, lint_fix, lint_only};
1818
use ruff_linter::message::Message;
@@ -64,7 +64,7 @@ impl Diagnostics {
6464
let source_file = SourceFileBuilder::new(name, "").finish();
6565
Self::new(
6666
vec![Message::from_diagnostic(
67-
Diagnostic::new(
67+
OldDiagnostic::new(
6868
IOError {
6969
message: err.to_string(),
7070
},

crates/ruff_linter/src/checkers/ast/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ use crate::rules::pyflakes::rules::{
7373
use crate::rules::pylint::rules::{AwaitOutsideAsync, LoadBeforeGlobalDeclaration};
7474
use crate::rules::{flake8_pyi, flake8_type_checking, pyflakes, pyupgrade};
7575
use crate::settings::{LinterSettings, TargetVersion, flags};
76-
use crate::{Diagnostic, Edit, Violation};
76+
use crate::{Edit, OldDiagnostic, Violation};
7777
use crate::{Locator, docstrings, noqa};
7878

7979
mod analyze;
@@ -225,7 +225,7 @@ pub(crate) struct Checker<'a> {
225225
/// A set of deferred nodes to be analyzed after the AST traversal (e.g., `for` loops).
226226
analyze: deferred::Analyze,
227227
/// The cumulative set of diagnostics computed across all lint rules.
228-
diagnostics: RefCell<Vec<Diagnostic>>,
228+
diagnostics: RefCell<Vec<OldDiagnostic>>,
229229
/// The list of names already seen by flake8-bugbear diagnostics, to avoid duplicate violations.
230230
flake8_bugbear_seen: RefCell<FxHashSet<TextRange>>,
231231
/// The end offset of the last visited statement.
@@ -391,7 +391,7 @@ impl<'a> Checker<'a> {
391391
) -> DiagnosticGuard<'chk, 'a> {
392392
DiagnosticGuard {
393393
checker: self,
394-
diagnostic: Some(Diagnostic::new(kind, range)),
394+
diagnostic: Some(OldDiagnostic::new(kind, range)),
395395
}
396396
}
397397

@@ -405,7 +405,7 @@ impl<'a> Checker<'a> {
405405
kind: T,
406406
range: TextRange,
407407
) -> Option<DiagnosticGuard<'chk, 'a>> {
408-
let diagnostic = Diagnostic::new(kind, range);
408+
let diagnostic = OldDiagnostic::new(kind, range);
409409
if self.enabled(diagnostic.rule()) {
410410
Some(DiagnosticGuard {
411411
checker: self,
@@ -2892,7 +2892,7 @@ impl<'a> Checker<'a> {
28922892
if self.semantic.global_scope().uses_star_imports() {
28932893
if self.enabled(Rule::UndefinedLocalWithImportStarUsage) {
28942894
self.diagnostics.get_mut().push(
2895-
Diagnostic::new(
2895+
OldDiagnostic::new(
28962896
pyflakes::rules::UndefinedLocalWithImportStarUsage {
28972897
name: name.to_string(),
28982898
},
@@ -2907,7 +2907,7 @@ impl<'a> Checker<'a> {
29072907
|| !self.path.ends_with("__init__.py")
29082908
{
29092909
self.diagnostics.get_mut().push(
2910-
Diagnostic::new(
2910+
OldDiagnostic::new(
29112911
pyflakes::rules::UndefinedExport {
29122912
name: name.to_string(),
29132913
},
@@ -2975,7 +2975,7 @@ pub(crate) fn check_ast(
29752975
cell_offsets: Option<&CellOffsets>,
29762976
notebook_index: Option<&NotebookIndex>,
29772977
target_version: TargetVersion,
2978-
) -> (Vec<Diagnostic>, Vec<SemanticSyntaxError>) {
2978+
) -> (Vec<OldDiagnostic>, Vec<SemanticSyntaxError>) {
29792979
let module_path = package
29802980
.map(PackageRoot::path)
29812981
.and_then(|package| to_module_path(package, path));
@@ -3062,7 +3062,7 @@ pub(crate) struct DiagnosticGuard<'a, 'b> {
30623062
/// The diagnostic that we want to report.
30633063
///
30643064
/// This is always `Some` until the `Drop` (or `defuse`) call.
3065-
diagnostic: Option<Diagnostic>,
3065+
diagnostic: Option<OldDiagnostic>,
30663066
}
30673067

30683068
impl DiagnosticGuard<'_, '_> {
@@ -3076,17 +3076,17 @@ impl DiagnosticGuard<'_, '_> {
30763076
}
30773077

30783078
impl std::ops::Deref for DiagnosticGuard<'_, '_> {
3079-
type Target = Diagnostic;
3079+
type Target = OldDiagnostic;
30803080

3081-
fn deref(&self) -> &Diagnostic {
3081+
fn deref(&self) -> &OldDiagnostic {
30823082
// OK because `self.diagnostic` is only `None` within `Drop`.
30833083
self.diagnostic.as_ref().unwrap()
30843084
}
30853085
}
30863086

30873087
/// Return a mutable borrow of the diagnostic in this guard.
30883088
impl std::ops::DerefMut for DiagnosticGuard<'_, '_> {
3089-
fn deref_mut(&mut self) -> &mut Diagnostic {
3089+
fn deref_mut(&mut self) -> &mut OldDiagnostic {
30903090
// OK because `self.diagnostic` is only `None` within `Drop`.
30913091
self.diagnostic.as_mut().unwrap()
30923092
}

crates/ruff_linter/src/checkers/filesystem.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use std::path::Path;
33
use ruff_python_ast::PythonVersion;
44
use ruff_python_trivia::CommentRanges;
55

6-
use crate::Diagnostic;
76
use crate::Locator;
7+
use crate::OldDiagnostic;
88
use crate::package::PackageRoot;
99
use crate::preview::is_allow_nested_roots_enabled;
1010
use crate::registry::Rule;
@@ -20,8 +20,8 @@ pub(crate) fn check_file_path(
2020
comment_ranges: &CommentRanges,
2121
settings: &LinterSettings,
2222
target_version: PythonVersion,
23-
) -> Vec<Diagnostic> {
24-
let mut diagnostics: Vec<Diagnostic> = vec![];
23+
) -> Vec<OldDiagnostic> {
24+
let mut diagnostics: Vec<OldDiagnostic> = vec![];
2525

2626
// flake8-no-pep420
2727
if settings.rules.enabled(Rule::ImplicitNamespacePackage) {

crates/ruff_linter/src/checkers/imports.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use ruff_python_codegen::Stylist;
77
use ruff_python_index::Indexer;
88
use ruff_python_parser::Parsed;
99

10-
use crate::Diagnostic;
1110
use crate::Locator;
11+
use crate::OldDiagnostic;
1212
use crate::directives::IsortDirectives;
1313
use crate::package::PackageRoot;
1414
use crate::registry::Rule;
@@ -28,7 +28,7 @@ pub(crate) fn check_imports(
2828
source_type: PySourceType,
2929
cell_offsets: Option<&CellOffsets>,
3030
target_version: PythonVersion,
31-
) -> Vec<Diagnostic> {
31+
) -> Vec<OldDiagnostic> {
3232
// Extract all import blocks from the AST.
3333
let tracker = {
3434
let mut tracker =

crates/ruff_linter/src/checkers/logical_lines.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use ruff_python_parser::{TokenKind, Tokens};
44
use ruff_source_file::LineRanges;
55
use ruff_text_size::{Ranged, TextRange};
66

7-
use crate::Diagnostic;
87
use crate::Locator;
8+
use crate::OldDiagnostic;
99
use crate::line_width::IndentWidth;
1010
use crate::registry::{AsRule, Rule};
1111
use crate::rules::pycodestyle::rules::logical_lines::{
@@ -40,7 +40,7 @@ pub(crate) fn check_logical_lines(
4040
indexer: &Indexer,
4141
stylist: &Stylist,
4242
settings: &LinterSettings,
43-
) -> Vec<Diagnostic> {
43+
) -> Vec<OldDiagnostic> {
4444
let mut context = LogicalLinesContext::new(settings);
4545

4646
let mut prev_line = None;
@@ -196,7 +196,7 @@ pub(crate) fn check_logical_lines(
196196
#[derive(Debug, Clone)]
197197
pub(crate) struct LogicalLinesContext<'a> {
198198
settings: &'a LinterSettings,
199-
diagnostics: Vec<Diagnostic>,
199+
diagnostics: Vec<OldDiagnostic>,
200200
}
201201

202202
impl<'a> LogicalLinesContext<'a> {
@@ -207,7 +207,7 @@ impl<'a> LogicalLinesContext<'a> {
207207
}
208208
}
209209

210-
pub(crate) fn push_diagnostic(&mut self, diagnostic: Diagnostic) {
210+
pub(crate) fn push_diagnostic(&mut self, diagnostic: OldDiagnostic) {
211211
if self.settings.rules.enabled(diagnostic.rule()) {
212212
self.diagnostics.push(diagnostic);
213213
}

crates/ruff_linter/src/checkers/noqa.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ use crate::rules::pygrep_hooks;
2020
use crate::rules::ruff;
2121
use crate::rules::ruff::rules::{UnusedCodes, UnusedNOQA};
2222
use crate::settings::LinterSettings;
23-
use crate::{Diagnostic, Edit, Fix};
23+
use crate::{Edit, Fix, OldDiagnostic};
2424

2525
#[expect(clippy::too_many_arguments)]
2626
pub(crate) fn check_noqa(
27-
diagnostics: &mut Vec<Diagnostic>,
27+
diagnostics: &mut Vec<OldDiagnostic>,
2828
path: &Path,
2929
locator: &Locator,
3030
comment_ranges: &CommentRanges,
@@ -136,7 +136,7 @@ pub(crate) fn check_noqa(
136136
if matches.is_empty() {
137137
let edit = delete_comment(directive.range(), locator);
138138
let mut diagnostic =
139-
Diagnostic::new(UnusedNOQA { codes: None }, directive.range());
139+
OldDiagnostic::new(UnusedNOQA { codes: None }, directive.range());
140140
diagnostic.set_fix(Fix::safe_edit(edit));
141141

142142
diagnostics.push(diagnostic);
@@ -212,7 +212,7 @@ pub(crate) fn check_noqa(
212212
directive.range(),
213213
)
214214
};
215-
let mut diagnostic = Diagnostic::new(
215+
let mut diagnostic = OldDiagnostic::new(
216216
UnusedNOQA {
217217
codes: Some(UnusedCodes {
218218
disabled: disabled_codes

crates/ruff_linter/src/checkers/physical_lines.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use ruff_python_index::Indexer;
55
use ruff_source_file::UniversalNewlines;
66
use ruff_text_size::TextSize;
77

8-
use crate::Diagnostic;
98
use crate::Locator;
9+
use crate::OldDiagnostic;
1010
use crate::registry::Rule;
1111
use crate::rules::flake8_copyright::rules::missing_copyright_notice;
1212
use crate::rules::pycodestyle::rules::{
@@ -23,8 +23,8 @@ pub(crate) fn check_physical_lines(
2323
indexer: &Indexer,
2424
doc_lines: &[TextSize],
2525
settings: &LinterSettings,
26-
) -> Vec<Diagnostic> {
27-
let mut diagnostics: Vec<Diagnostic> = vec![];
26+
) -> Vec<OldDiagnostic> {
27+
let mut diagnostics: Vec<OldDiagnostic> = vec![];
2828

2929
let enforce_doc_line_too_long = settings.rules.enabled(Rule::DocLineTooLong);
3030
let enforce_line_too_long = settings.rules.enabled(Rule::LineTooLong);

crates/ruff_linter/src/checkers/tokens.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use ruff_python_codegen::Stylist;
88
use ruff_python_index::Indexer;
99
use ruff_python_parser::Tokens;
1010

11-
use crate::Diagnostic;
1211
use crate::Locator;
12+
use crate::OldDiagnostic;
1313
use crate::directives::TodoComment;
1414
use crate::registry::{AsRule, Rule};
1515
use crate::rules::pycodestyle::rules::BlankLinesChecker;
@@ -29,8 +29,8 @@ pub(crate) fn check_tokens(
2929
settings: &LinterSettings,
3030
source_type: PySourceType,
3131
cell_offsets: Option<&CellOffsets>,
32-
) -> Vec<Diagnostic> {
33-
let mut diagnostics: Vec<Diagnostic> = vec![];
32+
) -> Vec<OldDiagnostic> {
33+
let mut diagnostics: Vec<OldDiagnostic> = vec![];
3434
let comment_ranges = indexer.comment_ranges();
3535

3636
if settings.rules.any_enabled(&[

crates/ruff_linter/src/diagnostic.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::violation::Violation;
88
use crate::{Fix, codes::Rule};
99

1010
#[derive(Debug, PartialEq, Eq, Clone)]
11-
pub struct Diagnostic {
11+
pub struct OldDiagnostic {
1212
/// The message body to display to the user, to explain the diagnostic.
1313
pub body: String,
1414
/// The message to display to the user, to explain the suggested fix.
@@ -20,7 +20,7 @@ pub struct Diagnostic {
2020
pub(crate) rule: Rule,
2121
}
2222

23-
impl Diagnostic {
23+
impl OldDiagnostic {
2424
// TODO(brent) We temporarily allow this to avoid updating all of the call sites to add
2525
// references. I expect this method to go away or change significantly with the rest of the
2626
// diagnostic refactor, but if it still exists in this form at the end of the refactor, we
@@ -87,13 +87,13 @@ impl Diagnostic {
8787
}
8888
}
8989

90-
impl AsRule for Diagnostic {
90+
impl AsRule for OldDiagnostic {
9191
fn rule(&self) -> Rule {
9292
self.rule
9393
}
9494
}
9595

96-
impl Ranged for Diagnostic {
96+
impl Ranged for OldDiagnostic {
9797
fn range(&self) -> TextRange {
9898
self.range
9999
}

0 commit comments

Comments
 (0)