Integration

Python Coverage integration

  1. Locate uncovered code source lines

  2. If the uncovered code is touched withing changes in current branch.

  3. Show only not tested file name and line to be covered with unittest.

$ custolint coverage --data-file=.coverage
INFO    :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/cli.py:67: ---- coverage ------
INFO    :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/git.py:218: Compare current branch with 'main' branch
WARNING :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/git.py:174: Be aware that current git version (2, 25, 1) is less than recommended (2, 39, 2)
INFO    :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/git.py:145: Execute git diff command 'git branch --show-current'
INFO    :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/git.py:185: Execute git pull --rebase command 'git pull --rebase origin main'
WARNING :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/git.py:189: Pull command failed: error: cannot pull with rebase: You have unstaged changes.
error: please commit or stash them.

INFO    :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/git.py:226: Execute git diff command 'git diff origin/main -U0 --diff-filter=ACMRTUXB'
INFO    :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/git.py:263: Git diff detected 3 filed affected
INFO    :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/coverage.py:101: execute coverage command: 'coverage report --rcfile=config.d/.coveragerc --data-file=.coverage'
src/custolint/mypy.py:253-254 not.committed.yet 2023-08-11
src/custolint/pylint.py:162 not.committed.yet 2023-08-11

Important

Please ensure set source in the configuration, otherwise coverage will include just files covered by the tests.

config.d/.coveragerc
[run]
source = src/custolint
branch = True

or

setup.cfg
[coverage:run]
source = src/custolint
branch = True

Flake8 integration

  1. Find affected files

$ git diff origin/main -U0 --diff-filter=ACMRTUXB
INFO:custolint.git:Git diff detected 16 filed affected
  1. Executing Flake8 linting only on affected file

$ flake8 --config=config.d/.flake8 src/custolint/flake8.py
src/custolint/flake8.py:65:1: W391 blank line at end of file
  1. Filter all original Flake8 message with custolint rules

$ custolint flake8
INFO    :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/cli.py:67: ---- flake8 ------
INFO    :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/git.py:218: Compare current branch with 'main' branch
WARNING :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/git.py:174: Be aware that current git version (2, 25, 1) is less than recommended (2, 39, 2)
INFO    :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/git.py:145: Execute git diff command 'git branch --show-current'
INFO    :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/git.py:185: Execute git pull --rebase command 'git pull --rebase origin main'
WARNING :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/git.py:189: Pull command failed: error: cannot pull with rebase: You have unstaged changes.
error: please commit or stash them.

INFO    :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/git.py:226: Execute git diff command 'git diff origin/main -U0 --diff-filter=ACMRTUXB'
INFO    :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/git.py:263: Git diff detected 3 filed affected
INFO    :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/generics.py:103: Execute lint commands 'flake8 --config=config.d/.flake8 {lint_file}' for 3 files ...
INFO    :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/generics.py:107: Execute lint command: 'flake8 --config=config.d/.flake8 src/custolint/flake8.py src/custolint/mypy.py src/custolint/pylint.py'
src/custolint/flake8.py:65 1: W391 blank line at end of file ## not.committed.yet:2023-08-11
src/custolint/mypy.py:253 1: E305 expected 2 blank lines after class or function definition, found 0 ## not.committed.yet:2023-08-11
src/custolint/pylint.py:162 1: F401 'os' imported but unused ## not.committed.yet:2023-08-11
src/custolint/pylint.py:162 1: E305 expected 2 blank lines after class or function definition, found 0 ## not.committed.yet:2023-08-11
src/custolint/pylint.py:162 1: E402 module level import not at top of file ## not.committed.yet:2023-08-11

MyPy: Static Typing for Python integration

Logic:

  1. Find affected files

$ git diff origin/main -U0 --diff-filter=ACMRTUXB
INFO:custolint.git:Git diff detected 16 filed affected
  1. Executing Mypy typing only on affected file

$ mypy --config=config.d/mypy.ini src/custolint/mypy.py
src/custolint/mypy.py:254: error: Incompatible types in assignment (expression has type "str", variable has type "bool")  [assignment]
Found 1 error in 1 file (checked 1 source file)

Important

If no configuration is provided, Custolint will fall back to strict mode.

$ mypy --strict --show-error-codes file1.py ... file16.py

Filter all original Mypy message with custolint rules

$ custolint mypy
INFO    :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/cli.py:67: ---- mypy ------
INFO    :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/git.py:218: Compare current branch with 'main' branch
WARNING :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/git.py:174: Be aware that current git version (2, 25, 1) is less than recommended (2, 39, 2)
INFO    :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/git.py:145: Execute git diff command 'git branch --show-current'
INFO    :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/git.py:185: Execute git pull --rebase command 'git pull --rebase origin main'
WARNING :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/git.py:189: Pull command failed: error: cannot pull with rebase: You have unstaged changes.
error: please commit or stash them.

INFO    :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/git.py:226: Execute git diff command 'git diff origin/main -U0 --diff-filter=ACMRTUXB'
INFO    :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/git.py:263: Git diff detected 3 filed affected
INFO    :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/mypy.py:225: Execute command 'mypy --config-file=config.d/mypy.ini @/tmp/tmprxmc723o'
src/custolint/mypy.py:254 Incompatible types in assignment (expression has type "str", variable has type "bool")  [assignment] ## not.committed.yet:2023-08-11

PyLint integration

  1. Find affected files

$ git diff origin/main -U0 --diff-filter=ACMRTUXB
INFO:custolint.git:Git diff detected 16 filed affected
  1. Executing PyLint typing only on affected file

$ pylint --rcfile=config.d/pylintrc src/custolint/pylint.py
************* Module custolint.pylint
src/custolint/pylint.py:162:0: C0413: Import "import os" should be placed at the top of the module (wrong-import-position)
src/custolint/pylint.py:162:0: C0411: standard import "import os" should be placed before "from . import _typing, env, generics" (wrong-import-order)
src/custolint/pylint.py:162:0: W0611: Unused import os (unused-import)

-----------------------------------
Your code has been rated at 9.46/10
  1. Filter all original PyLint message with custolint rules

$ custolint pylint
INFO    :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/cli.py:67: ---- pylint ------
INFO    :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/git.py:218: Compare current branch with 'main' branch
WARNING :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/git.py:174: Be aware that current git version (2, 25, 1) is less than recommended (2, 39, 2)
INFO    :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/git.py:145: Execute git diff command 'git branch --show-current'
INFO    :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/git.py:185: Execute git pull --rebase command 'git pull --rebase origin main'
WARNING :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/git.py:189: Pull command failed: error: cannot pull with rebase: You have unstaged changes.
error: please commit or stash them.

INFO    :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/git.py:226: Execute git diff command 'git diff origin/main -U0 --diff-filter=ACMRTUXB'
INFO    :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/git.py:263: Git diff detected 3 filed affected
INFO    :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/generics.py:103: Execute lint commands 'pylint --rcfile=config.d/pylintrc {lint_file}' for 3 files ...
INFO    :/home/docs/checkouts/readthedocs.org/user_builds/custolint/checkouts/latest/src/custolint/generics.py:107: Execute lint command: 'pylint --rcfile=config.d/pylintrc src/custolint/flake8.py src/custolint/mypy.py src/custolint/pylint.py'
src/custolint/flake8.py:65 0: C0305: Trailing newlines (trailing-newlines) ## not.committed.yet:2023-08-11
src/custolint/pylint.py:162 0: C0413: Import "import os" should be placed at the top of the module (wrong-import-position) ## not.committed.yet:2023-08-11
src/custolint/pylint.py:162 0: C0411: standard import "import os" should be placed before "from . import _typing, env, generics" (wrong-import-order) ## not.committed.yet:2023-08-11
src/custolint/pylint.py:162 0: W0611: Unused import os (unused-import) ## not.committed.yet:2023-08-11