Skip to content

Commit 207ec3a

Browse files
authored
[ty] Add diagnostic baseline support (#27636)
1 parent 6840db3 commit 207ec3a

28 files changed

Lines changed: 1300 additions & 20 deletions

File tree

‎Cargo.lock‎

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎crates/ruff_db/src/diagnostic/mod.rs‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,11 @@ impl Diagnostic {
286286
self.inner.severity
287287
}
288288

289+
/// Sets the severity of this diagnostic.
290+
pub fn set_severity(&mut self, severity: Severity) {
291+
Arc::make_mut(&mut self.inner).severity = severity;
292+
}
293+
289294
/// Returns a shared borrow of the "primary" annotation of this diagnostic
290295
/// if one exists.
291296
///
@@ -1098,6 +1103,9 @@ pub enum DiagnosticId {
10981103
/// Use of an invalid command-line option.
10991104
InvalidCliOption,
11001105

1106+
/// The configured diagnostic baseline is invalid.
1107+
InvalidBaseline,
1108+
11011109
/// Experimental feature requires preview mode.
11021110
PreviewFeature,
11031111

@@ -1156,6 +1164,7 @@ impl DiagnosticId {
11561164
DiagnosticId::UnsupportedPythonVersion => "unsupported-python-version",
11571165
DiagnosticId::Unformatted => "unformatted",
11581166
DiagnosticId::InvalidCliOption => "invalid-cli-option",
1167+
DiagnosticId::InvalidBaseline => "invalid-baseline",
11591168
DiagnosticId::PreviewFeature => "preview-feature",
11601169
DiagnosticId::InternalError => "internal-error",
11611170
}
@@ -1327,6 +1336,7 @@ impl From<crate::files::FileRange> for Span {
13271336
#[cfg_attr(feature = "serde", derive(Serialize))]
13281337
#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
13291338
pub enum Severity {
1339+
Hint,
13301340
Info,
13311341
Warning,
13321342
Error,
@@ -1336,7 +1346,7 @@ pub enum Severity {
13361346
impl Severity {
13371347
fn to_annotate(self) -> AnnotateLevel<'static> {
13381348
match self {
1339-
Severity::Info => AnnotateLevel::INFO,
1349+
Severity::Hint | Severity::Info => AnnotateLevel::INFO,
13401350
Severity::Warning => AnnotateLevel::WARNING,
13411351
Severity::Error => AnnotateLevel::ERROR,
13421352
// NOTE: Should we really collapse this to "error"?

‎crates/ruff_db/src/diagnostic/render/azure.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl Renderer for AzureRenderer<'_> {
2222
fn render(&self, f: &mut std::fmt::Formatter, diagnostics: &[Diagnostic]) -> std::fmt::Result {
2323
for diag in diagnostics {
2424
let severity = match diag.severity() {
25-
Severity::Info | Severity::Warning => "warning",
25+
Severity::Hint | Severity::Info | Severity::Warning => "warning",
2626
Severity::Error | Severity::Fatal => "error",
2727
};
2828
write!(f, "##vso[task.logissue type={severity};")?;

‎crates/ruff_db/src/diagnostic/render/concise.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ impl Renderer for ConciseRenderer<'_> {
9292
}
9393
} else {
9494
let (severity, severity_style) = match diag.severity() {
95+
Severity::Hint => ("hint", stylesheet.info),
9596
Severity::Info => ("info", stylesheet.info),
9697
Severity::Warning => ("warning", stylesheet.warning),
9798
Severity::Error => ("error", stylesheet.error),

‎crates/ruff_db/src/diagnostic/render/github.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl Renderer for GithubRenderer<'_> {
2222
fn render(&self, f: &mut std::fmt::Formatter, diagnostics: &[Diagnostic]) -> std::fmt::Result {
2323
for diagnostic in diagnostics {
2424
let severity = match diagnostic.severity() {
25-
Severity::Info => "notice",
25+
Severity::Hint | Severity::Info => "notice",
2626
Severity::Warning => "warning",
2727
Severity::Error | Severity::Fatal => "error",
2828
};

‎crates/ruff_db/src/diagnostic/render/gitlab.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl Serialize for SerializedMessages<'_> {
104104
diagnostic.secondary_code_or_id()
105105
};
106106
let severity = match diagnostic.severity() {
107-
Severity::Info => "info",
107+
Severity::Hint | Severity::Info => "info",
108108
Severity::Warning => "minor",
109109
Severity::Error => "major",
110110
// Another option here is `blocker`

‎crates/ruff_db/src/diagnostic/render/junit.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ impl Renderer for JunitRenderer<'_> {
110110

111111
const fn severity_name(severity: Severity) -> &'static str {
112112
match severity {
113+
Severity::Hint => "hint",
113114
Severity::Info => "info",
114115
Severity::Warning => "warning",
115116
Severity::Error => "error",

‎crates/ruff_db/src/diagnostic/render/sarif.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ enum SarifLevel {
318318
impl From<Severity> for SarifLevel {
319319
fn from(value: Severity) -> Self {
320320
match value {
321-
Severity::Info => SarifLevel::Note,
321+
Severity::Hint | Severity::Info => SarifLevel::Note,
322322
Severity::Warning => SarifLevel::Warning,
323323
Severity::Error | Severity::Fatal => SarifLevel::Error,
324324
}

‎crates/ruff_server/src/lint.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ fn to_lsp_diagnostic(
393393
match diagnostic.severity() {
394394
// Map lint diagnostics without codes to warning, like in `severity`.
395395
_ if diagnostic.id().is_lint() => lsp_types::DiagnosticSeverity::Warning,
396+
ruff_db::diagnostic::Severity::Hint => lsp_types::DiagnosticSeverity::Hint,
396397
ruff_db::diagnostic::Severity::Info => lsp_types::DiagnosticSeverity::Information,
397398
ruff_db::diagnostic::Severity::Warning => lsp_types::DiagnosticSeverity::Warning,
398399
ruff_db::diagnostic::Severity::Error => lsp_types::DiagnosticSeverity::Error,

‎crates/ty/docs/cli.md‎

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)