Skip to content

Commit

Permalink
Use ruff for linting (#347)
Browse files Browse the repository at this point in the history
  • Loading branch information
tqa236 authored Jan 19, 2024
1 parent e20349b commit aa42062
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 24 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: pre-commit

on:
pull_request:
push:
branches: [main]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- uses: pre-commit/[email protected]
11 changes: 3 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
74 changes: 74 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
19 changes: 4 additions & 15 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion vulture/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit aa42062

Please sign in to comment.