.pre-commit-config.yaml 4.3 KB

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