Add script for checking git commit is safe

This commit is contained in:
Robert Raposa
2016-04-25 14:15:23 -04:00
committed by Clinton Blackburn
parent 8d2357b0b3
commit ed8cf696f9
4 changed files with 95 additions and 26 deletions

View File

@@ -613,7 +613,7 @@ class FileResults(object):
Arguments:
options: A list of the following options:
is_quiet: True to print only file names, and False to print
list_files: True to print only file names, and False to print
all violations.
out: output file
@@ -623,7 +623,7 @@ class FileResults(object):
"""
num_violations = 0
if options['is_quiet']:
if options['list_files']:
if self.violations is not None and 0 < len(self.violations):
num_violations += 1
print(self.full_path, file=out)
@@ -2326,33 +2326,33 @@ def main():
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description='Checks that templates are safe.',
epilog=epilog
epilog=epilog,
)
parser.add_argument(
'--quiet', dest='quiet', action='store_true', help='only display the filenames that contain violations'
)
parser.add_argument('--file', dest='file', nargs=1, default=None, help='a single file to lint')
parser.add_argument(
'--dir', dest='directory', nargs=1, default=['.'], help='the directory to lint (including sub-directories)'
'--list-files', dest='list_files', action='store_true',
help='Only display the filenames that contain violations.'
)
parser.add_argument('path', nargs="?", default=None, help='A file to lint or directory to recursively lint.')
args = parser.parse_args()
options = {
'is_quiet': args.quiet,
'list_files': args.list_files,
}
template_linters = [MakoTemplateLinter(), UnderscoreTemplateLinter(), JavaScriptLinter(), PythonLinter()]
if args.file is not None:
if os.path.isfile(args.file[0]) is False:
raise ValueError("File [{}] is not a valid file.".format(args.file[0]))
num_violations = _process_file(args.file[0], template_linters, options, out=sys.stdout)
else:
if os.path.exists(args.directory[0]) is False or os.path.isfile(args.directory[0]) is True:
raise ValueError("Directory [{}] is not a valid directory.".format(args.directory[0]))
num_violations = _process_os_walk(args.directory[0], template_linters, options, out=sys.stdout)
if options['is_quiet'] is False:
if args.path is not None and os.path.isfile(args.path):
num_violations = _process_file(args.path, template_linters, options, out=sys.stdout)
else:
directory = "."
if args.path is not None:
if os.path.exists(args.path):
directory = args.path
else:
raise ValueError("Path [{}] is not a valid file or directory.".format(args.path))
num_violations = _process_os_walk(directory, template_linters, options, out=sys.stdout)
if options['list_files'] is False:
# matches output of jshint for simplicity
print("")
print("{} violations found".format(num_violations))