Skip to content

Conversation

@ntBre
Copy link
Contributor

@ntBre ntBre commented Jul 29, 2025

Summary

I noticed while reviewing #19390 that in check_tokens we were still passing
around an extra LinterSettings, despite all of the same functions also
receiving a LintContext with its own settings.

This PR adds the LintContext::settings method and calls that instead of using
the separate LinterSettings.

Test Plan

Existing tests

Summary
--

I noticed while reviewing #19390 that in `check_tokens` we were still passing
around an extra `LinterSettings`, despite all of the same functions also
receiving a `LintContext` with its own settings.

This PR adds the `LintContext::settings` method and calls that instead of using
the separate `LinterSettings`.

Test Plan
--

Existing tests
@ntBre ntBre added the internal An internal refactor or improvement label Jul 29, 2025
@github-actions
Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@ntBre ntBre requested a review from MichaReiser July 29, 2025 00:23
ntBre added a commit that referenced this pull request Jul 29, 2025
Summary
--

This PR is stacked on #19608 and of more dubious value. It bothered me to see
that `Candidate::into_diagnostic` and `Candidate::report_diagnostic` were
essentially the same, differing only in taking a `LintContext` instead of a
`Checker`. This was also the only reason we needed to collect a `Vec` of
`Candidate`s in `ambiguous_unicode_character` instead of reporting them
directly.

This PR fixes those two concerns, but at the cost of introducing a trait
implemented by `LintContext` and `Checker`. I'm leaning towards it not being
worth it, unless we think the trait will be useful elsewhere.

If we do want to keep the trait, we could obviously move `report_diagnostic`
into it and move the actual implementations into the trait impls. I held off
doing that for now to avoid a big import diff, especially if we didn't want this
change at all.

Test Plan
--

Existing tests
@ntBre ntBre merged commit 19569bf into main Jul 29, 2025
36 checks passed
@ntBre ntBre deleted the brent/lint-context-settings branch July 29, 2025 12:13
ntBre added a commit that referenced this pull request Jul 29, 2025
Summary
--

This PR is stacked on #19608 and of more dubious value. It bothered me to see
that `Candidate::into_diagnostic` and `Candidate::report_diagnostic` were
essentially the same, differing only in taking a `LintContext` instead of a
`Checker`. This was also the only reason we needed to collect a `Vec` of
`Candidate`s in `ambiguous_unicode_character` instead of reporting them
directly.

This PR fixes those two concerns, but at the cost of introducing a trait
implemented by `LintContext` and `Checker`. I'm leaning towards it not being
worth it, unless we think the trait will be useful elsewhere.

If we do want to keep the trait, we could obviously move `report_diagnostic`
into it and move the actual implementations into the trait impls. I held off
doing that for now to avoid a big import diff, especially if we didn't want this
change at all.

Test Plan
--

Existing tests
dcreager added a commit that referenced this pull request Aug 1, 2025
* main: (24 commits)
  Add `Checker::context` method, deduplicate Unicode checks (#19609)
  [`flake8-pyi`] Preserve inline comment in ellipsis removal (`PYI013`) (#19399)
  [ty] Add flow diagram for import resolution
  [ty] Add comments to some core resolver functions
  [ty] Add missing ticks and use consistent quoting
  [ty] Reflow some long lines
  [ty] Unexport helper function
  [ty] Remove offset from `CompletionTargetTokens::Unknown`
  [`pyupgrade`] Fix `UP030` to avoid modifying double curly braces in format strings (#19378)
  [ty] fix a typo  (#19621)
  [ty] synthesize `__replace__` for dataclasses (>=3.13) (#19545)
  [ty] Discard `Definition`s when normalizing `Signature`s (#19615)
  [ty] Fix empty spans following a line terminator and unprintable character spans in diagnostics (#19535)
  Add `LinterContext::settings` to avoid passing separate settings (#19608)
  Support `.pyi` files in ruff analyze graph (#19611)
  [ty] Sync vendored typeshed stubs (#19607)
  [ty] Bump docstring-adder pin (#19606)
  [`perflint`] Ignore rule if target is `global` or `nonlocal` (`PERF401`) (#19539)
  Add license classifier back to pyproject.toml (#19599)
  [ty] Add stub mapping support to signature help (#19570)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal An internal refactor or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants