Linting and code quality¶
Code can be linted and quality-checked with the command
just check
Note that this requires the prek hooks to be installed.
This command will run the following tools:
ruff¶
ruff is used to lint and format the code, and it is configured through pyproject.toml with comprehensive rules covering security, style, best practices, and documentation:
[tool.ruff]
line-length = 120
fix = true
[tool.ruff.lint]
preview = true
select = [
"FAST", # FastAPI - FastAPI specific rules
"YTT", # flake8-2020 - checks for Python 2020 best practices
"ANN", # flake8-annotations - enforces type annotation style
"S", # flake8-bandit - security issues
"BLE", # flake8-blind-except – flags bare excepts
"FBT", # flake8-boolean-trap – potential pitfalls with booleans
"B", # flake8-bugbear - common bug patterns
"A", # flake8-builtins - misuse of python builtin names
"C4", # flake8-comprehensions - best practices in comprehensions
"DTZ", # flake8-datetimez – requires timezone-aware datetime objects
"T10", # flake8-debugger – debugger statements (e.g. pdb)
"SIM", # flake8-simplify
"EM", # flake8-errmsg – error message style
"EXE", # flake8-executable – executable file checks
"FA", # flake8-future-annotations – future import for annotations
"ISC", # flake8-implicit-str-concat – warns on implicit string concatenation
"ICN", # flake8-import-conventions – enforces conventional import aliases
"LOG", # flake8-logging – proper logging usage
"G", # flake8-logging-format – logging format string issues
"INP", # flake8-no-pep420 – warns against non-PEP420 namespace usage
"PIE", # flake8-pie – Python improvement suggestions
"PYI", # flake8-pyi – checks for type stub (.pyi) consistency
"PT", # flake8-pytest-style – pytest best practices
"Q", # flake8-quotes – enforces quote style consistency
"RSE", # flake8-raise – proper raise statement usage
"RET", # flake8-return – return statement issues
"SLF", # flake8-self – flags instance methods that don't use self
"SLOT", # flake8-slots – suggests use of __slots__ where appropriate
"TID", # flake8-tidy-imports – enforces specific import styles
"TC", # flake8-type-checking – proper import of typing in type checks
"INT", # flake8-gettext – checks for proper internationalization usage
"ARG", # flake8-unused-arguments – flags unused function arguments
"PTH", # flake8-use-pathlib – encourages pathlib over os.path
"TD", # flake8-todos – flags TODO comments
"FIX", # flake8-fixme – flags FIXME comments
"FLY", # Flynt - f-string conversion suggestions
"I", # isort - import ordering checks
"C90", # mccabe - complexity metric for functions
"NPY", # NumPy-specific rules
"PD", # pandas-vet – pandas-specific code practices
"N", # PEP8 Naming – naming conventions
"PERF", # Perflint – performance-related checks
"E", # pycodestyle errors
"W", # pycodestyle warnings
"DOC", # pydoclint - docstring style
"D", # pydocstyle - docstring formatting
"F", # pyflakes - detects syntax errors and basic mistakes
"PGH", # pygrep-hooks - custom grep hooks for linting
"UP", # pyupgrade - upgrades syntax to newer Python versions
"RUF", # Ruff-specific rules
"TRY", # Tryceratops – try/except usage suggestions
]
ignore = [
"E501", # line-too-long
"S311", # suspicious-non-cryptographic-random-usage
"D107", # undocumented-public-init
]
[tool.ruff.lint.pydocstyle]
convention = "google"
[tool.ruff.lint.per-file-ignores]
"tests/*" = ["D", "S101", "ANN", "BLE", "TRY"]
This comprehensive rule set helps ensure code quality, security, and maintainability across your project.
mypy¶
mypy is used for static type checking, and it's configuration can be edited in pyproject.toml.
[tool.mypy]
disallow_untyped_defs = true
disallow_any_unimported = true
no_implicit_optional = true
check_untyped_defs = true
warn_return_any = true
warn_unused_ignores = true
show_error_codes = true
exclude = [
'\.venv',
'{{cookiecutter.project_name}}',
'tests'
]
ty¶
ty is an extremely fast type checker (and language server) that can be used instead of mypy, and it's configuration can be edited in pyproject.toml.
[tool.ty.environment]
python = "./.venv"
python-version = "3.10"
deptry¶
deptry is used to check the code for dependency issues, and it can be configured by adding a [tool.deptry] section in pyproject.toml. For more information, see this section documentation of deptry.
Github Actions¶
If include_github_actions is set to "y", code formatting is checked
for every merge request, every merge to main, and every release.