.pre-commit-config.yaml 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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: db7346d375eda68a0174f2c057dd97f2fbffe030 # frozen: v4.2.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-(clang-toolchain|execroot)$
  20. - id: check-yaml
  21. - id: detect-private-key
  22. - id: end-of-file-fixer
  23. exclude: '^(.*/fuzzer_corpus/.*)$'
  24. - id: mixed-line-ending
  25. args: ['--fix=lf']
  26. exclude: '^(.*/fuzzer_corpus/.*)$'
  27. - id: trailing-whitespace
  28. exclude: '^(.*/fuzzer_corpus/.*|.*/testdata/.*\.golden)$'
  29. - repo: https://github.com/google/pre-commit-tool-hooks
  30. rev: cb78d9293306d9f737c64d9702bbaa88e157caaa # frozen: v1.2.2
  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: ae2c0758c9e61a385df9700dc9c231bf54887041 # frozen: 22.3.0
  45. hooks:
  46. - id: black
  47. - repo: https://github.com/pre-commit/mirrors-prettier
  48. rev: 5e374fda194d7f7ce9eebbd582b2a5594838c85b # frozen: v2.6.2
  49. hooks:
  50. - id: prettier
  51. - repo: local
  52. hooks:
  53. - id: buildifier
  54. name: Bazel buildifier
  55. entry: scripts/run_buildifier.py
  56. language: python
  57. files: |
  58. (?x)^(
  59. .*BUILD.*|
  60. .*WORKSPACE.*|
  61. .*\.bzl
  62. )$'
  63. - id: clang-format
  64. name: clang-format
  65. entry: clang-format
  66. types_or: [c++, proto]
  67. language: python
  68. args: ['-i']
  69. additional_dependencies: ['clang-format==13.0.1']
  70. - id: explorer-format-grammar
  71. name: Format the explorer grammar file
  72. entry: explorer/syntax/format_grammar.py
  73. language: python
  74. files: ^explorer/syntax/(lexer.lpp|parser.ypp)$
  75. pass_filenames: false
  76. additional_dependencies: ['clang-format==13.0.1']
  77. - repo: local
  78. hooks:
  79. - id: check-header-guards
  80. # This should run after clang-format, which may reformat a guard.
  81. name: Check header guards
  82. entry: scripts/check_header_guards.py
  83. language: python
  84. files: '^.*\.h$'
  85. - id: check-sha-filenames
  86. # This may rename files, so it's deliberately between formatters and
  87. # linters.
  88. name: Check fuzzer SHA filenames
  89. entry: scripts/check_sha_filenames.py
  90. language: python
  91. files: ^.*/fuzzer_corpus/.*$
  92. # Run linters last, as formatters and other checks may fix issues.
  93. - repo: local
  94. hooks:
  95. - id: forbid-llvm-googletest
  96. name: Checks for deps on LLVM's version of GoogleTest
  97. entry: scripts/forbid_llvm_googletest.py
  98. language: python
  99. files: ^.*/BUILD$
  100. pass_filenames: false
  101. - repo: https://github.com/PyCQA/flake8
  102. rev: cbeb4c9c4137cff1568659fcc48e8b85cddd0c8d # frozen: 4.0.1
  103. hooks:
  104. - id: flake8
  105. - repo: https://github.com/pre-commit/mirrors-mypy
  106. rev: 'a04404bdf52c2cbc9c5bd705454b89bd83b84383' # frozen: v0.950
  107. hooks:
  108. - id: mypy
  109. # Use setup.cfg to match the command line.
  110. args:
  111. - --config-file=setup.cfg
  112. # This should match the requirements added in the WORKSPACE pip_install.
  113. additional_dependencies:
  114. - gql >= 2.0.0, < 3.0.0
  115. - PyGitHub
  116. # Exclusions are:
  117. # - p#### scripts because they're not tested or maintained.
  118. # - lit.cfg.py because it has multiple copies, breaking mypy.
  119. # - Unit tests because they sometimes violate typing, such as by
  120. # assigning a mock to a function.
  121. exclude: |
  122. (?x)^(
  123. proposals/(?!scripts/).*|
  124. .*/lit\.cfg\.py|
  125. .*_test\.py
  126. )$
  127. - repo: https://github.com/codespell-project/codespell
  128. rev: 01da43d753cdff4ea7dff952b4f5317450af31e3 # frozen: v2.1.0
  129. hooks:
  130. - id: codespell
  131. args: ['-I', '.codespell_ignore', '--uri-ignore-words-list', '*']
  132. # Test data may contain intentional misspellings, as well as short,
  133. # meaningless identifiers that codespell incorrectly identifies as
  134. # typos but that we would want to detect in other contexts.
  135. exclude: |
  136. (?x)^(
  137. .*/testdata/.*|
  138. .*/fuzzer_corpus/.*
  139. )$
  140. - repo: https://github.com/google/pre-commit-tool-hooks
  141. rev: cb78d9293306d9f737c64d9702bbaa88e157caaa # frozen: v1.2.2
  142. hooks:
  143. - id: check-copyright
  144. args:
  145. - --copyright
  146. - |+
  147. Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  148. Exceptions. See /LICENSE for license information.
  149. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  150. - --custom_format
  151. - '\.(carbon|proto|ypp)$'
  152. - ''
  153. - '// '
  154. - ''
  155. - --custom_format
  156. - '\.(l|lpp|y)$'
  157. - '/*'
  158. - ''
  159. - '*/'
  160. exclude: |
  161. (?x)^(
  162. .bazelversion|
  163. compile_flags.txt|
  164. third_party/.*|
  165. bazel/llvm-patches/.*\.patch|
  166. .*\.def|
  167. .*\.svg|
  168. .*/fuzzer_corpus/.*|
  169. .*/testdata/.*\.golden
  170. )$
  171. - id: check-links
  172. # Most third-party code is in submodules; local commits are excluded here.
  173. # We fully exclude fuzzer corpus directories as they are generated binary data.
  174. exclude: |
  175. (?x)^(
  176. third_party/examples/.*/carbon/.*|
  177. third_party/llvm-project/.*|
  178. )$