.pre-commit-config.yaml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. # Use setup.cfg to match the command line.
  88. args:
  89. - --config-file=setup.cfg
  90. # This should match the requirements added in the WORKSPACE pip_install.
  91. additional_dependencies:
  92. - gql >= 2.0.0, < 3.0.0
  93. - PyGitHub
  94. # Exclusions are:
  95. # - p#### scripts because they're not tested or maintained.
  96. # - lit.cfg.py because it has multiple copies, breaking mypy.
  97. # - Unit tests because they sometimes violate typing, such as by
  98. # assigning a mock to a function.
  99. exclude: |
  100. (?x)^(
  101. proposals/(?!scripts/).*|
  102. .*/lit\.cfg\.py|
  103. .*_test\.py
  104. )$
  105. - repo: https://github.com/codespell-project/codespell
  106. rev: 01da43d753cdff4ea7dff952b4f5317450af31e3 # frozen: v2.1.0
  107. hooks:
  108. - id: codespell
  109. args: ['-I', '.codespell_ignore', '--uri-ignore-words-list', '*']
  110. - repo: https://github.com/google/pre-commit-tool-hooks
  111. rev: cb78d9293306d9f737c64d9702bbaa88e157caaa # frozen: v1.2.2
  112. hooks:
  113. - id: check-copyright
  114. args:
  115. - --copyright
  116. - |+
  117. Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  118. Exceptions. See /LICENSE for license information.
  119. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  120. - --custom_format
  121. - '\.(carbon|proto|ypp)$'
  122. - ''
  123. - '// '
  124. - ''
  125. - --custom_format
  126. - '\.(l|lpp|y)$'
  127. - '/*'
  128. - ''
  129. - '*/'
  130. exclude: |
  131. (?x)^(
  132. .bazelversion|
  133. compile_flags.txt|
  134. third_party/.*|
  135. .*\.def|
  136. .*\.svg|
  137. .*/testdata/.*\.golden
  138. )$
  139. - id: check-links
  140. # Most third-party code is in submodules; local commits are excluded here.
  141. # We fully exclude fuzzer corpus directories as they are generated binary data.
  142. exclude: |
  143. (?x)^(
  144. third_party/examples/.*/carbon/.*|
  145. third_party/llvm-project/.*|
  146. .*/fuzzer_corpus/.*
  147. )$