.clang-tidy 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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-use-anyofallof'
  36. # Warns when we have multiple empty cases in switches, which we do for comment
  37. # reasons.
  38. - '-bugprone-branch-clone'
  39. # Frequently warns on multiple parameters of the same type.
  40. - '-bugprone-easily-swappable-parameters'
  41. # Finds issues like out-of-memory in main(). We don't use exceptions, so it's
  42. # unlikely to find real issues.
  43. - '-bugprone-exception-escape'
  44. # Has false positives in places such as using an argument to declare a name,
  45. # which cannot have parentheses. For our limited use of macros, this is a
  46. # common conflict.
  47. - '-bugprone-macro-parentheses'
  48. # Conflicts with integer type C++ style.
  49. - '-bugprone-narrowing-conversions'
  50. # Has false positives for `enum_base.h`. Clang's built-in switch warnings
  51. # cover most of our risk of bugs here.
  52. - '-bugprone-switch-missing-default-case'
  53. # In clang-tidy 16, has false positives on code like:
  54. # while (auto name_ref = insts().Get(inst_id).TryAs<SemIR::NameRef>()) {
  55. # inst_id = name_ref->value_id;
  56. # ^ unchecked access to optional value
  57. # }
  58. - '-bugprone-unchecked-optional-access'
  59. # Overlaps with `readability-function-size`.
  60. - '-google-readability-function-size'
  61. # Suggests usernames on TODOs, which we don't want.
  62. - '-google-readability-todo'
  63. # Extremely slow. TODO: Re-enable once
  64. # https://github.com/llvm/llvm-project/issues/128797 is fixed.
  65. - '-misc-confusable-identifiers'
  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. # We aren't using the ranges library due to performance concerns.
  78. - '-modernize-use-ranges'
  79. # Low value compared to the engineering cost.
  80. - '-performance-enum-size'
  81. # Duplicates `modernize-pass-by-value`.
  82. - '-performance-unnecessary-value-param'
  83. # Warns on enums which use the `LastValue = Value` pattern if all the other
  84. # discriminants aren't given an explicit value.
  85. - '-readability-enum-initial-value'
  86. # Warns too frequently.
  87. - '-readability-function-cognitive-complexity'
  88. # Warns in reasonably documented situations.
  89. - '-readability-magic-numbers'
  90. # Warns on `= {}` which is also used to indicate which fields do not need to
  91. # be explicitly initialized in aggregate initialization.
  92. - '-readability-redundant-member-init'
  93. # Warns when callers use similar names as different parameters.
  94. - '-readability-suspicious-call-argument'
  95. CheckOptions:
  96. # Don't warn on structs; done by ignoring when there are only public members.
  97. - key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
  98. value: true
  99. # CamelCase names.
  100. - key: readability-identifier-naming.ClassCase
  101. value: CamelCase
  102. - key: readability-identifier-naming.ClassConstantCase
  103. value: CamelCase
  104. - key: readability-identifier-naming.ConstexprVariableCase
  105. value: CamelCase
  106. - key: readability-identifier-naming.NamespaceCase
  107. value: CamelCase
  108. - key: readability-identifier-naming.StructCase
  109. value: CamelCase
  110. - key: readability-identifier-naming.TemplateParameterCase
  111. value: CamelCase
  112. - key: readability-identifier-naming.TypeAliasCase
  113. value: CamelCase
  114. - key: readability-identifier-naming.TypedefCase
  115. value: CamelCase
  116. - key: readability-identifier-naming.UnionCase
  117. value: CamelCase
  118. # lower_case names.
  119. - key: readability-identifier-naming.ClassMemberCase
  120. value: lower_case
  121. - key: readability-identifier-naming.ParameterCase
  122. value: lower_case
  123. - key: readability-identifier-naming.VariableCase
  124. value: lower_case
  125. # TODO: This is for explorer's use of LLVM casting support, so we should be
  126. # able to remove it once explorer is deleted.
  127. - key: readability-identifier-naming.MethodIgnoredRegexp
  128. value: '^classof$'
  129. # This erroneously fires in C++20 mode with LLVM 16 clang-tidy, due to:
  130. # https://github.com/llvm/llvm-project/issues/46097
  131. - key: readability-identifier-naming.TemplateParameterIgnoredRegexp
  132. value: '^expr-type$'
  133. # Don't require writing a return type on lambdas.
  134. - key: modernize-use-trailing-return-type.TransformLambdas
  135. value: none
  136. # Use lines rather than statements to measure function size, because
  137. # for readability purposes we care about the code as written, before
  138. # preprocessing.
  139. - key: readability-function-size.StatementThreshold
  140. value: none
  141. - key: readability-function-size.LineThreshold
  142. # Chose 800 to match the default for StatementThreshold.
  143. value: 800