ruff/crates/ruff_linter/src
Brent Westbrook e64d772788
Standardize syntax error construction (#20903)
Summary
--

This PR unifies the two different ways Ruff and ty construct syntax
errors. Ruff has been storing the primary message in the diagnostic
itself, while ty attached the message to the primary annotation:

```
> ruff check try.py
invalid-syntax: name capture `x` makes remaining patterns unreachable
 --> try.py:2:10
  |
1 | match 42:
2 |     case x: ...
  |          ^
3 |     case y: ...
  |

Found 1 error.
> uvx ty check try.py
WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors.
Checking ------------------------------------------------------------ 1/1 files                                                                                                 
error[invalid-syntax]
 --> try.py:2:10
  |
1 | match 42:
2 |     case x: ...
  |          ^ name capture `x` makes remaining patterns unreachable
3 |     case y: ...
  |

Found 1 diagnostic
```

I think there are benefits to both approaches, and I do like ty's
version, but I feel like we should pick one (and it might help with
#20901 eventually). I slightly prefer Ruff's version, so I went with
that. Hopefully this isn't too controversial, but I'm happy to close
this if it is.

Note that this shouldn't change any other diagnostic formats in ty
because
[`Diagnostic::primary_message`](98d27c4128/crates/ruff_db/src/diagnostic/mod.rs (L177))
was already falling back to the primary annotation message if the
diagnostic message was empty. As a result, I think this change will
partially resolve the FIXME therein.

Test Plan
--

Existing tests with updated snapshots
2025-10-16 11:56:32 -04:00
..
checkers [pydoclint] Implement docstring-extraneous-parameter (DOC102) (#20376) 2025-10-16 11:26:51 -04:00
comments
cst Update Rust toolchain to 1.89 (#19807) 2025-08-07 18:21:50 +02:00
docstrings Update Rust toolchain to 1.89 (#19807) 2025-08-07 18:21:50 +02:00
fix Update Rust crate anyhow to v1.0.100 (#20499) 2025-09-22 09:51:52 +02:00
importer [isort] Fix inserting required imports before future imports (I002) (#20676) 2025-10-06 13:40:36 +00:00
linter [pylint] Detect more exotic NaN literals in PLW0177 (#18630) 2025-06-19 11:05:06 +00:00
message Standardize syntax error construction (#20903) 2025-10-16 11:56:32 -04:00
registry Remove Message::to_rule (#18447) 2025-06-05 12:48:29 -04:00
rules [pydoclint] Implement docstring-extraneous-parameter (DOC102) (#20376) 2025-10-16 11:26:51 -04:00
settings Display diffs for ruff format --check and add support for different output formats (#20443) 2025-09-30 12:00:51 -04:00
snapshots [syntax-errors] Detect yield from inside async function (#20051) 2025-09-03 10:13:05 -04:00
codes.rs [pydoclint] Implement docstring-extraneous-parameter (DOC102) (#20376) 2025-10-16 11:26:51 -04:00
directives.rs Track t-strings and f-strings for token-based rules and suppression comments (#20357) 2025-09-12 13:00:12 -05:00
doc_lines.rs Update Rust toolchain to 1.89 (#19807) 2025-08-07 18:21:50 +02:00
fs.rs Render unsupported syntax errors in formatter tests (#20777) 2025-10-13 10:00:37 -04:00
lib.rs Combine OldDiagnostic and Diagnostic (#19053) 2025-07-03 13:01:09 -04:00
line_width.rs Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
linter.rs Standardize syntax error construction (#20903) 2025-10-16 11:56:32 -04:00
locator.rs Update Rust toolchain to 1.89 (#19807) 2025-08-07 18:21:50 +02:00
logging.rs Display diffs for ruff format --check and add support for different output formats (#20443) 2025-09-30 12:00:51 -04:00
noqa.rs Remove Diagnostic::expect_range and all consumers (#20322) 2025-09-10 17:19:20 -07:00
package.rs
packaging.rs
preview.rs [pyupgrade] Fix false negative for TypeVar with default argument in non-pep695-generic-class (UP046) (#20660) 2025-10-15 14:51:55 +00:00
pyproject_toml.rs Rename Diagnostic::syntax_error methods, separate Ord implementation (#19179) 2025-07-08 09:54:19 -04:00
registry.rs Apply fix availability and applicability when adding to DiagnosticGuard and remove NoqaCode::rule (#18834) 2025-06-24 10:08:36 -04:00
renamer.rs Add a ScopeKind for the __class__ cell (#20048) 2025-08-26 09:49:08 -04:00
rule_redirects.rs [flake8-bandit] Move unsafe-markup-use from RUF035 to S704 (#15957) 2025-03-13 15:37:37 +01:00
rule_selector.rs Ignore deprecated rules unless selected by exact code (#20167) 2025-09-10 09:00:27 -04:00
source_kind.rs Update MSRV to 1.85 and toolchain to 1.87 (#18126) 2025-05-16 09:19:55 +02:00
test.rs Standardize syntax error construction (#20903) 2025-10-16 11:56:32 -04:00
text_helpers.rs
upstream_categories.rs
violation.rs Rename Diagnostic::syntax_error methods, separate Ord implementation (#19179) 2025-07-08 09:54:19 -04:00