All Projects → duo-labs → Dlint

duo-labs / Dlint

Licence: bsd-3-clause
Dlint is a tool for encouraging best coding practices and helping ensure we're writing secure Python code.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Dlint

pahout
A pair programming partner for writing better PHP. Pahout means PHP mahout 🐘
Stars: ✭ 43 (-86.56%)
Mutual labels:  linter, static-analysis
Pytype
A static type analyzer for Python code
Stars: ✭ 3,545 (+1007.81%)
Mutual labels:  static-analysis, linter
golintui
A simple terminal UI for Go linters
Stars: ✭ 73 (-77.19%)
Mutual labels:  linter, static-analysis
sonar-gherkin-plugin
SonarQube Cucumber Gherkin Analyzer
Stars: ✭ 33 (-89.69%)
Mutual labels:  linter, static-analysis
Wotan
Pluggable TypeScript and JavaScript linter
Stars: ✭ 271 (-15.31%)
Mutual labels:  static-analysis, linter
codeclimate-eslint
Code Climate Engine for ESLint
Stars: ✭ 86 (-73.12%)
Mutual labels:  linter, static-analysis
addlint
An example linter written with go/analysis for tutorial purposes
Stars: ✭ 49 (-84.69%)
Mutual labels:  linter, static-analysis
goreporter
A Golang tool that does static analysis, unit testing, code review and generate code quality report.
Stars: ✭ 3,019 (+843.44%)
Mutual labels:  linter, static-analysis
Goreporter
A Golang tool that does static analysis, unit testing, code review and generate code quality report.
Stars: ✭ 2,943 (+819.69%)
Mutual labels:  static-analysis, linter
unimport
A linter, formatter for finding and removing unused import statements.
Stars: ✭ 119 (-62.81%)
Mutual labels:  linter, static-analysis
staticcheck-action
Staticcheck's official GitHub Action
Stars: ✭ 47 (-85.31%)
Mutual labels:  linter, static-analysis
Pylint
It's not just a linter that annoys you!
Stars: ✭ 3,733 (+1066.56%)
Mutual labels:  static-analysis, linter
constyble
CSS complexity linter
Stars: ✭ 92 (-71.25%)
Mutual labels:  linter, static-analysis
static-code-analysis-plugin
A plugin to simplify Static Code Analysis on Gradle. Not restricted to, but specially useful, in Android projects, by making sure all analysis can access the SDK classes.
Stars: ✭ 36 (-88.75%)
Mutual labels:  linter, static-analysis
mllint
`mllint` is a command-line utility to evaluate the technical quality of Python Machine Learning (ML) projects by means of static analysis of the project's repository.
Stars: ✭ 67 (-79.06%)
Mutual labels:  linter, static-analysis
illuaminate
Very WIP static analysis for Lua
Stars: ✭ 21 (-93.44%)
Mutual labels:  linter, static-analysis
sonar-css-plugin
SonarQube CSS / SCSS / Less Analyzer
Stars: ✭ 46 (-85.62%)
Mutual labels:  linter, static-analysis
nestif
Detect deeply nested if statements in Go source code
Stars: ✭ 30 (-90.62%)
Mutual labels:  linter, static-analysis
automutate
Applies waves of mutations provided by other tools, such as linters or codemods.
Stars: ✭ 13 (-95.94%)
Mutual labels:  linter, static-analysis
Linter
Static Analysis Compiler Plugin for Scala
Stars: ✭ 273 (-14.69%)
Mutual labels:  static-analysis, linter

Dlint

Build Status Build Status Coverage Status Python Versions PyPI Version

Dlint 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.

For a static analysis project to succeed, developers must feel they benefit from and enjoy using it.

For documentation and a list of rules see docs.

Installing

$ python -m pip install dlint

Specify python2 or python3 to install for a specific Python version.

And double check that it was installed correctly:

$ python -m flake8 -h
Usage: flake8 [options] file file ...

...

Installed plugins: dlint: 0.10.2, mccabe: 0.5.3, pycodestyle: 2.2.0, pyflakes: 1.3.0

Note the dlint: 0.10.2.

Using

Dlint uses flake8 to perform its linting functionality which provides many useful features without re-inventing the wheel.

CLI

Let's run a simple check:

$ cat << EOF > test.py
print("TEST1")
exec('print("TEST2")')
EOF
$ python test.py
TEST1
TEST2
$ python -m flake8 --select=DUO test.py
test.py:2:1: DUO105 use of "exec" is insecure

The --select=DUO flag tells flake8 to only run Dlint lint rules.

From here, we can easily run Dlint against a directory of Python code:

$ python -m flake8 --select=DUO /path/to/code

To fine-tune your linting, check out the flake8 help:

$ python -m flake8 --help

Inline Editor

Dlint 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:

Integrating

Dlint can easily be integrated into CI pipelines, or anything really.

For more information and examples see 'How can I integrate Dlint into XYZ?'.

Custom Plugins

Dlint's custom plugins are built on a simple naming convention, and rely on Python modules. To make a Dlint custom plugin use the following conventions:

  • The Python module name must start with dlint_plugin_.
  • The linter class name must start with Dlint.
  • The linter class should inherit from dlint.linters.base.BaseLinter.
    • If for some reason you'd like to avoid this, then you must implement the get_results function appropriately and inherit from ast.NodeVisitor.

See an example plugin for further details.

Developing

First, install development packages:

$ python -m pip install -r requirements.txt
$ python -m pip install -r requirements-dev.txt
$ python -m pip install -e .

Testing

$ pytest

Linting

$ flake8

Coverage

$ pytest --cov

Benchmarking

$ pytest -k test_benchmark_run --benchmark-py-file /path/to/file.py tests/test_benchmark/

Or get benchmark results for linters individually:

$ pytest -k test_benchmark_individual --benchmark-py-file /path/to/file.py tests/test_benchmark/

Or run against a single linter:

$ pytest -k test_benchmark_individual[DUO138-BadReCatastrophicUseLinter] --benchmark-py-file /path/to/file.py tests/test_benchmark/
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].