Skip to content

Commit 08128ea

Browse files
authored
Merge pull request #13 from nifadyev/feature/#5/add-optional-ruff-config
#5: Allow to choose linter, add configs for Ruff
2 parents 2cf2afb + 80eef8c commit 08128ea

File tree

4 files changed

+78
-5
lines changed

4 files changed

+78
-5
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

+62-3
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ pytest = "^8.1.1"
1717
pytest-cov = "^5.0.0"
1818
pytest-django = "^4.8.0"
1919

20-
[tool.poetry.group.dev.dependencies]
21-
black = "^24.3.0"
22-
isort = "^5.13.2"
20+
[tool.poetry.dev-dependencies]
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,13 +36,17 @@ 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
pytest-randomly = "^3.15.0"
4246
faker = "^28.4.1"
4347
factory-boy = "^3.3.1"
4448

49+
{%- if cookiecutter.linter == 'Flake8' %}
4550
[tool.black]
4651
line-length = 100
4752
target-version = ['py312']
@@ -69,6 +74,7 @@ known_django = "django"
6974
profile = "django"
7075
src_paths = "app"
7176
lines_after_imports = 2
77+
{%- endif %}
7278

7379
[build-system]
7480
requires = ["poetry-core>=1.0.0"]
@@ -95,6 +101,7 @@ plugins = "mypy_django_plugin.main"
95101
[tool.django-stubs]
96102
django_settings_module = "app.settings.base"
97103

104+
{%- if cookiecutter.linter == 'Flake8' %}
98105
[tool.flake8]
99106
ignore = [
100107
"C812", # missing trailing comma
@@ -187,6 +194,7 @@ max-complexity = 15
187194
max-name-length = 60
188195
max-line-length = 100
189196
count = true
197+
{%- endif %}
190198

191199

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

0 commit comments

Comments
 (0)