如何转储 CLion 的默认 clang-tidy 配置?
Posted
技术标签:
【中文标题】如何转储 CLion 的默认 clang-tidy 配置?【英文标题】:How to dump CLion's default clang-tidy configuration? 【发布时间】:2021-04-30 17:01:11 【问题描述】:我想使用 CLion 中启用/禁用检查的默认配置(有一些小的更改),并且我想在构建我的应用程序时强制执行它。
通过使用 cmake 指令来执行 clang-tidy 可以完美地执行 clang-tidy,例如启用所有检查:
set(CMAKE_CXX_CLANG_TIDY clang-tidy;
-checks=*,
-warnings-as-errors=*;
)
可以在on the website 找到 CLion 中启用和禁用检查的默认列表,但不是机器可读的方式。
由于clang-tidy
可执行文件提供了选项-dump-config
,是否可以转储CLion 使用的配置,就像它用于clang 格式一样?如果有,怎么做?
【问题讨论】:
【参考方案1】:是的,可以转储配置,但很难做到。我不得不在一个大型项目上运行代码分析器,并且幸运地捕获了命令行参数。
C:\Users\peter\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\211.7628.27\bin\clang\win\clang-tidy.exe -config='"\"Checks\":\"-*,bugprone-argument-comment,bugprone-assert-side-effect,bugprone-bad-signal-to-kill-thread,bugprone-branch-clone,bugprone-copy-constructor-init,bugprone-dangling-handle,bugprone-dynamic-static-initializers,bugprone-fold-init-type,bugprone-forward-declaration-namespace,bugprone-forwarding-reference-overload,bugprone-inaccurate-erase,bugprone-incorrect-roundings,bugprone-integer-division,bugprone-lambda-function-name,bugprone-macro-parentheses,bugprone-macro-repeated-side-effects,bugprone-misplaced-operator-in-strlen-in-alloc,bugprone-misplaced-pointer-arithmetic-in-alloc,bugprone-misplaced-widening-cast,bugprone-move-forwarding-reference,bugprone-multiple-statement-macro,bugprone-no-escape,bugprone-not-null-terminated-result,bugprone-parent-virtual-call,bugprone-posix-return,bugprone-reserved-identifier,bugprone-sizeof-container,bugprone-sizeof-expression,bugprone-spuriously-wake-up-functions,bugprone-string-constructor,bugprone-string-integer-assignment,bugprone-string-literal-with-embedded-nul,bugprone-suspicious-enum-usage,bugprone-suspicious-include,bugprone-suspicious-memset-usage,bugprone-suspicious-missing-comma,bugprone-suspicious-semicolon,bugprone-suspicious-string-compare,bugprone-swapped-arguments,bugprone-terminating-continue,bugprone-throw-keyword-missing,bugprone-too-small-loop-variable,bugprone-undefined-memory-manipulation,bugprone-undelegated-constructor,bugprone-unhandled-self-assignment,bugprone-unused-raii,bugprone-unused-return-value,bugprone-use-after-move,bugprone-virtual-near-miss,cert-dcl21-cpp,cert-dcl58-cpp,cert-err34-c,cert-err52-cpp,cert-err58-cpp,cert-err60-cpp,cert-flp30-c,cert-msc50-cpp,cert-msc51-cpp,cert-str34-c,cppcoreguidelines-interfaces-global-init,cppcoreguidelines-narrowing-conversions,cppcoreguidelines-pro-type-member-init,cppcoreguidelines-pro-type-static-cast-downcast,cppcoreguidelines-slicing,google-default-arguments,google-explicit-constructor,google-runtime-operator,hicpp-exception-baseclass,hicpp-multiway-paths-covered,misc-misplaced-const,misc-new-delete-overloads,misc-no-recursion,misc-non-copyable-objects,misc-throw-by-value-catch-by-reference,misc-unconventional-assign-operator,misc-uniqueptr-reset-release,modernize-avoid-bind,modernize-concat-nested-namespaces,modernize-deprecated-headers,modernize-deprecated-ios-base-aliases,modernize-loop-convert,modernize-make-shared,modernize-make-unique,modernize-pass-by-value,modernize-raw-string-literal,modernize-redundant-void-arg,modernize-replace-auto-ptr,modernize-replace-disallow-copy-and-assign-macro,modernize-replace-random-shuffle,modernize-return-braced-init-list,modernize-shrink-to-fit,modernize-unary-static-assert,modernize-use-auto,modernize-use-bool-literals,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-transparent-functors,modernize-use-uncaught-exceptions,mpi-buffer-deref,mpi-type-mismatch,openmp-use-default-none,performance-faster-string-find,performance-for-range-copy,performance-implicit-conversion-in-loop,performance-inefficient-algorithm,performance-inefficient-string-concatenation,performance-inefficient-vector-operation,performance-move-const-arg,performance-move-constructor-init,performance-no-automatic-move,performance-noexcept-move-constructor,performance-trivially-destructible,performance-type-promotion-in-math-fn,performance-unnecessary-copy-initialization,performance-unnecessary-value-param,portability-simd-intrinsics,readability-avoid-const-params-in-decls,readability-const-return-type,readability-container-size-empty,readability-convert-member-functions-to-static,readability-delete-null-pointer,readability-deleted-default,readability-inconsistent-declaration-parameter-name,readability-make-member-function-const,readability-misleading-indentation,readability-misplaced-array-index,readability-non-const-parameter,readability-redundant-control-flow,readability-redundant-declaration,readability-redundant-function-ptr-dereference,readability-redundant-smartptr-get,readability-redundant-string-cstr,readability-redundant-string-init,readability-simplify-subscript-expr,readability-static-accessed-through-instance,readability-static-definition-in-anonymous-namespace,readability-string-compare,readability-uniqueptr-delete-release,readability-use-anyofallof,-clion-*\",\"CheckOptions\":[]"' -dump-config > clion.yml
这是我用来将其转储为 yaml 格式的命令。并且命令的输出可以在这里看到这个要点https://gist.github.com/jfm535/7581ccadbd539303d8bed2f46f973108
gist 还包含 clions clang-tidy 支持的选项的完整列表
【讨论】:
您是如何找出您为生成输出而提供的参数-config
的值的?【参考方案2】:
将规则列表从 Clion 复制到名为 rules.txt
的文件中:
然后:
clang-tidy -checks="$(cat rules.txt | tr '\n' ',' | sed 's/,$//')" --dump-config > .clang-tidy
这是写这篇文章的当天结果的要点:https://gist.github.com/ArnaudValensi/0d36639fb84b80ee57d0c3c977deb70e
【讨论】:
以上是关于如何转储 CLion 的默认 clang-tidy 配置?的主要内容,如果未能解决你的问题,请参考以下文章
如何在 Visual Studio 和 CMake 中使用 clang-tidy?
C++Clang-Tidy提示:“Clang-Tidy: Potential uncovered code path; add a default label”的解决方案