diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 00000000..9e962883 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,13 @@ +name: pre-commit + +on: + pull_request: + push: + branches: [main] + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4.1.1 + - uses: pre-commit/action@v3.0.0 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index eae14a85..294d2543 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,13 +6,8 @@ repos: language_version: python3 exclude: rednotebook/external/.*\.py - - repo: https://github.com/pycqa/flake8 - rev: '6.1.0' + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.1.13 hooks: - - id: flake8 - - - repo: https://github.com/asottile/pyupgrade - rev: v2.28.0 - hooks: - - id: pyupgrade + - id: ruff exclude: rednotebook/external/.*\.py diff --git a/pyproject.toml b/pyproject.toml index 6f11efe4..04dbb3c0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,3 +17,77 @@ exclude = ''' | dist )/ ''' + +[tool.ruff] +# Exclude a variety of commonly ignored directories. +exclude = [ + ".eggs", + ".git", + "_build", + "build", + "dist", + "htmlcov", + "vulture.egg-info", + ".cache", + ".coverag", + ".pytest_cache", + ".tox", + ".venv", + ".vscode", +] + +# Same as Black. +line-length = 79 +indent-width = 4 + +target-version = "py38" + +[tool.ruff.lint] +# ruff enables Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default. +select = [ + "F", # pyflakes + "E4", "E7", "E9", # pycodestyle + "B", # flake8-bugbear + "C4", # comprehensions + "UP", # pyupgrade +] +ignore = [ + "C408", # unnecessary dict call +] + +# Allow fix for all enabled rules (when `--fix`) is provided. +fixable = ["ALL"] +unfixable = [] + +# Allow unused variables when underscore-prefixed. +dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" + +[tool.ruff.lint.per-file-ignores] +"vulture/whitelists/*.py" = ["B018"] + +[tool.ruff.format] +# Like Black, use double quotes for strings. +quote-style = "double" + +# Like Black, indent with spaces, rather than tabs. +indent-style = "space" + +# Like Black, respect magic trailing commas. +skip-magic-trailing-comma = false + +# Like Black, automatically detect the appropriate line ending. +line-ending = "auto" + +# Enable auto-formatting of code examples in docstrings. Markdown, +# reStructuredText code/literal blocks and doctests are all supported. +# +# This is currently disabled by default, but it is planned for this +# to be opt-out in the future. +docstring-code-format = false + +# Set the line length limit used when formatting code snippets in +# docstrings. +# +# This only has an effect when the `docstring-code-format` setting is +# enabled. +docstring-code-line-length = "dynamic" diff --git a/tox.ini b/tox.ini index 308fed9e..8350f5d2 100644 --- a/tox.ini +++ b/tox.ini @@ -30,27 +30,16 @@ filterwarnings = basepython = python3 deps = black==22.3.0 - flake8==6.1.0 - flake8-2020==1.7.0 - flake8-bugbear==23.9.16 - flake8-comprehensions==3.14.0 - pyupgrade==2.28.0 -allowlist_externals = - bash + ruff==0.1.13 commands = black --check --diff . - # B028: use !r conversion flag - # C408: unnecessary dict call - flake8 --extend-ignore=B028,C408 setup.py tests/ vulture/ - bash -c "pyupgrade --py38-plus `find dev/ tests/ vulture/ -name '*.py'` setup.py" + ruff . [testenv:fix-style] basepython = python3 deps = black==22.3.0 - pyupgrade==2.28.0 -allowlist_externals = - bash + ruff==0.1.13 commands = black . - bash -c "pyupgrade --py38-plus --exit-zero `find dev/ tests/ vulture/ -name '*.py'` setup.py" + ruff . --fix diff --git a/vulture/utils.py b/vulture/utils.py index 011bb130..3382dca3 100644 --- a/vulture/utils.py +++ b/vulture/utils.py @@ -108,7 +108,7 @@ def read_file(filename): with tokenize.open(filename) as f: return f.read() except (SyntaxError, UnicodeDecodeError) as err: - raise VultureInputException(err) + raise VultureInputException from err class LoggingList(list):