Package: cardboardlint
IntroductionCardboardlint is a cheap lint solution for pull requests.It is a non-hosted and customizable tool similar to commercial services like:Hound CI:https://houndci.com/Stickler CI:https://stickler-ci.com/landscape.io:https://landscape.io/…For more advanced analysis, one could use Coverty Scan.
(https://scan.coverity.com/)Cardboardlint wraps a collection of linters, intended to be used on a project
in a Git repository. Cardboardlint is able to report just those messages related
to lines that have changed in your development branch, compared to another
commit, e.g. the HEAD of the master branch. This is intended to make life easier
for contributors to a project: in their pull requests, they will only see
linting issues related to the code they have touched. For some linters,
cardboardlint also supports automatic fixes of linting issues, optionally
restricted to code that has changed in your development branch.Some example projects that use Cardboardlint:Cardboardlint, obviouslyRoberto:https://github.com/theochem/roberto(Cardboardlint also uses Roberto.)IOData:https://github.com/theochem/iodataCellCutoff:https://github.com/theochem/cellcutoffCGrid:https://github.com/theochem/cgridUsageInstall cardboardlint, which requires python 3.6 or 3.7 and PyYaml. You must
have Python 3 installed, PyYaml will be installed automatically for you with
the instructions below.# Install cardboardlint with pip. Any of the following that works for you
# is fine:pipinstallcardboardlintpipinstallcardboardlint--userpython3-mpipinstallcardboardlintpython3-mpipinstallcardboardlint--user# Or install cardboardlint with conda:condainstalltheochem::cardboardlintAdd a.cardboardlint.ymlto the root of your source tree. It should at least contain
alinterssection with a list of linters, e.g.linters:-pylint:pylintrc:tools/your_custom_pylintrc-cppcheck:-import:...A list of supported linters is easily deduced from the source code. Just look into
thecardboardlint/linter_*.pyfiles. Each of these files has a module docstring with
some explanations and a DEFAULT_CONFIG dictionary with the available configuration vars.You can repeat any linter multiple times with different configuration settings. This can
be useful, e.g. when unit tests must be linted differently than the rest of the source
code. This is a simple example where unit tests have a different pylint config:pre_filefilter:['+tools/demo/*.py','-tools/*','+*']linters:-pylint:pylintrc:tools/pylintrcfilefilter:['-test_*.py','+*.py']exclude:-pylint:pylintrc:tools/pylintrc_testsfilefilter:['+test_*.py']-import:...When cardboardlint starts, it makes a list of files not ignored by
git in the current repository. These filenames are first filtered by a
so-calledpre_filefilter. Files that pass thepre_filefilterare then
tested with linter-specificfilefiltersto end up with a list of files to
be checked by a given linter.Apre_filefilterorfilefilterconsists of a list of rules to test if
a file should be considered for linting or not. Each rule starts with a
possible outcome,+(include) or a-(exclude), followed by a glob
pattern. At the moment, the pattern ignores the presence of directory
separators and treats the complete path as a single string on which the
pattern is tested, using Pythonsfnmatchbuiltin module. The rules are
tested in order and when a pattern matches, the corresponding decision is made
(include and exclude), without considering subsequent rules. When no patterns
give a match, the file is excluded.The following tricks might be useful:If you would like to include files that did not match any pattern, add'+ *'as last pattern, which is often useful for thepre_filefilter.If you would like to include all python files, in all directories, use'+ *.py'. The wildcard will also match directories containing the Python
file. For example it would matcha/bin the patha/b.py.Install the linters you intend to run (either locally or in your CI environment). These
dependencies are not installed automatically because you may not want to use all of
them.Conda packages for all supported linters can be found in the main conda
channels an in conda-forge (https://anaconda.org/conda-forge). We have added
packages to conda-forge forcppcheckandcpplint. All other linters
were already available. To install all of them, we can recommend the following
commands:# Add conda-forga channel with lower priority as the default channels. This
# prevents your conda env from being flooded by conda-forga packages.condaconfig--appendchannelsconda-forge# Install all linters for which cardboardlint has wrappers:condainstallpycodestylepydocstylecppcheckcpplintyamllintflake8\doxygenpylintautopep8,yapf,blackRun the cardboardlinter, which can be done in several ways:# runs all linters and use multiple cpuscardboardlinter-nauto# runs all linters and only shows messages for changes relative to mastercardboardlinter-rmaster# run only static linterscardboardlinter-fstatic# run only dynamic linters, which require in-place buildcardboardlinter-fdynamic# run fixers, which automaticaly solve trivial problemscardboardlinter-F# run fixers, which automaticaly solve trivial problems, only on those
# lines that have changed w.r.t. the master branch.cardboardlinter-F-rmasterUsage in CI:Travis-CI (in.travis.yml). This will only report messages for lines that have
changed in the PR.install:# Install the latest cardboardlinter-if [ "$TRAVIS_PULL_REQUEST" != "false" ]; thenpip install --upgrade cardboardlintfiscript:# Run the cardboardlinter, in case of pull requests-if [ "$TRAVIS_PULL_REQUEST" != "false" ]; thencardboardlinter --refspec $TRAVIS_BRANCH -n auto;fiOne can also use Roberto to drive the entire build+test+package workflow,
which includes linting with Cardboardlint.
Seehttps://theochem.github.io/roberto/Change logVersion 1.3.1 August 26, 2020Improve interaction with Roberto.Hide duplicate messages.Version 1.3.0 April 14, 2019More verbose output. List of selected files for linting is always shown.Fix default location for Python command-line scripts is ./bin, not ./scripts.Wall time of linters is printed.Few cleanups.Version 1.2.0 April 12, 2019Added support for fixers. The following liners can also fix problems:
header, whitespace, autopep8, yapf, black. The latter three are new.Removed some Python-2 compatibility code.Replace nosetests by pytest.Add more context to README.Add RST linter.Version 1.1.0 April 3, 2019Add option for number of processors to use.Version 1.0.1 March 30, 2019Add missing config options for cpplint.Version 1.0.0 March 27, 2019First release, mainly in anticipation of API-breaking changes, which will
result in a major version increase. By making a release, we can handle this
change in API gracefully. Notable features include:Support for the following linters: cppcheck, ccplint, doxygen, flake8,
header (internal), import (internal), namespace (internal), pycodestyle,
pydocstyle, pylint, whitespace (internal), yamllintFor all supported linters, the output can be restricted to files and (lines
in those files) that have changed between two git commits. In pull requests,
this will then only show errors that are relevant for the code touched in
the PR. This is intended for making life easy for contributors, i.e. to not
bother them with linting issues in code they have not touched.Flexible file filtering, essentially a simplified version of rsync’s file
filtering rules.Consistent and colored output for all linters, making it easy to process
linting issues.