Skip to content

Commit

Permalink
Add detectors_to_include to override exclude args
Browse files Browse the repository at this point in the history
  • Loading branch information
nsiregar committed Apr 23, 2024
1 parent 7f82f4a commit 6d92113
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
42 changes: 42 additions & 0 deletions slither/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,19 +223,38 @@ def choose_detectors(
detectors_to_run = [
d for d in detectors_to_run if d.IMPACT != DetectorClassification.OPTIMIZATION
]
detectors_to_run = __include_detectors(
detectors_to_run, args.detectors_to_include, detectors
)

if args.exclude_informational:
detectors_to_run = [
d for d in detectors_to_run if d.IMPACT != DetectorClassification.INFORMATIONAL
]
detectors_to_run = __include_detectors(
detectors_to_run, args.detectors_to_include, detectors
)

if args.exclude_low:
detectors_to_run = [d for d in detectors_to_run if d.IMPACT != DetectorClassification.LOW]
detectors_to_run = __include_detectors(
detectors_to_run, args.detectors_to_include, detectors
)

if args.exclude_medium:
detectors_to_run = [
d for d in detectors_to_run if d.IMPACT != DetectorClassification.MEDIUM
]
detectors_to_run = __include_detectors(
detectors_to_run, args.detectors_to_include, detectors
)

if args.exclude_high:
detectors_to_run = [d for d in detectors_to_run if d.IMPACT != DetectorClassification.HIGH]
detectors_to_run = __include_detectors(
detectors_to_run, args.detectors_to_include, detectors
)

if args.detectors_to_exclude:
detectors_to_run = [
d for d in detectors_to_run if d.ARGUMENT not in args.detectors_to_exclude
Expand All @@ -246,6 +265,21 @@ def choose_detectors(
return detectors_to_run


def __include_detectors(
detectors_to_run: List[Type[AbstractDetector]],
detectors_to_include: str,
detectors: Dict[str, Type[AbstractDetector]],
) -> List[Type[AbstractDetector]]:
include_detectors = detectors_to_include.split(",")

for detector in include_detectors:
if detector in detectors:
detectors_to_run.append(detectors[detector])
else:
raise ValueError(f"Error: {detector} is not a detector")
return detectors_to_run


def choose_printers(
args: argparse.Namespace, all_printer_classes: List[Type[AbstractPrinter]]
) -> List[Type[AbstractPrinter]]:
Expand Down Expand Up @@ -401,6 +435,14 @@ def parse_args(
default=defaults_flag_in_config["exclude_high"],
)

group_detector.add_argument(
"--include",
help="Comma-separated list of detectors that should be excluded",
action="store",
dest="detectors_to_include",
default=defaults_flag_in_config["detectors_to_include"],
)

fail_on_group = group_detector.add_mutually_exclusive_group()
fail_on_group.add_argument(
"--fail-pedantic",
Expand Down
1 change: 1 addition & 0 deletions slither/utils/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class FailOnLevel(enum.Enum):
"detectors_to_run": "all",
"printers_to_run": None,
"detectors_to_exclude": None,
"detectors_to_include": None,
"exclude_dependencies": False,
"exclude_informational": False,
"exclude_optimization": False,
Expand Down

0 comments on commit 6d92113

Please sign in to comment.