@@ -37,17 +37,39 @@ exclude = ["**/test_cases/**/*.py"]
37
37
# tell ruff not to flag these as e.g. "unused noqa comments"
38
38
external = [" F821" , " NQA" , " Y" ]
39
39
select = [
40
+ " ARG" , # flake8-unused-arguments
40
41
" B" , # flake8-bugbear
42
+ " D" , # pydocstyle
43
+ " EXE" , # flake8-executable
41
44
" FA" , # flake8-future-annotations
42
45
" I" , # isort
46
+ " N" , # pep8-naming
43
47
" PGH" , # pygrep-hooks
44
48
" RUF" , # Ruff-specific and unused-noqa
49
+ " TRY" , # tryceratops
45
50
" UP" , # pyupgrade
46
51
" YTT" , # flake8-2020
47
52
# Flake8 base rules
48
53
" E" , # pycodestyle Error
49
54
" F" , # Pyflakes
50
55
" W" , # pycodestyle Warning
56
+ # Only include flake8-annotations rules that are autofixable. Otherwise leave this to mypy+pyright
57
+ " ANN2" ,
58
+ # Don't include TC rules that create a TYPE_CHECKING block or stringifies annotations
59
+ " TC004" , # Move import `{qualified_name}` out of type-checking block. Import is used for more than type hinting.
60
+ " TC005" , # Found empty type-checking block
61
+ # "TC008", # TODO: Enable when out of preview
62
+ " TC010" , # Invalid string member in `X | Y`-style union type
63
+ # Most refurb rules are in preview and can be opinionated,
64
+ # consider them individually as they come out of preview (last check: 0.8.4)
65
+ " FURB105" , # Unnecessary empty string passed to `print`
66
+ " FURB129" , # Instead of calling `readlines()`, iterate over file object directly
67
+ " FURB136" , # Replace `if` expression with `{min_max}` call
68
+ " FURB167" , # Use of regular expression alias `re.{}`
69
+ " FURB168" , # Prefer `is` operator over `isinstance` to check if an object is `None`
70
+ " FURB169" , # Compare the identities of `{object}` and None instead of their respective types
71
+ " FURB177" , # Prefer `Path.cwd()` over `Path().resolve()` for current-directory lookups
72
+ " FURB187" , # Use of assignment of `reversed` on list `{name}`
51
73
# PYI: only enable rules that have autofixes and that we always want to fix (even manually),
52
74
# avoids duplicate # noqa with flake8-pyi and flake8-noqa flagging `PYI` codes
53
75
# See https://github.com/plinss/flake8-noqa/issues/22
@@ -77,10 +99,6 @@ extend-safe-fixes = [
77
99
" UP036" , # Remove unnecessary `sys.version_info` blocks
78
100
]
79
101
ignore = [
80
- # TODO: Ruff 0.8.0 added sorting of __all__ and __slots_. Validate whether we want this in stubs
81
- " RUF022" ,
82
- " RUF023" ,
83
-
84
102
# ##
85
103
# Rules that can conflict with the formatter (Black)
86
104
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
@@ -92,11 +110,17 @@ ignore = [
92
110
# ##
93
111
# Rules we don't want or don't agree with
94
112
# ##
95
- # Slower and more verbose https://github.com/astral-sh/ruff/issues/7871
96
- " UP038" , # Use `X | Y` in `isinstance` call instead of `(X, Y)`
113
+ # We're not a library, no need to document everything
114
+ " D1" , # Missing docstring in ...
115
+ # Doesn't support split "summary line"
116
+ " D205" , # 1 blank line required between summary line and description
97
117
# Used for direct, non-subclass type comparison, for example: `type(val) is str`
98
118
# see https://github.com/astral-sh/ruff/issues/6465
99
119
" E721" , # Do not compare types, use `isinstance()`
120
+ # Mostly from scripts and tests, it's ok to have messages passed directly to exceptions
121
+ " TRY003" , # Avoid specifying long messages outside the exception class
122
+ # Slower and more verbose https://github.com/astral-sh/ruff/issues/7871
123
+ " UP038" , # Use `X | Y` in `isinstance` call instead of `(X, Y)`
100
124
# ##
101
125
# False-positives, but already checked by type-checkers
102
126
# ##
@@ -106,20 +130,33 @@ ignore = [
106
130
107
131
[tool .ruff .lint .per-file-ignores ]
108
132
"*.pyi" = [
109
- # Most flake8-bugbear rules don't apply for third-party stubs like typeshed.
110
- # B033 could be slightly useful but Ruff doesn't have per-file select
111
- " B" , # flake8-bugbear
133
+ # A lot of stubs are incomplete on purpose, and that's configured through pyright
134
+ # Some ANN204 (special method) are autofixable in stubs, but not all.
135
+ " ANN2" , # Missing return type annotation for ...
136
+ # Most pep8-naming rules don't apply for third-party stubs like typeshed.
137
+ # N811 to N814 could apply, but we often use them to disambiguate a name whilst making it look like a more common one
138
+ " N8" ,
112
139
# Rules that are out of the control of stub authors:
113
140
" F403" , # `from . import *` used; unable to detect undefined names
114
141
# Stubs can sometimes re-export entire modules.
115
142
# Issues with using a star-imported name will be caught by type-checkers.
116
143
" F405" , # may be undefined, or defined from star imports
144
+ # Ruff 0.8.0 added sorting of __all__ and __slots_.
145
+ # There is no consensus on whether we want to apply this to stubs, so keeping the status quo.
146
+ # See https://github.com/python/typeshed/pull/13108
147
+ " RUF022" ,
148
+ " RUF023" ,
117
149
]
118
- # See comment on black's force-exclude config above
119
150
"*_pb2.pyi" = [
151
+ # Leave the docstrings as-is, matching source
152
+ " D" , # pydocstyle
153
+ # See comment on black's force-exclude config above
120
154
" E501" , # Line too long
121
155
]
122
156
157
+ [tool .ruff .lint .pydocstyle ]
158
+ convention = " pep257" # https://docs.astral.sh/ruff/settings/#lint_pydocstyle_convention
159
+
123
160
[tool .ruff .lint .isort ]
124
161
split-on-trailing-comma = false
125
162
combine-as-imports = true
0 commit comments