Use LintContext::report_diagnostic_if_enabled in check_tokens
#18769
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 avoids the
Vec::retaincall incheck_tokensby checking if rules are enabled as their diagnostics are constructed.ruff/crates/ruff_linter/src/checkers/tokens.rs
Lines 174 to 176 in 2a425e4
Since
LintContext::report_diagnostic_if_enabledrequired aLinterSettings, I added asettingsfield to the context itself instead of trying to pass it everywhere. This also turnedLogicalLinesContextinto a trivial wrapper aroundLintContext, so I just removed it in favor of usingLintContextdirectly too.The diff is a bit smaller with whitespace hidden since many blocks got moved into something like this:
Test Plan
Existing tests