.pre-commit-config.yaml 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. default_install_hook_types: ['pre-commit', 'pre-push']
  2. default_stages: [pre-commit]
  3. exclude: >
  4. (?x)(
  5. LICENSE.md$|
  6. \.snap$|
  7. \.map$|
  8. \.map\.js$|
  9. ^src/sentry/static/sentry/vendor/|
  10. ^src/.*/locale/|
  11. ^src/sentry/data/
  12. )
  13. repos:
  14. # Many of these hooks are local because people use a variety of IDEs
  15. # with autoformatters that need to call out to things like `black` directly.
  16. # pre-commit run is not the same, and something like pre-commit exec does
  17. # not exist yet.
  18. - repo: local
  19. hooks:
  20. - id: pyupgrade
  21. name: pyupgrade
  22. entry: pyupgrade
  23. args: ['--py311-plus']
  24. language: system
  25. types: [python]
  26. # Configuration for black exists in pyproject.toml,
  27. # but we let pre-commit take care of the file filtering.
  28. - id: black
  29. name: black
  30. entry: black
  31. language: system
  32. types_or: [python, pyi]
  33. require_serial: true
  34. # Configuration for isort exists in pyproject.toml,
  35. # but we let pre-commit take care of the file filtering.
  36. - id: isort
  37. name: isort
  38. entry: isort
  39. language: system
  40. types: [python]
  41. # Configuration for flake8 exists in setup.cfg,
  42. # but we let pre-commit take care of the file filtering.
  43. - id: flake8
  44. name: flake8
  45. entry: flake8
  46. language: system
  47. types: [python]
  48. log_file: '.artifacts/flake8.pycodestyle.log'
  49. - id: mypy
  50. name: mypy
  51. entry: bash -c 'if [ -n "${SENTRY_MYPY_PRE_PUSH:-}" ]; then exec mypy "$@"; fi' --
  52. language: system
  53. stages: [pre-push]
  54. types: [python]
  55. require_serial: true
  56. - id: lint-requirements
  57. name: lint-requirements
  58. entry: python -m tools.lint_requirements
  59. language: python
  60. files: requirements-.*\.txt$
  61. # exclude the overrides file from this linter -- it doesn't apply at all
  62. exclude: ^requirements-getsentry-overrides\.txt$
  63. additional_dependencies: [packaging==21.3]
  64. - id: requirements-overrides
  65. name: use pinned archives (see comment in file)
  66. stages: [commit]
  67. language: pygrep
  68. entry: |
  69. (?x)
  70. ^
  71. # it's a comment line
  72. (?!\#.*$)
  73. # it's a blank line
  74. (?!$)
  75. # it's a pinned archive
  76. (?![a-z-]+[ ]@[ ]https://github\.com/getsentry/[^/]+/archive/[a-f0-9]{40}\.zip$)
  77. files: ^requirements-getsentry-overrides\.txt$
  78. - id: check-mypy-bypass
  79. name: do not bypass the type checker
  80. entry: '(^# *mypy: *ignore-errors|^# *type: *ignore|\bno_type_check\b)'
  81. language: pygrep
  82. types: [python]
  83. - id: sort-stronger-mypy-list
  84. name: sort stronger mypy list
  85. entry: python3 -m tools.mypy_helpers.sort_stronger_modules
  86. files: ^pyproject\.toml$
  87. language: python
  88. - id: check-mypy-stronglist
  89. name: check mypy stronglist
  90. entry: python3 -m tools.mypy_helpers.check_stronglist
  91. files: ^pyproject\.toml$
  92. language: python
  93. - id: prevent-push
  94. name: prevent pushing master
  95. stages: [pre-push]
  96. entry: bash -c 'test "$PRE_COMMIT_REMOTE_BRANCH" != "refs/heads/master"'
  97. always_run: true
  98. pass_filenames: false
  99. language: system
  100. - repo: https://github.com/pre-commit/pygrep-hooks
  101. rev: v1.10.0
  102. hooks:
  103. - id: python-use-type-annotations
  104. - id: python-check-blanket-type-ignore
  105. - repo: https://github.com/python-jsonschema/check-jsonschema
  106. rev: 0.24.1
  107. hooks:
  108. - id: check-github-actions
  109. - id: check-github-workflows
  110. args: [--verbose]
  111. - repo: https://github.com/pre-commit/pre-commit-hooks
  112. rev: v4.3.0
  113. hooks:
  114. - id: check-case-conflict
  115. - id: check-executables-have-shebangs
  116. - id: check-merge-conflict
  117. - id: check-symlinks
  118. - id: check-yaml
  119. - id: end-of-file-fixer
  120. exclude_types: [svg]
  121. exclude: ^fixtures/
  122. - id: trailing-whitespace
  123. exclude_types: [svg]
  124. exclude: ^(fixtures/|scripts/patches/)
  125. - id: debug-statements
  126. - id: name-tests-test
  127. args: [--pytest-test-first]
  128. - repo: https://github.com/biomejs/pre-commit
  129. rev: v0.2.0
  130. hooks:
  131. - id: biome-check
  132. name: biome (javascript, typescript, json)
  133. additional_dependencies: ['@biomejs/biome@1.8.3']
  134. - repo: https://github.com/pre-commit/mirrors-prettier
  135. rev: 'v3.1.0' # Use the sha or tag you want to point at
  136. hooks:
  137. - id: prettier
  138. name: prettier (yaml, markdown, ts, tsx, js, jsx, css)
  139. # TODO: Remove tsx and jsx when Biome supports styled CSS formatting.
  140. types_or: [yaml, markdown, ts, tsx, javascript, jsx, css]
  141. # Override the default version of prettier since there isn't a tag with 3.2.5
  142. additional_dependencies: ['prettier@3.3.2']
  143. # https://pre-commit.com/#regular-expressions
  144. exclude: |
  145. (?x)^($^
  146. # prettier crashes on some of these, by intent:
  147. |fixtures/.*
  148. # these have enormous diffs when formatted:
  149. |api-docs/paths/events/issue-hashes\.json
  150. |api-docs/paths/events/latest-event\.json
  151. |api-docs/paths/events/oldest-event\.json
  152. |api-docs/paths/events/project-event-details\.json
  153. |src/sentry/issues/event\.schema\.json
  154. |static/app/data/world\.json
  155. |static/app/utils/profiling/profile/formats/android/trace\.json
  156. |static/app/utils/profiling/profile/formats/ios/trace\.json
  157. |static/app/utils/profiling/profile/formats/node/trace\.json
  158. |static/app/utils/profiling/profile/formats/typescript/trace\.json
  159. )$
  160. - repo: https://github.com/shellcheck-py/shellcheck-py
  161. rev: v0.9.0.6
  162. hooks:
  163. - id: shellcheck
  164. types: [file]
  165. files: ^\.envrc$
  166. args: [--external-sources]