-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add ruff as default linting + formatting option #387
base: master
Are you sure you want to change the base?
Conversation
## Format source code with ruff | ||
.PHONY: format | ||
format: | ||
ruff check --select I --fix {{ cookiecutter.module_name }} |
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.
I don't like --select I
here. We should use the fixable
or unfixable
configuration in pyproject.toml
.
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.
Agreed on removing --select. Do you have an opinion on whether we should keep the default (everything is fixable) or specify fixable vs unfixable categories?
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.
In my other projects so far, I've been setting F
as unfixable and it's been working for me so far. I haven't looked that hard at the rulesets though.
…oject.toml config and not command line args
I'm in favor of having the default to be Ruff. It's clear that Ruff is the emerging standard, and they describe themselves as production-ready. There are major projects that are fully using Ruff for linting and formatting. Lots of other major projects (e.g., pip, matplotlib, PyTorch) are using Ruff for linting over flake8, though are still using black for now. |
It seems that slight adjustments to the linter rules are necessary to ensure similar behavior as the flake8/black/isort alternative. Most of the rules that flake8 ignores in the If I am not wrong, these additional lines in [tool.ruff.lint]
ignore = [
"E731" # lambda-assignment: Do not assign a lambda expression, use a def
] Update: Additionally, the [tool.ruff.lint]
ignore = ["E731"] # Ignore lambda-assignment
extend-select = ["I"] # Add sorting imports (isort ruleset) to defaults |
Closes #374
Closes #388
This PR adds ruff as the default linting and formatting option for new ccds projects.
Implementation notes
pyproject.toml
and removedsetup.cfg
if using ruff since it's no longer needed.Discussion
As mentioned, this PR makes ruff the default option. I think there's good arguments for this that mostly boil down to "it's simpler + faster":
setup.cfg
file so everything can live inpyproject.toml
However, ruff is still (relatively) new, whereas flake8/black/isort is more mature, and most projects won't notice the speed difference until they get quite large. I could be persuaded that we should introduce ruff without making it the default option.