Skip to content

Collect preview lint behaviors in separate module #17646

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 28, 2025

Conversation

dylwil3
Copy link
Collaborator

@dylwil3 dylwil3 commented Apr 26, 2025

This PR collects all behavior gated under preview into a new module ruff_linter::preview that exposes functions like is_my_new_feature_enabled - just as is done in the formatter crate.

One thing I'd like to do before moving this out of draft is see if there is a way to enforce that ruff_linter::rules can never access the preview field in LinterSettings.

Here is one approach to this:

  • Make the preview field private
  • Make a public trait like QueryPreview with one member fn preview(&self) -> PreviewMode;, then implement this member for LinterSettings
  • Inside ruff_linter::preview, import the trait. But don't import it in ruff_linter::rules

The downside of this approach is that there are several places where we initialize LinterSettings by specifying all of its fields. So we'd have to change those to builder methods.

I would not be surprised if there is a simple and standard way to enforce the visibility I'm after, I just don't quite know which pub(in ...), pub(super), pub(crate), etc. thing I should be doing that would basically make preview accessible everywhere except in ruff_linter::rules. Suggestions?

Copy link
Contributor

github-actions bot commented Apr 26, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@MichaReiser
Copy link
Member

You could probably do a pub(in crate::preview) but I'm not sure if we have to enforce this statically.

@dylwil3 dylwil3 marked this pull request as ready for review April 27, 2025 20:28
@dylwil3 dylwil3 requested a review from AlexWaygood as a code owner April 27, 2025 20:28
@dylwil3
Copy link
Collaborator Author

dylwil3 commented Apr 27, 2025

You could probably do a pub(in crate::preview) but I'm not sure if we have to enforce this statically.

Unfortunately that's not an allowed visibility (it has to be an ancestor module). But if you think it's okay to not enforce this statically, then I'm on board too!

@AlexWaygood AlexWaygood removed their request for review April 27, 2025 20:44
Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

Nice. Thanks for going through all existing preview checks. I'm surprised that there aren't more.

Would the visibility restriction work if you moved preview.rs to settings/preview?

As an "alternative", we could consider making preview private and instead expose it as a preview method and document that it's recommended to add a new function to preview.rs.

@dylwil3
Copy link
Collaborator Author

dylwil3 commented Apr 28, 2025

Would the visibility restriction work if you moved preview.rs to settings/preview?

As an "alternative", we could consider making preview private and instead expose it as a preview method and document that it's recommended to add a new function to preview.rs.

So I tried something like this, but the issue was:

The downside of this approach is that there are several places where we initialize LinterSettings by specifying all of its fields. So we'd have to change those to builder methods.

So it's less about controlling the visibility of querying preview, and more about figuring out how to deal with the resulting difficulty in setting preview. I'm also happy to leave this as is for now if there isn't a simple solution, or if we want to do a follow up later.

@MichaReiser
Copy link
Member

MichaReiser commented Apr 28, 2025

Oh, I missed that. I'm fine leaving it pub. It's pub in the formatter and that hasn't been a problem.

@dylwil3 dylwil3 merged commit 152a0b6 into astral-sh:main Apr 28, 2025
33 checks passed
dcreager added a commit that referenced this pull request Apr 28, 2025
* main: (37 commits)
  [red-knot] Revert blanket `clippy::too_many_arguments` allow (#17688)
  Add config option to disable `typing_extensions` imports  (#17611)
  ruff_db: render file paths in diagnostics as relative paths if possible
  Bump mypy_primer pin (#17685)
  red_knot_python_semantic: improve `not-iterable` diagnostic
  [red-knot] Allow all callables to be assignable to @Todo-signatures (#17680)
  [`refurb`] Mark fix as safe for `readlines-in-for` (`FURB129`) (#17644)
  Collect preview lint behaviors in separate module (#17646)
  Upgrade Salsa to a more recent commit (#17678)
  [red-knot] TypedDict: No errors for introspection dunder attributes (#17677)
  [`flake8-pyi`] Ensure `Literal[None,] | Literal[None,]` is not autofixed to `None | None` (`PYI061`) (#17659)
  [red-knot] No errors for definitions of `TypedDict`s (#17674)
  Update actions/download-artifact digest to d3f86a1 (#17664)
  [red-knot] Use 101 exit code when there's at least one diagnostic with severity 'fatal' (#17640)
  [`pycodestyle`] Fix duplicated diagnostic in `E712` (#17651)
  [airflow] fix typos `AIR312` (#17673)
  [red-knot] Don't ignore hidden files by default (#17655)
  Update pre-commit hook astral-sh/ruff-pre-commit to v0.11.7 (#17670)
  Update docker/build-push-action digest to 14487ce (#17665)
  Update taiki-e/install-action digest to ab3728c (#17666)
  ...
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.

2 participants