Skip to content

Commit 0d3445c

Browse files
joemallersindresorhus
authored andcommitted
Close #57 PR: Attach jscs errors to the file object, like gulp-jshint.. Fixes #51, Fixes #39, Fixes #41
1 parent a6ca0a2 commit 0d3445c

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,14 @@ module.exports = function (options) {
5151

5252
try {
5353
var errors = checker.checkString(file.contents.toString(), file.relative);
54-
errors.getErrorList().forEach(function (err) {
54+
var errorList = errors.getErrorList();
55+
file.jscs = {success: true, errorCount: 0, errors: []};
56+
if (errorList.length > 0) {
57+
file.jscs.success = false;
58+
file.jscs.errorCount = errorList.length;
59+
file.jscs.errors = errorList;
60+
}
61+
errorList.forEach(function (err) {
5562
out.push(errors.explainError(err, true));
5663
});
5764
} catch (err) {

readme.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ gulp.task('default', function () {
2727
```
2828

2929

30+
## Results
31+
32+
A `jscs` object will be attached to the file object which can be used for custom error reporting. An example with one error might look like this:
33+
34+
```js
35+
{ success: false, // or true if no errors
36+
errorCount: 1, // number of errors in the errors array
37+
errors: [ // an array of jscs error objects
38+
{ filename: 'index.js', // basename of the file
39+
rule: 'requireCamelCaseOrUpperCaseIdentifiers', // jscs rule which triggered the error
40+
message: 'All identifiers must be camelCase or UPPER_CASE', // error message returned by the rule
41+
line: 32, // error line number
42+
column: 7 } // error column
43+
]};
44+
```
45+
3046
## API
3147

3248
### jscs(options)

0 commit comments

Comments
 (0)