Skip to content

Commit

Permalink
Merge pull request #6 from pandell/allow-jshintchaining
Browse files Browse the repository at this point in the history
Allow JSHint chaining
  • Loading branch information
milang committed Jun 11, 2014
2 parents 8eb66f2 + ebeda6c commit 9ae989b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 26 deletions.
6 changes: 2 additions & 4 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/.editor*
/.git*
/.travis*
/.npmignore
/.*
/gulpfile.js
/lib/monitorCtrlC.js
/test/

# from .gitignore
Expand Down
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*jslint node: true, vars: true, unparam: true */
/*jslint node: true, vars: true */

"use strict";

Expand Down
2 changes: 1 addition & 1 deletion lib/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = function simpleReport(options) {
failed = true;
}

return cb(undefined, file);
return cb(null, file);
});

if (options.emitErrorAtEnd) {
Expand Down
48 changes: 28 additions & 20 deletions lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,31 +53,39 @@ var jslint = requireJslint("jslint.js");
module.exports = function simpleJslint(options) {
var includeData = !!(options && options.includeData);
return through.obj(function gulpSimpleJslint(file, enc, cb) {
if (file.isBuffer()) {
var fileStr = bufferToScript(file.contents, enc);
var ok = jslint(fileStr, options);
if (!ok || includeData) {
var filePath = (options && options.useRelativePath ? path.relative(file.base, file.path) : file.path);
file.jslint = file.jshint = {
opt: options,
success: ok,
results: jslint.errors.filter(Boolean).map(function (e) { // filter(Boolean) removes falsy values from errors array
e.code = "E_" + e.code; // some reporters look at 1st letter of "code" to determine type of error (E: Error, W: Warning, I: Info)
return { file: filePath, error: e };
}),
data: (includeData ? [jslint.data()] : null)
};
if (includeData) {
file.jshint.data[0].file = filePath;
}
if (file.jshint) { // this file has already been analysed by this plugin or "gulp-jshint"
if (file.jslint || !file.jshint.success) { // do not re-analyse this file if already analysed by this plugin or if "gulp-jshint" analysis failed
return cb(null, file);
}
} else {
}

if (!file.isBuffer()) {
var err = new gutil.PluginError(pluginName, "This plugin requires bufferred files", {});
err.code = "ENOTSUPPORTED";
this.emit("error", err);
this.end();
return cb();
}

var fileStr = bufferToScript(file.contents, enc);
var ok = jslint(fileStr, options);
if (!ok || includeData) {
var filePath = (options && options.useRelativePath ? path.relative(file.base, file.path) : file.path);
file.jslint = file.jshint = {
opt: options,
success: ok,
data: null,
results: jslint.errors.filter(Boolean).map(function (e) { // filter(Boolean) removes falsy values from errors array
e.code = "E_" + e.code; // some reporters look at 1st letter of "code" to determine type of error (E: Error, W: Warning, I: Info)
return { file: filePath, error: e };
})
};
if (includeData) {
file.jslint.data = [jslint.data()];
file.jslint.data[0].file = filePath;
}
}

this.push(file);
return cb();
return cb(null, file);
});
};

0 comments on commit 9ae989b

Please sign in to comment.