Skip to content

Commit 622b9dc

Browse files
committed
Adds ruff linter
1 parent a0bf0e4 commit 622b9dc

3 files changed

Lines changed: 98 additions & 79 deletions

File tree

.flake8

Lines changed: 0 additions & 18 deletions
This file was deleted.

pyproject.toml

Lines changed: 93 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,6 @@ toml = ["tomli"]
7070
requires = ["poetry-core>=1.0.7"]
7171
build-backend = "poetry.core.masonry.api"
7272

73-
[tool.black]
74-
line-length = 88
75-
target-version = ['py310']
76-
include = '\.pyi?$'
77-
exclude = "tests/fixtures/*"
78-
79-
[tool.isort]
80-
profile = "black"
81-
extend_skip = "tests/fixtures/"
82-
83-
[tool.pylint.master]
84-
max-line-length = 100
85-
load-plugins = [
86-
"pylint_pytest",
87-
]
88-
8973
[tool.coverage.run]
9074
branch = true
9175
relative_files = true
@@ -96,50 +80,19 @@ omit = ["./tests/*"]
9680

9781
[tool.coverage.report]
9882
show_missing = true
83+
exclude_also = [
84+
"if typing.TYPE_CHECKING:",
85+
"if TYPE_CHECKING:",
86+
# Don't complain if tests don't hit defensive assertion code:
87+
"raise NotImplementedError",
88+
"raise AssertionError",
89+
"pass",
90+
]
9991

10092
[tool.coverage.html]
10193
show_contexts = true
10294
skip_covered = false
10395

104-
[tool.pylint."messages control"]
105-
enable = ["all"]
106-
disable = [
107-
# allow TODO comments
108-
"fixme",
109-
# allow disables
110-
"locally-disabled",
111-
"suppressed-message",
112-
# covered by isort
113-
"ungrouped-imports",
114-
# allow classes and functions w/o docstring
115-
"missing-docstring",
116-
# hard number checks can be ignored, because they are covered in code reviews
117-
"too-many-instance-attributes",
118-
"too-many-arguments",
119-
"too-many-locals",
120-
"too-many-branches",
121-
"too-few-public-methods",
122-
"too-many-nested-blocks",
123-
"too-many-public-methods",
124-
# allow methods not to use self
125-
"no-self-use",
126-
# currently some code seems duplicated for pylint
127-
"duplicate-code",
128-
# we are a command line tool and don't want to show all internals
129-
"raise-missing-from",
130-
]
131-
132-
[tool.pylint.basic]
133-
good-names = [
134-
"_",
135-
"i",
136-
"setUp",
137-
"tearDown",
138-
"e",
139-
"ex",
140-
]
141-
no-docstring-rgx = "^_"
142-
14396
[tool.pytest.ini_options]
14497
addopts = "--strict-markers"
14598
xfail_strict = true
@@ -149,3 +102,88 @@ markers = [
149102

150103
[tool.doc8]
151104
max_line_length = 120
105+
106+
[tool.ruff]
107+
line-length = 88
108+
target-version = "py39"
109+
src = ["diff_cover", "tests"]
110+
exclude = ["tests/fixtures/*"]
111+
112+
[tool.ruff.format]
113+
quote-style = "double"
114+
indent-style = "space"
115+
skip-magic-trailing-comma = false
116+
line-ending = "auto"
117+
118+
[tool.ruff.lint]
119+
select = ["ALL"]
120+
ignore = [
121+
# Disable all annotations
122+
"ANN",
123+
# allow TODO comments (equivalent to "fixme")
124+
"FIX",
125+
126+
"D200", # Disables One-line docstring should fit on one line
127+
"D205", # Disables 1 blank line required between summary line and description
128+
"D212", # Disables Multi-line docstring summary should start at the first line
129+
"D400", # Disables First line should end with a period
130+
"D415", # Disables First line should end with a period, question mark, or exclamation point
131+
132+
# allow disables (equivalent to "locally-disabled", "suppressed-message")
133+
"RUF100",
134+
135+
# covered by isort (equivalent to "ungrouped-imports")
136+
"I",
137+
138+
# allow classes and functions w/o docstring (equivalent to "missing-docstring")
139+
"D1",
140+
141+
# hard number checks (equivalent to "too-many-*" rules)
142+
"C901", # complexity
143+
"PLR0912", # too many branches
144+
"PLR0913", # too many arguments
145+
"PLR0914", # too many locals
146+
"PLR0915", # too many statements
147+
"PLR0916", # too many nested blocks
148+
"PLR0904", # too many public methods
149+
150+
# duplicate code detection (equivalent to "duplicate-code")
151+
"CPY",
152+
153+
# we are a command line tool (equivalent to "raise-missing-from")
154+
"B904",
155+
156+
# Resolve incompatible docstring rules
157+
"D203", # Keep D211 (no-blank-line-before-class)
158+
"D213", # Keep D212 (multi-line-summary-first-line)
159+
160+
# Avoid formatter conflicts
161+
"COM812",
162+
]
163+
164+
# The equivalent of pylint's good-names
165+
allowed-confusables = ["_"]
166+
167+
[tool.ruff.lint.pep8-naming]
168+
# Allow specific names that might otherwise violate naming conventions
169+
ignore-names = ["i", "e", "ex", "setUp", "tearDown"]
170+
171+
[tool.ruff.lint.per-file-ignores]
172+
"tests/*" = [
173+
"S101", # Disables Assert statements
174+
"PLR2004", # Disables Magic value
175+
"PT011", # Disables Exception is too broad
176+
"RUF012", # Disables Mutable class attributes should be annotated with typing.ClassVar
177+
]
178+
179+
[tool.ruff.lint.pydocstyle]
180+
# Equivalent to pylint's no-docstring-rgx
181+
ignore-decorators = ["^_"]
182+
183+
[tool.ruff.lint.isort]
184+
known-first-party = ["diff_cover", "tests"]
185+
section-order = ["future", "standard-library", "third-party", "first-party", "local-folder"]
186+
lines-between-types = 0
187+
lines-after-imports = 2
188+
combine-as-imports = true
189+
split-on-trailing-comma = false

verify.sh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
#!/bin/bash
22
set -euo pipefail
33
IFS=$'\n\t'
4+
COMPARE_BRANCH=${COMPARE_BRANCH:-origin/main}
45

5-
black diff_cover tests --check
6-
isort diff_cover tests --check
6+
ruff format --check
7+
ruff check --select I
78
python -m pytest -n auto --cov-context test --cov --cov-report=xml tests
89
git fetch origin main:refs/remotes/origin/main
910
diff-cover --version
1011
diff-quality --version
11-
diff-cover coverage.xml --include-untracked
12-
diff-quality --violations flake8 --include-untracked
13-
diff-quality --violations pylint --include-untracked
12+
diff-cover coverage.xml --include-untracked --compare-branch=$COMPARE_BRANCH
13+
diff-quality --violations ruff.check --include-untracked --compare-branch=$COMPARE_BRANCH
1414
doc8 README.rst --ignore D001
15-

0 commit comments

Comments
 (0)