Skip to content

Commit 3dd61a1

Browse files
Merge pull request #21 from analog-garage/ruff
Add ruff linting support
2 parents a80eb60 + 722fded commit 3dd61a1

File tree

4 files changed

+71
-7
lines changed

4 files changed

+71
-7
lines changed

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ PYTEST_ARGS :=
4545
TOX_ARGS :=
4646
PYLINT_ARGS :=
4747
MYPY_ARGS :=
48+
RUFF_ARGS :=
4849

4950
DOC_DIR := docs
5051
MKDOC_CONFIG := mkdocs.yml
@@ -71,7 +72,7 @@ help:
7172
@$(ECHO)
7273
@$(ECHO) "$(SECTION_COLOR)--- lint ---$(COLORLESS)"
7374
@$(ECHO) "lint - Run linting commands in '$(DEV_ENV)' environment."
74-
@$(ECHO) "pylint - Run pylint in '$(DEV_ENV)' environment."
75+
@$(ECHO) "ruff - Run ruff in '$(DEV_ENV)' environment."
7576
@$(ECHO) "mypy - Run mypy in '$(DEV_ENV)' environment."
7677
@$(ECHO)
7778
@$(ECHO) "$(SECTION_COLOR)--- build ---$(COLORLESS)"
@@ -137,10 +138,13 @@ coverage-show:
137138
pylint:
138139
$(CONDA_RUN) pylint src/mkdocstrings_handlers tests $(PYLINT_ARGS)
139140

141+
ruff:
142+
$(CONDA_RUN) ruff check src/mkdocstrings_handlers tests $(RUFF_ARGS)
143+
140144
mypy:
141145
$(CONDA_RUN) mypy $(MYPY_ARGS)
142146

143-
lint: pylint mypy
147+
lint: ruff mypy
144148

145149
WHEEL_FILE := dist/$(subst -,_,$(PACKAGE))-$(VERSION)-py3-none-any.whl
146150
CONDA_FILE := dist/$(PACKAGE)-$(VERSION)-py_0.conda

environment.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ dependencies:
1111
- hatchling >=1.21
1212
# test
1313
- coverage >=7.4.0
14-
- pytest >=7.4.0
15-
- pytest-cov >=4.1.0
14+
- pytest >=8.2
15+
- pytest-cov >=5.0
1616
- pylint >=3.0.3
17-
- mypy >=1.8
17+
- mypy >=1.10
18+
- ruff >=0.4.10
1819
- beautifulsoup4 >=4.12
1920
# documentation
2021
- black >=23.12

pyproject.toml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,66 @@ module = [
7474
]
7575
ignore_missing_imports = true
7676

77+
[tool.ruff.lint]
78+
# TODO add "I" (isort)
79+
# TODO add "RUF"
80+
# TODO add "ARG"
81+
# TODO add "SIM"
82+
# TODO add "S" (bandit)
83+
# TODO add "PT" (pytest style)
84+
# TODO add "CPY101"
85+
select = ["E", "F", "PL", "D", "R", "T10", "EXE"]
86+
ignore = [
87+
"D105", # missing doc string for dunder methods
88+
"D200", # one line doc string
89+
"D202", # blank lines after function docstring
90+
"D205", # doc on first line
91+
"D212", # doc on first line
92+
"D410", # blank line after doc section
93+
"D411", # blank line before doc section
94+
"D412", # no blank lines after section header
95+
"D415", # doc title punctuation
96+
"E501", # line too long
97+
"PLC0105", # covariant metatype names
98+
"PLR0913", # too-many-argument
99+
"PLR2004", # magic value
100+
"PT001", # allow @pytest.fixture without parens
101+
"RET504", # unnecessary assignment to variable before return
102+
"S101", # use of assert - do we care?
103+
# TODO: fix the ones below
104+
"D403", # capitalize first word of doc string
105+
"D102", # undocumented public method
106+
"D104", # missing docstring in public package
107+
"D107", # __init__ docstring
108+
"D417", # missing argument description
109+
]
110+
preview = true
111+
explicit-preview-rules = true # only preview explicitly selected rules (E.g. CPY001)
112+
113+
[tool.ruff.lint.per-file-ignores]
114+
# Ignore some issues in tests
115+
"tests/**" = [
116+
"F401", # unused import (pytest fixture)
117+
"F403", # wildcard import (for fixtures)
118+
"F405", # defined from star imports (typicallky a pytest fixture)
119+
"F811", # redefinition of unused (typically a pytest fixture)
120+
"PLR0912", # too many branches
121+
"PLR0915", # too many statements
122+
"S", # bandit rules
123+
]
124+
125+
[tool.ruff.lint.pylint]
126+
#max-locals = 30
127+
max-branches = 15
128+
#max-attributes = 30
129+
130+
[tool.ruff.lint.pydocstyle]
131+
convention = "google"
132+
133+
[too.ruff.format]
134+
skip-magic-trailing-comma = false
135+
line-ending = "lf"
136+
77137
[tool.pylint.main]
78138
jobs = 0
79139
# Minimum Python version to use for version dependent checks.

tests/test_handler.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ def test_handler(tmpdir: PathLike,
7474
def fake_collect(_self: PythonHandler, identifier: str, _config: dict) -> Any:
7575
if identifier.startswith('mod'):
7676
return Object(identifier)
77-
else:
78-
raise CollectionError(identifier)
77+
raise CollectionError(identifier)
7978

8079
def fake_render(_self: PythonHandler, data: Object, _config: dict) -> str:
8180
assert data.docstring is not None

0 commit comments

Comments
 (0)