Refactor TOML file linting - #26806
Merged
Merged
Conversation
Summary -- This PR was spun off from #26772 to handle some of the refactors to RUF200. The first non-empty commit is purely moving the implementation of RUF200 from the general `lint_pyproject_toml` function into its own rule file. In #26772, `lint_pyproject_toml` will become `lint_toml` and invoke multiple rules. The second commit drops the overly defensive range check, as noted in #26772 (comment). The third commit refactors the rule to use a `LintContext`. This not only sets up to run multiple rules in this function, but also fixes a latent bug in rule suppression for RUF200. Because the rule previously checked whether it was enabled via the `LinterSettings::rules.enabled` directly, it didn't take into account settings like `per-file-ignores` (this also affects `unfixable` and other fix-related settings for RUF201). The fourth commit contains a new mdtest for this that currently fails on main. Finally, the fifth commit moves parsing out of RUF200. We still parse into a `PyProjectToml` for now, but at least this sets us up to share parsing between rules once we find the right shared representation. Test Plan -- New mdtest mentioned above and then rebasing #26772 onto this.
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 94.61%. The percentage of expected errors that received a diagnostic held steady at 90.27%. The number of fully passing files held steady at 97/134. |
Memory usage reportMemory usage unchanged ✅ |
|
|
ntBre
force-pushed
the
brent/refactor-toml-rules
branch
from
July 14, 2026 16:43
76587c0 to
a465d35
Compare
ntBre
marked this pull request as ready for review
July 14, 2026 17:00
MichaReiser
approved these changes
Jul 15, 2026
MichaReiser
left a comment
Member
There was a problem hiding this comment.
Thank you. Also thanks for taking the time to split the change into multiple commits and writing the excellent PR summary.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR was spun off from #26772 to handle some of the refactors to RUF200. The first non-empty
commit is purely moving the implementation of RUF200 from the general
lint_pyproject_tomlfunctioninto its own rule file. In #26772,
lint_pyproject_tomlwill becomelint_tomland invoke multiplerules.
The second commit drops the overly defensive range check, as noted in #26772 (comment).
The third commit refactors the rule to use a
LintContext. This not only sets up to run multiplerules in this function, but also fixes a latent bug in rule suppression for RUF200. Because the rule
previously checked whether it was enabled via the
LinterSettings::rules.enableddirectly, itdidn't take into account settings like
per-file-ignores(this also affectsunfixableand otherfix-related settings for RUF201). The fourth commit contains a new mdtest for this that currently
fails on main.
Finally, the fifth commit moves parsing out of RUF200. We still parse into a
PyProjectTomlfornow, but at least this sets us up to share parsing between rules once we find the right shared
representation.
Test Plan
New mdtest mentioned above and then rebasing #26772 onto this.