mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-18 11:31:46 +04:00
Added config parameter hide_skipped
This commit is contained in:
parent
b3582dfd31
commit
7c883d038d
7 changed files with 130 additions and 8 deletions
|
|
@ -262,6 +262,7 @@ CONFIG_SCHEMA = cfgv.Map(
|
|||
),
|
||||
cfgv.Optional('exclude', cfgv.check_regex, '^$'),
|
||||
cfgv.Optional('fail_fast', cfgv.check_bool, False),
|
||||
cfgv.Optional('hide_skipped', cfgv.check_bool, False),
|
||||
cfgv.Optional(
|
||||
'minimum_pre_commit_version',
|
||||
cfgv.check_and(cfgv.check_string, check_min_version),
|
||||
|
|
@ -274,6 +275,7 @@ CONFIG_SCHEMA = cfgv.Map(
|
|||
'default_stages',
|
||||
'exclude',
|
||||
'fail_fast',
|
||||
'hide_skipped',
|
||||
'minimum_pre_commit_version',
|
||||
),
|
||||
warn_unknown_keys_root,
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ from pre_commit.staged_files_only import staged_files_only
|
|||
from pre_commit.util import cmd_output_b
|
||||
from pre_commit.util import noop_context
|
||||
|
||||
|
||||
logger = logging.getLogger('pre_commit')
|
||||
|
||||
|
||||
|
|
@ -70,10 +69,16 @@ def _hook_msg_start(hook, verbose):
|
|||
|
||||
|
||||
SKIPPED = 'Skipped'
|
||||
FAILED = 'Failed'
|
||||
PASSED = 'Passed'
|
||||
NO_FILES = '(no files to check)'
|
||||
|
||||
|
||||
def _run_single_hook(classifier, hook, args, skips, cols, use_color):
|
||||
def _run_single_hook(
|
||||
classifier, hook, args, skips, cols,
|
||||
use_color,
|
||||
hide_skipped,
|
||||
):
|
||||
filenames = classifier.filenames_for_hook(hook)
|
||||
|
||||
if hook.language == 'pcre':
|
||||
|
|
@ -93,6 +98,7 @@ def _run_single_hook(classifier, hook, args, skips, cols, use_color):
|
|||
use_color=args.color,
|
||||
cols=cols,
|
||||
),
|
||||
cond=not hide_skipped,
|
||||
)
|
||||
return 0
|
||||
elif not filenames and not hook.always_run:
|
||||
|
|
@ -105,6 +111,7 @@ def _run_single_hook(classifier, hook, args, skips, cols, use_color):
|
|||
use_color=args.color,
|
||||
cols=cols,
|
||||
),
|
||||
cond=not hide_skipped,
|
||||
)
|
||||
return 0
|
||||
|
||||
|
|
@ -131,11 +138,11 @@ def _run_single_hook(classifier, hook, args, skips, cols, use_color):
|
|||
if retcode:
|
||||
retcode = 1
|
||||
print_color = color.RED
|
||||
pass_fail = 'Failed'
|
||||
pass_fail = FAILED
|
||||
else:
|
||||
retcode = 0
|
||||
print_color = color.GREEN
|
||||
pass_fail = 'Passed'
|
||||
pass_fail = PASSED
|
||||
|
||||
output.write_line(color.format_color(pass_fail, print_color, args.color))
|
||||
|
||||
|
|
@ -202,10 +209,12 @@ def _run_hooks(config, hooks, args, environ):
|
|||
filenames = _all_filenames(args)
|
||||
filenames = filter_by_include_exclude(filenames, '', config['exclude'])
|
||||
classifier = Classifier(filenames)
|
||||
hide_skipped = False if args.verbose else config['hide_skipped']
|
||||
retval = 0
|
||||
for hook in hooks:
|
||||
retval |= _run_single_hook(
|
||||
classifier, hook, args, skips, cols, args.color,
|
||||
hide_skipped,
|
||||
)
|
||||
if retval and config['fail_fast']:
|
||||
break
|
||||
|
|
@ -219,6 +228,7 @@ def _run_hooks(config, hooks, args, environ):
|
|||
'`pre-commit install`.',
|
||||
)
|
||||
output.write_line('All changes made by hooks:')
|
||||
|
||||
# args.color is a boolean.
|
||||
# See user_color function in color.py
|
||||
subprocess.call((
|
||||
|
|
|
|||
|
|
@ -67,12 +67,21 @@ def get_hook_message(
|
|||
stdout_byte_stream = getattr(sys.stdout, 'buffer', sys.stdout)
|
||||
|
||||
|
||||
def write(s, stream=stdout_byte_stream):
|
||||
def write(s, stream=stdout_byte_stream, cond=True):
|
||||
if not cond:
|
||||
return
|
||||
stream.write(five.to_bytes(s))
|
||||
stream.flush()
|
||||
|
||||
|
||||
def write_line(s=None, stream=stdout_byte_stream, logfile_name=None):
|
||||
def write_line(
|
||||
s=None,
|
||||
stream=stdout_byte_stream,
|
||||
logfile_name=None,
|
||||
cond=True,
|
||||
):
|
||||
if not cond:
|
||||
return
|
||||
output_streams = [stream]
|
||||
if logfile_name:
|
||||
ctx = open(logfile_name, 'ab')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue