Skip to content

a-da/custolint

Repository files navigation

custolint - custom linter

Custolint logo

Your current code-validation pipeline rules may be changed more easily using custolint.

Documentation Python Code Coverage License

Source Code: https://github.com/a-da/custolint.

Custolint add new layer on top of:

Motivation

You cannot just add a linter and activate 100% inspections when you have a large, ancient codebase with thousands of lines.

You cannot just take and (Boromir meme)

Instead, you only make 1% of the checks available, which is really frustrating for a decent developer.

You could enable those 100% checks just for your changes with "custolint".

Idea

Given we have a project alike this one, where we:

  1. had added a function custolint/generics.py:filer_output.
  2. had modified the function custolint/git.py:_blame
$ tree
...
|-- src
|   |-- custolint
...
|   |   |-- generics.py <<<< 1
|   |   |-- git.py      <<<< 2
|   |   |-- mypy.py
|   |   |-- pylint.py
|   |   `-- typing.py
|-- tests
|   `-- test_custolint.py
...

When:

  • Detect affected files with git diff and git blame
    • custolint/git.py
    • custolint/generics.py
  • Run the linter tool (pylint, flake8, mypy, coverage ...) with all available feature enables (the configuration have to be placed into config.d/ folder) only on changed affected files or parse log/result of the linter tool.
  • Match changed code with the linters output, and consider only the match lines as failed lint criteria. It has to detect that custolint/generics.py:filer_output need unitest for coverage and custolint/git.py:_blame introduce a mypy typing issue.

Then:

  • Fail or Report the build.
$ coverage run --rcfile=config.d/.coveragerc -m pytest && \
    custolint coverage config.d/.coveragerc
INFO:custolint.git:Execute git diff command 'git diff origin/main -U0 --diff-filter=ACMRTUXB'
INFO:custolint.git:Git diff detected 16 filed affected
INFO:custolint.coverage:execute coverage command: 'coverage report --data-file=.coverage --show-missing'
src/custolint/git.py:66 not.committed.yet 2022-08-31

$ custolint mypy
INFO:custolint.mypy:MYPY COMPARE WITH 'main' branch
INFO:custolint.git:Execute git diff command 'git diff origin/main -U0 --diff-filter=ACMRTUXB'
INFO:custolint.git:Git diff detected 16 filed affected
INFO:custolint.mypy:execute command 'mypy --config-file=config.d/mypy.ini @/tmp/f/59..000gq/T/tmp...'
tests/test_custolint.py 31 Module has no attribute "bash"  [attr-defined] not.committed.yet 2022-08-31
tests/test_custolint.py 125 Function is missing a return type annotation  [no-untyped-def] not.committed.yet 2022-08-31
tests/test_custolint.py 140 Function is missing a return type annotation  [no-untyped-def] not.committed.yet 2022-08-31

Install

See Install dev version

How to run:

cd "${YOUR_CODE}/"

# check typing
custolint mypy

# code smell checking with pylint
custolint pylint

# code smell checking with flake8
custolint flake8

# 100% coverage checking for new commits
coverage run --rcfile=config.d/.coveragerc -m pytest
custolint coverage config.d/.coverage

Releases

No releases published

Packages

No packages published