seddonym / import-linter

Import Linter allows you to define and enforce rules for the internal and external imports within your Python project.
https://import-linter.readthedocs.io/
BSD 2-Clause "Simplified" License
664 stars 45 forks source link

Proposal: introduce Ruff and make mypy more strict #226

Open mikeleppane opened 3 months ago

mikeleppane commented 3 months ago

Hey!

What do you think, would it make sense to replace flake8 with Ruff and make mypy config more strict?

Running mypy in a more strict mode results in the following:

$ mypy src
...
Found 21 errors in 9 files (checked 36 source files)

And the same with Ruff:

$ ruff check src
... 
Found 90 errors.

Below is the used config (assuming the project supports any Python version from 3.8 onwards):

[tool.mypy]
# basic
python-version = "3.8"
exclude = ['^tests/assets/']

# be strict(ish)
disallow_untyped_calls = true
disallow_untyped_defs = true
check_untyped_defs = true
strict_equality = true
no_implicit_optional = true

# warnings
warn_unused_ignores = true
warn_unreachable = true
warn_redundant_casts = true
warn_unused_configs = true

[tool.ruff]
select = [
    "E",
    "F",
    "B",
    "W",
    "C4",
    "PIE",
    "RET",
    "SIM",
    "RUF",
    "C90",
    "UP",
    "ERA",
    "ARG",
    "TID",
    "PERF",
    "SLF",
    "PTH",
    "FURB",
    "I",
    "PL",
]

ignore = [
    "E501",    # line-too-long
    "PLR0913", # Too many arguments in function definition
    "PLR2004", # Magic value used in comparison"
]

# Exclude a variety of commonly ignored directories.
exclude = [".git", ".mypy_cache", ".ruff_cache"]
per-file-ignores = {}

# Same as Black.
line-length = 99

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[tool.ruff.mccabe]
max-complexity = 10
seddonym commented 3 months ago

I like the idea, happy to consider a pull request!