.pre-commit-config.yaml 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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: 3298ddab3c13dd77d6ce1fc0baf97691430d84b0 # frozen: v4.3.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: f6c139c5215ce04fd3e73a900f1372942d58eca0 # frozen: 22.6.0
  45. hooks:
  46. - id: black
  47. - repo: https://github.com/pre-commit/mirrors-prettier
  48. rev: d0a4882e1c96eca274f90b273f0f809ab3d98aff # frozen: v3.0.0-alpha.0
  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==13.0.1']
  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==13.0.1']
  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. # Run linters last, as formatters and other checks may fix issues.
  94. - repo: local
  95. hooks:
  96. - id: forbid-llvm-googletest
  97. name: Checks for deps on LLVM's version of GoogleTest
  98. entry: scripts/forbid_llvm_googletest.py
  99. language: python
  100. files: ^.*/BUILD$
  101. pass_filenames: false
  102. - repo: https://github.com/PyCQA/flake8
  103. rev: f8e1b317742036ff11ff86356fd2b68147e169f7 # frozen: 5.0.4
  104. hooks:
  105. - id: flake8
  106. - repo: https://github.com/pre-commit/mirrors-mypy
  107. rev: 'fde4bb992b03943ecb94207a52739ba07957bd06' # frozen: v0.971
  108. hooks:
  109. - id: mypy
  110. # Use setup.cfg to match the command line.
  111. args:
  112. - --config-file=setup.cfg
  113. # This should match the requirements added in the WORKSPACE pip_install.
  114. additional_dependencies:
  115. - gql >= 2.0.0, < 3.0.0
  116. - PyGitHub
  117. # Exclusions are:
  118. # - p#### scripts because they're not tested or maintained.
  119. # - lit.cfg.py because it has multiple copies, breaking mypy.
  120. # - Unit tests because they sometimes violate typing, such as by
  121. # assigning a mock to a function.
  122. exclude: |
  123. (?x)^(
  124. proposals/(?!scripts/).*|
  125. .*/lit\.cfg\.py|
  126. .*_test\.py
  127. )$
  128. - repo: https://github.com/codespell-project/codespell
  129. rev: c6ecb9fc51571a77bc92e6c265c358aef7cb6c38 # frozen: v2.2.1
  130. hooks:
  131. - id: codespell
  132. args: ['-I', '.codespell_ignore', '--uri-ignore-words-list', '*']
  133. # Test data may contain intentional misspellings, as well as short,
  134. # meaningless identifiers that codespell incorrectly identifies as
  135. # typos but that we would want to detect in other contexts.
  136. exclude: |
  137. (?x)^(
  138. .*/testdata/.*|
  139. .*/fuzzer_corpus/.*
  140. )$
  141. - repo: https://github.com/google/pre-commit-tool-hooks
  142. rev: e006c8ab09f96ec32ba728b488ea5d17e1f8f6c0 # frozen: v1.2.4
  143. hooks:
  144. - id: check-copyright
  145. args:
  146. - --copyright
  147. - |+
  148. Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  149. Exceptions. See /LICENSE for license information.
  150. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  151. - --custom_format
  152. - '\.(carbon|proto|ypp)$'
  153. - ''
  154. - '// '
  155. - ''
  156. - --custom_format
  157. - '\.(l|lpp|y)$'
  158. - '/*'
  159. - ''
  160. - '*/'
  161. - --custom_format
  162. - '\.(plist)$'
  163. - '<!--'
  164. - ''
  165. - '\-->'
  166. - --custom_format
  167. - '\.vim$'
  168. - ''
  169. - '" '
  170. - ''
  171. exclude: |
  172. (?x)^(
  173. .bazelversion|
  174. compile_flags.txt|
  175. third_party/.*|
  176. bazel/llvm-patches/.*\.patch|
  177. .*\.def|
  178. .*\.svg|
  179. .*/fuzzer_corpus/.*|
  180. .*/testdata/.*\.golden
  181. )$
  182. - id: check-links
  183. # Most third-party code is in submodules; local commits are excluded here.
  184. # We fully exclude fuzzer corpus directories as they are generated binary data.
  185. exclude: |
  186. (?x)^(
  187. third_party/examples/.*/carbon/.*|
  188. third_party/llvm-project/.*|
  189. )$