Support lint:<rule> in mdtests (#14914)
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / benchmarks (push) Blocked by required conditions

## Summary

Fixes a small scoping issue in `DiagnosticId::matches`

Note: I don't think we should use `lint:id` in mdtests just yet. I worry
that it could lead to many unnecessary churns if we decide **not** to
use `lint:<id>` as the format (e.g., `lint/id`).

The reason why users even see `lint:<rule>` is because the mdtest
framework uses the diagnostic infrastructure

Closes #14910

## Test Plan

Added tests
This commit is contained in:
Micha Reiser 2024-12-11 14:37:12 +01:00 committed by GitHub
parent 28653c7c47
commit 6e11086c98
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -91,10 +91,20 @@ impl DiagnosticId {
matches!(self, DiagnosticId::Lint(self_name) if self_name == name) matches!(self, DiagnosticId::Lint(self_name) if self_name == name)
} }
pub fn matches(&self, name: &str) -> bool { /// Returns `true` if this `DiagnosticId` matches the given name.
///
/// ## Examples
/// ```
/// use ruff_db::diagnostic::DiagnosticId;
///
/// assert!(DiagnosticId::Io.matches("io"));
/// assert!(DiagnosticId::lint("test").matches("lint:test"));
/// assert!(!DiagnosticId::lint("test").matches("test"));
/// ```
pub fn matches(&self, expected_name: &str) -> bool {
match self.as_str() { match self.as_str() {
Ok(id) => id == name, Ok(id) => id == expected_name,
Err(DiagnosticAsStrError::Category { category, name }) => name Err(DiagnosticAsStrError::Category { category, name }) => expected_name
.strip_prefix(category) .strip_prefix(category)
.and_then(|prefix| prefix.strip_prefix(":")) .and_then(|prefix| prefix.strip_prefix(":"))
.is_some_and(|rest| rest == name), .is_some_and(|rest| rest == name),