diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index 44a8648d..860c8a66 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -124,6 +124,12 @@ entry: detect-private-key language: python types: [text] +- id: detect-do-not-commit + name: Detect do-not-commit + description: Detects the presence of do-not-commit + entry: detect-do-not-commit + language: python + types: [file] - id: double-quote-string-fixer name: fix double quoted strings description: replaces double quoted strings with single quoted strings. diff --git a/pre_commit_hooks/detect_do_not_commit.py b/pre_commit_hooks/detect_do_not_commit.py new file mode 100644 index 00000000..1d7d6a60 --- /dev/null +++ b/pre_commit_hooks/detect_do_not_commit.py @@ -0,0 +1,32 @@ +import argparse +from typing import Optional +from typing import Sequence + +BLACKLIST = [ + b'\x64\x6e\x63', #dnc +] + + +def main(argv: Optional[Sequence[str]] = None) -> int: + parser = argparse.ArgumentParser() + parser.add_argument('filenames', nargs='*', help='Filenames to check') + args = parser.parse_args(argv) + + bad_files = [] + + for filename in args.filenames: + with open(filename, 'rb') as f: + content = f.read() + if any(line in content for line in BLACKLIST): + bad_files.append(filename) + + if bad_files: + for bad_file in bad_files: + print(f'do not commit tag found: {bad_file}') + return 1 + else: + return 0 + + +if __name__ == '__main__': + exit(main()) diff --git a/setup.cfg b/setup.cfg index 82a5457c..fa292484 100644 --- a/setup.cfg +++ b/setup.cfg @@ -49,6 +49,7 @@ console_scripts = destroyed-symlinks = pre_commit_hooks.destroyed_symlinks:main detect-aws-credentials = pre_commit_hooks.detect_aws_credentials:main detect-private-key = pre_commit_hooks.detect_private_key:main + detect-do-not-commit = pre_commit_hooks.detect_do_not_commit:main double-quote-string-fixer = pre_commit_hooks.string_fixer:main end-of-file-fixer = pre_commit_hooks.end_of_file_fixer:main file-contents-sorter = pre_commit_hooks.file_contents_sorter:main