.pre-commit-config.yaml 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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: executable-semantics-format-grammar
  35. name: Format the executable_semantics grammar file
  36. entry: executable_semantics/syntax/format_grammar.py
  37. language: python
  38. files: ^executable_semantics/syntax/(lexer.lpp|parser.ypp)$
  39. pass_filenames: false
  40. - id: fix-cc-deps
  41. name: Fix missing C++ deps
  42. entry: scripts/fix_cc_deps.py
  43. language: python
  44. files: ^.*/(BUILD|[^/]+\.(h|cpp))$
  45. pass_filenames: false
  46. # Formatters should be run late so that they can re-format any prior changes.
  47. - repo: https://github.com/psf/black
  48. rev: fc0be6eb1e2a96091e6f64009ee5e9081bf8b6c6 # frozen: 22.1.0
  49. hooks:
  50. - id: black
  51. - repo: https://github.com/pre-commit/mirrors-clang-format
  52. rev: 1fc50313b6e8c2580c4736af57575e0b7de1501c # frozen: v13.0.0
  53. hooks:
  54. - id: clang-format
  55. - repo: https://github.com/pre-commit/mirrors-prettier
  56. rev: ea782651a7e32f40a3d13b76c79d5a2474ee8723 # frozen: v2.5.1
  57. hooks:
  58. - id: prettier
  59. - repo: local
  60. hooks:
  61. - id: buildifier
  62. name: Bazel buildifier
  63. entry: scripts/run_buildifier.py
  64. language: python
  65. files: '^(.*/)?(BUILD\.bazel|BUILD|WORKSPACE)$|\.BUILD$|\.bzl$'
  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|ypp)$'
  96. - ''
  97. - '// '
  98. - ''
  99. - --custom_format
  100. - '\.(l|lpp|y)$'
  101. - '/*'
  102. - ''
  103. - '*/'
  104. exclude: |
  105. (?x)^(
  106. .bazelversion|
  107. compile_flags.txt|
  108. third_party/examples/.*/compile_flags.carbon.txt|
  109. .*\.def|
  110. .*\.svg|
  111. .*/testdata/.*\.golden
  112. )$
  113. - id: check-links
  114. name: Check links in non-proposal files
  115. exclude: ^proposals/.*$
  116. - id: check-links
  117. name: Check links in proposal files
  118. args: ['--anchors-only']
  119. files: ^proposals/.*$
  120. # Most third-party code is in submodules; local commits are excluded here.
  121. # We fully exclude fuzzer corpus directories as they are generated binary data.
  122. exclude: |
  123. (?x)^(
  124. third_party/examples/.*/carbon/.*|
  125. third_party/llvm-project/.*|
  126. .*/fuzzer_corpus/.*
  127. )$