ubuntu-dev-tools/run-linters
Benjamin Drung 4a2f194860 run-linters: add --errors-only mode
Add `--errors-only` that runs only linters that can detect real errors
and all other ignoring the result.
2025-12-03 14:10:11 +01:00

41 lines
806 B
Bash
Executable File

#!/bin/sh
set -eu
# Copyright 2023, Canonical Ltd.
# SPDX-License-Identifier: GPL-3.0
PYTHON_SCRIPTS=$(grep -l -r '^#! */usr/bin/python3$' .)
run_black() {
echo "Running black..."
black -C --check --diff . ${PYTHON_SCRIPTS}
}
run_isort() {
echo "Running isort..."
isort --check-only --diff .
}
run_flake8() {
echo "Running flake8..."
flake8 --max-line-length=99 --ignore=E203,W503 . $PYTHON_SCRIPTS
}
run_pylint() {
echo "Running pylint..."
pylint "$@" $(find * -name '*.py') $PYTHON_SCRIPTS
}
if test "${1-}" = "--errors-only"; then
# Run only linters that can detect real errors (ignore formatting)
run_black || true
run_isort || true
run_flake8 || true
run_pylint --errors-only
else
run_black
run_isort
run_flake8
run_pylint
fi