Adopt the Ruff code linting tool

https://github.com/charliermarsh/ruff
This commit is contained in:
Adam Turner
2022-12-29 17:00:27 +00:00
parent f852661243
commit 8634fbce60
6 changed files with 78 additions and 3 deletions

View File

@@ -28,6 +28,22 @@ jobs:
- name: Run Tox
run: tox -e ${{ matrix.tool }}
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade ruff
- name: Lint with Ruff
run: ruff . --diff --format github
pre-commit:
runs-on: ubuntu-latest
steps:

View File

@@ -135,6 +135,54 @@ exclude = [
[tool.isort]
line_length = 95
[tool.ruff]
target-version = "py38" # Pin Ruff to Python 3.8
line-length = 95
exclude = [
'.git',
'.tox',
'.venv',
'tests/roots/*',
'build/*',
'doc/_build/*',
'sphinx/search/*',
'doc/usage/extensions/example*.py',
]
ignore = [
# pycodestyle
'E741',
# flake8-bugbear
'B006',
'B023',
# flake8-bugbear opinionated (disabled by default in flake8)
'B904',
'B905',
]
external = [ # Whitelist for RUF100 unkown code warnings
"E704",
"W291",
"W293",
]
select = [
"E", # pycodestyle
"F", # Pyflakes
"W", # pycodestyle
# plugins:
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"SIM", # flake8-simplify
"RUF100" # yesqa
]
[tool.ruff.per-file-ignores]
"tests/*" = ["E501"]
"sphinx/environment/collectors/toctree.py" = ["B026"]
"sphinx/environment/adapters/toctree.py" = ["B026"]
# Ruff does not support 'import-order-style = smarkets'
"sphinx/util/__init__.py" = ["F401"]
"sphinx/util/inspect.py" = ["F401"]
[tool.mypy]
check_untyped_defs = true
disallow_incomplete_defs = true

View File

@@ -1320,7 +1320,7 @@ def deprecate_html_4(_app: Sphinx, config: Config) -> None:
# for compatibility
import sphinxcontrib.serializinghtml # noqa: E402,F401
import sphinx.builders.dirhtml # noqa: E402,F401
import sphinx.builders.dirhtml # noqa: E402,F401,RUF100
import sphinx.builders.singlehtml # noqa: E402,F401
deprecated_alias('sphinx.builders.html',

View File

@@ -27,7 +27,7 @@ from sphinx.util.nodes import (caption_ref_re, explicit_title_re, # noqa: F401
nested_parse_with_titles, split_explicit_title)
# import other utilities; partly for backwards compatibility, so don't
# prune unused ones indiscriminately
from sphinx.util.osutil import (SEP, copyfile, copytimes, ensuredir, # noqa: F401,E501
from sphinx.util.osutil import (SEP, copyfile, copytimes, ensuredir, # noqa: F401
make_filename, mtimes_of_files, os_path, relative_uri)
from sphinx.util.typing import PathMatcher

View File

@@ -159,7 +159,7 @@ def test_restify_type_hints_alias():
def test_restify_type_ForwardRef():
from typing import ForwardRef # type: ignore
assert restify(ForwardRef("myint")) == ":py:class:`myint`"
assert restify(ForwardRef("myint")) == ":py:class:`myint`" # NoQA: F821
def test_restify_type_Literal():

11
tox.ini
View File

@@ -43,6 +43,17 @@ extras =
commands =
flake8 {posargs}
[testenv:ruff]
basepython = python3
description =
Run style checks with ruff.
whitelist_externals =
ruff
extras =
lint
commands =
ruff {posargs}
[testenv:isort]
basepython = python3
description =