Skip to content

Commit cd6b1a3

Browse files
delamboccpricenytimes
authored andcommitted
adds better exit code handling to lint and lint-style commands (#93)
1 parent bb729c7 commit cd6b1a3

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

cli/actions/lint.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11

22
// Command to lint src code
33

4-
const path = require('path');
54
const CLIEngine = require('eslint').CLIEngine;
6-
const shell = require('shelljs');
75
const logger = require('./../logger');
86
const glob = require('glob');
97
const { userRootPath } = require('../../utils/paths')();
@@ -22,14 +20,16 @@ module.exports = () => {
2220
const cli = new CLIEngine(eslintCLI);
2321
const report = cli.executeOnFiles(files);
2422
const formatter = cli.getFormatter();
25-
logger.log(formatter(report.results));
23+
logger.log(`${formatter(report.results)}\n`);
24+
process.exit(report.errorCount + report.warningCount > 0 ? 1 : 0);
2625
};
2726

2827
// Check to see if eslint file exists
2928
const eslintrc = glob.sync(`${userRootPath}/.*eslintrc*`);
3029
if (!eslintrc.length) {
3130
logger.error('You do not have an eslintrc file in the root of your project');
32-
process.exit();
31+
process.exit(1);
3332
}
33+
3434
lint();
3535
};

cli/actions/lintStyle.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ const glob = require('glob');
55
const { userRootPath } = require('../../utils/paths')();
66

77
module.exports = () => {
8+
const handleError = (error) => {
9+
logger.error(error);
10+
process.exit(1);
11+
};
12+
813
// Check to see if stylelint file exists
914
const stylelintrc = glob.sync(`${userRootPath}/.stylelintrc`);
1015
if (!stylelintrc.length) {
11-
logger.error('You do not have a .stylelintrc file in the root of your project');
12-
process.exit();
16+
handleError('You do not have a .stylelintrc file in the root of your project');
1317
}
1418

1519
stylelint.lint({
@@ -18,13 +22,14 @@ module.exports = () => {
1822
})
1923
.then((result) => {
2024
if (result.output) {
21-
logger.log(result.output);
25+
handleError(`\n${result.output}`);
2226
} else {
2327
logger.log('');
2428
logger.end('Your styles look good! ✨\n');
29+
process.exit(0);
2530
}
2631
})
27-
.catch((err) => {
28-
logger.error(err.stack);
32+
.catch((error) => {
33+
handleError(error.stack);
2934
});
3035
};

0 commit comments

Comments
 (0)