Skip to content

Commit

Permalink
adds better exit code handling to lint and lint-style commands (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
delambo authored and ccpricenytimes committed Sep 5, 2016
1 parent bb729c7 commit cd6b1a3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
8 changes: 4 additions & 4 deletions cli/actions/lint.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

// Command to lint src code

const path = require('path');
const CLIEngine = require('eslint').CLIEngine;
const shell = require('shelljs');
const logger = require('./../logger');
const glob = require('glob');
const { userRootPath } = require('../../utils/paths')();
Expand All @@ -22,14 +20,16 @@ module.exports = () => {
const cli = new CLIEngine(eslintCLI);
const report = cli.executeOnFiles(files);
const formatter = cli.getFormatter();
logger.log(formatter(report.results));
logger.log(`${formatter(report.results)}\n`);
process.exit(report.errorCount + report.warningCount > 0 ? 1 : 0);
};

// Check to see if eslint file exists
const eslintrc = glob.sync(`${userRootPath}/.*eslintrc*`);
if (!eslintrc.length) {
logger.error('You do not have an eslintrc file in the root of your project');
process.exit();
process.exit(1);
}

lint();
};
15 changes: 10 additions & 5 deletions cli/actions/lintStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ const glob = require('glob');
const { userRootPath } = require('../../utils/paths')();

module.exports = () => {
const handleError = (error) => {
logger.error(error);
process.exit(1);
};

// Check to see if stylelint file exists
const stylelintrc = glob.sync(`${userRootPath}/.stylelintrc`);
if (!stylelintrc.length) {
logger.error('You do not have a .stylelintrc file in the root of your project');
process.exit();
handleError('You do not have a .stylelintrc file in the root of your project');
}

stylelint.lint({
Expand All @@ -18,13 +22,14 @@ module.exports = () => {
})
.then((result) => {
if (result.output) {
logger.log(result.output);
handleError(`\n${result.output}`);
} else {
logger.log('');
logger.end('Your styles look good! ✨\n');
process.exit(0);
}
})
.catch((err) => {
logger.error(err.stack);
.catch((error) => {
handleError(error.stack);
});
};

0 comments on commit cd6b1a3

Please sign in to comment.