ScreenPyHQ / screenpy

Screenplay pattern base for Python automated UI test suites.
MIT License
27 stars 3 forks source link

#88: Add Ruff! #106

Closed perrygoy closed 11 months ago

perrygoy commented 11 months ago

Ruff is pretty neat. It's got a lot of different linters all in one spot, and it runs super freakin' quick.

This PR adds ruff with our own stew of selected-and-ignored rules and rulesets.

bandophahita commented 11 months ago

This would be my suggested rule adjustments. Some of the super opinionated rules could be left out. There are also a couple of rulesets that will conflict with 3.8 & 3.9.

[tool.ruff]
target-version = "py38"  # minimum supported version
line-length = 88  # same as Black.
select = [
    "A",  # flake8-builtins
    "ANN",  # flake8-annotations
    "B",  # flake8-bugbear
    "C4",  # flake8-comprehensions
    "D",  # pydocstyle
    "E",  # pycodestyle error
    "ERA",  # eradicate
    "F",  # Pyflakes
    "FIX",  # flake8-fixme
    "FLY",  # flynt
    "I",  # isort
    "ICN",  # flake8-import-conventions
    "ISC",  # flake8-implicit-str-concat
    "PGH",  # pygrep-hooks
    "PIE",  # flake8-pie
    "PERF",  # perflint
    "PL",  # pylint
    "PT",  # flake8-pytest-style
    "Q",  # flake8-quotes
    "RET",  # flake8-return
    "RSE",  # flake8-raise
    "RUF",  # ruff specific
    "SIM",  # flake8-simplify
    "T10",  # flake8-debugger
    "T20",  # flake8-print
    "TCH",  # flake8-type-checking
    "TRY",  # tryceratops
    "W",  # pycodestyle warning
    "YTT",  # flake8-2020

    # would leave off
#    "FURB",  # refurb  # requires use of --preview
#    "ARG",  # flake8-unused-arguments  # more false positives than helpful
#    "BLE",  # flake8-blind-except  # we already use # pylint: disable=broad-except
#    "EM",  # flake8-errmsg  # very opinionated
#    "FA",  # flake8-future-annotations  # conflicts with 3.8 & 3.9
#    "FBT",  # flake8-boolean-trap  # opinionated
#    "UP",  # python upgrade  # conflicts with 3.8
]
ignore = [
    "D107",  # missing __init__ docstring, we do that in the class docstring.
    "D203",  # one blank line before class; we want 2!
    "D212",  # multi line summary first line, we want a one line summary.
    "ANN101",  # missing self annotation, we only annotate self when we return it.
    "ANN401",  # no `**kwargs: Any` typing; unfortunately we don't have a better way.

    # should include to avoid issues

    # maybe just ignore in the files where needed?
    "A003", # Class attribute shadow builtin   
    "ANN102",  # cls  # mypy doesnt need it. will always be 'Self'
    "D200", # One-line docstring should fit on one line
    "PLR2004", # magic-value-comparison  # super opinionated

    # explicit is always better
    "PT003", # [*] `scope='function'` is implied in `@pytest.fixture()`
    "PT011", # `pytest.raises(ValueError)` is too broad -- REALLY?!
]   
# when we get done, we're gonig to want to be able to run `ruff .` against the whole
# project in github actions or tox.  For some reason setting these doesn't allow me to
# run `ruff .`
#include = [
#    "screenpy",
#    "tests",
#]
exclude = [
    "screenpy/__init__.py",
    "screenpy/__version__.py",
    "docs",
]

[tool.ruff.per-file-ignores]
"tests/*" = ["D"]
"setup.py" = ["D"]
"screenpy/actions/debug.py" = ["T100"] # T100 `pdb`, `breakpoint` found/used
perrygoy commented 11 months ago

@bandophahita ready for review! Thank you for your thoughts—i rearranged the includes/excludes, commented out FURB until it's ready for prime time, and added tests to the mix.

I actually like and agree with the opinions in the rulesets you marked as opinionated, we can talk more about those if you'd like. I've used them in other projects and found the code much easier to read, maintain, and understand with their suggestions.