.clang-tidy 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. - 'modernize-*'
  15. - 'performance-*'
  16. - 'readability-*'
  17. # `misc` is selectively enabled because we want a minority of them.
  18. - 'misc-definitions-in-headers'
  19. - 'misc-misplaced-const'
  20. - 'misc-redundant-expression'
  21. - 'misc-static-assert'
  22. - 'misc-unconventional-assign-operator'
  23. - 'misc-uniqueptr-reset-release'
  24. - 'misc-unused-*'
  25. # Disabled due to the implied style choices.
  26. - '-modernize-return-braced-init-list'
  27. - '-modernize-use-default-member-init'
  28. - '-modernize-use-emplace'
  29. - '-readability-convert-member-functions-to-static'
  30. - '-readability-else-after-return'
  31. - '-readability-identifier-length'
  32. - '-readability-implicit-bool-conversion'
  33. - '-readability-make-member-function-const'
  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. # Suggests `std::array`, which we could migrate to, but conflicts with the
  64. # status quo.
  65. - '-modernize-avoid-c-arrays'
  66. # Warns on creation of SemIR typed insts, for which we do not currently want
  67. # to use designated initialization.
  68. - '-modernize-use-designated-initializers'
  69. # Only fixes const methods, not non-const, which yields distracting results on
  70. # accessors.
  71. - '-modernize-use-nodiscard'
  72. # Duplicates `modernize-pass-by-value`.
  73. - '-performance-unnecessary-value-param'
  74. # Warns on enums which use the `LastValue = Value` pattern if all the other
  75. # discriminants aren't given an explicit value.
  76. - '-readability-enum-initial-value'
  77. # Warns too frequently.
  78. - '-readability-function-cognitive-complexity'
  79. # Warns in reasonably documented situations.
  80. - '-readability-magic-numbers'
  81. # Warns on `= {}` which is also used to indicate which fields do not need to
  82. # be explicitly initialized in aggregate initialization.
  83. - '-readability-redundant-member-init'
  84. # Warns when callers use similar names as different parameters.
  85. - '-readability-suspicious-call-argument'
  86. CheckOptions:
  87. - key: readability-identifier-naming.ClassCase
  88. value: CamelCase
  89. - key: readability-identifier-naming.ClassConstantCase
  90. value: CamelCase
  91. - key: readability-identifier-naming.ConstexprVariableCase
  92. value: CamelCase
  93. - key: readability-identifier-naming.NamespaceCase
  94. value: CamelCase
  95. - key: readability-identifier-naming.StructCase
  96. value: CamelCase
  97. - key: readability-identifier-naming.TemplateParameterCase
  98. value: CamelCase
  99. - key: readability-identifier-naming.TypeAliasCase
  100. value: CamelCase
  101. - key: readability-identifier-naming.TypedefCase
  102. value: CamelCase
  103. - key: readability-identifier-naming.UnionCase
  104. value: CamelCase
  105. - key: readability-identifier-naming.ClassMemberCase
  106. value: lower_case
  107. - key: readability-identifier-naming.ParameterCase
  108. value: lower_case
  109. - key: readability-identifier-naming.VariableCase
  110. value: lower_case
  111. - key: readability-identifier-naming.MethodIgnoredRegexp
  112. value: '^classof$'
  113. # This erroneously fires in C++20 mode with LLVM 16 clang-tidy, due to:
  114. # https://github.com/llvm/llvm-project/issues/46097
  115. - key: readability-identifier-naming.TemplateParameterIgnoredRegexp
  116. value: '^expr-type$'