File: run-linters

package info (click to toggle)
ubuntu-dev-tools 0.208
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,172 kB
  • sloc: python: 9,118; sh: 1,330; perl: 135; makefile: 11
file content (48 lines) | stat: -rwxr-xr-x 966 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/sh
set -eu

# Copyright 2023, Canonical Ltd.
# SPDX-License-Identifier: GPL-3.0

PYTHON_SCRIPTS=$(find . -maxdepth 1 -type f -exec grep -l '^#! */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_mypy() {
    echo "Running mypy..."
    mypy .
    mypy --scripts-are-modules $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_mypy
    run_pylint --errors-only
else
    run_black
    run_isort
    run_flake8
    run_mypy
    run_pylint
fi