Linting Code

Enabling Lint Checks

First, please follow the procedure in Development Conda Environment to set up a conda environment for linting the code and building the docs.

Once on each machine you are developing on, before committing code, please run:

pre-commit install

After this, your code will be linted with all the tools discussed below as part of each call to git commit. Any modified files will also be linted when CI (GitHub Actions) runs on each pull request and merge to the develop branch.

You can lint the full code using all the tools with:

pre-commit run --all-files

Bypassing Linting

If you wish to commit without first checking the code for lint (e.g. you plan to fix the code in a later commit), run:

git commit --no-verify ...

with the same arguments you would normally use for git commit.

Linting C++ Code

The tools used to lint C++ code are from cmake-pre-commit-hooks and include clang-format, clang-tidy, cppcheck, and include-what-you-use. (Currently clang-tidy, cppcheck and include-what-you-use are disabled but they will be enabled shortly.)

You can run these tools individually if you need to:

pre-commit run clang-format --all-files
pre-commit run clang-tidy --all-files
pre-commit run cppcheck --all-files
pre-commit run include-what-you-use --all-files

You can specify one more more files instead of --all-files.

Linting Python Code

The tools used to lint python code include isort for sorting imports, flynt for enforcing string formatting with f-strings, flake8 for enforcing the PEP8 style guide for python, and mypy for performing variable type checking.

You can run these tools individually if you need to:

pre-commit run isort --all-files
pre-commit run flynt --all-files
pre-commit run flake8 --all-files
pre-commit run mypy --all-files

You can specify one more more files instead of --all-files.

Updating the linting pacakge

To update the linting packages, you just need to recreate the development conda environment. See Updating the Conda Environment.