Skip to content

Commit

Permalink
[cli] Print linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyganch committed Aug 3, 2016
1 parent 822f546 commit 6c88e7e
Showing 1 changed file with 40 additions and 8 deletions.
48 changes: 40 additions & 8 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,59 @@ function processInputData(input) {
process.stderr.write(e.message);
process.exit(1);
}).then(output => {
process.stdout.write(output);
process.exit(0);
if (!output.length) {
process.exit(0);
} else {
process.stdout.write(output);
process.exit(1);
}
});
}

function processSTDIN() {
getInputData.then(processInputData);
}

function processFiles(files, config) {
function processFiles(files) {
let anyErrorsFound = false;

const promises = files.map(file => {
return comb.lintPath(file);
return comb.lintPath(file).then(errors => {
if (!errors.length) {
return;
}

anyErrorsFound = true;
const message = formatErrors(file, errors);
process.stdout.write(message);
});
});

Promise.all(promises).catch(error => {
process.stderr.write(error.message);
process.exit(1);
}).then(function(c) {
console.log(c);
process.exit(0);
}).then(function() {
if (anyErrorsFound) {
process.exit(1);
} else {
process.exit(0);
}
});
}

function formatErrors(fileName, errors) {
let message = [];

errors.forEach(error => {
message.push(
error.message + ' at ' + fileName + ':' + error.line,
error.context,
'',
''
);
});

return message.join('\n');
}

function getOptions() {
Expand Down Expand Up @@ -157,7 +189,7 @@ var config = getConfig(options);
comb.configure(config);

if (process.stdin.isTTY) {
processFiles(options._, config);
processFiles(options._);
} else {
processSTDIN();
}

0 comments on commit 6c88e7e

Please sign in to comment.