diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000000..7245011a06 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,179 @@ +FormatStyle: file +Checks: "+*,\ + -bugprone-argument-comment,\ + -bugprone-branch-clone,\ + -bugprone-copy-constructor-init,\ + -bugprone-easily-swappable-parameters,\ + -bugprone-exception-escape,\ + -bugprone-fold-init-type,\ + -bugprone-forward-declaration-namespace,\ + -bugprone-forwarding-reference-overload,\ + -bugprone-implicit-widening-of-multiplication-result,\ + -bugprone-incorrect-roundings,\ + -bugprone-infinite-loop,\ + -bugprone-integer-division,\ + -bugprone-lambda-function-name,\ + -bugprone-macro-parentheses,\ + -bugprone-misplaced-widening-cast,\ + -bugprone-move-forwarding-reference,\ + -bugprone-multiple-statement-macro,\ + -bugprone-narrowing-conversions,\ + -bugprone-not-null-terminated-result,\ + -bugprone-parent-virtual-call,\ + -bugprone-redundant-branch-condition,\ + -bugprone-reserved-identifier,\ + -bugprone-signed-char-misuse,\ + -bugprone-sizeof-expression,\ + -bugprone-string-constructor,\ + -bugprone-suspicious-enum-usage,\ + -bugprone-suspicious-include,\ + -bugprone-suspicious-memory-comparison,\ + -bugprone-suspicious-string-compare,\ + -bugprone-terminating-continue,\ + -bugprone-throw-keyword-missing,\ + -bugprone-too-small-loop-variable,\ + -bugprone-undefined-memory-manipulation,\ + -bugprone-unhandled-self-assignment,\ + -bugprone-unused-raii,\ + -bugprone-unused-return-value,\ + -bugprone-use-after-move,\ + -bugprone-virtual-near-miss,\ + -cert-dcl03-c,\ + -cert-dcl16-c,\ + -cert-dcl21-cpp,\ + -cert-dcl50-cpp,\ + -cert-dcl54-cpp,\ + -cert-dcl58-cpp,\ + -cert-dcl59-cpp,\ + -cert-err09-cpp,\ + -cert-err33-c,\ + -cert-err34-c,\ + -cert-err52-cpp,\ + -cert-err58-cpp,\ + -cert-msc30-c,\ + -cert-msc32-c,\ + -cert-oop11-cpp,\ + -cert-oop54-cpp,\ + -cert-oop57-cpp,\ + -clang-analyzer-core.CallAndMessage,\ + -clang-analyzer-core.DivideZero,\ + -clang-analyzer-core.NonNullParamChecker,\ + -clang-analyzer-core.NullDereference,\ + -clang-analyzer-core.UndefinedBinaryOperatorResult,\ + -clang-analyzer-core.uninitialized.Assign,\ + -clang-analyzer-core.uninitialized.Branch,\ + -clang-analyzer-core.uninitialized.UndefReturn,\ + -clang-analyzer-cplusplus.Move,\ + -clang-analyzer-cplusplus.NewDelete,\ + -clang-analyzer-cplusplus.NewDeleteLeaks,\ + -clang-analyzer-cplusplus.PlacementNew,\ + -clang-analyzer-deadcode.DeadStores,\ + -clang-analyzer-optin.cplusplus.UninitializedObject,\ + -clang-analyzer-optin.cplusplus.VirtualCall,\ + -clang-analyzer-optin.performance.Padding,\ + -clang-analyzer-optin.portability.UnixAPI,\ + -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,\ + -clang-analyzer-security.insecureAPI.strcpy,\ + -clang-analyzer-unix.Malloc,\ + -clang-analyzer-valist.Unterminated,\ + -concurrency-mt-unsafe,\ + -google-build-using-namespace,\ + -google-default-arguments,\ + -google-explicit-constructor,\ + -google-global-names-in-headers,\ + -google-readability-avoid-underscore-in-googletest-name,\ + -google-readability-braces-around-statements,\ + -google-readability-casting,\ + -google-readability-function-size,\ + -google-readability-namespace-comments,\ + -google-readability-todo,\ + -google-runtime-int,\ + -google-runtime-operator,\ + -google-upgrade-googletest-case,\ + -misc-definitions-in-headers,\ + -misc-misplaced-const,\ + -misc-non-private-member-variables-in-classes,\ + -misc-no-recursion,\ + -misc-redundant-expression,\ + -misc-unconventional-assign-operator,\ + -misc-uniqueptr-reset-release,\ + -misc-unused-parameters,\ + -misc-unused-using-decls,\ + -modernize-avoid-bind,\ + -modernize-avoid-c-arrays,\ + -modernize-concat-nested-namespaces,\ + -modernize-deprecated-headers,\ + -modernize-loop-convert,\ + -modernize-macro-to-enum,\ + -modernize-make-shared,\ + -modernize-make-unique,\ + -modernize-pass-by-value,\ + -modernize-raw-string-literal,\ + -modernize-redundant-void-arg,\ + -modernize-replace-disallow-copy-and-assign-macro,\ + -modernize-return-braced-init-list,\ + -modernize-unary-static-assert,\ + -modernize-use-auto,\ + -modernize-use-bool-literals,\ + -modernize-use-default-member-init,\ + -modernize-use-emplace,\ + -modernize-use-equals-default,\ + -modernize-use-equals-delete,\ + -modernize-use-nodiscard,\ + -modernize-use-noexcept,\ + -modernize-use-nullptr,\ + -modernize-use-override,\ + -modernize-use-trailing-return-type,\ + -modernize-use-transparent-functors,\ + -modernize-use-using,\ + -performance-faster-string-find,\ + -performance-for-range-copy,\ + -performance-inefficient-algorithm,\ + -performance-inefficient-string-concatenation,\ + -performance-inefficient-vector-operation,\ + -performance-move-const-arg,\ + -performance-no-automatic-move,\ + -performance-noexcept-move-constructor,\ + -performance-no-int-to-ptr,\ + -performance-trivially-destructible,\ + -performance-unnecessary-copy-initialization,\ + -performance-unnecessary-value-param,\ + -portability-std-allocator-const,\ + -readability-avoid-const-params-in-decls,\ + -readability-braces-around-statements,\ + -readability-const-return-type,\ + -readability-container-data-pointer,\ + -readability-container-size-empty,\ + -readability-convert-member-functions-to-static,\ + -readability-delete-null-pointer,\ + -readability-duplicate-include,\ + -readability-else-after-return,\ + -readability-function-cognitive-complexity,\ + -readability-identifier-length,\ + -readability-identifier-naming,\ + -readability-implicit-bool-conversion,\ + -readability-inconsistent-declaration-parameter-name,\ + -readability-isolate-declaration,\ + -readability-magic-numbers,\ + -readability-make-member-function-const,\ + -readability-misleading-indentation,\ + -readability-named-parameter,\ + -readability-non-const-parameter,\ + -readability-qualified-auto,\ + -readability-redundant-access-specifiers,\ + -readability-redundant-control-flow,\ + -readability-redundant-declaration,\ + -readability-redundant-member-init,\ + -readability-redundant-preprocessor,\ + -readability-redundant-smartptr-get,\ + -readability-redundant-string-cstr,\ + -readability-redundant-string-init,\ + -readability-simplify-boolean-expr,\ + -readability-simplify-subscript-expr,\ + -readability-static-accessed-through-instance,\ + -readability-static-definition-in-anonymous-namespace,\ + -readability-string-compare,\ + -readability-suspicious-call-argument,\ + -readability-uppercase-literal-suffix,\ + -readability-use-anyofallof,\ + " diff --git a/.gitignore b/.gitignore index 91b8350335..397a623a31 100644 --- a/.gitignore +++ b/.gitignore @@ -122,3 +122,7 @@ default.profraw lcov.info /cmake-build-*/ /testing + +### Clang-Tidy files +all_findings.json + diff --git a/DEPS b/DEPS index c1080ce556..196755f5cc 100644 --- a/DEPS +++ b/DEPS @@ -26,6 +26,9 @@ vars = { # GN variable required by //testing that will be output in the gclient_args.gni 'generate_location_tags': False, + + # Fetch clang-tidy into the same bin/ directory as our clang binary. + 'checkout_clang_tidy': False, } deps = { @@ -242,6 +245,15 @@ hooks = [ 'action': ['python3', 'tools/clang/scripts/update.py'], 'condition': 'dawn_standalone', }, + { + # This is also supposed to support the same set of platforms as 'clang' + # above. LLVM ToT support isn't provided at the moment. + 'name': 'clang_tidy', + 'pattern': '.', + 'condition': 'checkout_clang_tidy', + 'action': ['python3', 'tools/clang/scripts/update.py', + '--package=clang-tidy'], + }, { # Pull rc binaries using checked-in hashes. 'name': 'rc_win', diff --git a/docs/clang-tidy.md b/docs/clang-tidy.md new file mode 100644 index 0000000000..e2f9738c7f --- /dev/null +++ b/docs/clang-tidy.md @@ -0,0 +1,37 @@ +# Running clang-tidy + +* Add `"checkout_clang_tidy": True` to `.gclient` file in the `custom_vars`. + ``` + { + "custom_vars": { + "checkout_clang_tidy": True, + } + } + ``` +* `gclient sync` + +There should now be `third_party/llvm-build/Release+Asserts/bin/clang-tidy` + +* `cd out` +* `git clone https://chromium.googlesource.com/chromium/tools/build` + +The Chromium build folder contains the `tricium` files used to run `clang-tidy` + +Running clang-tidy over all the source can be done with: + +``` +cd .. +out/build/recipes/recipe_modules/tricium_clang_tidy/resources/tricium_clang_tidy_script.py \ +--base_path $PWD \ +--out_dir out/Debug \ +--findings_file all_findings.json \ +--clang_tidy_binary $PWD/third_party/llvm-build/Release+Asserts/bin/clang-tidy \ +--all +``` + +`--all` can be replaced by specific files if desired to run on individual source +files. + + +## References +* https://chromium.googlesource.com/chromium/src.git/+/HEAD/docs/clang_tidy.md