.pre-commit-config.yaml 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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: https://github.com/PyCQA/flake8
  68. rev: cbeb4c9c4137cff1568659fcc48e8b85cddd0c8d # frozen: 4.0.1
  69. hooks:
  70. - id: flake8
  71. - repo: https://github.com/codespell-project/codespell
  72. rev: 01da43d753cdff4ea7dff952b4f5317450af31e3 # frozen: v2.1.0
  73. hooks:
  74. - id: codespell
  75. args: ['-I', '.codespell_ignore', '--uri-ignore-words-list', '*']
  76. - repo: https://github.com/google/pre-commit-tool-hooks
  77. rev: cb78d9293306d9f737c64d9702bbaa88e157caaa # frozen: v1.2.2
  78. hooks:
  79. - id: check-copyright
  80. args:
  81. - --copyright
  82. - |+
  83. Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  84. Exceptions. See /LICENSE for license information.
  85. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  86. - --custom_format
  87. - '\.carbon$'
  88. - ''
  89. - '// '
  90. - ''
  91. - --custom_format
  92. - '\.lpp$'
  93. - '/*'
  94. - ''
  95. - '*/'
  96. - --custom_format
  97. - '\.ypp$'
  98. - ''
  99. - '// '
  100. - ''
  101. - --custom_format
  102. - '\.l$'
  103. - '/*'
  104. - ''
  105. - '*/'
  106. - --custom_format
  107. - '\.y$'
  108. - '/*'
  109. - ''
  110. - '*/'
  111. exclude: |
  112. (?x)^(
  113. .bazelversion|
  114. compile_flags.txt|
  115. third_party/examples/.*/compile_flags.carbon.txt|
  116. .*\.def|
  117. .*\.svg|
  118. .*/testdata/.*\.golden
  119. )$
  120. - id: check-links
  121. name: Check links in non-proposal files
  122. exclude: ^proposals/.*$
  123. - id: check-links
  124. name: Check links in proposal files
  125. args: ['--anchors-only']
  126. files: ^proposals/.*$
  127. # Most third-party code is in submodules; local commits are excluded here.
  128. # We fully exclude fuzzer corpus directories as they are generated binary data.
  129. exclude: |
  130. (?x)^(
  131. third_party/examples/.*/carbon/.*|
  132. .*/fuzzer_corpus/.*
  133. )$