mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:56 +00:00
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
This commit is contained in:
parent
28653c7c47
commit
6e11086c98
1 changed files with 13 additions and 3 deletions
|
@ -91,10 +91,20 @@ impl DiagnosticId {
|
|||
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() {
|
||||
Ok(id) => id == name,
|
||||
Err(DiagnosticAsStrError::Category { category, name }) => name
|
||||
Ok(id) => id == expected_name,
|
||||
Err(DiagnosticAsStrError::Category { category, name }) => expected_name
|
||||
.strip_prefix(category)
|
||||
.and_then(|prefix| prefix.strip_prefix(":"))
|
||||
.is_some_and(|rest| rest == name),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue