Skip to content

Commit 4132fa1

Browse files
committed
Allow to choose linter, add configs for Ruff
1 parent b57760b commit 4132fa1

File tree

4 files changed

+77
-4
lines changed

4 files changed

+77
-4
lines changed

cookiecutter.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
22
"project_name": "evrone"
3+
"linter": ["Ruff", "Flake8"]
34
}

{{cookiecutter.project_name}}/.pre-commit-config.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ repos:
1515
entry: isort app
1616
language: python
1717
types: [python]
18+
- id: ruff
19+
name: ruff
20+
entry: ruff check app
21+
language: python
22+
types: [python]

{{cookiecutter.project_name}}/Makefile

+10-2
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,25 @@ install-pre-commit:
5959
poetry run pre-commit install
6060

6161
check:
62+
{%- if cookiecutter.linter == 'Flake8' %}
6263
poetry run black --check backend
6364
poetry run isort --check backend
65+
{%- endif %}
66+
{%- if cookiecutter.linter == 'Ruff' %}
67+
poetry run ruff check backend
6468

6569
format:
70+
{%- if cookiecutter.linter == 'Flake8' %}
6671
poetry run black .
6772
poetry run isort .
73+
{%- endif %}
74+
{%- if cookiecutter.linter == 'Ruff' %}
75+
poetry run ruff check --fix .
6876

6977
lint:
70-
poetry run black --check backend
71-
poetry run isort --check backend
78+
{%- if cookiecutter.linter == 'Flake8' %}
7279
poetry run flake8 --inline-quotes '"'
80+
make check
7381
@# For some reason, mypy and pylint fails to resolve PYTHONPATH, set manually.
7482
PYTHONPATH=./app poetry run pylint app
7583
PYTHONPATH=./app poetry run mypy --namespace-packages --show-error-codes app --check-untyped-defs --ignore-missing-imports --show-traceback

{{cookiecutter.project_name}}/pyproject.toml

+61-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ pytest-cov = "^5.0.0"
1818
pytest-django = "^4.8.0"
1919

2020
[tool.poetry.dev-dependencies]
21-
black = "^24.3.0"
22-
isort = "^5.13.2"
2321
pre-commit = "^3.7.0"
2422
django-stubs = "^4.2.7"
23+
{%- if cookiecutter.linter == 'Flake8' %}
24+
isort = "^5.13.2"
25+
black = "^24.3.0"
2526
flake8 = "^7.0.0"
2627
flake8-bandit = "^4.1.1"
2728
flake8-broken-line = "^1.0.0"
@@ -35,10 +36,14 @@ flake8-string-format = "^0.3.0"
3536
flake8-pyproject = "^1.2.3"
3637
flake8-bugbear = "^24.2.6"
3738
flake8-rst-docstrings = "^0.3.0"
39+
{%- endif %}
40+
{%- if cookiecutter.linter == 'Ruff' %}
41+
ruff = "^0.5.7"
3842
mypy = "^1.9.0"
3943
pylint = "^3.1.0"
4044
safety = "^3.1.0"
4145

46+
{%- if cookiecutter.linter == 'Flake8' %}
4247
[tool.black]
4348
line-length = 100
4449
target-version = ['py312']
@@ -66,6 +71,7 @@ known_django = "django"
6671
profile = "django"
6772
src_paths = "app"
6873
lines_after_imports = 2
74+
{%- endif %}
6975

7076
[build-system]
7177
requires = ["poetry-core>=1.0.0"]
@@ -92,6 +98,7 @@ plugins = "mypy_django_plugin.main"
9298
[tool.django-stubs]
9399
django_settings_module = "app.settings.base"
94100

101+
{%- if cookiecutter.linter == 'Flake8' %}
95102
[tool.flake8]
96103
ignore = [
97104
"C812", # missing trailing comma
@@ -184,6 +191,7 @@ max-complexity = 15
184191
max-name-length = 60
185192
max-line-length = 100
186193
count = true
194+
{%- endif %}
187195

188196

189197
[tool.pylint.main]
@@ -267,3 +275,54 @@ ignored-classes = [
267275
"_thread._local",
268276
"argparse.Namespace",
269277
]
278+
279+
280+
{%- if cookiecutter.linter == 'Ruff' %}
281+
[tool.ruff]
282+
src = ["{{cookiecutter.project_name}}"]
283+
line-length = 99
284+
unsafe-fixes = true
285+
extend-exclude = [
286+
"docs/*",
287+
".venv",
288+
"venv",
289+
]
290+
291+
[tool.ruff.lint]
292+
select = ["ALL"]
293+
ignore = [
294+
"COM812", # Trailing comma missing
295+
"D100", # Missing docstring in public module
296+
"D101", # Missing docstring in public class
297+
"D102", # Missing docstring in public method
298+
"D103", # Missing docstring in public function
299+
"D104", # Missing docstring in public package
300+
"D105", # Missing docstring in magic method
301+
"D106", # Missing docstring in public nested class
302+
"D107", # Missing docstring in __init__
303+
"FBT001", # Boolean-typed positional argument in function definition
304+
"FBT002", # Boolean default positional argument in function definition
305+
"N818", # Exception name should be named with Error suffix
306+
"PT004", # Deprecated error, will be removed in future release
307+
]
308+
309+
[tool.ruff.lint.per-file-ignores]
310+
"tests/*" = [
311+
"S101", # Use of assert detected
312+
"S106", # Possible hardcoded password assigned to argument
313+
]
314+
315+
[tool.ruff.lint.isort]
316+
lines-after-imports = 2
317+
318+
[tool.ruff.lint.pylint]
319+
max-args = 12
320+
max-public-methods = 10
321+
max-locals = 16
322+
323+
[tool.ruff.lint.mccabe]
324+
max-complexity = 10
325+
326+
[tool.ruff.lint.pydocstyle]
327+
convention = "google"
328+
{%- endif %}

0 commit comments

Comments
 (0)