sourcegraph/.pre-commit-config.yaml
Jean-Hadrien Chabran ded610d887
chore(local): add FORBIDCOMMIT pragma to prevent accidental commits (#63581)
@chrsmith suggested this idea, which I like very much as well. 

Pretty straightforward: 

- if you're adding something you really don't want to commit and suspect
your future self to forget about it, you can add `FORBIDCOMMIT` anywhere
in your changes, and precommit will prevent you from accidentally
committing it.
  - check is case insensitive.

I went for this instead of `NOCOMMIT` because it could be legitimately
be used for a var with the number of commits for example. And that's not
really something we want to add a pragma to disable the string itself
for either.


## Test plan

![CleanShot 2024-07-01 at 19 44
31@2x](https://github.com/sourcegraph/sourcegraph/assets/10151/3ff3420e-4012-4018-a1e3-42ae2fb53cb4)
2024-07-01 18:27:26 +00:00

50 lines
1.5 KiB
YAML

exclude: (^.*\.snap$)|(^internal/database/.*\.json)|(^internal/database/.*\.md)|(^migrations/[^/]+/squashed\.sql)
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
exclude: 'pnpm-lock.yaml'
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/keith/pre-commit-buildifier
rev: 5.0.1
hooks:
- id: buildifier
- id: buildifier-lint
- repo: local
hooks:
- id: check-tokens
name: check-tokens
description: 'Check for common tokens being committed'
entry: ./dev/check-tokens.sh
language: script
'types': [text]
args: []
require_serial: false
- id: shellcheck
name: shellcheck
description: 'Run shellcheck'
entry: ./dev/check/shellcheck.sh
language: script
# TODO: adapt shellcheck.sh to only operate on passed-in files,
# and fallback to git ls-files when empty
pass_filenames: false
files: '.*\.(sh|bash)'
stages: [pre-push]
- id: shfmt
name: shfmt
description: 'Run shfmt'
entry: ./dev/check/shfmt.sh
language: script
# TODO: adapt shfmt.sh to only operate on passed-in files,
# and fallback to git ls-files when empty
pass_filenames: false
files: '.*\.(sh|bash)'
stages: [pre-push]
- id: forbidcommit
name: forbidcommit
description: 'Prevent commits with a FORBIDCOMMIT string in the diff'
entry: ./dev/forbidcommit.sh
language: script