slither-format: add --exclude flag

pull/238/head
Josselin 6 years ago
parent 80db6cc543
commit 4330b9421a
  1. 8
      utils/slither_format/__main__.py
  2. 14
      utils/slither_format/slither_format.py

@ -50,6 +50,14 @@ def parse_args():
dest='detectors_to_run', dest='detectors_to_run',
default='all') default='all')
group_detector.add_argument('--exclude',
help='Comma-separated list of detectors to exclude,'
'available detectors: {}'.format(
', '.join(d for d in available_detectors)),
action='store',
dest='detectors_to_exclude',
default='all')
cryticparser.init(parser) cryticparser.init(parser)
if len(sys.argv) == 1: if len(sys.argv) == 1:

@ -30,7 +30,8 @@ def slither_format(slither, **kwargs):
detectors_to_run (str): Comma-separated list of detectors, defaults to all detectors_to_run (str): Comma-separated list of detectors, defaults to all
''' '''
detectors_to_run = choose_detectors(kwargs.get('detectors_to_run', 'all')) detectors_to_run = choose_detectors(kwargs.get('detectors_to_run', 'all'),
kwargs.get('detectors_to_exclude', ''))
for detector in detectors_to_run: for detector in detectors_to_run:
slither.register_detector(detector) slither.register_detector(detector)
@ -64,6 +65,9 @@ def slither_format(slither, **kwargs):
result['paches_diff'] = diff result['paches_diff'] = diff
if skip_file_generation: if skip_file_generation:
continue continue
if not diff:
logger.info(f'Empty patch generated {result}')
continue
path = os.path.join(export, f'fix_{counter}.patch') path = os.path.join(export, f'fix_{counter}.patch')
logger.info(f'\t- {path}') logger.info(f'\t- {path}')
with open(path, 'w') as f: with open(path, 'w') as f:
@ -78,15 +82,21 @@ def slither_format(slither, **kwargs):
################################################################################### ###################################################################################
################################################################################### ###################################################################################
def choose_detectors(detectors_to_run): def choose_detectors(detectors_to_run, detectors_to_exclude):
# If detectors are specified, run only these ones # If detectors are specified, run only these ones
cls_detectors_to_run = [] cls_detectors_to_run = []
exclude = detectors_to_exclude.split(',')
if detectors_to_run == 'all': if detectors_to_run == 'all':
for d in all_detectors: for d in all_detectors:
if d in exclude:
continue
cls_detectors_to_run.append(all_detectors[d]) cls_detectors_to_run.append(all_detectors[d])
else: else:
exclude = detectors_to_exclude.split(',')
for d in detectors_to_run.split(','): for d in detectors_to_run.split(','):
if d in all_detectors: if d in all_detectors:
if d in exclude:
continue
cls_detectors_to_run.append(all_detectors[d]) cls_detectors_to_run.append(all_detectors[d])
else: else:
raise Exception('Error: {} is not a detector'.format(d)) raise Exception('Error: {} is not a detector'.format(d))

Loading…
Cancel
Save