.pre-commit-config.yaml 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. # Javascript linting, formatting.
  101. # We're using the local node_modules to simplify things, otherwise would
  102. # need an easy way to keep versions in sync. Furthermore some repositories
  103. # are either not on pre-commit mirrors or are missing some tagged versions.
  104. # pre-commit-managed nodeenv environments also do not work out of the box because
  105. # additional_dependencies does not install a flattened dependency tree which is needed by,
  106. # for example, our eslint setup.
  107. - id: biome
  108. name: biome (javascript, typescript, json)
  109. language: system
  110. files: \.(jsx?|tsx?|css)$
  111. entry: ./node_modules/.bin/biome check --log-level=error --write --files-ignore-unknown=true --no-errors-on-unmatched
  112. - id: eslint
  113. name: eslint
  114. language: system
  115. files: \.[jt]sx?$
  116. entry: ./node_modules/.bin/eslint --quiet --fix
  117. - id: stylelint
  118. name: stylelint
  119. language: system
  120. files: \.[jt]sx?$
  121. entry: ./node_modules/.bin/stylelint --quiet
  122. - id: prettier
  123. name: prettier (yaml, markdown, ts, tsx, js, jsx, css)
  124. language: system
  125. # TODO: Remove tsx and jsx when Biome supports styled CSS formatting.
  126. types_or: [yaml, markdown, ts, tsx, javascript, jsx, css]
  127. entry: ./node_modules/.bin/prettier --log-level=error --write
  128. # https://pre-commit.com/#regular-expressions
  129. exclude: |
  130. (?x)^($^
  131. # prettier crashes on some of these, by intent:
  132. |fixtures/.*
  133. # these have enormous diffs when formatted:
  134. |api-docs/paths/events/issue-hashes\.json
  135. |api-docs/paths/events/latest-event\.json
  136. |api-docs/paths/events/oldest-event\.json
  137. |api-docs/paths/events/project-event-details\.json
  138. |src/sentry/issues/event\.schema\.json
  139. |static/app/data/world\.json
  140. |static/app/utils/profiling/profile/formats/android/trace\.json
  141. |static/app/utils/profiling/profile/formats/ios/trace\.json
  142. |static/app/utils/profiling/profile/formats/node/trace\.json
  143. |static/app/utils/profiling/profile/formats/typescript/trace\.json
  144. )$
  145. - repo: https://github.com/pre-commit/pygrep-hooks
  146. rev: v1.10.0
  147. hooks:
  148. - id: python-use-type-annotations
  149. - id: python-check-blanket-type-ignore
  150. - repo: https://github.com/python-jsonschema/check-jsonschema
  151. rev: 0.24.1
  152. hooks:
  153. - id: check-github-actions
  154. - id: check-github-workflows
  155. args: [--verbose]
  156. - repo: https://github.com/pre-commit/pre-commit-hooks
  157. rev: v4.3.0
  158. hooks:
  159. - id: check-case-conflict
  160. - id: check-executables-have-shebangs
  161. - id: check-merge-conflict
  162. - id: check-symlinks
  163. - id: check-yaml
  164. - id: end-of-file-fixer
  165. exclude_types: [svg]
  166. exclude: ^fixtures/
  167. - id: trailing-whitespace
  168. exclude_types: [svg]
  169. exclude: ^(fixtures/|scripts/patches/)
  170. - id: debug-statements
  171. - id: name-tests-test
  172. args: [--pytest-test-first]
  173. - repo: https://github.com/shellcheck-py/shellcheck-py
  174. rev: v0.9.0.6
  175. hooks:
  176. - id: shellcheck
  177. types: [file]
  178. files: ^\.envrc$
  179. args: [--external-sources]