Dry run now works.

This commit is contained in:
Elf M. Sternberg 2016-09-26 15:51:31 -07:00
parent bacbdd7179
commit ac7df1d17b
1 changed files with 45 additions and 5 deletions

View File

@ -16,6 +16,10 @@ except ImportError as e:
_ = gettext.gettext _ = gettext.gettext
def tap(a):
print("TAP:", a)
return a
VERSION = '0.0.4' VERSION = '0.0.4'
NAME = 'git-lint' NAME = 'git-lint'
OPTIONS_LIST = [ OPTIONS_LIST = [
@ -537,6 +541,21 @@ def build_lint_runner(linters, filenames):
[run_one_linter(linter, filenames) for linter in linters], []) [run_one_linter(linter, filenames) for linter in linters], [])
return lint_runner return lint_runner
def dryrun(linters, filenames):
def dryrunonefile(filename, linter):
trimmed_filename = filename.replace(git_base + '/', '', 1)
return (trimmed_filename, linter.name, 0, [' {}'.format(trimmed_filename)])
def dryrunonce(linter, filenames):
match_filter = make_match_filter([linter])
files_to_check = [filename for filename in filenames if match_filter(filename)]
return [dryrunonefile(filename, linter) for filename in files_to_check]
return reduce(operator.add, [dryrunonce(linter, filenames) for linter in linters], [])
# __ __ _ # __ __ _
# | \/ |__ _(_)_ _ # | \/ |__ _(_)_ _
@ -544,10 +563,11 @@ def build_lint_runner(linters, filenames):
# |_| |_\__,_|_|_||_| # |_| |_\__,_|_|_||_|
# #
def print_report(results, config): def print_report(results, cmdline, unlintable_filenames, cant_lint_filenames,
broken_linter_names, unfindable_filenames):
sort_position = 1 sort_position = 1
grouping = 'Linter: {}' grouping = 'Linter: {}'
if 'byfile' in config: if 'byfile' in cmdline:
sort_position = 0 sort_position = 0
grouping = 'Filename: {}' grouping = 'Filename: {}'
grouped_results = group_by(results, sort_position) grouped_results = group_by(results, sort_position)
@ -556,6 +576,17 @@ def print_report(results, config):
for (filename, lintername, returncode, text) in group[1]: for (filename, lintername, returncode, text) in group[1]:
print("\n".join(text)) print("\n".join(text))
print("") print("")
if len(broken_linter_names):
print("These linters could not be run:", ",".join(broken_linter_names))
if len(cant_lint_filenames):
print("As a result, these files were not linted:")
print("\n".join([" {}".format(f) for f in cant_lint_filenames]))
if len(unlintable_filenames):
print("The following files had no recognizeable linters:")
print("\n".join([" {}".format(f) for f in unlintable_filenames]))
if len(unfindable_filenames):
print("The following files could not be found:")
print("\n".join([" {}".format(f) for f in unfindable_filenames]))
def run_gitlint(cmdline, config, extras): def run_gitlint(cmdline, config, extras):
@ -566,29 +597,38 @@ def run_gitlint(cmdline, config, extras):
""" Runs the requested linters """ """ Runs the requested linters """
all_filenames, unfindable_filenames = get_filelist(cmdline, extras) all_filenames, unfindable_filenames = get_filelist(cmdline, extras)
stash_runner = pick_stash_runner(cmdline) stash_runner = pick_stash_runner(cmdline)
is_lintable = make_match_filter(config) is_lintable = make_match_filter(config)
lintable_filenames = set([filename for filename in all_filenames lintable_filenames = set([filename for filename in all_filenames
if is_lintable(filename)]) if is_lintable(filename)])
unlintable_filenames = set(all_filenames) - lintable_filenames unlintable_filenames = set(all_filenames) - lintable_filenames
working_linter_names, broken_linter_names = get_linter_status(config) working_linter_names, broken_linter_names = get_linter_status(config)
cant_lint_filter = make_match_filter(build_config_subset( cant_lint_filter = make_match_filter(build_config_subset(
broken_linter_names)) broken_linter_names))
cant_lint_filenames = [filename for filename in lintable_filenames cant_lint_filenames = [filename for filename in lintable_filenames
if cant_lint_filter(filename)] if cant_lint_filter(filename)]
if 'dryrun' in cmdline: if 'dryrun' in cmdline:
return dryrun( return print_report(
build_config_subset(working_linter_names), sorted(lintable_filenames)) dryrun(
build_config_subset(working_linter_names), sorted(lintable_filenames)),
cmdline, unlintable_filenames, cant_lint_filenames,
broken_linter_names, unfindable_filenames)
lint_runner = build_lint_runner( lint_runner = build_lint_runner(
build_config_subset(working_linter_names), sorted(lintable_filenames)) build_config_subset(working_linter_names), sorted(lintable_filenames))
results = stash_runner(lint_runner, lintable_filenames) results = stash_runner(lint_runner, lintable_filenames)
print_report(results, cmdline) print_report(results, cmdline, unlintable_filenames, cant_lint_filenames,
broken_linter_names, unfindable_filenames)
if not len(results): if not len(results):
return 0 return 0
return max([i[2] for i in results if len(i)]) return max([i[2] for i in results if len(i)])