-
Notifications
You must be signed in to change notification settings - Fork 13
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
[Issue #1587] Switch to use ruff instead of flake8 #1626
Conversation
@@ -120,7 +120,7 @@ def reload_repl() -> None: | |||
|
|||
try: | |||
importlib.reload(module) | |||
except: # noqa: B001 | |||
except Exception: |
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.
This is the only necessary code change. We used to ignore bare exceptions, but I think I prefer having that check in place. Since it only occurred in a single place within a local development tool and the docs even explicitly state that one reason you don't want to do this is keyboard interrupts, I think its just better to get rid of it:
https://docs.astral.sh/ruff/rules/bare-except/
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.
🚚 ship it
## Ticket Resolves #107 ## Changes Change our linter from flake8 to ruff Python package updates ## Context for reviewers [ruff](https://docs.astral.sh/ruff/) is a linter built in Rust that is both better performing and contains much more options than flake8 (including many of the Flake8 rules). Ruff has a lot of [potential rules](https://docs.astral.sh/ruff/rules/) we could configure, but to keep things simple, I ported over the same rules that we already had configured. If we want to try out any of the other rules, we can follow up with that. For context, enabling all rules causes ~1300 errors, although many of the common ones I see are not issues I think we would want to actually consider (complaining about using `assert` in test functions) Ruff can also serve as a formatter of code, potentially replacing black + isort, but I'll explore using that later as the change is likely much bigger as it would cause a lot of little formatting differences ## Testing Was able to run ruff via `make lint-ruff` and only encountered a few small issues that I fixed. We also switched to using this approach a few months ago in the simpler grants codebase and haven't run into any issues. HHS/simpler-grants-gov#1626 --------- Co-authored-by: nava-platform-bot <[email protected]>
Summary
Fixes #1587
Time to review: 3 mins
Changes proposed
Update our API linting to use ruff instead of flake8
Context for reviewers
ruff is a linter (and formatter although we aren't using that yet) that does what flake8 does, but does it faster and with many more configuration options (not yet used). Conveniently, it even uses the same rules as flake8, so switching just required adjusting where the configuration was defined.
Note that https://pypi.org/project/flake8-mypy/ was something we previously had configured, but has been abandoned for years, and I'm not quite sure what its purpose was (we use mypy - which handles type linting anyways?).
A few of the ignore rules were modified as we were either ignoring things that were removed or that just made sense to no longer ignore.
There are many, many rules that we could add, but I wanted to keep this PR contained to just porting us over, and not reconfiguring things - turning on every rule gives 3k+ errors, mostly in our tests for things we wouldn't care about. We likely will need to have different settings for tests and non-tests if we want to turn on a lot more.
Additionally, while ruff can be used as a formatter, and replace our usage of isort & black potentially, that would cause a fair number of changes at the moment (~25 files, mostly commas, line-length and white space), and I'll leave that as a later follow-up.