Move fix suggestion to subdiagnostic by ntBre · Pull Request #19464 · astral-sh/ruff (original) (raw)

@ntBre added internal

An internal refactor or improvement

diagnostics

Related to reporting of diagnostics.

labels

Jul 21, 2025

@ntBre ntBre marked this pull request as ready for review

July 21, 2025 15:44

MichaReiser

MichaReiser

@ntBre

Summary

This PR tweaks Ruff's internal usage of the new diagnostic model to more closely match the intended use, as I understand it. Specifically, it moves the fix/help suggestion from the primary annotation's message to a subdiagnostic. In turn, it adds the secondary/noqa code as the new primary annotation message. As shown in the new ruff_db tests, this more closely mirrors Ruff's current diagnostic output.

I also added Severity::Help to render the fix suggestion with a help: prefix instead of info:.

These changes don't have any external impact now but should help a bit with

Test Plan

New full output format tests in ruff_db

@ntBre

@ntBre

@ntBre

@ntBre

the idea here is that NoqaCode::display is the expensive step and this basically reduces it to cloning a string instead of reformatting the noqa code

@ntBre

@ntBre ntBre deleted the brent/new-diagnostic-suggestion branch

July 22, 2025 14:03

ntBre added a commit that referenced this pull request

Jul 22, 2025

@ntBre

BurntSushi

dcreager added a commit that referenced this pull request

Jul 22, 2025

@dcreager

dcreager added a commit that referenced this pull request

Jul 22, 2025

@dcreager

UnboundVariable pushed a commit to UnboundVariable/ruff that referenced this pull request

Jul 23, 2025

Conflicts:

crates/ty_ide/src/goto.rs

KotlinIsland pushed a commit to KotlinIsland/basedpython that referenced this pull request

May 1, 2026

@ntBre

Summary

This PR tweaks Ruff's internal usage of the new diagnostic model to more closely match the intended use, as I understand it. Specifically, it moves the fix/help suggestion from the primary annotation's message to a subdiagnostic. In turn, it adds the secondary/noqa code as the new primary annotation message. As shown in the new ruff_db tests, this more closely mirrors Ruff's current diagnostic output.

I also added Severity::Help to render the fix suggestion with a help: prefix instead of info:.

These changes don't have any external impact now but should help a bit with #19415.

Test Plan

New full output format tests in ruff_db

Rendered Diagnostics

Full diagnostic output from annotate-snippets in this PR:

error[unused-import]: `os` imported but unused
  --> fib.py:1:8
   |
 1 | import os
   |        ^^
   |
 help: Remove unused import: `os`

Current Ruff output for the same code:

fib.py:1:8: F401 [*] `os` imported but unused
  |
1 | import os
  |        ^^ F401
  |
  = help: Remove unused import: `os`

Proposed final output after #19415:

F401 [*] `os` imported but unused
  --> fib.py:1:8
   |
 1 | import os
   |        ^^
   |
 help: Remove unused import: `os`

These are slightly updated from astral-sh/ruff#19464 (comment) below to remove the extra noqa codes in the primary annotation messages for the first and third cases.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})