Package: bugalint
BugalintAn abstraction package for running linters on code, outputting the results in a unified format.UsageFirst,pipinstall bugalint:$ pip install bugalintBugalint requires Python 3.7+.Next, you need to setup a configuration file, named by defaultsetup.cfg:[bugalint.lints.example]
path = source_code/
mypy = True
flake8 = True
pylint = TrueNow, simply runbugalintfrom the directory in whichsetup.cfgresides:$ bugalintbugalintwill run the selected 3 linters (mypy, flake8, and pylint) on the selected path (source_code/)Supported Built-in Lintersflake8pylintmypyAdditional linters can be added in thesetup.cfgfile.Adding Lint RunsBugalint can run linters on more than one directory. It looks for any section of the form[bugalint.lints.<name>]in the configuration file,
and expects it to contain a key namedpath, which supports glob syntax, and any other key with a name of a linter, and the valueTrue.
Bugalint will run the given linters, withpathas their working directory.For example, suppose we have the following file structure:+-- foo
|   +-- file.py
+-- bar
|   +-- foo1
|   |   +-- bar
|   |   |   +-- file.py
|   +-- foo2
|   |   +-- bar
|   |   |   +-- file.pyAnd suppose we have the following configuration file:[bugalint.lints.lint1]
path = foo
mypy = True

[bugalint.lints.lint2]
path = bar/*/bar
mypy = True
flake8 = TrueBugalint will run the following:mypy .withfooas its working directorymypy .withbar/foo1/baras its working directorymypy .withbar/foo2/baras its working directoryflake8 .withbar/foo1/baras its working directoryflake8 .withbar/foo2/baras its working directoryBugalint will combine all of their warnings to a unified output format.Using Additional LintersFor running a linter that isn't built-in, Bugalint needs only two strings:The command line to runThe regular expression to apply on its standard outputThis information needs to be placed inside thesetup.cfgfile in the working directory of Bugalint.
An example of the configuration file adding a new linter called my-lint can be:[bugalint.linters.my-lint]
cmdline = my-lint --my-flag .
regex = ^(?P<file>[^:]*):(?P<line>\d*):(?P<col>\d*): (?P<code>[^:]*): (?P<text>.*)$Bugalint will run the given command line, and try to match each line of its standard output to the given regular expression.
If the regular expression matches a line, it will be considered "a linter warning", and some named captures from the regular expression
will be used to determine its location in the code, message, etc.Linter Regex Named CapturesBugalint will use named captures from the regular expression to determine the information about a linter warning. All of the named captures are optional.
The list of supported named captures is:file- The path to the file in which the warning was triggered. Can be absolute, or relative to the working directory of the linterline- The line number in which the warning was triggeredcol- The column number in which the warning was triggeredcode- A short code or number representing the issue foundtext- A free text describing the issueModifying Built-in Linters BehaviorIn most cases, modifying the behavior of one of the built-in linters can and should be done using a configuration file (see docs relevant to that linter).
Nevertheless, in some cases, you might want to change the command line that Bugalint runs.Doing this is simple, and similar to defining new linters.
Adding the following to the configuration file, will modify the command line ofmypy:[bugalint.linters.mypy]
cmdline = mypy --additional-flag .Similarly, the regex of a built-in linter can be modified too:[bugalint.linters.mypy]
cmdline = mypy --additional-flag .
regex = ^my new regex$Command lineA list of all configuration values can be viewed by runningbugalint --help.usage: bugalint [-h] [--config CONFIG] [--verbose] [--output {textual,json}]

optional arguments:
  -h, --help            show this help message and exit
  --config CONFIG       The config file to use (default: setup.cfg)
  --verbose             Write debug log messages to stderr (default: False)
  --output {textual,json}
                        The output format (default: textual)The return value of Bugalint is the number of linter warnings it detected (0 = no warnings)Integration with LintlyBugalint can be easily integrated withLintly.
It supports the command line argument--output=json, which outputs the warnings in a JSON format similar to that of pylint.
It can then be passed to Lintly:bugalint --output=json | lintly --format=pylint-jsonBugalint will output file paths relative to its working directory, so as long as it is being run from the root of the repository,
lintly will receive paths it can handle correctly.A full example of a GitHub check workflow:name: Lint

on:
  pull_request:
    paths:
      - 'python_project/**/*'

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-python@v2
      with:
        python-version: 3.8
    - name: Install dependencies
      run: |
        python -m pip install bugalint lintly mypy pylint flake8
    - name: Lint
      run: |
        bugalint --output=json | lintly --format=pylint-json
      env:
        LINTLY_API_KEY: ${{ secrets.GITHUB_TOKEN }}