Skip to content

Commit 6c88e7e

Browse files
committed
[cli] Print linter errors
1 parent 822f546 commit 6c88e7e

1 file changed

Lines changed: 40 additions & 8 deletions

File tree

src/cli.js

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,27 +53,59 @@ function processInputData(input) {
5353
process.stderr.write(e.message);
5454
process.exit(1);
5555
}).then(output => {
56-
process.stdout.write(output);
57-
process.exit(0);
56+
if (!output.length) {
57+
process.exit(0);
58+
} else {
59+
process.stdout.write(output);
60+
process.exit(1);
61+
}
5862
});
5963
}
6064

6165
function processSTDIN() {
6266
getInputData.then(processInputData);
6367
}
6468

65-
function processFiles(files, config) {
69+
function processFiles(files) {
70+
let anyErrorsFound = false;
71+
6672
const promises = files.map(file => {
67-
return comb.lintPath(file);
73+
return comb.lintPath(file).then(errors => {
74+
if (!errors.length) {
75+
return;
76+
}
77+
78+
anyErrorsFound = true;
79+
const message = formatErrors(file, errors);
80+
process.stdout.write(message);
81+
});
6882
});
6983

7084
Promise.all(promises).catch(error => {
7185
process.stderr.write(error.message);
7286
process.exit(1);
73-
}).then(function(c) {
74-
console.log(c);
75-
process.exit(0);
87+
}).then(function() {
88+
if (anyErrorsFound) {
89+
process.exit(1);
90+
} else {
91+
process.exit(0);
92+
}
93+
});
94+
}
95+
96+
function formatErrors(fileName, errors) {
97+
let message = [];
98+
99+
errors.forEach(error => {
100+
message.push(
101+
error.message + ' at ' + fileName + ':' + error.line,
102+
error.context,
103+
'',
104+
''
105+
);
76106
});
107+
108+
return message.join('\n');
77109
}
78110

79111
function getOptions() {
@@ -157,7 +189,7 @@ var config = getConfig(options);
157189
comb.configure(config);
158190

159191
if (process.stdin.isTTY) {
160-
processFiles(options._, config);
192+
processFiles(options._);
161193
} else {
162194
processSTDIN();
163195
}

0 commit comments

Comments
 (0)