.clang-tidy 6.3 KB

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