Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 57dbd17

Browse files
committedApr 26, 2024·
Add detectors_to_include to override exclude args
1 parent ded705d commit 57dbd17

File tree

2 files changed

+38
-13
lines changed

2 files changed

+38
-13
lines changed
 

‎slither/__main__.py

+37-13
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import sys
1212
import traceback
1313
from importlib import metadata
14-
from typing import Tuple, Optional, List, Dict, Type, Union, Any, Sequence
14+
from typing import Any, Dict, List, Optional, Sequence, Set, Tuple, Type, Union
1515

1616

1717
from crytic_compile import cryticparser, CryticCompile, InvalidCompilation
@@ -211,18 +211,10 @@ def choose_detectors(
211211

212212
if args.detectors_to_run == "all":
213213
detectors_to_run = all_detector_classes
214-
if args.detectors_to_exclude:
215-
detectors_excluded = args.detectors_to_exclude.split(",")
216-
for detector in detectors:
217-
if detector in detectors_excluded:
218-
detectors_to_run.remove(detectors[detector])
219214
else:
220-
for detector in args.detectors_to_run.split(","):
221-
if detector in detectors:
222-
detectors_to_run.append(detectors[detector])
223-
else:
224-
raise ValueError(f"Error: {detector} is not a detector")
225-
detectors_to_run = sorted(detectors_to_run, key=lambda x: x.IMPACT)
215+
detectors_to_run = __include_detectors(
216+
set(detectors_to_run), args.detectors_to_run, detectors
217+
)
226218
return detectors_to_run
227219

228220
if args.exclude_optimization:
@@ -234,24 +226,48 @@ def choose_detectors(
234226
detectors_to_run = [
235227
d for d in detectors_to_run if d.IMPACT != DetectorClassification.INFORMATIONAL
236228
]
229+
237230
if args.exclude_low:
238231
detectors_to_run = [d for d in detectors_to_run if d.IMPACT != DetectorClassification.LOW]
232+
239233
if args.exclude_medium:
240234
detectors_to_run = [
241235
d for d in detectors_to_run if d.IMPACT != DetectorClassification.MEDIUM
242236
]
237+
243238
if args.exclude_high:
244239
detectors_to_run = [d for d in detectors_to_run if d.IMPACT != DetectorClassification.HIGH]
240+
245241
if args.detectors_to_exclude:
246242
detectors_to_run = [
247243
d for d in detectors_to_run if d.ARGUMENT not in args.detectors_to_exclude
248244
]
249245

250-
detectors_to_run = sorted(detectors_to_run, key=lambda x: x.IMPACT)
246+
if args.detectors_to_include:
247+
detectors_to_run = __include_detectors(
248+
set(detectors_to_run), args.detectors_to_include, detectors
249+
)
251250

252251
return detectors_to_run
253252

254253

254+
def __include_detectors(
255+
detectors_to_run: Set[Type[AbstractDetector]],
256+
detectors_to_include: str,
257+
detectors: Dict[str, Type[AbstractDetector]],
258+
) -> List[Type[AbstractDetector]]:
259+
include_detectors = detectors_to_include.split(",")
260+
261+
for detector in include_detectors:
262+
if detector in detectors:
263+
detectors_to_run.add(detectors[detector])
264+
else:
265+
raise ValueError(f"Error: {detector} is not a detector")
266+
267+
detectors_to_run = sorted(detectors_to_run, key=lambda x: x.IMPACT)
268+
return detectors_to_run
269+
270+
255271
def choose_printers(
256272
args: argparse.Namespace, all_printer_classes: List[Type[AbstractPrinter]]
257273
) -> List[Type[AbstractPrinter]]:
@@ -407,6 +423,14 @@ def parse_args(
407423
default=defaults_flag_in_config["exclude_high"],
408424
)
409425

426+
group_detector.add_argument(
427+
"--include-detectors",
428+
help="Comma-separated list of detectors that should be included",
429+
action="store",
430+
dest="detectors_to_include",
431+
default=defaults_flag_in_config["detectors_to_include"],
432+
)
433+
410434
fail_on_group = group_detector.add_mutually_exclusive_group()
411435
fail_on_group.add_argument(
412436
"--fail-pedantic",

‎slither/utils/command_line.py

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class FailOnLevel(enum.Enum):
4848
"detectors_to_run": "all",
4949
"printers_to_run": None,
5050
"detectors_to_exclude": None,
51+
"detectors_to_include": None,
5152
"exclude_dependencies": False,
5253
"exclude_informational": False,
5354
"exclude_optimization": False,

0 commit comments

Comments
 (0)
Please sign in to comment.