Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/ruff/src/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rayon::prelude::*;
use rustc_hash::FxHashMap;

use ruff_db::panic::catch_unwind;
use ruff_linter::Diagnostic;
use ruff_linter::OldDiagnostic;
use ruff_linter::message::Message;
use ruff_linter::package::PackageRoot;
use ruff_linter::registry::Rule;
Expand Down Expand Up @@ -131,7 +131,7 @@ pub(crate) fn check(

Diagnostics::new(
vec![Message::from_diagnostic(
Diagnostic::new(IOError { message }, TextRange::default()),
OldDiagnostic::new(IOError { message }, TextRange::default()),
dummy,
None,
)],
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use colored::Colorize;
use log::{debug, warn};
use rustc_hash::FxHashMap;

use ruff_linter::Diagnostic;
use ruff_linter::OldDiagnostic;
use ruff_linter::codes::Rule;
use ruff_linter::linter::{FixTable, FixerResult, LinterResult, ParseSource, lint_fix, lint_only};
use ruff_linter::message::Message;
Expand Down Expand Up @@ -64,7 +64,7 @@ impl Diagnostics {
let source_file = SourceFileBuilder::new(name, "").finish();
Self::new(
vec![Message::from_diagnostic(
Diagnostic::new(
OldDiagnostic::new(
IOError {
message: err.to_string(),
},
Expand Down
22 changes: 11 additions & 11 deletions crates/ruff_linter/src/checkers/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ use crate::rules::pyflakes::rules::{
use crate::rules::pylint::rules::{AwaitOutsideAsync, LoadBeforeGlobalDeclaration};
use crate::rules::{flake8_pyi, flake8_type_checking, pyflakes, pyupgrade};
use crate::settings::{LinterSettings, TargetVersion, flags};
use crate::{Diagnostic, Edit, Violation};
use crate::{Edit, OldDiagnostic, Violation};
use crate::{Locator, docstrings, noqa};

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

Expand All @@ -405,7 +405,7 @@ impl<'a> Checker<'a> {
kind: T,
range: TextRange,
) -> Option<DiagnosticGuard<'chk, 'a>> {
let diagnostic = Diagnostic::new(kind, range);
let diagnostic = OldDiagnostic::new(kind, range);
if self.enabled(diagnostic.rule()) {
Some(DiagnosticGuard {
checker: self,
Expand Down Expand Up @@ -2892,7 +2892,7 @@ impl<'a> Checker<'a> {
if self.semantic.global_scope().uses_star_imports() {
if self.enabled(Rule::UndefinedLocalWithImportStarUsage) {
self.diagnostics.get_mut().push(
Diagnostic::new(
OldDiagnostic::new(
pyflakes::rules::UndefinedLocalWithImportStarUsage {
name: name.to_string(),
},
Expand All @@ -2907,7 +2907,7 @@ impl<'a> Checker<'a> {
|| !self.path.ends_with("__init__.py")
{
self.diagnostics.get_mut().push(
Diagnostic::new(
OldDiagnostic::new(
pyflakes::rules::UndefinedExport {
name: name.to_string(),
},
Expand Down Expand Up @@ -2975,7 +2975,7 @@ pub(crate) fn check_ast(
cell_offsets: Option<&CellOffsets>,
notebook_index: Option<&NotebookIndex>,
target_version: TargetVersion,
) -> (Vec<Diagnostic>, Vec<SemanticSyntaxError>) {
) -> (Vec<OldDiagnostic>, Vec<SemanticSyntaxError>) {
let module_path = package
.map(PackageRoot::path)
.and_then(|package| to_module_path(package, path));
Expand Down Expand Up @@ -3062,7 +3062,7 @@ pub(crate) struct DiagnosticGuard<'a, 'b> {
/// The diagnostic that we want to report.
///
/// This is always `Some` until the `Drop` (or `defuse`) call.
diagnostic: Option<Diagnostic>,
diagnostic: Option<OldDiagnostic>,
}

impl DiagnosticGuard<'_, '_> {
Expand All @@ -3076,17 +3076,17 @@ impl DiagnosticGuard<'_, '_> {
}

impl std::ops::Deref for DiagnosticGuard<'_, '_> {
type Target = Diagnostic;
type Target = OldDiagnostic;

fn deref(&self) -> &Diagnostic {
fn deref(&self) -> &OldDiagnostic {
// OK because `self.diagnostic` is only `None` within `Drop`.
self.diagnostic.as_ref().unwrap()
}
}

/// Return a mutable borrow of the diagnostic in this guard.
impl std::ops::DerefMut for DiagnosticGuard<'_, '_> {
fn deref_mut(&mut self) -> &mut Diagnostic {
fn deref_mut(&mut self) -> &mut OldDiagnostic {
// OK because `self.diagnostic` is only `None` within `Drop`.
self.diagnostic.as_mut().unwrap()
}
Expand Down
6 changes: 3 additions & 3 deletions crates/ruff_linter/src/checkers/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::path::Path;
use ruff_python_ast::PythonVersion;
use ruff_python_trivia::CommentRanges;

use crate::Diagnostic;
use crate::Locator;
use crate::OldDiagnostic;
use crate::package::PackageRoot;
use crate::preview::is_allow_nested_roots_enabled;
use crate::registry::Rule;
Expand All @@ -20,8 +20,8 @@ pub(crate) fn check_file_path(
comment_ranges: &CommentRanges,
settings: &LinterSettings,
target_version: PythonVersion,
) -> Vec<Diagnostic> {
let mut diagnostics: Vec<Diagnostic> = vec![];
) -> Vec<OldDiagnostic> {
let mut diagnostics: Vec<OldDiagnostic> = vec![];

// flake8-no-pep420
if settings.rules.enabled(Rule::ImplicitNamespacePackage) {
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff_linter/src/checkers/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use ruff_python_codegen::Stylist;
use ruff_python_index::Indexer;
use ruff_python_parser::Parsed;

use crate::Diagnostic;
use crate::Locator;
use crate::OldDiagnostic;
use crate::directives::IsortDirectives;
use crate::package::PackageRoot;
use crate::registry::Rule;
Expand All @@ -28,7 +28,7 @@ pub(crate) fn check_imports(
source_type: PySourceType,
cell_offsets: Option<&CellOffsets>,
target_version: PythonVersion,
) -> Vec<Diagnostic> {
) -> Vec<OldDiagnostic> {
// Extract all import blocks from the AST.
let tracker = {
let mut tracker =
Expand Down
8 changes: 4 additions & 4 deletions crates/ruff_linter/src/checkers/logical_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use ruff_python_parser::{TokenKind, Tokens};
use ruff_source_file::LineRanges;
use ruff_text_size::{Ranged, TextRange};

use crate::Diagnostic;
use crate::Locator;
use crate::OldDiagnostic;
use crate::line_width::IndentWidth;
use crate::registry::{AsRule, Rule};
use crate::rules::pycodestyle::rules::logical_lines::{
Expand Down Expand Up @@ -40,7 +40,7 @@ pub(crate) fn check_logical_lines(
indexer: &Indexer,
stylist: &Stylist,
settings: &LinterSettings,
) -> Vec<Diagnostic> {
) -> Vec<OldDiagnostic> {
let mut context = LogicalLinesContext::new(settings);

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

impl<'a> LogicalLinesContext<'a> {
Expand All @@ -207,7 +207,7 @@ impl<'a> LogicalLinesContext<'a> {
}
}

pub(crate) fn push_diagnostic(&mut self, diagnostic: Diagnostic) {
pub(crate) fn push_diagnostic(&mut self, diagnostic: OldDiagnostic) {
if self.settings.rules.enabled(diagnostic.rule()) {
self.diagnostics.push(diagnostic);
}
Expand Down
8 changes: 4 additions & 4 deletions crates/ruff_linter/src/checkers/noqa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ use crate::rules::pygrep_hooks;
use crate::rules::ruff;
use crate::rules::ruff::rules::{UnusedCodes, UnusedNOQA};
use crate::settings::LinterSettings;
use crate::{Diagnostic, Edit, Fix};
use crate::{Edit, Fix, OldDiagnostic};

#[expect(clippy::too_many_arguments)]
pub(crate) fn check_noqa(
diagnostics: &mut Vec<Diagnostic>,
diagnostics: &mut Vec<OldDiagnostic>,
path: &Path,
locator: &Locator,
comment_ranges: &CommentRanges,
Expand Down Expand Up @@ -136,7 +136,7 @@ pub(crate) fn check_noqa(
if matches.is_empty() {
let edit = delete_comment(directive.range(), locator);
let mut diagnostic =
Diagnostic::new(UnusedNOQA { codes: None }, directive.range());
OldDiagnostic::new(UnusedNOQA { codes: None }, directive.range());
diagnostic.set_fix(Fix::safe_edit(edit));

diagnostics.push(diagnostic);
Expand Down Expand Up @@ -212,7 +212,7 @@ pub(crate) fn check_noqa(
directive.range(),
)
};
let mut diagnostic = Diagnostic::new(
let mut diagnostic = OldDiagnostic::new(
UnusedNOQA {
codes: Some(UnusedCodes {
disabled: disabled_codes
Expand Down
6 changes: 3 additions & 3 deletions crates/ruff_linter/src/checkers/physical_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use ruff_python_index::Indexer;
use ruff_source_file::UniversalNewlines;
use ruff_text_size::TextSize;

use crate::Diagnostic;
use crate::Locator;
use crate::OldDiagnostic;
use crate::registry::Rule;
use crate::rules::flake8_copyright::rules::missing_copyright_notice;
use crate::rules::pycodestyle::rules::{
Expand All @@ -23,8 +23,8 @@ pub(crate) fn check_physical_lines(
indexer: &Indexer,
doc_lines: &[TextSize],
settings: &LinterSettings,
) -> Vec<Diagnostic> {
let mut diagnostics: Vec<Diagnostic> = vec![];
) -> Vec<OldDiagnostic> {
let mut diagnostics: Vec<OldDiagnostic> = vec![];

let enforce_doc_line_too_long = settings.rules.enabled(Rule::DocLineTooLong);
let enforce_line_too_long = settings.rules.enabled(Rule::LineTooLong);
Expand Down
6 changes: 3 additions & 3 deletions crates/ruff_linter/src/checkers/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use ruff_python_codegen::Stylist;
use ruff_python_index::Indexer;
use ruff_python_parser::Tokens;

use crate::Diagnostic;
use crate::Locator;
use crate::OldDiagnostic;
use crate::directives::TodoComment;
use crate::registry::{AsRule, Rule};
use crate::rules::pycodestyle::rules::BlankLinesChecker;
Expand All @@ -29,8 +29,8 @@ pub(crate) fn check_tokens(
settings: &LinterSettings,
source_type: PySourceType,
cell_offsets: Option<&CellOffsets>,
) -> Vec<Diagnostic> {
let mut diagnostics: Vec<Diagnostic> = vec![];
) -> Vec<OldDiagnostic> {
let mut diagnostics: Vec<OldDiagnostic> = vec![];
let comment_ranges = indexer.comment_ranges();

if settings.rules.any_enabled(&[
Expand Down
8 changes: 4 additions & 4 deletions crates/ruff_linter/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::violation::Violation;
use crate::{Fix, codes::Rule};

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

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

impl AsRule for Diagnostic {
impl AsRule for OldDiagnostic {
fn rule(&self) -> Rule {
self.rule
}
}

impl Ranged for Diagnostic {
impl Ranged for OldDiagnostic {
fn range(&self) -> TextRange {
self.range
}
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff_linter/src/fix/edits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ mod tests {
add_to_dunder_all, make_redundant_alias, next_stmt_break, trailing_semicolon,
};
use crate::message::Message;
use crate::{Diagnostic, Edit, Fix};
use crate::{Edit, Fix, OldDiagnostic};

/// Parse the given source using [`Mode::Module`] and return the first statement.
fn parse_first_stmt(source: &str) -> Result<Stmt> {
Expand Down Expand Up @@ -738,7 +738,7 @@ x = 1 \
let diag = {
use crate::rules::pycodestyle::rules::MissingNewlineAtEndOfFile;
let mut iter = edits.into_iter();
let diag = Diagnostic::new(
let diag = OldDiagnostic::new(
MissingNewlineAtEndOfFile, // The choice of rule here is arbitrary.
TextRange::default(),
)
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff_linter/src/fix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ mod tests {
use ruff_text_size::{Ranged, TextSize};

use crate::Locator;
use crate::diagnostic::Diagnostic;
use crate::diagnostic::OldDiagnostic;
use crate::fix::{FixResult, apply_fixes};
use crate::message::Message;
use crate::rules::pycodestyle::rules::MissingNewlineAtEndOfFile;
Expand All @@ -177,7 +177,7 @@ mod tests {
edit.into_iter()
.map(|edit| {
// The choice of rule here is arbitrary.
let diagnostic = Diagnostic::new(MissingNewlineAtEndOfFile, edit.range());
let diagnostic = OldDiagnostic::new(MissingNewlineAtEndOfFile, edit.range());
Message::from_diagnostic(
diagnostic.with_fix(Fix::safe_edit(edit)),
SourceFileBuilder::new(filename, source).finish(),
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_linter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub use rule_selector::RuleSelector;
pub use rule_selector::clap_completion::RuleSelectorParser;
pub use rules::pycodestyle::rules::IOError;

pub use diagnostic::Diagnostic;
pub use diagnostic::OldDiagnostic;
pub(crate) use ruff_diagnostics::{Applicability, Edit, Fix};
pub use violation::{AlwaysFixableViolation, FixAvailability, Violation, ViolationMetadata};

Expand Down
6 changes: 3 additions & 3 deletions crates/ruff_linter/src/linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use ruff_python_parser::{ParseError, ParseOptions, Parsed, UnsupportedSyntaxErro
use ruff_source_file::SourceFileBuilder;
use ruff_text_size::Ranged;

use crate::Diagnostic;
use crate::OldDiagnostic;
use crate::checkers::ast::check_ast;
use crate::checkers::filesystem::check_file_path;
use crate::checkers::imports::check_imports;
Expand Down Expand Up @@ -438,7 +438,7 @@ pub fn add_noqa_to_path(
)
}

/// Generate a [`Message`] for each [`Diagnostic`] triggered by the given source
/// Generate a [`Message`] for each [`OldDiagnostic`] triggered by the given source
/// code.
pub fn lint_only(
path: &Path,
Expand Down Expand Up @@ -503,7 +503,7 @@ pub fn lint_only(

/// Convert from diagnostics to messages.
fn diagnostics_to_messages(
diagnostics: Vec<Diagnostic>,
diagnostics: Vec<OldDiagnostic>,
parse_errors: &[ParseError],
unsupported_syntax_errors: &[UnsupportedSyntaxError],
semantic_syntax_errors: &[SemanticSyntaxError],
Expand Down
Loading
Loading