Skip to content

Commit

Permalink
Fix wrong exit code which has to be related to --failon option (defau…
Browse files Browse the repository at this point in the history
…lt: `error`)

Fixes #71
  • Loading branch information
nvuillam authored and RubenHalman committed Nov 7, 2023
1 parent c32c63f commit d5c8e24
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased] (beta, main branch content)

- Fix wrong exit code which has to be related to --failon option (default: `error`)

## [2.12.0] 2023-08-29

- Fix exit code that should be 1 according to --failon value [#71](https://github.com/Force-Config-Control/lightning-flow-scanner-sfdx/issues/71)
Expand Down
22 changes: 13 additions & 9 deletions src/commands/flow/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default class scan extends SfdxCommand {

protected userConfig;
protected failOn = "error";
protected errorCounters: Map<string,number> = new Map<string,number>();

protected static flagsConfig = {
directory: flags.filepath({
Expand Down Expand Up @@ -118,7 +119,7 @@ export default class scan extends SfdxCommand {
this.ux.log(c.bold(c.italic(c.yellowBright('Be a part of our mission to champion Best Practices and empower Flow Builders by starring us on GitHub:'))));
this.ux.log(c.italic(c.blueBright(c.underline("https://github.com/Force-Config-Control/lightning-flow-scanner-sfdx"))));

const status = this.getStatus({});
const status = this.getStatus();
// Set status code = 1 if there are errors, that will make cli exit with code 1 when not in --json mode
if (status > 0) {
process.exitCode = status;
Expand Down Expand Up @@ -153,24 +154,24 @@ export default class scan extends SfdxCommand {
return flowFiles;
}

private getStatus(errorLevelsNumber) {
private getStatus() {
let status = 0;
if (this.failOn === 'never') {
status = 0;
}
else {
if (this.failOn === "error" && (errorLevelsNumber["error"] || 0) > 0) {
if (this.failOn === "error" && (this.errorCounters["error"] || 0) > 0) {
status = 1;
}
else if (this.failOn === 'warning' &&
((errorLevelsNumber["error"] || 0) > 0)
|| ((errorLevelsNumber["warning"] || 0) > 0)) {
((this.errorCounters["error"] || 0) > 0)
|| ((this.errorCounters["warning"] || 0) > 0)) {
status = 1;
}
else if (this.failOn === 'note' &&
((errorLevelsNumber["error"] || 0) > 0)
|| ((errorLevelsNumber["warning"] || 0) > 0)
|| ((errorLevelsNumber["note"] || 0) > 0)) {
((this.errorCounters["error"] || 0) > 0)
|| ((this.errorCounters["warning"] || 0) > 0)
|| ((this.errorCounters["note"] || 0) > 0)) {
status = 1;
}
}
Expand All @@ -186,17 +187,20 @@ export default class scan extends SfdxCommand {
const ruleDescription = ruleResult.ruleDefinition.description;
const rule = ruleResult.ruleDefinition.label;
if (ruleResult.occurs && ruleResult.details && ruleResult.details.length > 0) {
const severity = ruleResult.severity || "error"
for (const result of (ruleResult.details as ResultDetails[])) {
const detailObj = Object.assign(
result,
{
ruleDescription,
rule,
flowName,
flowType
flowType,
severity
}
);
errors.push(detailObj);
this.errorCounters[severity] = (this.errorCounters[severity] || 0) + 1;
}
}
}
Expand Down

0 comments on commit d5c8e24

Please sign in to comment.