Skip to content

Commit

Permalink
feat: fail on specific issue type and/or severity
Browse files Browse the repository at this point in the history
  • Loading branch information
gabidobo committed Feb 21, 2023
1 parent 9cc2d1f commit e19f48a
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ require('yargs')
default: 'registry',
describe: 'Load data from "registry" or "disk"',
type: 'string',
})
.option('fo', {
alias: 'fail-on',
demandOption: false,
default: '[]',
describe: 'Fail policy JSON string',
type: 'string',
});
},
async (argv) => {
Expand Down Expand Up @@ -237,7 +244,32 @@ require('yargs')
logger.log('✨ Done');
} else {
logger.log('✨ Done, but with errors:');
errors.forEach((error) => logger.log('⚠️ \x1b[31m%s\x1b[0m', error));
errors.forEach((error) => logger.log('❌ \x1b[31m%s\x1b[0m', error));
logger.log('❌ Failing because of errors');
process.exit(1);
}

const failOn = fileConfig.failOn || (argv.fo && JSON.parse(argv.fo));

if (failOn) {
Object.entries(issueCountsByType).forEach(([issueType, typeCountBySeverity]) => {
Object.entries(typeCountBySeverity).forEach(([issueSeverity, count]) => {
if (count > 0) {
failOn.forEach((failOnOption) => {
const [failType, failSeverity] = failOnOption.split('.');
if (
(failType === '*' && failSeverity === '*') ||
(failType === issueType && failSeverity === issueSeverity) ||
(failType === '*' && failSeverity === issueSeverity) ||
(failType === issueType && failSeverity === '*')
) {
logger.log(`❌ Failing because of rule "${failOnOption}"`);
process.exit(1);
}
});
}
});
});
}
},
)
Expand Down

0 comments on commit e19f48a

Please sign in to comment.