mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-06 03:56:54 +00:00
Add new hook
This commit is contained in:
parent
b1a8062750
commit
7e1df7a0cb
2 changed files with 41 additions and 0 deletions
24
pre_commit_hooks/detect_datetime_now.py
Normal file
24
pre_commit_hooks/detect_datetime_now.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import argparse
|
||||
import os
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
parser = argparse.ArgumentParser(description='Check if datetime.now is being used.')
|
||||
parser.add_argument('filenames', nargs='*', help='Filenames to check')
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
for filename in args.filenames:
|
||||
if os.path.isfile(filename):
|
||||
with open(filename, 'rb') as f:
|
||||
if b'datetime.now()' in f.read():
|
||||
return 1
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
exit(main())
|
||||
Loading…
Add table
Add a link
Reference in a new issue