ruff/python/ruff-ecosystem/ruff_ecosystem
Brent Westbrook 78e5fe0a51
Allow hiding the diagnostic severity in ruff_db (#19644)
## Summary

This PR is a spin-off from https://github.com/astral-sh/ruff/pull/19415.
It enables replacing the severity and lint name in a ty-style
diagnostic:

```
error[unused-import]: `os` imported but unused
```

with the noqa code and optional fix availability icon for a Ruff
diagnostic:

```
F401 [*] `os` imported but unused
F821 Undefined name `a`
```

or nothing at all for a Ruff syntax error:

```
SyntaxError: Expected one or more symbol names after import
```

Ruff adds the `SyntaxError` prefix to these messages manually.

Initially (d912458), I just passed a `hide_severity` flag through a
bunch of calls to get it into `annotate-snippets`, but after looking at
it again today, I think reusing the `None` severity/level gave a nicer
result. As I note in a lengthy code comment, I think all of this code
should be temporary and reverted when Ruff gets real severities, so
hopefully it's okay if it feels a little hacky.

I think the main visible downside of this approach is that we can't
style the asterisk in the fix availabilty icon in cyan, as in Ruff's
current output. It's part of the message in this PR and any styling gets
overwritten in `annotate-snippets`.

<img width="400" height="342" alt="image"
src="https://github.com/user-attachments/assets/57542ec9-a81c-4a01-91c7-bd6d7ec99f99"
/>

Hmm, I guess reusing `Level::None` also means the `F401` isn't red
anymore. Maybe my initial approach was better after all. In any case,
the rest of the PR should be basically the same, it just depends how we
want to toggle the severity.

## Test Plan

New `ruff_db` tests. These snapshots should be compared to the two tests
just above them (`hide_severity_output` vs `output` and
`hide_severity_syntax_errors` against `syntax_errors`).
2025-08-05 09:56:18 -04:00
..
__init__.py Rewrite ecosystem checks and add ruff format reports (#8223) 2023-10-27 17:28:01 -05:00
__main__.py Rewrite ecosystem checks and add ruff format reports (#8223) 2023-10-27 17:28:01 -05:00
check.py Allow hiding the diagnostic severity in ruff_db (#19644) 2025-08-05 09:56:18 -04:00
cli.py Add support for ruff-ecosystem format comparisons with black (#8419) 2023-11-02 01:29:25 +00:00
defaults.py Skip notebook with errors in ecosystem check (#19491) 2025-07-22 12:29:38 -04:00
format.py Allow config-file overrides in ecosystem checks (#9286) 2023-12-28 10:44:50 -06:00
main.py Allow config-file overrides in ecosystem checks (#9286) 2023-12-28 10:44:50 -06:00
markdown.py Fix up some types in the ecosystem code (#8898) 2023-11-30 16:02:20 -06:00
projects.py Don't fix in ecosystem check (#15267) 2025-01-06 10:21:34 +01:00
types.py Fix ecosystem format line changed counts (#9158) 2023-12-16 00:14:17 -06:00