Package: dlint
DlintDlint is a tool for encouraging best coding practices and helping ensure Python code is secure.The most important thing I have done as a programmer in recent years is to
aggressively pursue static code analysis. Even more valuable than the
hundreds of serious bugs I have prevented with it is the change in mindset
about the way I view software reliability and code quality.John Carmack, 2011For a static analysis project to succeed, developers must feel they benefit
from and enjoy using it.Lessons from Building Static Analysis Tools at GoogleFor documentation and a list of rules seedocs.Installing$python-mpipinstalldlintAnd double check that it was installed correctly:$python-mflake8-h
Usage:flake8[options]filefile...

...

Installedplugins:dlint:0.14.1,mccabe:0.5.3,pycodestyle:2.2.0,pyflakes:1.3.0Note thedlint: 0.14.1.UsingDlint builds onflake8to perform its linting. This provides many
useful features without re-inventing the wheel.CLILet's run a simple check:$cat<< EOF > test.pyprint("TEST1")exec('print("TEST2")')EOF$pythontest.py
TEST1
TEST2$python-mflake8--select=DUOtest.py
test.py:2:1:DUO105useof"exec"isinsecureWhy is this insecure? To learn more visit/docs/linters/DUO105.md.WhyDUO? Dlint was originally developed by theDuo Labsteam.The--select=DUOflag tellsflake8to only run Dlint lint rules.From here, we can easily run Dlint against a directory of Python code:$python-mflake8--select=DUO/path/to/codeTo fine-tune your linting, check out theflake8help:$python-mflake8--helpInline EditorDlint results can also be included inline in your editor for fast feedback.
This typically requires an editor plugin or extension. Here are some starting
points for common editors:Vim:https://github.com/vim-syntastic/syntasticEmacs:https://github.com/flycheck/flycheckSublime:https://github.com/SublimeLinter/SublimeLinter-flake8PyCharm:https://foxmask.net/post/2016/02/17/pycharm-running-flake8/Atom:https://atom.io/packages/linter-flake8Visual Studio Code:https://code.visualstudio.com/docs/python/linting#_flake8IntegratingDlint can easily be integrated into CI pipelines, or anything really.For more information and examples see'How can I integrate Dlint into XYZ?'.Custom PluginsDlint's custom plugins are built on asimple naming convention,
and rely onPython modules.
To make a Dlint custom plugin use the following conventions:The Python module namemuststart withdlint_plugin_.The linter class namemuststart withDlint.The linter classshouldinherit fromdlint.linters.base.BaseLinter.If for some reason you'd like to avoid this, then youmustimplement
theget_resultsfunction appropriately and inherit fromast.NodeVisitor.See anexample pluginfor further details.DevelopingFirst, install development packages:$python-mpipinstall-rrequirements.txt
$python-mpipinstall-rrequirements-dev.txt
$python-mpipinstall-e.Testing$pytestLinting$flake8Coverage$pytest--covBenchmarking$pytest-ktest_benchmark_run--benchmark-py-file/path/to/file.pytests/test_benchmark/Or get benchmark results for linters individually:$pytest-ktest_benchmark_individual--benchmark-py-file/path/to/file.pytests/test_benchmark/Or run against a single linter:$pytest-ktest_benchmark_individual[DUO138-BadReCatastrophicUseLinter]--benchmark-py-file/path/to/file.pytests/test_benchmark/