summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortrahman1318 <tausif.rahman@mongodb.com>2022-03-31 17:12:23 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-03-31 19:32:55 +0000
commit8711aedfc3e06626309eaed6a854c72a056ff2d8 (patch)
tree6615f50e8484f20733ff80e6f986b1e09c9a2636
parent75cbc1477e90fc4ac145a718a5b646724e483104 (diff)
downloadmongo-8711aedfc3e06626309eaed6a854c72a056ff2d8.tar.gz
SERVER-60831 Document configuration for Server linting tools
-rw-r--r--.clang-tidy3
-rw-r--r--docs/linting.md91
-rwxr-xr-xevergreen/run_clang_tidy.sh5
3 files changed, 95 insertions, 4 deletions
diff --git a/.clang-tidy b/.clang-tidy
new file mode 100644
index 00000000000..ea5badd8c12
--- /dev/null
+++ b/.clang-tidy
@@ -0,0 +1,3 @@
+Checks: '-*,bugprone-unused-raii,bugprone-use-after-move,readability-const-return-type,readability-avoid-const-params-in-decls'
+WarningsAsErrors: '*'
+HeaderFilterRegex: '(mongo/.*|build/.*)'
diff --git a/docs/linting.md b/docs/linting.md
new file mode 100644
index 00000000000..a6a13fa2d19
--- /dev/null
+++ b/docs/linting.md
@@ -0,0 +1,91 @@
+# Linting in the MongoDB codebase
+
+## C++ Linters
+
+### `clang-format`
+The `buildscripts/clang_format.py` wrapper script runs the `clang-format` linter. You can see the
+usage message for the wrapper by running `buildscripts/clang_format.py --help`.
+
+Ex: `buildscripts/clang_format.py lint`
+
+| Linter | Configuration File(s) | Help Command | Documentation |
+| --- | --- | --- | --- |
+| `clang-format` | `.clang-format` | `clang-format --help` | [https://clang.llvm.org/docs/ClangFormat.html](https://clang.llvm.org/docs/ClangFormat.html) |
+
+### `clang-tidy`
+The `evergreen/run_clang_tidy.sh` shell script runs the `clang-tidy` linter. In order to run
+`clang-tidy` you must have a compilation database (`compile_commands.json` file).
+
+Ex: `bash buildscripts/run_clang_tidy.sh`
+
+| Linter | Configuration File(s) | Help Command | Documentation |
+| --- | --- | --- | --- |
+| `clang-tidy` | `.clang-tidy` | `clang-tidy --help` | [https://clang.llvm.org/extra/clang-tidy/index.html](https://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`
+
+### `quickcpplint.py`
+The `buildscripts/quickcpplint.py` script runs a simple MongoDB C++ linter. You can see the usage
+by running the following command: `buildscripts/quickcpplint.py --help`. You can take a look at
+`buildscripts/linter/simplecpplint.py` to better understand the rules for this linter.
+
+Ex: `buildscripts/quickcpplint.py lint`
+
+## Javascript Linters
+The `buildscripts/eslint.py` wrapper script runs the `eslint` javascript linter. You can see the
+usage message for the wrapper by running `buildscripts/eslint.py --help`.
+
+Ex: `buildscripts/eslint.py lint`
+
+| Linter | Configuration File(s) | Help Command | Documentation |
+| --- | --- | --- | --- |
+| `eslint` | `.eslintrc.yml` `.eslintignore` | `eslint --help` | [https://eslint.org/](https://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`
+
+| Linter | Configuration File(s) | Help Command | Documentation |
+| --- | --- | --- | --- |
+| `yamllint` | `etc/yamllint_config.yml` | `yamllint --help` | [https://readthedocs.org/projects/yamllint/](https://readthedocs.org/projects/yamllint/) |
+| `evergreen-lint` | `etc/evergreen_lint.yml` | `python -m evergreen_lint --help` | [https://github.com/evergreen-ci/config-linter](https://github.com/evergreen-ci/config-linter) |
+
+## Python Linters
+The `buildscripts/pylinters.py` wrapper script runs the Python linters. You can
+see the usage message for the wrapper by running the following command:
+`buildscripts/pylinters.py --help`. The following linters are supported: `pylint`, `mypy`,
+`pydocstyle` & `yapf`.
+
+Ex: `buildscripts/pylinters.py lint`
+
+| Linter | Configuration File(s) | Help Command | Documentation |
+| --- | --- | --- | --- |
+| `pylint` | `.pylintrc` | `pylint --help` | [https://www.pylint.org/](https://www.pylint.org/) |
+| `mypy` | `.mypy.ini` | `mypy --help` | [https://readthedocs.org/projects/mypy/](https://readthedocs.org/projects/mypy/) |
+| `pydocstyle` | `.pydocstyle` | `pydocstyle --help` | [https://readthedocs.org/projects/pydocstyle/](https://readthedocs.org/projects/pydocstyle/) |
+| `yapf` | `.style.yapf` | `yapf --help` | [https://github.com/google/yapf](https://github.com/google/yapf) |
+
+## Using SCons for linting
+You can use SCons to run most of the linters listed above via their corresponding Python wrapper
+script. SCons also provides the ability to run multiple linters in a single command. At this time,
+SCons does not support `clang-tidy` or `buildscripts/yamllinters.sh`
+
+Here are some examples:
+
+| SCons Target | Linter(s) | Example |
+| --- | --- | --- |
+| `lint` | `clang-format` `errorcodes.py` `quickcpplint.py` `eslint` `pylint` `mypy` `pydocstyle` `yapf` | `buildscripts/scons.py lint` |
+| `lint-fast` | `clang-format` `errorcodes.py` `eslint` `pylint` `mypy` `pydocstyle` `yapf` | `buildscripts/scons.py lint-fast` |
+| `lint-clang-format` | `clang-format` | `buildscripts/scons.py lint-clang-format` |
+| `lint-errorcodes` | `errorcodes.py` | `buildscripts/scons.py lint-errorcodes` |
+| `lint-lint.py` | `quickcpplint.py` | `buildscripts/scons.py lint-lint.py` |
+| `lint-eslint` | `eslint` | `buildscripts/scons.py lint-eslint` |
+| `lint-pylinters` | `pylint` `mypy` `pydocstyle` `yapf` | `buildscripts/scons.py lint-pylinters` |
diff --git a/evergreen/run_clang_tidy.sh b/evergreen/run_clang_tidy.sh
index 07f3ec4067c..03e312e12ae 100755
--- a/evergreen/run_clang_tidy.sh
+++ b/evergreen/run_clang_tidy.sh
@@ -12,7 +12,4 @@ jq -r '.[] | .file' compile_commands.json \
| grep -v $BISON_GENERATED_PATTERN \
| xargs -n 32 -P $(grep -c ^processor /proc/cpuinfo) -t \
/opt/mongodbtoolchain/v3/bin/clang-tidy \
- -p ./compile_commands.json \
- -header-filter='(mongo/.*|build/.*)' \
- --checks="-*,bugprone-unused-raii,bugprone-use-after-move,readability-const-return-type,readability-avoid-const-params-in-decls" \
- -warnings-as-errors="*"
+ -p ./compile_commands.json