ruff/crates
Brent Westbrook 77a5c5ac80
Combine OldDiagnostic and Diagnostic (#19053)
## Summary

This PR is a collaboration with @AlexWaygood from our pairing session
last Friday.

The main goal here is removing `ruff_linter::message::OldDiagnostic` in
favor of
using `ruff_db::diagnostic::Diagnostic` directly. This involved a few
major steps:

- Transferring the fields
- Transferring the methods and trait implementations, where possible
- Converting some constructor methods to free functions
- Moving the `SecondaryCode` struct
- Updating the method names

I'm hoping that some of the methods, especially those in the
`expect_ruff_*`
family, won't be necessary long-term, but I avoided trying to replace
them
entirely for now to keep the already-large diff a bit smaller.

### Related refactors

Alex and I noticed a few refactoring opportunities while looking at the
code,
specifically the very similar implementations for
`create_parse_diagnostic`,
`create_unsupported_syntax_diagnostic`, and
`create_semantic_syntax_diagnostic`.
We combined these into a single generic function, which I then copied
into
`ruff_linter::message` with some small changes and a TODO to combine
them in the
future.

I also deleted the `DisplayParseErrorType` and `TruncateAtNewline` types
for
reporting parse errors. These were added in #4124, I believe to work
around the
error messages from LALRPOP. Removing these didn't affect any tests, so
I think
they were unnecessary now that we fully control the error messages from
the
parser.

On a more minor note, I factored out some calls to the
`OldDiagnostic::filename`
(now `Diagnostic::expect_ruff_filename`) function to avoid repeatedly
allocating
`String`s in some places.

### Snapshot changes

The `show_statistics_syntax_errors` integration test changed because the
`OldDiagnostic::name` method used `syntax-error` instead of
`invalid-syntax`
like in ty. I think this (`--statistics`) is one of the only places we
actually
use this name for syntax errors, so I hope this is okay. An alternative
is to
use `syntax-error` in ty too.

The other snapshot changes are from removing this code, as discussed on

[Discord](1388252408):


34052a1185/crates/ruff_linter/src/message/mod.rs (L128-L135)

I think both of these are technically breaking changes, but they only
affect
syntax errors and are very narrow in scope, while also pretty
substantially
simplifying the refactor, so I hope they're okay to include in a patch
release.

## Test plan

Existing tests, with the adjustments mentioned above

---------

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2025-07-03 13:01:09 -04:00
..
ruff Combine OldDiagnostic and Diagnostic (#19053) 2025-07-03 13:01:09 -04:00
ruff_annotate_snippets Update Rust toolchain to 1.88 and MSRV to 1.86 (#19011) 2025-06-28 20:24:00 +02:00
ruff_benchmark [ty] Temporarily disable the multithreaded pydantic benchmark (#19119) 2025-07-03 14:34:52 +02:00
ruff_cache Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_db Combine OldDiagnostic and Diagnostic (#19053) 2025-07-03 13:01:09 -04:00
ruff_dev Avoid reformatting comments in rules reference documentation (#19093) 2025-07-02 17:16:44 +02:00
ruff_diagnostics Combine OldDiagnostic and Diagnostic (#19053) 2025-07-03 13:01:09 -04:00
ruff_formatter Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_graph Update Rust toolchain to 1.88 and MSRV to 1.86 (#19011) 2025-06-28 20:24:00 +02:00
ruff_index Update Rust toolchain to 1.88 and MSRV to 1.86 (#19011) 2025-06-28 20:24:00 +02:00
ruff_linter Combine OldDiagnostic and Diagnostic (#19053) 2025-07-03 13:01:09 -04:00
ruff_macros Apply fix availability and applicability when adding to DiagnosticGuard and remove NoqaCode::rule (#18834) 2025-06-24 10:08:36 -04:00
ruff_notebook Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_options_metadata [ty] Document configuration schema (#17950) 2025-05-09 10:47:45 +02:00
ruff_python_ast Make dependency get-size2 truly optional in ruff_python_ast (#19052) 2025-06-30 21:50:59 -05:00
ruff_python_ast_integration_tests [ty] AST garbage collection (#18482) 2025-06-13 08:40:11 -04:00
ruff_python_codegen Fix f-string interpolation escaping (#18882) 2025-06-25 10:04:15 +02:00
ruff_python_formatter Update Rust toolchain to 1.88 and MSRV to 1.86 (#19011) 2025-06-28 20:24:00 +02:00
ruff_python_index Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_python_literal Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_python_parser Combine OldDiagnostic and Diagnostic (#19053) 2025-07-03 13:01:09 -04:00
ruff_python_semantic [flake8-pyi] Expand Optional[A] to A | None (PYI016) (#18572) 2025-06-27 15:43:11 +00:00
ruff_python_stdlib Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_python_trivia Treat ty: comments as pragma comments (#18532) 2025-06-07 16:02:43 +02:00
ruff_python_trivia_integration_tests Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_server Combine OldDiagnostic and Diagnostic (#19053) 2025-07-03 13:01:09 -04:00
ruff_source_file [ty] Add environment variable to dump Salsa memory usage stats (#18928) 2025-06-26 21:27:51 +00:00
ruff_text_size [ty] Add environment variable to dump Salsa memory usage stats (#18928) 2025-06-26 21:27:51 +00:00
ruff_wasm Combine OldDiagnostic and Diagnostic (#19053) 2025-07-03 13:01:09 -04:00
ruff_workspace Fix description of the format.skip-magic-trailing-comma example (#19095) 2025-07-03 10:39:59 -04:00
ty [ty] Update docs links (#19092) 2025-07-02 17:34:56 +02:00
ty_ide Filter private symbols from stubs if they are internal types (#19121) 2025-07-03 10:19:21 -05:00
ty_project Combine OldDiagnostic and Diagnostic (#19053) 2025-07-03 13:01:09 -04:00
ty_python_semantic Combine OldDiagnostic and Diagnostic (#19053) 2025-07-03 13:01:09 -04:00
ty_server [ty] Initial support for workspace diagnostics (#18939) 2025-07-03 11:04:54 +00:00
ty_test Combine OldDiagnostic and Diagnostic (#19053) 2025-07-03 13:01:09 -04:00
ty_vendored [ty] Support LSP go-to with vendored typeshed stubs (#19057) 2025-07-02 07:58:58 -04:00
ty_wasm [ty] Support LSP go-to with vendored typeshed stubs (#19057) 2025-07-02 07:58:58 -04:00