.pre-commit-config.yaml 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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: b0d1fba7ac3be53c71fb0d3211d911e629f8aecb # frozen: 23.1.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==16.0.0']
  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==16.0.0']
  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/check_diagnostics\.py|
  102. toolchain/diagnostics/diagnostic_kind\.def
  103. )$
  104. pass_filenames: false
  105. # Run linters last, as formatters and other checks may fix issues.
  106. - repo: local
  107. hooks:
  108. - id: forbid-llvm-googletest
  109. name: Checks for deps on LLVM's version of GoogleTest
  110. entry: scripts/forbid_llvm_googletest.py
  111. language: python
  112. files: ^.*/BUILD$
  113. pass_filenames: false
  114. - repo: https://github.com/PyCQA/flake8
  115. rev: c838a5e98878f17889cfce311e1406d252f87ec5 # frozen: 6.0.0
  116. hooks:
  117. - id: flake8
  118. - repo: https://github.com/pre-commit/mirrors-mypy
  119. rev: '0b037c2b59aa62dc3be3287d175295f1a5547eb9' # frozen: v0.991
  120. hooks:
  121. - id: mypy
  122. # Use setup.cfg to match the command line.
  123. args:
  124. - --config-file=setup.cfg
  125. # This should match the requirements added in the WORKSPACE pip_install.
  126. additional_dependencies:
  127. - gql >= 2.0.0, < 3.0.0
  128. - PyGitHub
  129. # Exclusions are:
  130. # - p#### scripts because they're not tested or maintained.
  131. # - lit.cfg.py because it has multiple copies, breaking mypy.
  132. # - Unit tests because they sometimes violate typing, such as by
  133. # assigning a mock to a function.
  134. exclude: |
  135. (?x)^(
  136. proposals/(?!scripts/).*|
  137. .*/lit\.cfg\.py|
  138. .*_test\.py
  139. )$
  140. - repo: https://github.com/codespell-project/codespell
  141. rev: 055cb2a9bc1e98a9800a352c53c38a50faf62dc3 # frozen: v2.2.2
  142. hooks:
  143. - id: codespell
  144. args: ['-I', '.codespell_ignore', '--uri-ignore-words-list', '*']
  145. # Test data may contain intentional misspellings, as well as short,
  146. # meaningless identifiers that codespell incorrectly identifies as
  147. # typos but that we would want to detect in other contexts.
  148. exclude: |
  149. (?x)^(
  150. .*/testdata/.*|
  151. .*/fuzzer_corpus/.*
  152. )$
  153. - repo: https://github.com/google/pre-commit-tool-hooks
  154. rev: e006c8ab09f96ec32ba728b488ea5d17e1f8f6c0 # frozen: v1.2.4
  155. hooks:
  156. - id: check-copyright
  157. args:
  158. - --copyright
  159. - |+
  160. Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  161. Exceptions. See /LICENSE for license information.
  162. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  163. - --custom_format
  164. - '\.(carbon|proto|ypp)$'
  165. - ''
  166. - '// '
  167. - ''
  168. - --custom_format
  169. - '\.(l|lpp|y)$'
  170. - '/*'
  171. - ''
  172. - '*/'
  173. - --custom_format
  174. - '\.(plist)$'
  175. - '<!--'
  176. - ''
  177. - '\-->'
  178. - --custom_format
  179. - '\.vim$'
  180. - ''
  181. - '" '
  182. - ''
  183. exclude: |
  184. (?x)^(
  185. .bazelversion|
  186. .github/pull_request_template.md|
  187. compile_flags.txt|
  188. third_party/.*|
  189. .*\.def|
  190. .*\.svg|
  191. .*/fuzzer_corpus/.*|
  192. .*/testdata/.*\.golden
  193. )$
  194. - id: check-links
  195. # This excludes third-party code, and patches to third-party code.
  196. exclude: |
  197. (?x)^(
  198. bazel/patches/.*\.patch|
  199. third_party/examples/.*/carbon/.*|
  200. third_party/llvm-project/.*|
  201. )$