Skip to content

Conversation

@Avasam
Copy link
Collaborator

@Avasam Avasam commented Feb 29, 2024

I got curious to see if we could replace the rest of Flake8 (but keeping flake8-pyi and with it flake8-noqa) with Ruff.
I've also been less selective about UP and RUF rules.

This is the result.
The bigger challenges and possible roadbump I'd say are astral-sh/ruff#3011 and plinss/flake8-noqa#22 / plinss/flake8-noqa#30

There's a couple things here that can be immediately useful that I'll split up into smaller PRs.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@Avasam
Copy link
Collaborator Author

Avasam commented Mar 2, 2024

warning: Invalid rule code provided to # ruff: noqa at stubs/six/six/moves/builtins.pyi:1: NQA102

docs.astral.sh/ruff/settings/#lint_external

NQA is already marked as external. I opened astral-sh/ruff#10202

@Avasam
Copy link
Collaborator Author

Avasam commented Mar 2, 2024

This will conflict with #11522 and some Ruff config changes don't make sense w/o the pre-commit changes, so we can't have this PR work standalone whilst avoiding conflicts. Keeping as draft for now for that reason.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@Avasam Avasam marked this pull request as ready for review March 3, 2024 23:25
@github-actions

This comment has been minimized.

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Very nice! One comment suggestion, and one question:

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

LGTM!

@AlexWaygood
Copy link
Member

If we did want to use extend-select rather than select in pyproject.toml, we could possibly do something like this:

diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index dc4bc138b..9612c5417 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -20,12 +20,12 @@ repos:
         # Run this separately because we don't really want
         # to use --unsafe-fixes for all rules
         name: Remove unnecessary `sys.version_info` blocks
-        args: ["--exit-non-zero-on-fix", "--select=UP036", "--unsafe-fixes"]
+        args: ["--isolated", "--target-version=py38", "--exit-non-zero-on-fix", "--select=UP036", "--fix", "--unsafe-fixes"]
       - id: ruff
         # Very few rules are useful to run on our test cases;
         # we explicitly enumerate them here:
         name: Run ruff on the test cases
-        args: ["--exit-non-zero-on-fix", "--select=FA,I", "--no-force-exclude", "--unsafe-fixes"]
+        args: ["--isolated", "--target-version=py38", "--exit-non-zero-on-fix", "--select=FA,I", "--no-force-exclude", "--fix", "--unsafe-fixes"]
         files: '.*test_cases/.+\.py$'

But I personally find this PR's current solution cleaner!

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@AlexWaygood AlexWaygood merged commit 1a942aa into python:main Mar 10, 2024
@Avasam Avasam deleted the go-ruff branch March 10, 2024 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants