Skip to content

Make runCheck return a bool instead of enum #6110

@kevinrr888

Description

@kevinrr888

"From what I could find SKIPPED_DEPENDENCY_FAILED and FILTERED_OUT were only used in the code that you see below:

private static int executeRunCheckCommand(CheckCommand cmd, List<CheckCommand.Check> givenChecks,
ServerContext context, ServerUtilOpts opts) throws Exception {
// Get all the checks in the order they are declared in the enum
final var allChecks = CheckCommand.Check.values();
final TreeMap<CheckCommand.Check,CheckCommand.CheckStatus> checkStatus = new TreeMap<>();
for (CheckCommand.Check check : allChecks) {
if (depsFailed(check, checkStatus)) {
checkStatus.put(check, CheckCommand.CheckStatus.SKIPPED_DEPENDENCY_FAILED);
} else {
if (givenChecks.contains(check)) {
checkStatus.put(check, cmd.getCheckRunner(check).runCheck(context, opts, cmd.fixFiles));
} else {
checkStatus.put(check, CheckCommand.CheckStatus.FILTERED_OUT);
}
}
}
printChecksResults(checkStatus);
if (checkStatus.values().stream()
.anyMatch(status -> status == CheckCommand.CheckStatus.FAILED)) {
return 5;
} else {
return 0;
}
}
private static boolean depsFailed(CheckCommand.Check check,
TreeMap<CheckCommand.Check,CheckCommand.CheckStatus> checkStatus) {
return check.getDependencies().stream()
.anyMatch(dep -> checkStatus.get(dep) == CheckCommand.CheckStatus.FAILED
|| checkStatus.get(dep) == CheckCommand.CheckStatus.SKIPPED_DEPENDENCY_FAILED);
}

If runCheck on line 1439 returned a boolean, then you could convert that to OK or FAILED at that time and I think it would make the checks a little easier to read. I'm happy to do it in a follow-on."

Originally posted by @dlmarion in #5348 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions