Skip to content

Commit 6e11086

Browse files
authored
Support lint:<rule> in mdtests (#14914)
## 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
1 parent 28653c7 commit 6e11086

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

crates/ruff_db/src/diagnostic.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,20 @@ impl DiagnosticId {
9191
matches!(self, DiagnosticId::Lint(self_name) if self_name == name)
9292
}
9393

94-
pub fn matches(&self, name: &str) -> bool {
94+
/// Returns `true` if this `DiagnosticId` matches the given name.
95+
///
96+
/// ## Examples
97+
/// ```
98+
/// use ruff_db::diagnostic::DiagnosticId;
99+
///
100+
/// assert!(DiagnosticId::Io.matches("io"));
101+
/// assert!(DiagnosticId::lint("test").matches("lint:test"));
102+
/// assert!(!DiagnosticId::lint("test").matches("test"));
103+
/// ```
104+
pub fn matches(&self, expected_name: &str) -> bool {
95105
match self.as_str() {
96-
Ok(id) => id == name,
97-
Err(DiagnosticAsStrError::Category { category, name }) => name
106+
Ok(id) => id == expected_name,
107+
Err(DiagnosticAsStrError::Category { category, name }) => expected_name
98108
.strip_prefix(category)
99109
.and_then(|prefix| prefix.strip_prefix(":"))
100110
.is_some_and(|rest| rest == name),

0 commit comments

Comments
 (0)