.pre-commit-config.yaml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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/mattlqx/pre-commit-search-and-replace
  28. rev: 417c99dafb534d7517d9abc17f0293de3c915a72 # frozen: v1.0.5
  29. hooks:
  30. - id: search-and-replace
  31. files: '\.md$'
  32. - repo: https://github.com/google/pre-commit-tool-hooks
  33. rev: cb78d9293306d9f737c64d9702bbaa88e157caaa # frozen: v1.2.2
  34. hooks:
  35. - id: check-google-doc-style
  36. - id: markdown-toc
  37. - repo: local
  38. hooks:
  39. - id: executable-semantics-format-grammar
  40. name: Format the executable_semantics grammar file
  41. entry: executable_semantics/syntax/format_grammar.py
  42. language: python
  43. files: ^executable_semantics/syntax/(lexer.lpp|parser.ypp)$
  44. pass_filenames: false
  45. - id: fix-cc-deps
  46. name: Fix missing C++ deps
  47. entry: scripts/fix_cc_deps.py
  48. language: python
  49. files: ^.*/(BUILD|[^/]+\.(h|cpp))$
  50. pass_filenames: false
  51. # Formatters should be run late so that they can re-format any prior changes.
  52. - repo: https://github.com/psf/black
  53. rev: f1d4e742c91dd5179d742b0db9293c4472b765f8 # frozen: 21.12b0
  54. hooks:
  55. - id: black
  56. - repo: https://github.com/jlebar/pre-commit-hooks.git
  57. rev: fb5e481f35f5a9b32a06ccfc28b8d6dda4525f75
  58. hooks:
  59. - id: bazel-buildifier
  60. - id: clang-format-whole-file
  61. types: [c++]
  62. - repo: https://github.com/pre-commit/mirrors-prettier
  63. rev: ea782651a7e32f40a3d13b76c79d5a2474ee8723 # frozen: v2.5.1
  64. hooks:
  65. - id: prettier
  66. # Run linters last, as formatters and other checks may fix issues.
  67. - repo: local
  68. hooks:
  69. - id: forbid-llvm-googletest
  70. name: Checks for deps on LLVM's version of GoogleTest
  71. entry: scripts/forbid_llvm_googletest.py
  72. language: python
  73. files: ^.*/BUILD$
  74. pass_filenames: false
  75. - repo: https://github.com/PyCQA/flake8
  76. rev: cbeb4c9c4137cff1568659fcc48e8b85cddd0c8d # frozen: 4.0.1
  77. hooks:
  78. - id: flake8
  79. - repo: https://github.com/codespell-project/codespell
  80. rev: 01da43d753cdff4ea7dff952b4f5317450af31e3 # frozen: v2.1.0
  81. hooks:
  82. - id: codespell
  83. args: ['-I', '.codespell_ignore', '--uri-ignore-words-list', '*']
  84. - repo: https://github.com/google/pre-commit-tool-hooks
  85. rev: cb78d9293306d9f737c64d9702bbaa88e157caaa # frozen: v1.2.2
  86. hooks:
  87. - id: check-copyright
  88. args:
  89. - --copyright
  90. - |+
  91. Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  92. Exceptions. See /LICENSE for license information.
  93. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  94. - --custom_format
  95. - '\.carbon$'
  96. - ''
  97. - '// '
  98. - ''
  99. - --custom_format
  100. - '\.lpp$'
  101. - '/*'
  102. - ''
  103. - '*/'
  104. - --custom_format
  105. - '\.ypp$'
  106. - ''
  107. - '// '
  108. - ''
  109. - --custom_format
  110. - '\.l$'
  111. - '/*'
  112. - ''
  113. - '*/'
  114. - --custom_format
  115. - '\.y$'
  116. - '/*'
  117. - ''
  118. - '*/'
  119. exclude: |
  120. (?x)^(
  121. .bazelversion|
  122. compile_flags.txt|
  123. third_party/examples/.*/compile_flags.carbon.txt|
  124. .*\.def|
  125. .*\.svg|
  126. .*/testdata/.*\.golden
  127. )$
  128. - id: check-links
  129. name: Check links in non-proposal files
  130. exclude: ^proposals/.*$
  131. - id: check-links
  132. name: Check links in proposal files
  133. args: ['--anchors-only']
  134. files: ^proposals/.*$
  135. # Most third-party code is in submodules; local commits are excluded here.
  136. # We fully exclude fuzzer corpus directories as they are generated binary data.
  137. exclude: |
  138. (?x)^(
  139. third_party/examples/.*/carbon/.*|
  140. .*/fuzzer_corpus/.*
  141. )$