.clang-tidy 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. # Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. # Exceptions. See /LICENSE for license information.
  3. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. ---
  5. # Get colors when outputting through `bazel build --config=clang-tidy`.
  6. UseColor: true
  7. # This is necessary for `--config=clang-tidy` to catch errors.
  8. WarningsAsErrors: '*'
  9. # TODO: clang-tidy-16 doesn't support this format; it's retained for comments.
  10. # Switch once we update the minimum version.
  11. #
  12. # # We turn on all of a few categories by default.
  13. # - '-*'
  14. # - 'bugprone-*'
  15. # - 'google-*'
  16. # - 'misc-*'
  17. # - 'modernize-*'
  18. # - 'performance-*'
  19. # - 'readability-*'
  20. #
  21. # # Disabled due to the implied style choices.
  22. # - '-misc-const-correctness'
  23. # - '-misc-include-cleaner'
  24. # - '-misc-use-anonymous-namespace'
  25. # - '-modernize-return-braced-init-list'
  26. # - '-modernize-use-default-member-init'
  27. # - '-modernize-use-integer-sign-comparison'
  28. # - '-modernize-use-emplace'
  29. # - '-readability-avoid-nested-conditional-operator'
  30. # - '-readability-convert-member-functions-to-static'
  31. # - '-readability-else-after-return'
  32. # - '-readability-identifier-length'
  33. # - '-readability-implicit-bool-conversion'
  34. # - '-readability-make-member-function-const'
  35. # - '-readability-math-missing-parentheses'
  36. # - '-readability-static-definition-in-anonymous-namespace'
  37. # - '-readability-use-anyofallof'
  38. #
  39. # # Warns when we have multiple empty cases in switches, which we do for comment
  40. # # reasons.
  41. # - '-bugprone-branch-clone'
  42. # # Frequently warns on multiple parameters of the same type.
  43. # - '-bugprone-easily-swappable-parameters'
  44. # # Finds issues like out-of-memory in main(). We don't use exceptions, so it's
  45. # # unlikely to find real issues.
  46. # - '-bugprone-exception-escape'
  47. # # Has false positives in places such as using an argument to declare a name,
  48. # # which cannot have parentheses. For our limited use of macros, this is a
  49. # # common conflict.
  50. # - '-bugprone-macro-parentheses'
  51. # # Conflicts with integer type C++ style.
  52. # - '-bugprone-narrowing-conversions'
  53. # # Has false positives for `enum_base.h`. Clang's built-in switch warnings
  54. # # cover most of our risk of bugs here.
  55. # - '-bugprone-switch-missing-default-case'
  56. # # In clang-tidy 16, has false positives on code like:
  57. # # while (auto name_ref = insts().Get(inst_id).TryAs<SemIR::NameRef>()) {
  58. # # inst_id = name_ref->value_id;
  59. # # ^ unchecked access to optional value
  60. # # }
  61. # - '-bugprone-unchecked-optional-access'
  62. # # Overlaps with `readability-function-size`.
  63. # - '-google-readability-function-size'
  64. # # Suggests usernames on TODOs, which we don't want.
  65. # - '-google-readability-todo'
  66. # # Overlaps with `-Wno-missing-prototypes`.
  67. # - '-misc-use-internal-linkage'
  68. # # Suggests `std::array`, which we could migrate to, but conflicts with the
  69. # # status quo.
  70. # - '-modernize-avoid-c-arrays'
  71. # # Warns on creation of SemIR typed insts, for which we do not currently want
  72. # # to use designated initialization.
  73. # - '-modernize-use-designated-initializers'
  74. # # Only fixes const methods, not non-const, which yields distracting results on
  75. # # accessors.
  76. # - '-modernize-use-nodiscard'
  77. # # Duplicates `modernize-pass-by-value`.
  78. # - '-performance-unnecessary-value-param'
  79. # # Warns on enums which use the `LastValue = Value` pattern if all the other
  80. # # discriminants aren't given an explicit value.
  81. # - '-readability-enum-initial-value'
  82. # # Warns too frequently.
  83. # - '-readability-function-cognitive-complexity'
  84. # # Warns in reasonably documented situations.
  85. # - '-readability-magic-numbers'
  86. # # Warns on `= {}` which is also used to indicate which fields do not need to
  87. # # be explicitly initialized in aggregate initialization.
  88. # - '-readability-redundant-member-init'
  89. # # Warns when callers use similar names as different parameters.
  90. # - '-readability-suspicious-call-argument'
  91. Checks:
  92. -*, bugprone-*, google-*, misc-*, modernize-*, performance-*, readability-*,
  93. -misc-const-correctness, -misc-include-cleaner, -misc-use-anonymous-namespace,
  94. -modernize-return-braced-init-list, -modernize-use-default-member-init,
  95. -modernize-use-integer-sign-comparison, -modernize-use-emplace,
  96. -readability-avoid-nested-conditional-operator,
  97. -readability-convert-member-functions-to-static,
  98. -readability-else-after-return, -readability-identifier-length,
  99. -readability-implicit-bool-conversion,
  100. -readability-make-member-function-const,
  101. -readability-math-missing-parentheses,
  102. -readability-static-definition-in-anonymous-namespace,
  103. -readability-use-anyofallof, -bugprone-branch-clone,
  104. -bugprone-easily-swappable-parameters, -bugprone-exception-escape,
  105. -bugprone-macro-parentheses, -bugprone-narrowing-conversions,
  106. -bugprone-switch-missing-default-case, -bugprone-unchecked-optional-access,
  107. -google-readability-function-size, -google-readability-todo,
  108. -misc-use-internal-linkage, -modernize-avoid-c-arrays,
  109. -modernize-use-designated-initializers, -modernize-use-nodiscard,
  110. -performance-unnecessary-value-param, -readability-enum-initial-value,
  111. -readability-function-cognitive-complexity, -readability-magic-numbers,
  112. -readability-redundant-member-init, -readability-suspicious-call-argument
  113. CheckOptions:
  114. # Don't warn on structs; done by ignoring when there are only public members.
  115. - key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
  116. value: true
  117. # CamelCase names.
  118. - key: readability-identifier-naming.ClassCase
  119. value: CamelCase
  120. - key: readability-identifier-naming.ClassConstantCase
  121. value: CamelCase
  122. - key: readability-identifier-naming.ConstexprVariableCase
  123. value: CamelCase
  124. - key: readability-identifier-naming.NamespaceCase
  125. value: CamelCase
  126. - key: readability-identifier-naming.StructCase
  127. value: CamelCase
  128. - key: readability-identifier-naming.TemplateParameterCase
  129. value: CamelCase
  130. - key: readability-identifier-naming.TypeAliasCase
  131. value: CamelCase
  132. - key: readability-identifier-naming.TypedefCase
  133. value: CamelCase
  134. - key: readability-identifier-naming.UnionCase
  135. value: CamelCase
  136. # lower_case names.
  137. - key: readability-identifier-naming.ClassMemberCase
  138. value: lower_case
  139. - key: readability-identifier-naming.ParameterCase
  140. value: lower_case
  141. - key: readability-identifier-naming.VariableCase
  142. value: lower_case
  143. # TODO: This is for explorer's use of LLVM casting support, so we should be
  144. # able to remove it once explorer is deleted.
  145. - key: readability-identifier-naming.MethodIgnoredRegexp
  146. value: '^classof$'
  147. # This erroneously fires in C++20 mode with LLVM 16 clang-tidy, due to:
  148. # https://github.com/llvm/llvm-project/issues/46097
  149. - key: readability-identifier-naming.TemplateParameterIgnoredRegexp
  150. value: '^expr-type$'