Skip to content

Add an option to opt out of human-readable names - #27160

Merged
ntBre merged 7 commits into
mainfrom
brent/rule-name-opt-out
Jul 28, 2026
Merged

Add an option to opt out of human-readable names#27160
ntBre merged 7 commits into
mainfrom
brent/rule-name-opt-out

Conversation

@ntBre

@ntBre ntBre commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR closes #26320 by adding the new output-prefer-rule-codes option that defaults to
false and disables the use of human-readable rule names in most output formats, even in preview.
This does not affect formats like JSON that include the name and code as separate fields.

Test Plan

New CLI test enabling the option, as well as manual testing in the playground:

image

and in VS Code:

image

Note the human-readable name in the ruff: ignore comment, which shows that preview is enabled, while the (F401) in the output shows that the setting is being used.

Summary
--

This PR closes #26320 by adding the new `lint.prefer-rule-codes-in-output` option that defaults to
`false` and disables the use of human-readable rule names in most output formats, even in preview.
This does not affect formats like JSON that include the name and code as separate fields.

Test Plan
--

New CLI test enabling the option
@ntBre ntBre added configuration Related to settings and configuration preview Related to preview mode features labels Jul 24, 2026
@astral-sh-bot

astral-sh-bot Bot commented Jul 24, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot

astral-sh-bot Bot commented Jul 24, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Flaky changes detected. This PR summary excludes flaky changes; see the HTML report for details.

Full report with detailed diff (timing results)

@astral-sh-bot

astral-sh-bot Bot commented Jul 24, 2026

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@ntBre ntBre closed this Jul 24, 2026
@ntBre ntBre reopened this Jul 24, 2026
@ntBre
ntBre marked this pull request as ready for review July 24, 2026 18:57
@ntBre
ntBre requested a review from a team as a code owner July 24, 2026 18:57
@astral-sh-bot
astral-sh-bot Bot requested a review from carljm July 24, 2026 18:57
@ntBre
ntBre requested review from MichaReiser and removed request for a team and carljm July 24, 2026 18:57

@MichaReiser MichaReiser left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I'm a bit torn whether the option should be in lint or not. While it only applies to lints, it does change the CLI output, making it nice if it were next to output-format.

I also considered naming it output-prefer-rule-codes or output-prefer-codes, so that it sorts next to output-format.

No strong opinion on this, happy to go with what you choose.

}
}
let code = if self.config.preview {
let code = if self.config.preview && !self.config.prefer_rule_codes {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may use preview for more checks. But if not, could we set prefer_rule_codes to !linter.preview.is_enabled() || self.config.prefer_rule_codes? It may allow you to reduce the arguments that you need to pass to the rendering code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that's interesting. Codex originally tried to fold the preview && !prefer_rule_codes check into the existing preview field, which does work since this is all we're currently using preview for. I kept them separate in case we needed preview again in the future and because it seemed confusing to include that check in a field named preview. Removing the preview field and folding the condition into prefer_rule_codes sounds more appealing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After thinking about this a bit more, I'm again leaning toward keeping the fields separate. In a very strict sense, we are still using preview for two features: showing the real severity in JSON output and human-readable names. It seems possible that we will expand the preview-gate for severity in the near future and may want to keep that separate from human-readable names.

Happy to follow up if you feel strongly, of course.

Comment thread crates/ruff_db/src/diagnostic/mod.rs Outdated
Comment thread crates/ruff_workspace/src/options.rs Outdated
@ntBre

ntBre commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

Thank you. I'm a bit torn whether the option should be in lint or not. While it only applies to lints, it does change the CLI output, making it nice if it were next to output-format.

I also considered naming it output-prefer-rule-codes or output-prefer-codes, so that it sorts next to output-format.

No strong opinion on this, happy to go with what you choose.

Conceptually I think I like lint.prefer-rule-codes-in-output, but I also like your idea of having it sort next to output-format, so I made both of these changes.

@ntBre
ntBre merged commit 231eb33 into main Jul 28, 2026
62 checks passed
@ntBre
ntBre deleted the brent/rule-name-opt-out branch July 28, 2026 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

configuration Related to settings and configuration preview Related to preview mode features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Option to opt in to showing error codes or show error codes in addition to rule names

2 participants