~martijnbraam/almobootstrap

27618d5ffdb0b6cbf9471dc01a2ed14e1655ced0 — Hugo Osvaldo Barrera 8 months ago ecb7660
Use ruff for linting

Use ruff instead of flake8. Aside from being substantially faster, ruff
includes a lot of flake's plug-ins built-in, some of which may be useful
to enable as a follow-up.

Also move the relevant configuration out of the script in .ci/ and into
the project-wide settings. A side effect of this is that IDEs should
detect these settings, and ignore the same rules as CI, avoiding false
positives while developing locally.

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230529203448.18656-1-hugo@whynothugo.nl%3E
5 files changed, 11 insertions(+), 14 deletions(-)

M .build.yml
R .ci/{flake8.sh => ruff.sh}
M pmb/ci/__init__.py
A pyproject.toml
M setup.cfg
M .build.yml => .build.yml +2 -2
@@ 9,9 9,9 @@ tasks:
  - shellcheck: |
      cd pmbootstrap
      sudo .ci/shellcheck.sh
  - flake8: |
  - ruff: |
      cd pmbootstrap
      sudo .ci/flake8.sh
      sudo .ci/ruff.sh
  - vermin: |
      cd pmbootstrap
      sudo .ci/vermin.sh

R .ci/flake8.sh => .ci/ruff.sh +3 -8
@@ 4,21 4,16 @@

if [ "$(id -u)" = 0 ]; then
	set -x
	apk -q add py3-flake8
	apk -q add ruff
	exec su "${TESTUSER:-build}" -c "sh -e $0"
fi

# E402: module import not on top of file, not possible for testcases
# E722: do not use bare except
# W504: line break occurred after a binary operator
ign="E402,E722,W504"

set -x

# __init__.py with additional ignore:
# F401: imported, but not used
# shellcheck disable=SC2046
flake8 --ignore "F401,$ign" $(find . -not -path '*/venv/*' -name '__init__.py')
ruff --ignore "F401" $(find . -not -path '*/venv/*' -name '__init__.py')

# Check all other files
flake8 --ignore="$ign" --exclude=__init__.py
ruff  --exclude=__init__.py .

M pmb/ci/__init__.py => pmb/ci/__init__.py +1 -1
@@ 16,7 16,7 @@ def get_ci_scripts(topdir):
        :param topdir: top directory of the git repository, get it with:
                       pmb.helpers.git.get_topdir()
        :returns: a dict of CI scripts found in the git repository, e.g.
                  {"flake8": {"description": "lint all python scripts",
                  {"ruff": {"description": "lint all python scripts",
                              "options": []},
                   ...} """
    ret = {}

A pyproject.toml => pyproject.toml +5 -0
@@ 0,0 1,5 @@
[tool.ruff]
# E402: module import not on top of file, not possible for testcases
# E722: do not use bare except
ignore=["E402", "E722"]
line-length=100

M setup.cfg => setup.cfg +0 -3
@@ 1,5 1,2 @@
[bdist_wheel]
universal=0

[flake8]
max-line-length=100