Skip to content
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

Speedup pre-commit run by excluding python files from trailing hooks #11777

Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ repos:
rev: v4.5.0 # must match requirements-tests.txt
hooks:
- id: trailing-whitespace
# speedup hook by leaving python files to Black & Ruff
exclude: .*\.pyi?$
Copy link
Member

Choose a reason for hiding this comment

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

Black does not necessarily fix trailing whitespace in string literals

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That would only be multiline string literals right?
Do we even have those in stubs? Given we don't have docstrings (outside maybe generated protobuf files)

After checking, yes we do, in deprecated multiline messages, but it seems think Ruff does catch those, although it's considered an "unsafe-fix" (which is true and why black doesn't touch them):
image

That being said, if it was removed anyway by another pre-commit hook, I can just add W291 to our unsafe fixes hook.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

On that note, @AlexWaygood any reason not to use https://docs.astral.sh/ruff/settings/#lint_extend-safe-fixes instead of a separate pre-commit hook?

Copy link
Member

@AlexWaygood AlexWaygood Apr 17, 2024

Choose a reason for hiding this comment

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

no reason other than that I forgot about that option, I guess 😄

- id: end-of-file-fixer
# speedup hook by leaving python files to Black & Ruff
exclude: .*\.pyi?$
- id: check-yaml
- id: check-toml
- id: check-merge-conflict
Expand Down