Back to Mongo

Linting in the MongoDB codebase

docs/linting.md

3.6.17-windows-splunk-v33.3 KB
Original Source

Linting in the MongoDB codebase

C++ Linters

clang-tidy

The buildscripts/clang_tidy.py shell script runs the clang-tidy linter. In order to run clang-tidy you must have a compilation database (compile_commands.json file).

Ex: python3 buildscripts/clang_tidy.py

LinterConfiguration File(s)Help CommandDocumentation
clang-tidy.clang-tidyclang-tidy --helphttps://clang.llvm.org/extra/clang-tidy/index.html

errorcodes.py

The buildscripts/errorcodes.py script runs a custom error code linter, which verifies that all assertion codes are distinct. You can see the usage by running the following command: buildscripts/errorcodes.py --help.

Ex: buildscripts/errorcodes.py

quickmongolint.py

The buildscripts/quickmongolint.py script runs a simple MongoDB C++ linter. You can see the usage by running the following command: buildscripts/quickmongolint.py --help. You can take a look at buildscripts/linter/mongolint.py to better understand the rules for this linter.

Ex: buildscripts/quickmongolint.py lint

Javascript Linters

The bazel run lint command runs the eslint javascript linter.

LinterConfiguration File(s)Help CommandDocumentation
eslint.eslint.config.mjshttps://eslint.org/

Yaml Linters

The buildscripts/yamllinters.sh shell script runs the yaml linters. The supported yaml linters are: yamllint & evergreen-lint. evergreen-lint is a custom MongoDB linter used specifically for evergreen yaml files.

Ex: bash buildscripts/yamllinters.sh

LinterConfiguration File(s)Help CommandDocumentation
yamllintetc/yamllint_config.ymlyamllint --helphttps://readthedocs.org/projects/yamllint/
evergreen-lintetc/evergreen_lint.ymlpython -m evergreen_lint --helphttps://github.com/evergreen-ci/config-linter

Python Linters

The bazel run lint command runs all Python linters as well as several other linters in our code base. You can run auto-remediations via: bazel run lint --fix.

Ex: bazel run lint

LinterConfiguration File(s)Help CommandDocumentation
ruffpyproject.tomlhttps://docs.astral.sh/ruff/