.pre-commit-config.yaml 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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: cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b # frozen: v5.0.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: efaea7c61c774c0b1a9805fd999e754a2d19dbd1 # frozen: v1.2.5
  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: 8a737e727ac5ab2f1d4cf5876720ed276dc8dc4b # frozen: 25.1.0
  45. hooks:
  46. - id: black
  47. - repo: local
  48. hooks:
  49. - id: prettier
  50. name: prettier
  51. language: node
  52. # TODO: Not upgrading to/past 3.4.0 due to list indent changes that may
  53. # get fixed. See: https://github.com/prettier/prettier/issues/16929
  54. additional_dependencies: ['prettier@3.3.3']
  55. types_or: [html, javascript, json, markdown, yaml]
  56. entry: npx prettier@3.3.3 --write --log-level=warn
  57. - repo: local
  58. hooks:
  59. - id: buildifier
  60. name: Bazel buildifier
  61. entry: scripts/run_buildifier.py
  62. # Beyond just formatting, explicitly fix lint warnings.
  63. args: ['--lint=fix', '--warnings=all', '-r', '.']
  64. language: python
  65. files: |
  66. (?x)^(
  67. .*BUILD.*|
  68. .*MODULE.bazel.*|
  69. .*WORKSPACE.*|
  70. .*\.bzl
  71. )$
  72. - id: check-bazel-mod-deps
  73. # Check this after buildifier because buildifier may modify inputs, and
  74. # MODULE.bazel.lock includes line/column details.
  75. name: Check bazel mod deps
  76. entry: scripts/bazel_mod_deps.py
  77. language: python
  78. files: |
  79. (?x)^(
  80. .*MODULE.bazel.*|
  81. .*WORKSPACE.*
  82. )$
  83. - id: clang-format
  84. name: clang-format
  85. entry: clang-format
  86. types_or: [c++, def]
  87. language: python
  88. args: ['-i']
  89. additional_dependencies: ['clang-format==20.1.8']
  90. - repo: local
  91. hooks:
  92. - id: check-header-guards
  93. # This should run after clang-format, which may reformat a guard.
  94. name: Check header guards
  95. entry: scripts/check_header_guards.py
  96. language: python
  97. files: ^.*\.h$
  98. - id: check-sha-filenames
  99. # This may rename files, so it's deliberately between formatters and
  100. # linters.
  101. name: Check fuzzer SHA filenames
  102. entry: scripts/check_sha_filenames.py
  103. language: python
  104. files: ^.*/fuzzer_corpus/.*$
  105. - id: check-toolchain-diagnostics
  106. name: Check toolchain diagnostics
  107. entry: toolchain/diagnostics/check_diagnostics.py
  108. language: python
  109. files: |
  110. (?x)^(
  111. toolchain/.*\.cpp|
  112. toolchain/.*\.h|
  113. toolchain/diagnostics/check_diagnostics\.py|
  114. toolchain/diagnostics/diagnostic_kind\.def
  115. )$
  116. pass_filenames: false
  117. # Run linters last, as formatters and other checks may fix issues.
  118. - repo: local
  119. hooks:
  120. - id: forbid-llvm-googletest
  121. name: Checks for deps on LLVM's version of GoogleTest
  122. entry: scripts/forbid_llvm_googletest.py
  123. language: python
  124. files: ^.*/BUILD$
  125. pass_filenames: false
  126. - repo: https://github.com/PyCQA/flake8
  127. rev: d93590f5be797aabb60e3b09f2f52dddb02f349f # frozen: 7.3.0
  128. hooks:
  129. - id: flake8
  130. - repo: https://github.com/pre-commit/mirrors-mypy
  131. rev: '850d8bf806620ef89a99381c5cf5ea2c1ea826dd' # frozen: v1.17.0
  132. hooks:
  133. - id: mypy
  134. # Use setup.cfg to match the command line.
  135. args:
  136. - --config-file=setup.cfg
  137. # This should match the requirements added in the WORKSPACE pip_install.
  138. additional_dependencies:
  139. - gql >= 2.0.0, < 3.0.0
  140. - PyGitHub
  141. - rich
  142. # Exclusions are:
  143. # - p#### scripts because they're not tested or maintained.
  144. # - lit.cfg.py because it has multiple copies, breaking mypy.
  145. # - Unit tests because they sometimes violate typing, such as by
  146. # assigning a mock to a function.
  147. exclude: |
  148. (?x)^(
  149. proposals/(?!scripts/).*|
  150. .*/lit\.cfg\.py|
  151. .*_test\.py
  152. )$
  153. - repo: https://github.com/codespell-project/codespell
  154. rev: 63c8f8312b7559622c0d82815639671ae42132ac # frozen: v2.4.1
  155. hooks:
  156. - id: codespell
  157. args: ['-I', '.codespell_ignore', '--uri-ignore-words-list', '*']
  158. # Test data may contain intentional misspellings, as well as short,
  159. # meaningless identifiers that codespell incorrectly identifies as
  160. # typos but that we would want to detect in other contexts.
  161. exclude: |
  162. (?x)^(
  163. .*/testdata/.*|
  164. .*/fuzzer_corpus/.*
  165. )$
  166. - repo: https://github.com/google/pre-commit-tool-hooks
  167. rev: efaea7c61c774c0b1a9805fd999e754a2d19dbd1 # frozen: v1.2.5
  168. hooks:
  169. - id: check-copyright
  170. args:
  171. - --copyright
  172. - |+
  173. Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  174. Exceptions. See /LICENSE for license information.
  175. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  176. - --custom_format
  177. - '\.(carbon|c|json|scss|ypp)(\.tmpl)?$'
  178. - ''
  179. - '// '
  180. - ''
  181. - --custom_format
  182. - '\.(js|ts|mjs)$'
  183. - '/*'
  184. - ' * '
  185. - ' */'
  186. - --custom_format
  187. - '\.(l|lpp|y)$'
  188. - '/*'
  189. - ''
  190. - '*/'
  191. - --custom_format
  192. - '\.(plist)$'
  193. - '<!--'
  194. - ''
  195. - '\-->'
  196. - --custom_format
  197. - '\.vim$'
  198. - ''
  199. - '" '
  200. - ''
  201. - --custom_format
  202. - '\.scm$'
  203. - ''
  204. - '; '
  205. - ''
  206. - --custom_format
  207. - '\.lua$'
  208. - ''
  209. - '-- '
  210. - ''
  211. exclude: |
  212. (?x)^(
  213. .bazelversion|
  214. .github/pull_request_template.md|
  215. .python-version|
  216. compile_flags.txt|
  217. github_tools/requirements.txt|
  218. third_party/.*|
  219. utils/vscode/esbuild.js|
  220. website/.ruby-version|
  221. website/Gemfile.lock|
  222. .*\.def|
  223. .*\.png|
  224. .*\.svg|
  225. .*/fuzzer_corpus/.*|
  226. .*/testdata/.*\.golden
  227. )$
  228. - id: check-links
  229. - repo: local
  230. hooks:
  231. - id: check-build-graph
  232. name: Check build graph
  233. entry: scripts/check_build_graph.py
  234. language: python
  235. files: |
  236. (?x)^(
  237. .*BUILD.*|
  238. .*MODULE.bazel.*|
  239. .*WORKSPACE.*|
  240. .*\.bzl
  241. )$
  242. # This excludes third-party code, and patches to third-party code.
  243. exclude: |
  244. (?x)^(
  245. MODULE.bazel.lock|
  246. bazel/bazel_clang_tidy/.*\.patch|
  247. bazel/google_benchmark/.*\.patch|
  248. bazel/libpfm/.*\.patch|
  249. bazel/llvm_project/.*\.patch|
  250. third_party/examples/.*/carbon/.*|
  251. )$