.pre-commit-config.yaml 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. # Update versions with:
  5. # pre-commit autoupdate --freeze && pre-commit run -a
  6. # See https://pre-commit.com for more information
  7. # See https://pre-commit.com/hooks.html for more hooks
  8. default_language_version:
  9. python: python3 # Defaults to python2, so override it.
  10. repos:
  11. - repo: https://github.com/pre-commit/pre-commit-hooks
  12. rev: f71fa2c1f9cf5cb705f73dffe4b21f7c61470ba9 # frozen: v4.4.0
  13. hooks:
  14. - id: check-added-large-files
  15. - id: check-case-conflict
  16. - id: check-executables-have-shebangs
  17. - id: check-merge-conflict
  18. - id: check-symlinks
  19. exclude: ^bazel-execroot$
  20. - id: check-yaml
  21. - id: detect-private-key
  22. - id: end-of-file-fixer
  23. exclude: '^(.*/fuzzer_corpus/.*|.*\.svg)$'
  24. - id: mixed-line-ending
  25. args: ['--fix=lf']
  26. exclude: '^(.*/fuzzer_corpus/.*|.*\.svg)$'
  27. - id: trailing-whitespace
  28. exclude: '^(.*/fuzzer_corpus/.*|.*/testdata/.*\.golden|.*\.svg)$'
  29. - repo: https://github.com/google/pre-commit-tool-hooks
  30. rev: e006c8ab09f96ec32ba728b488ea5d17e1f8f6c0 # frozen: v1.2.4
  31. hooks:
  32. - id: check-google-doc-style
  33. - id: markdown-toc
  34. - repo: local
  35. hooks:
  36. - id: fix-cc-deps
  37. name: Fix missing C++ deps
  38. entry: scripts/fix_cc_deps.py
  39. language: python
  40. files: ^.*/(BUILD|[^/]+\.(h|cpp))$
  41. pass_filenames: false
  42. # Formatters should be run late so that they can re-format any prior changes.
  43. - repo: https://github.com/psf/black
  44. rev: 2ddea293a88919650266472186620a98a4a8bb37 # frozen: 22.12.0
  45. hooks:
  46. - id: black
  47. - repo: https://github.com/pre-commit/mirrors-prettier
  48. rev: cafd5506f18eea191804850dacc0a4264772d59d # frozen: v3.0.0-alpha.4
  49. hooks:
  50. - id: prettier
  51. - repo: local
  52. hooks:
  53. - id: buildifier
  54. name: Bazel buildifier
  55. entry: scripts/run_buildifier.py
  56. args: ['-r', '.']
  57. language: python
  58. files: |
  59. (?x)^(
  60. .*BUILD.*|
  61. .*WORKSPACE.*|
  62. .*\.bzl
  63. )$
  64. - id: clang-format
  65. name: clang-format
  66. entry: clang-format
  67. types_or: [c++, proto]
  68. language: python
  69. args: ['-i']
  70. additional_dependencies: ['clang-format==14.0.6']
  71. - id: explorer-format-grammar
  72. name: Format the explorer grammar file
  73. entry: explorer/syntax/format_grammar.py
  74. language: python
  75. files: ^explorer/syntax/(lexer.lpp|parser.ypp)$
  76. pass_filenames: false
  77. additional_dependencies: ['clang-format==14.0.6']
  78. - repo: local
  79. hooks:
  80. - id: check-header-guards
  81. # This should run after clang-format, which may reformat a guard.
  82. name: Check header guards
  83. entry: scripts/check_header_guards.py
  84. language: python
  85. files: ^.*\.h$
  86. - id: check-sha-filenames
  87. # This may rename files, so it's deliberately between formatters and
  88. # linters.
  89. name: Check fuzzer SHA filenames
  90. entry: scripts/check_sha_filenames.py
  91. language: python
  92. files: ^.*/fuzzer_corpus/.*$
  93. - id: check-toolchain-diagnostics
  94. name: Check toolchain diagnostics
  95. entry: toolchain/diagnostics/check_diagnostics.py
  96. language: python
  97. files: |
  98. (?x)^(
  99. toolchain/.*\.cpp|
  100. toolchain/.*\.h|
  101. toolchain/diagnostics/diagnostic_registry\.def
  102. )$
  103. # Run linters last, as formatters and other checks may fix issues.
  104. - repo: local
  105. hooks:
  106. - id: forbid-llvm-googletest
  107. name: Checks for deps on LLVM's version of GoogleTest
  108. entry: scripts/forbid_llvm_googletest.py
  109. language: python
  110. files: ^.*/BUILD$
  111. pass_filenames: false
  112. - repo: https://github.com/PyCQA/flake8
  113. rev: c838a5e98878f17889cfce311e1406d252f87ec5 # frozen: 6.0.0
  114. hooks:
  115. - id: flake8
  116. - repo: https://github.com/pre-commit/mirrors-mypy
  117. rev: '0b037c2b59aa62dc3be3287d175295f1a5547eb9' # frozen: v0.991
  118. hooks:
  119. - id: mypy
  120. # Use setup.cfg to match the command line.
  121. args:
  122. - --config-file=setup.cfg
  123. # This should match the requirements added in the WORKSPACE pip_install.
  124. additional_dependencies:
  125. - gql >= 2.0.0, < 3.0.0
  126. - PyGitHub
  127. # Exclusions are:
  128. # - p#### scripts because they're not tested or maintained.
  129. # - lit.cfg.py because it has multiple copies, breaking mypy.
  130. # - Unit tests because they sometimes violate typing, such as by
  131. # assigning a mock to a function.
  132. exclude: |
  133. (?x)^(
  134. proposals/(?!scripts/).*|
  135. .*/lit\.cfg\.py|
  136. .*_test\.py
  137. )$
  138. - repo: https://github.com/codespell-project/codespell
  139. rev: 055cb2a9bc1e98a9800a352c53c38a50faf62dc3 # frozen: v2.2.2
  140. hooks:
  141. - id: codespell
  142. args: ['-I', '.codespell_ignore', '--uri-ignore-words-list', '*']
  143. # Test data may contain intentional misspellings, as well as short,
  144. # meaningless identifiers that codespell incorrectly identifies as
  145. # typos but that we would want to detect in other contexts.
  146. exclude: |
  147. (?x)^(
  148. .*/testdata/.*|
  149. .*/fuzzer_corpus/.*
  150. )$
  151. - repo: https://github.com/google/pre-commit-tool-hooks
  152. rev: e006c8ab09f96ec32ba728b488ea5d17e1f8f6c0 # frozen: v1.2.4
  153. hooks:
  154. - id: check-copyright
  155. args:
  156. - --copyright
  157. - |+
  158. Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  159. Exceptions. See /LICENSE for license information.
  160. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  161. - --custom_format
  162. - '\.(carbon|proto|ypp)$'
  163. - ''
  164. - '// '
  165. - ''
  166. - --custom_format
  167. - '\.(l|lpp|y)$'
  168. - '/*'
  169. - ''
  170. - '*/'
  171. - --custom_format
  172. - '\.(plist)$'
  173. - '<!--'
  174. - ''
  175. - '\-->'
  176. - --custom_format
  177. - '\.vim$'
  178. - ''
  179. - '" '
  180. - ''
  181. exclude: |
  182. (?x)^(
  183. .bazelversion|
  184. .github/pull_request_template.md|
  185. compile_flags.txt|
  186. third_party/.*|
  187. .*\.def|
  188. .*\.svg|
  189. .*/fuzzer_corpus/.*|
  190. .*/testdata/.*\.golden
  191. )$
  192. - id: check-links
  193. # This excludes third-party code, and patches to third-party code.
  194. exclude: |
  195. (?x)^(
  196. bazel/patches/.*\.patch|
  197. third_party/examples/.*/carbon/.*|
  198. third_party/llvm-project/.*|
  199. )$