mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-05 19:28:11 +00:00
![]() ## Summary This PR moves most of the work of rendering concise diagnostics in Ruff into `ruff_db`, where the code is shared with ty. To accomplish this without breaking backwards compatibility in Ruff, there are two main changes on the `ruff_db`/ty side: - Added the logic from Ruff for remapping notebook line numbers to cells - Reordered the fields in the diagnostic to match Ruff and rustc ```text # old error[invalid-assignment] try.py:3:1: Object of type `Literal[1]` is not assignable to `str` # new try.py:3:1: error[invalid-assignment]: Object of type `Literal[1]` is not assignable to `str` ``` I don't think the notebook change failed any tests on its own, and only a handful of snaphots changed in ty after reordering the fields, but this will obviously affect any other uses of the concise format, outside of tests, too. The other big change should only affect Ruff: - Added three new `DisplayDiagnosticConfig` options Micha and I hoped that we could get by with one option (`hide_severity`), but Ruff also toggles `show_fix_status` itself, independently (there are cases where we want neither severity nor the fix status), and during the implementation I realized we also needed access to an `Applicability`. The main goal here is to suppress the severity (`error` above) because ruff only uses the `error` severity and to use the secondary/noqa code instead of the line name (`invalid-assignment` above). ```text # ty - same as "new" above try.py:3:1: error[invalid-assignment]: Object of type `Literal[1]` is not assignable to `str` # ruff try.py:3:1: RUF123 [*] Object of type `Literal[1]` is not assignable to `str` ``` This part of the concise diagnostic is actually shared with the `full` output format in Ruff, but with the settings above, there are no snapshot changes to either format. ## Test Plan Existing tests with the handful of updates mentioned above, as well as some new tests in the `concise` module. Also this PR. Swapping the fields might have broken mypy_primer, unless it occasionally times out on its own. I also ran this script in the root of my Ruff checkout, which also has CPython in it: ```shell flags=(--isolated --no-cache --no-respect-gitignore --output-format concise .) diff <(target/release/ruff check ${flags[@]} 2> /dev/null) \ <(ruff check ${flags[@]} 2> /dev/null) ``` This yielded an expected diff due to some t-string error changes on main since 0.12.4: ```diff 33622c33622 < crates/ruff_python_parser/resources/inline/err/f_string_lambda_without_parentheses.py:1:15: SyntaxError: Expected an element of or the end of the f-string --- > crates/ruff_python_parser/resources/inline/err/f_string_lambda_without_parentheses.py:1:15: SyntaxError: Expected an f-string or t-string element or the end of the f-string or t-string 33742c33742 < crates/ruff_python_parser/resources/inline/err/implicitly_concatenated_unterminated_string_multiline.py:4:1: SyntaxError: Expected an element of or the end of the f-string --- > crates/ruff_python_parser/resources/inline/err/implicitly_concatenated_unterminated_string_multiline.py:4:1: SyntaxError: Expected an f-string or t-string element or the end of the f-string or t-string 34131c34131 < crates/ruff_python_parser/resources/inline/err/t_string_lambda_without_parentheses.py:2:15: SyntaxError: Expected an element of or the end of the t-string --- > crates/ruff_python_parser/resources/inline/err/t_string_lambda_without_parentheses.py:2:15: SyntaxError: Expected an f-string or t-string element or the end of the f-string or t-string ``` So modulo color, the results are identical on 38,186 errors in our test suite and CPython 3.10. --------- Co-authored-by: David Peter <mail@david-peter.de> |
||
---|---|---|
.. | ||
cli | ||
file_watching.rs |