.pre-commit-config.yaml 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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: 8fe62d14e0b4d7d845a7022c5c2c3ae41bdd3f26 # frozen: v4.1.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. - id: mixed-line-ending
  24. args: ['--fix=lf']
  25. - id: trailing-whitespace
  26. exclude: '^(.*/testdata/.*\.golden)$'
  27. - repo: https://github.com/google/pre-commit-tool-hooks
  28. rev: cb78d9293306d9f737c64d9702bbaa88e157caaa # frozen: v1.2.2
  29. hooks:
  30. - id: check-google-doc-style
  31. - id: markdown-toc
  32. - repo: local
  33. hooks:
  34. - id: fix-cc-deps
  35. name: Fix missing C++ deps
  36. entry: scripts/fix_cc_deps.py
  37. language: python
  38. files: ^.*/(BUILD|[^/]+\.(h|cpp))$
  39. pass_filenames: false
  40. # Formatters should be run late so that they can re-format any prior changes.
  41. - repo: https://github.com/psf/black
  42. rev: ae2c0758c9e61a385df9700dc9c231bf54887041 # frozen: 22.3.0
  43. hooks:
  44. - id: black
  45. - repo: https://github.com/pre-commit/mirrors-prettier
  46. rev: 5e374fda194d7f7ce9eebbd582b2a5594838c85b # frozen: v2.6.2
  47. hooks:
  48. - id: prettier
  49. - repo: local
  50. hooks:
  51. - id: buildifier
  52. name: Bazel buildifier
  53. entry: scripts/run_buildifier.py
  54. language: python
  55. files: '^(.*/)?(BUILD\.bazel|BUILD|WORKSPACE)$|\.BUILD$|\.bzl$'
  56. - id: explorer-format-grammar
  57. name: Format the explorer grammar file
  58. entry: explorer/syntax/format_grammar.py
  59. language: python
  60. files: ^explorer/syntax/(lexer.lpp|parser.ypp)$
  61. pass_filenames: false
  62. additional_dependencies: ['clang-format==13.0.1']
  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. # Run linters last, as formatters and other checks may fix issues.
  71. - repo: local
  72. hooks:
  73. - id: forbid-llvm-googletest
  74. name: Checks for deps on LLVM's version of GoogleTest
  75. entry: scripts/forbid_llvm_googletest.py
  76. language: python
  77. files: ^.*/BUILD$
  78. pass_filenames: false
  79. - repo: https://github.com/PyCQA/flake8
  80. rev: cbeb4c9c4137cff1568659fcc48e8b85cddd0c8d # frozen: 4.0.1
  81. hooks:
  82. - id: flake8
  83. - repo: https://github.com/pre-commit/mirrors-mypy
  84. rev: 'v0.950'
  85. hooks:
  86. - id: mypy
  87. args:
  88. - --disallow-untyped-decorators
  89. - --warn-unused-configs
  90. - --disallow-subclassing-any
  91. - --disallow-untyped-calls
  92. - --disallow-untyped-defs
  93. - --disallow-incomplete-defs
  94. - --check-untyped-defs
  95. - --no-implicit-optional
  96. - --warn-redundant-casts
  97. - --warn-unused-ignores
  98. - --warn-return-any
  99. - --pretty
  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. # TODO: should probably fix gen_rtti.
  105. exclude: |
  106. (?x)^(
  107. explorer/gen_rtti\.py|
  108. proposals/.*|
  109. .*/lit\.cfg\.py|
  110. .*_test\.py
  111. )$
  112. - repo: https://github.com/codespell-project/codespell
  113. rev: 01da43d753cdff4ea7dff952b4f5317450af31e3 # frozen: v2.1.0
  114. hooks:
  115. - id: codespell
  116. args: ['-I', '.codespell_ignore', '--uri-ignore-words-list', '*']
  117. - repo: https://github.com/google/pre-commit-tool-hooks
  118. rev: cb78d9293306d9f737c64d9702bbaa88e157caaa # frozen: v1.2.2
  119. hooks:
  120. - id: check-copyright
  121. args:
  122. - --copyright
  123. - |+
  124. Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  125. Exceptions. See /LICENSE for license information.
  126. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  127. - --custom_format
  128. - '\.(carbon|proto|ypp)$'
  129. - ''
  130. - '// '
  131. - ''
  132. - --custom_format
  133. - '\.(l|lpp|y)$'
  134. - '/*'
  135. - ''
  136. - '*/'
  137. exclude: |
  138. (?x)^(
  139. .bazelversion|
  140. compile_flags.txt|
  141. third_party/.*|
  142. .*\.def|
  143. .*\.svg|
  144. .*/testdata/.*\.golden
  145. )$
  146. - id: check-links
  147. # Most third-party code is in submodules; local commits are excluded here.
  148. # We fully exclude fuzzer corpus directories as they are generated binary data.
  149. exclude: |
  150. (?x)^(
  151. third_party/examples/.*/carbon/.*|
  152. third_party/llvm-project/.*|
  153. .*/fuzzer_corpus/.*
  154. )$