Skip to content

Commit c8881b9

Browse files
authored
Updated the cli to generate non-zero exit code if issues are detected (#26)
* Updated the cli to generate non-zero exit code if issues are detected Fixes #25 CLI will now exit with an exit code of 2 if issues are detected during the scan. Bumped version to 2.1.0 and bumped underlying dependencies. * Remove magic numbers from code
1 parent 2ce8105 commit c8881b9

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1111

1212
### Removed
1313

14+
## [2.1.0] - 2017-04-09
15+
### Changed
16+
- CLI process exit code to 2 (non-zero) if issues are detected in the scan
17+
1418
## [2.0.2] - 2017-02-18
1519
### Fixed
1620
- Issue .npmpackagejsonlintrc.json files that only have a extends value with no rules object

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "npm-package-json-lint",
3-
"version": "2.0.2",
3+
"version": "2.1.0",
44
"description": "CLI app for linting package.json files.",
55
"keywords": [
66
"lint",
@@ -33,9 +33,9 @@
3333
"validator": "^6.2.1"
3434
},
3535
"devDependencies": {
36-
"eslint": "^3.15.0",
37-
"eslint-config-tc": "^1.4.0",
38-
"eslint-formatter-pretty": "^1.0.0",
36+
"eslint": "^3.19.0",
37+
"eslint-config-tc": "^1.5.0",
38+
"eslint-formatter-pretty": "^1.1.0",
3939
"grunt": "^1.0.1",
4040
"grunt-bump": "^0.8.0",
4141
"grunt-contrib-clean": "^1.0.0",
@@ -48,7 +48,7 @@
4848
"grunt-jsonlint": "^1.1.0",
4949
"grunt-mocha-test": "^0.13.2",
5050
"mocha": "^3.2.0",
51-
"should": "^11.2.0",
51+
"should": "^11.2.1",
5252
"sinon": "^1.17.7",
5353
"time-grunt": "^1.4.0"
5454
},

src/cli.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,23 +80,29 @@ if (!rulesLoaded) {
8080
let fileData = null;
8181

8282
try {
83+
let exitCode = 0;
84+
const noIssues = 0;
85+
const issuesDetectedErrorCode = 2;
8386
const parser = new Parser();
8487

8588
fileData = parser.parse(filePath);
8689

8790
const npmPackageJsonLint = new NpmPackageJsonLint(fileData, rulesConfig, options);
8891
const output = npmPackageJsonLint.lint();
89-
9092
const reporter = new Reporter();
9193

9294
for (const issueType in output) {
9395
const issues = output[issueType];
9496

95-
reporter.write(output[issueType], issueType);
97+
if (issues.length > noIssues) {
98+
exitCode = issuesDetectedErrorCode;
99+
reporter.write(output[issueType], issueType);
100+
}
96101
}
97102

98103
const formattedFileName = chalk.bold.green(filePath);
99104

105+
process.exitCode = exitCode;
100106
console.log(`${formattedFileName} check complete`);
101107
} catch (err) {
102108
handleError(err);

0 commit comments

Comments
 (0)