Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#5: Allow to choose linter, add configs for Ruff #13

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"project_name": "evrone"
"linter": ["Ruff", "Flake8"]
}
5 changes: 5 additions & 0 deletions {{cookiecutter.project_name}}/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ repos:
entry: isort app
language: python
types: [python]
- id: ruff
name: ruff
entry: ruff check app
language: python
types: [python]
12 changes: 10 additions & 2 deletions {{cookiecutter.project_name}}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,25 @@ install-pre-commit:
poetry run pre-commit install

check:
{%- if cookiecutter.linter == 'Flake8' %}
poetry run black --check backend
poetry run isort --check backend
{%- endif %}
{%- if cookiecutter.linter == 'Ruff' %}
poetry run ruff check backend

format:
{%- if cookiecutter.linter == 'Flake8' %}
poetry run black .
poetry run isort .
{%- endif %}
{%- if cookiecutter.linter == 'Ruff' %}
poetry run ruff check --fix .

lint:
poetry run black --check backend
poetry run isort --check backend
{%- if cookiecutter.linter == 'Flake8' %}
poetry run flake8 --inline-quotes '"'
make check
@# For some reason, mypy and pylint fails to resolve PYTHONPATH, set manually.
PYTHONPATH=./app poetry run pylint app
PYTHONPATH=./app poetry run mypy --namespace-packages --show-error-codes app --check-untyped-defs --ignore-missing-imports --show-traceback
Expand Down
65 changes: 62 additions & 3 deletions {{cookiecutter.project_name}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ pytest = "^8.1.1"
pytest-cov = "^5.0.0"
pytest-django = "^4.8.0"

[tool.poetry.group.dev.dependencies]
black = "^24.3.0"
isort = "^5.13.2"
[tool.poetry.dev-dependencies]
pre-commit = "^3.7.0"
django-stubs = "^4.2.7"
{%- if cookiecutter.linter == 'Flake8' %}
isort = "^5.13.2"
black = "^24.3.0"
flake8 = "^7.0.0"
flake8-bandit = "^4.1.1"
flake8-broken-line = "^1.0.0"
Expand All @@ -35,13 +36,17 @@ flake8-string-format = "^0.3.0"
flake8-pyproject = "^1.2.3"
flake8-bugbear = "^24.2.6"
flake8-rst-docstrings = "^0.3.0"
{%- endif %}
{%- if cookiecutter.linter == 'Ruff' %}
ruff = "^0.5.7"
mypy = "^1.9.0"
pylint = "^3.1.0"
safety = "^3.1.0"
pytest-randomly = "^3.15.0"
faker = "^28.4.1"
factory-boy = "^3.3.1"

{%- if cookiecutter.linter == 'Flake8' %}
[tool.black]
line-length = 100
target-version = ['py312']
Expand Down Expand Up @@ -69,6 +74,7 @@ known_django = "django"
profile = "django"
src_paths = "app"
lines_after_imports = 2
{%- endif %}

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

{%- if cookiecutter.linter == 'Flake8' %}
[tool.flake8]
ignore = [
"C812", # missing trailing comma
Expand Down Expand Up @@ -187,6 +194,7 @@ max-complexity = 15
max-name-length = 60
max-line-length = 100
count = true
{%- endif %}


[tool.pylint.main]
Expand Down Expand Up @@ -270,3 +278,54 @@ ignored-classes = [
"_thread._local",
"argparse.Namespace",
]


{%- if cookiecutter.linter == 'Ruff' %}
[tool.ruff]
src = ["{{cookiecutter.project_name}}"]
line-length = 99
unsafe-fixes = true
extend-exclude = [
"docs/*",
".venv",
"venv",
]

[tool.ruff.lint]
select = ["ALL"]
ignore = [
"COM812", # Trailing comma missing
"D100", # Missing docstring in public module
"D101", # Missing docstring in public class
"D102", # Missing docstring in public method
"D103", # Missing docstring in public function
"D104", # Missing docstring in public package
"D105", # Missing docstring in magic method
"D106", # Missing docstring in public nested class
"D107", # Missing docstring in __init__
"FBT001", # Boolean-typed positional argument in function definition
"FBT002", # Boolean default positional argument in function definition
"N818", # Exception name should be named with Error suffix
"PT004", # Deprecated error, will be removed in future release
]

[tool.ruff.lint.per-file-ignores]
"tests/*" = [
"S101", # Use of assert detected
"S106", # Possible hardcoded password assigned to argument
]

[tool.ruff.lint.isort]
lines-after-imports = 2

[tool.ruff.lint.pylint]
max-args = 12
max-public-methods = 10
max-locals = 16

[tool.ruff.lint.mccabe]
max-complexity = 10

[tool.ruff.lint.pydocstyle]
convention = "google"
{%- endif %}