Ruff

November, 17, 2025

As you know, I'm working on this project by myself, so over time, a lot of garbage has accumulated in the code. I’ve decided to use the Ruff linter to check the code and push corrections to the project, so that gradually my code will evolve into something with a decent structure and appearance.

Here is a ruff.toml file:

# Ruff configuration for a Django project
#
# HOW TO USE:
# 1. Save this file as `ruff.toml` in your project root (same folder as manage.py).
#    - Alternatively, you can copy this into `pyproject.toml` under:
#        [tool.ruff]
#        [tool.ruff.lint]
#        [tool.ruff.format]
#
# 2. Install / run Ruff (choose ONE of the following approaches):
#
#    a) Using uv (recommended):
#         # One-off runs without installing Ruff globally:
#         uvx ruff check .          # Lint the whole project
#         uvx ruff check . --fix    # Lint and auto-fix what can be fixed
#         uvx ruff format .         # Auto-format your code
#
#       # Or install Ruff as a uv tool:
#         uv tool install ruff
#         ruff check .
#         ruff format .
#
#    b) Using pip:
#         pip install ruff
#         ruff check .              # Lint the whole project
#         ruff check . --fix        # Lint and auto-fix
#         ruff format .             # Auto-format your code
#
# 3. Tweak the config below as your project grows.


# Global options
line-length = 120          # Max allowed line length in characters
target-version = "py314"   # Target Python version
src = ["."]                # Treat current directory as the source root
respect-gitignore = true   # Ignore files/directories listed in .gitignore

# Don't waste time linting generated or irrelevant stuff
exclude = [
    ".venv",        # Virtual environment
    "venv",         # Alternative virtualenv name
    "migrations",   # Django migrations (auto-generated)
    "static",       # Collected/compiled static files
    "node_modules", # Frontend dependencies
    "dist",         # Build artifacts
    "build",        # Build artifacts
]

[lint]
# Enable main rule families:
select = [
    "E",   # pycodestyle errors
    "F",   # pyflakes (undefined names, unused vars, etc.)
    "W",   # pycodestyle warnings
    "I",   # isort (import sorting)
    "B",   # flake8-bugbear (bug-prone patterns)
    "DJ",  # flake8-django rules
    "UP",  # pyupgrade (modern Python syntax)
    "N",   # pep8-naming (naming conventions)
    "SIM", # flake8-simplify (suggest simpler code)
    "COM", # flake8-commas (comma style)
    "PT",  # pytest-style (pytest-specific best practices)
]

# Globally ignore rules that are noisy or handled by a formatter
ignore = [
    "E501",   # Line too long (let `ruff format` or `black` handle wrapping instead)
]

[lint.per-file-ignores]
# manage.py and settings files often need special-case handling
"manage.py" = ["DJ001", "DJ008"]                     # Django entry point; allow some Django-specific patterns
"*/settings.py" = ["E402", "F401", "F403"]           # Settings often have imports in odd places, unused imports, and `import *`

# Django migrations are generated; don't fight them
"*/migrations/*.py" = [
    "E501",  # Long lines
    "E402",  # Imports not at top of file
    "F401",  # Unused imports
    "F403",  # `from x import *`
    "B008",  # Function calls in default arguments (common in migrations)
    "DJ001", # Django rule often noisy in migrations
]

[format]
# Only used if you run `ruff format`
quote-style = "double"         # Prefer double quotes for strings
indent-style = "space"         # Use spaces for indentation
line-ending = "lf"             # Use Unix line endings
docstring-code-format = true   # Also format code examples inside docstrings

 


Similar articles:

Learning Modern Linux

Learning Python

Rust course for begginers

Reddit