-
Notifications
You must be signed in to change notification settings - Fork 173
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
Use ruff
for linting and code formatting
#1019
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jkarasti for the work on this :-)
Here is some feedback:
- To me,
make check
conveys less meaning thanmake lint
, so we might maybe keep the last one. - We are currently using
isort
in addition to ruff, but ruff can do this for us. I think we should do this before merging.
Thanks a lot 👍 let me know when you need another review :-)
c794c6e
to
41a6c59
Compare
My thinking was to have a complementary target for
I've enabled the isort rules. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for enabling the I
rules for isort, and for explaining your thinking.
Rather than having detailed targets, regrouping them behind the fix
and lint
targets seems to cut it while being self-explanatory. What do you think?
It's what the securedrop folks are doing, and having the same naming seems the right thing to do. Here's what's inside their makefile:
.PHONY: lint
lint:
@ruff check .
@ruff format --check .
.PHONY: fix
fix:
@ruff check . --fix
@ruff format .
Also, thanks for enabling the isort rule. The linter is currently failing with:
dangerzone/args.py:109: error: Unused "type: ignore" comment [unused-ignore]
41a6c59
to
a3a93ea
Compare
- Use `ruff` instead of `black` and `isort` in the `lint` target for linting and code formatting. - Add a new target `fix` which applies all suggestions from `ruff check` and `ruff format`.
a3a93ea
to
74f4636
Compare
74f4636
to
87eac56
Compare
I was thinking to either have the targets be Also noticed that the CI gets confused and breaks when running the ruff commands and then mypy from a makefile target. It tries to run mypy directly instead of the target so
That's a bit odd, the error is coming from mypy which this PR shouldn't touch. (Other than tweaking the makefile targets now, but the error was happening before I did those changes too.) I'm not able to reproduce the error locally either. e.g running this succeeds: poetry run mypy --ignore-missing-imports --disallow-incomplete-defs --disallow-untyped-defs --show-error-codes --warn-unreachable --warn-unused-ignores --exclude tests/test_docs_large/*.py dangerzone/args.py |
I've been able to reproduce the error locally by only installing the dependencies in the poetry install --only lint,test
poetry run make lint
<snip>
dangerzone/args.py:109: error: Unused "type: ignore" comment [unused-ignore]
Found 1 error in 1 file (checked 22 source files) This seem to point to the fact that I took the liberty to add a commit on top of yours, when the CI is green I will merge :-) |
See jkarasti#1 |
Thanks. I managed to reproduce this now. Turns out Also, while poking around the codebase with mypys |
Thanks, that would be appreciated. The CI is red because of #1028, so I'll close your PR and reopen a new one from a branch on this repo to circumvent this, until it is resolved. |
Replace
black
andisort
withruff
for linting and code formatting and fixes everything found by ruffs default configuration. Also add onefix
to rule them all from freedomofpress/securedrop-tooling/issues/11 and a complementarycheck
target that runsruff check
,ruff format
andmypy
useful for CI. Note that this "reverts" #904.This is ready for merge as is but not complete as I'd I'd like to enable more lint rules.
Closes #254