.pre-commit-config.yaml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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: '^(.*/)?(BUILD\.bazel|BUILD|WORKSPACE)$|\.BUILD$|\.bzl$'
  58. - id: clang-format
  59. name: clang-format
  60. entry: clang-format
  61. types_or: [c++, proto]
  62. language: python
  63. args: ['-i']
  64. additional_dependencies: ['clang-format==13.0.1']
  65. - id: explorer-format-grammar
  66. name: Format the explorer grammar file
  67. entry: explorer/syntax/format_grammar.py
  68. language: python
  69. files: ^explorer/syntax/(lexer.lpp|parser.ypp)$
  70. pass_filenames: false
  71. additional_dependencies: ['clang-format==13.0.1']
  72. # This may rename files, so it's deliberately between formatters and linters.
  73. - repo: local
  74. hooks:
  75. - id: check-sha-filenames
  76. name: Check fuzzer SHA filenames
  77. entry: scripts/check_sha_filenames.py
  78. language: python
  79. files: ^.*/fuzzer_corpus/.*$
  80. # Run linters last, as formatters and other checks may fix issues.
  81. - repo: local
  82. hooks:
  83. - id: forbid-llvm-googletest
  84. name: Checks for deps on LLVM's version of GoogleTest
  85. entry: scripts/forbid_llvm_googletest.py
  86. language: python
  87. files: ^.*/BUILD$
  88. pass_filenames: false
  89. - repo: https://github.com/PyCQA/flake8
  90. rev: cbeb4c9c4137cff1568659fcc48e8b85cddd0c8d # frozen: 4.0.1
  91. hooks:
  92. - id: flake8
  93. - repo: https://github.com/pre-commit/mirrors-mypy
  94. rev: 'a04404bdf52c2cbc9c5bd705454b89bd83b84383' # frozen: v0.950
  95. hooks:
  96. - id: mypy
  97. # Use setup.cfg to match the command line.
  98. args:
  99. - --config-file=setup.cfg
  100. # This should match the requirements added in the WORKSPACE pip_install.
  101. additional_dependencies:
  102. - gql >= 2.0.0, < 3.0.0
  103. - PyGitHub
  104. # Exclusions are:
  105. # - p#### scripts because they're not tested or maintained.
  106. # - lit.cfg.py because it has multiple copies, breaking mypy.
  107. # - Unit tests because they sometimes violate typing, such as by
  108. # assigning a mock to a function.
  109. exclude: |
  110. (?x)^(
  111. proposals/(?!scripts/).*|
  112. .*/lit\.cfg\.py|
  113. .*_test\.py
  114. )$
  115. - repo: https://github.com/codespell-project/codespell
  116. rev: 01da43d753cdff4ea7dff952b4f5317450af31e3 # frozen: v2.1.0
  117. hooks:
  118. - id: codespell
  119. args: ['-I', '.codespell_ignore', '--uri-ignore-words-list', '*']
  120. - repo: https://github.com/google/pre-commit-tool-hooks
  121. rev: cb78d9293306d9f737c64d9702bbaa88e157caaa # frozen: v1.2.2
  122. hooks:
  123. - id: check-copyright
  124. args:
  125. - --copyright
  126. - |+
  127. Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  128. Exceptions. See /LICENSE for license information.
  129. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  130. - --custom_format
  131. - '\.(carbon|proto|ypp)$'
  132. - ''
  133. - '// '
  134. - ''
  135. - --custom_format
  136. - '\.(l|lpp|y)$'
  137. - '/*'
  138. - ''
  139. - '*/'
  140. exclude: |
  141. (?x)^(
  142. .bazelversion|
  143. compile_flags.txt|
  144. third_party/.*|
  145. .*\.def|
  146. .*\.svg|
  147. .*/fuzzer_corpus/.*|
  148. .*/testdata/.*\.golden
  149. )$
  150. - id: check-links
  151. # Most third-party code is in submodules; local commits are excluded here.
  152. # We fully exclude fuzzer corpus directories as they are generated binary data.
  153. exclude: |
  154. (?x)^(
  155. third_party/examples/.*/carbon/.*|
  156. third_party/llvm-project/.*|
  157. )$