.clang-tidy 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. # We turn on all `bugprone`, `google`, `modernize`, `performance`, and
  10. # `readability` by default. A few `misc` are selectively enabled, and a few
  11. # other checks are selectively disabled.
  12. #
  13. # Checks with nuanced reasons for disabling are:
  14. #
  15. # - `bugprone-branch-clone` warns when we have multiple empty cases in switches,
  16. # which we do for comment reasons.
  17. # - `bugprone-easily-swappable-parameters` frequently warns on multiple
  18. # parameters of the same type.
  19. # - `bugprone-exception-escape` finds issues like out-of-memory in main(). We
  20. # don't use exceptions, so it's unlikely to find real issues.
  21. # - `bugprone-macro-parentheses` has false positives in places such as using an
  22. # argument to declare a name, which cannot have parentheses. For our limited
  23. # use of macros, this is a common conflict.
  24. # - `bugprone-narrowing-conversions` conflicts with integer type C++ style.
  25. # - `google-readability-todo` suggests usernames on TODOs, which we don't want.
  26. # - `bugprone-switch-missing-default-case` has false positives for
  27. # `enum_base.h`. Clang's built-in switch warnings cover most of our risk of
  28. # bugs here.
  29. # - `bugprone-unchecked-optional-access` in clang-tidy 16 has false positives on
  30. # code like:
  31. # while (auto name_ref = insts().Get(inst_id).TryAs<SemIR::NameRef>()) {
  32. # inst_id = name_ref->value_id;
  33. # ^ unchecked access to optional value
  34. # }
  35. # - `google-readability-function-size` overlaps with
  36. # `readability-function-size`.
  37. # - `modernize-avoid-c-arrays` suggests `std::array`, which we could migrate to,
  38. # but conflicts with the status quo.
  39. # - `modernize-use-designated-initializers` fires on creation of SemIR typed
  40. # insts, for which we do not currently want to use designated initialization.
  41. # - `modernize-use-nodiscard` is disabled because it only fixes const methods,
  42. # not non-const, which yields distracting results on accessors.
  43. # - `performance-unnecessary-value-param` duplicates `modernize-pass-by-value`.
  44. # - `readability-enum-initial-value` warns on enums which use the
  45. # `LastValue = Value` pattern if all the other discriminants aren't given an
  46. # explicit value.
  47. # - `readability-function-cognitive-complexity` warns too frequently.
  48. # - `readability-magic-numbers` warns in reasonably documented situations.
  49. # - `readability-suspicious-call-argument` warns when callers use similar names
  50. # as different parameters.
  51. #
  52. # Checks that are essentially style choices we don't apply are:
  53. #
  54. # - `modernize-return-braced-init-list`
  55. # - `modernize-use-default-member-init`
  56. # - `modernize-use-emplace`
  57. # - `readability-convert-member-functions-to-static`
  58. # - `readability-else-after-return`
  59. # - `readability-identifier-length`
  60. # - `readability-implicit-bool-conversion`
  61. # - `readability-make-member-function-const`
  62. # - `readability-static-definition-in-anonymous-namespace`
  63. # - `readability-use-anyofallof`
  64. Checks:
  65. -*, bugprone-*, -bugprone-branch-clone, -bugprone-easily-swappable-parameters,
  66. -bugprone-exception-escape, -bugprone-macro-parentheses,
  67. -bugprone-narrowing-conversions, -bugprone-switch-missing-default-case,
  68. -bugprone-unchecked-optional-access, google-*,
  69. -google-readability-function-size, -google-readability-todo,
  70. misc-definitions-in-headers, misc-misplaced-const, misc-redundant-expression,
  71. misc-static-assert, misc-unconventional-assign-operator,
  72. misc-uniqueptr-reset-release, misc-unused-*, modernize-*,
  73. -modernize-avoid-c-arrays, -modernize-return-braced-init-list,
  74. -modernize-use-default-member-init, -modernize-use-designated-initializers,
  75. -modernize-use-emplace, -modernize-use-nodiscard, performance-*,
  76. -performance-unnecessary-value-param, readability-*,
  77. -readability-convert-member-functions-to-static,
  78. -readability-else-after-return, -readability-enum-initial-value,
  79. -readability-function-cognitive-complexity, -readability-identifier-length,
  80. -readability-implicit-bool-conversion, -readability-magic-numbers,
  81. -readability-make-member-function-const,
  82. -readability-static-definition-in-anonymous-namespace,
  83. -readability-suspicious-call-argument, -readability-use-anyofallof
  84. CheckOptions:
  85. - { key: readability-identifier-naming.ClassCase, value: CamelCase }
  86. - { key: readability-identifier-naming.ClassConstantCase, value: CamelCase }
  87. - {
  88. key: readability-identifier-naming.ConstexprVariableCase,
  89. value: CamelCase,
  90. }
  91. - { key: readability-identifier-naming.NamespaceCase, value: CamelCase }
  92. - { key: readability-identifier-naming.StructCase, value: CamelCase }
  93. - {
  94. key: readability-identifier-naming.TemplateParameterCase,
  95. value: CamelCase,
  96. }
  97. - { key: readability-identifier-naming.TypeAliasCase, value: CamelCase }
  98. - { key: readability-identifier-naming.TypedefCase, value: CamelCase }
  99. - { key: readability-identifier-naming.UnionCase, value: CamelCase }
  100. - { key: readability-identifier-naming.VariableCase, value: lower_case }
  101. - { key: readability-identifier-naming.ParameterCase, value: lower_case }
  102. - { key: readability-identifier-naming.ClassMemberCase, value: lower_case }
  103. - {
  104. key: readability-identifier-naming.MethodIgnoredRegexp,
  105. value: '^classof$',
  106. }
  107. - {
  108. # This erroneously fires in C++20 mode with LLVM 16 clang-tidy, due to:
  109. # https://github.com/llvm/llvm-project/issues/46097
  110. key: readability-identifier-naming.TemplateParameterIgnoredRegexp,
  111. value: '^expr-type$',
  112. }