`ruff init`
I often see projects that do something like this in their pyproject.toml:
[tool.ruff]
target-version = "py39"
line-length = 88
select = [
"A", # flake8-builtins
# "ARG", # flake8-unused-arguments
# "ANN", # flake8-annotations
"B", # flake8-bugbear
# "BLE", # flake8-blind-except
# "C4", # flake8-comprehensions
# "COM", # flake8-commas
"DTZ", # flake8-datetimez
"D", # pydocstyle
"E", # pydocstyle
# "ERA", # eradicate
# "EM", # flake8-errmsg
"EXE", # flake8-executable
"F", # flake8
"G", # flake8-logging-format
"ICN", # flake8-import-conventions
"INP", # flake8-no-pep420
"ISC", # flake8-implicit-str-concat
"N", # pep8-naming
# "PD", # pandas-vet
"PIE", # flake8-pie
# "PGH", # pygrep-hooks [Enable]
# "PT", # flake8-pytest-style [Enable]
# "PTH", # flake8-use-pathlib
"Q", # flake8-quotes
"RET", # flake8-return
"S", # flake8-bandit
"SIM", # flake8-simplify
"T10", # flake8-debugger
"T20", # flake8-print
# "TCH", # flake8-type-checking
"TID", # flake8-tidy-imports
"UP", # pyupgrade
"W", # pydocstyle
"YTT" # flake8-2020
]
ignore = [
"B008",
"B905",
"D104",
"D200",
"D202",
"D205",
"D301",
"D400",
"N801",
"N802",
"N803",
"N806",
"N813",
"N815",
"N816",
"PIE804",
"RET504",
"RET505",
"RET506",
"RET507",
"RET508",
"UP007"
]
typing-modules = ["colour.hints"]
fixable = ["B", "E", "F", "PIE", "SIM","UP", "W"]
[tool.ruff.pydocstyle]
convention = "numpy"
Or, I'll see that projects have copied the "default" configuration included in the docs.
It could be interesting to ship a ruff init command that generates something similar, with useful defaults.
As a proposal to tear down, ruff init would:
- Generate the "default" configuration from the docs, but...
- Include all code classes in
select, with each code followed by a comment to indicate the name of the source plugin as seen above. All of the classes would be commented out apart fromEandF(our current defaults). - Include all code classes in
fixable, with each code followed by a comment to indicate the name of the source plugin as seen above, and a few of the more aggressive sections commented out (likeSIMandB).
Built a small implementation that outputs this:
[tool.ruff]
line-length = 88
select = [
"F", # pyflakes
"E", # pycodestyle
# "W", # pycodestyle
# "C90", # mccabe
# "I", # isort
# "N", # pep8-naming
# "D", # pydocstyle
# "UP", # pyupgrade
# "YTT", # flake8-2020
# "ANN", # flake8-annotations
# "S", # flake8-bandit
# "BLE", # flake8-blind-except
# "FBT", # flake8-boolean-trap
# "B", # flake8-bugbear
# "A", # flake8-builtins
# "COM", # flake8-commas
# "C4", # flake8-comprehensions
# "DTZ", # flake8-datetimez
# "T10", # flake8-debugger
# "EM", # flake8-errmsg
# "EXE", # flake8-executable
# "ISC", # flake8-implicit-str-concat
# "ICN", # flake8-import-conventions
# "G", # flake8-logging-format
# "INP", # flake8-no-pep420
# "PIE", # flake8-pie
# "T20", # flake8-print
# "PT", # flake8-pytest-style
# "Q", # flake8-quotes
# "RET", # flake8-return
# "SIM", # flake8-simplify
# "TID", # flake8-tidy-imports
# "TCH", # flake8-type-checking
# "ARG", # flake8-unused-arguments
# "PTH", # flake8-use-pathlib
# "ERA", # eradicate
# "PD", # pandas-vet
# "PGH", # pygrep-hooks
# "PL", # pylint
# "TRY", # tryceratops
# "RSE", # flake8-raise
# "RUF", # ruff-specific rules
]
fixable = [
"F", # pyflakes
"E", # pycodestyle
# "W", # pycodestyle
# "I", # isort
# "D", # pydocstyle
# "UP", # pyupgrade
# "ANN", # flake8-annotations
# "B", # flake8-bugbear
# "COM", # flake8-commas
# "C4", # flake8-comprehensions
# "EXE", # flake8-executable
# "G", # flake8-logging-format
# "PIE", # flake8-pie
# "T20", # flake8-print
# "PT", # flake8-pytest-style
# "Q", # flake8-quotes
# "RET", # flake8-return
# "SIM", # flake8-simplify
# "ERA", # eradicate
# "PD", # pandas-vet
# "PL", # pylint
# "TRY", # tryceratops
# "RUF", # ruff-specific rules
]
Do we need to add anything else by default?
I'm tempted to include the defaults for src and exclude too.
The bigger block though is deciding whether this is actually a good idea :)
The bigger block though is deciding whether this is actually a good idea :)
@charliermarsh Do you mean including src and exclude or ruff init in general?
I think we can add some of the options and comment them out and list options can also be added as a empty list. E g: ignore = []
Oh sorry! I mean, determining whether ruff init is a good idea.
I do think it makes sense to include the defaults explicitly, like:
src = ["."]
...and so on.
Oh sorry! I mean, determining whether
ruff initis a good idea.
Let me know if you decide to go through with it, I can submit a PR :)
I do think it makes sense to include the defaults explicitly, like:
src = ["."]...and so on.
Sounds good 👍
One thing that could be really cool is creating files for other linters that ignore things we cover. For example, if we cover 50% of pylint's rules, we could generate a file that makes pylint ignore those rules. That way, their pylint takes way less time to run.
Hmm, personally I've been doing the opposite - synchronizing other tool's configurations with what I configured in ruff so that if anyone happens to run that other tool rather than ruff (maybe because that's what they have configured to run in their editor long ago and have never heard about ruff) will still be informed about issues with that subset of rules.
An option which sets select=ALL and all current violations in the project to ignore would be great. Then one could start with a config which is valid and improve from there on.