mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-12 15:45:07 +00:00
![]() This commit shuffles the reporting API around a little bit such that a range is required, up front, when reporting a lint diagnostic. This in turn enables us to make suppression checking eager. In order to avoid callers needing to provide the range twice, we create a primary annotation *without* a message inside the `Diagnostic` encapsulated by the guard. We do this instead of requiring the message up front because we're concerned about API complexity and the effort involved in creating the message. In order to provide a means of attaching a message to the primary annotation, we expose a convenience API on `LintDiagnosticGuard` for setting the message. This isn't generally possible for a `Diagnostic`, but since a `LintDiagnosticGuard` knows how the `Diagnostic` was constructed, we can offer this API correctly. It strikes me that it might be easy to forget to attach a primary annotation message, btu I think this the "least" bad failure mode. And in particular, it should be somewhat obvious that it's missing once one adds a snapshot test for how the diagnostic renders. Otherwise, this API gives us the ability to eagerly check whether a diagnostic should be reported with nearly minimal information. It also shouldn't have any footguns since it guarantees that the primary annotation is tied to the file in the typing context. And it keeps things pretty simple: callers only need to provide what is actually strictly necessary to make a diagnostic. |
||
---|---|---|
.. | ||
src | ||
Cargo.toml |