gulp-eslint
Advanced tools
Comparing version 0.2.0 to 0.2.2
52
index.js
@@ -5,3 +5,4 @@ 'use strict'; | ||
PluginError = require('gulp-util').PluginError, | ||
EsLint = require('eslint').CLIEngine, | ||
eslint = require('eslint').linter, | ||
CLIEngine = require('eslint').CLIEngine, | ||
util = require('./util'); | ||
@@ -13,9 +14,12 @@ | ||
function gulpEslint(options) { | ||
var linter = new EsLint(util.migrateOptions(options)); | ||
options = util.migrateOptions(options); | ||
var linter = new CLIEngine(options); | ||
function verify(filePath, contents) { | ||
var result = linter.executeOnText(contents).results[0]; | ||
var config = linter.getConfigForFile(filePath); | ||
var messages = eslint.verify(contents, config, filePath); | ||
//eslint.reset(); | ||
return { | ||
filePath: filePath, | ||
messages: result && result.messages || [] | ||
messages: messages || [] | ||
}; | ||
@@ -25,4 +29,4 @@ } | ||
return map(function (file, output) { | ||
if (linter.isPathIgnored(file.path) || file.isNull()) { | ||
// remove base path from file path before calling isPathIgnored | ||
if (util.isPathIgnored(file, linter.options) || file.isNull()) { | ||
output(null, file); | ||
@@ -57,8 +61,3 @@ | ||
messages.some(function (message) { | ||
var level = message.fatal ? 2 : message.severity; | ||
if (Array.isArray(level)) { | ||
level = level[0]; | ||
} | ||
if (level > 1) { | ||
if (util.isErrorMessage(message)) { | ||
error = new PluginError( | ||
@@ -82,2 +81,31 @@ 'gulp-eslint', | ||
/** | ||
* Fail when the stream ends if any eslint error(s) occurred | ||
*/ | ||
gulpEslint.failAfterError = function () { | ||
var errorCount = 0; | ||
return map(function (file, output) { | ||
var messages = file.eslint && file.eslint.messages || []; | ||
messages.forEach(function (message) { | ||
if (util.isErrorMessage(message)) { | ||
errorCount++; | ||
} | ||
}); | ||
output(null, file); | ||
}).once('end', function () { | ||
// Only format results if files has been lint'd | ||
if (errorCount > 0) { | ||
this.emit('error', new PluginError( | ||
'gulp-eslint', | ||
{ | ||
name: 'ESLintError', | ||
message: 'Failed with ' + errorCount + (errorCount === 1 ? ' error' : ' errors') | ||
} | ||
)); | ||
} | ||
}); | ||
}; | ||
/** | ||
* Wait until all files have been linted and format all results at once. | ||
@@ -84,0 +112,0 @@ */ |
{ | ||
"name": "gulp-eslint", | ||
"version": "0.2.0", | ||
"version": "0.2.2", | ||
"description": "A gulp plugin for processing files with eslint", | ||
@@ -18,3 +18,5 @@ "main": "index.js", | ||
"test": "mocha", | ||
"gulp": "gulp" | ||
"gulp": "gulp", | ||
"throw-on-error": "gulp throw-on-error", | ||
"throw-after-error": "gulp throw-after-error" | ||
}, | ||
@@ -47,3 +49,3 @@ "keywords": [ | ||
"dependencies": { | ||
"eslint": "^0.9.2", | ||
"eslint": "^0.13.0", | ||
"gulp-util": "^3.0.1", | ||
@@ -50,0 +52,0 @@ "map-stream": "^0.1.0", |
# gulp-eslint [![Build Status](https://travis-ci.org/adametry/gulp-eslint.png)](https://travis-ci.org/adametry/gulp-eslint) | ||
> A [Gulp](https://github.com/wearefractal/gulp) plugin for [eslint](https://github.com/wearefractal/gulp). | ||
> A [Gulp](https://github.com/wearefractal/gulp) plugin for [eslint](http://eslint.org/). | ||
@@ -4,0 +4,0 @@ ## Usage |
41
util.js
@@ -6,4 +6,8 @@ 'use strict'; | ||
through = require('through'), | ||
Config = require('eslint/lib/config'); | ||
EsLint = require('eslint').CLIEngine, | ||
IgnoredPaths = require('eslint/lib/ignored-paths'), | ||
FileFinder = require('eslint/lib/file-finder'); | ||
var ignoreFileFinder = new FileFinder('.eslintignore'); | ||
/** | ||
@@ -35,2 +39,21 @@ * Optional import, if not found, returns null. | ||
/** | ||
* Mimic the CLIEngine.isPathIgnored, but resolve .eslintignore based on file's directory rather than process.cwd() | ||
*/ | ||
exports.isPathIgnored = function (file, options) { | ||
var filePath; | ||
if (!options.ignore) { | ||
return false; | ||
} | ||
if (typeof options.ignorePath !== 'string') { | ||
options = { | ||
ignore: true, | ||
ignorePath: ignoreFileFinder.findInDirectoryOrParents(path.dirname(file.path || '')) | ||
}; | ||
} | ||
// set file path relative to the .eslintignore directory or cwd | ||
filePath = path.relative(path.dirname(options.ignorePath || '') || process.cwd(), file.path); | ||
return IgnoredPaths.load(options).contains(filePath); | ||
}; | ||
/** | ||
* Create config helper to merge various config sources | ||
@@ -92,2 +115,13 @@ */ | ||
/** | ||
* Resolve writable | ||
*/ | ||
exports.isErrorMessage = function (message) { | ||
var level = message.fatal ? 2 : message.severity; | ||
if (Array.isArray(level)) { | ||
level = level[0]; | ||
} | ||
return (level > 1); | ||
}; | ||
/** | ||
* Resolve formatter from unknown type (accepts string or function) | ||
@@ -103,6 +137,5 @@ * @exception TypeError thrown if unable to resolve the formatter type | ||
if (typeof formatter === 'string') { | ||
// load formatter (module, relative to cwd, eslint formatter) | ||
formatter = optional(formatter) | ||
|| optional(path.resolve(process.cwd(), formatter)) | ||
|| optional('eslint/lib/formatters/' + formatter); | ||
formatter = (new EsLint()).getFormatter(formatter); | ||
@@ -109,0 +142,0 @@ if (typeof formatter === 'string') { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18371
6
290
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedd@0.1.11.0.2(transitive)
+ Addeddoctrine@0.6.4(transitive)
+ Addedes5-ext@0.10.64(transitive)
+ Addedes6-iterator@0.1.32.0.3(transitive)
+ Addedes6-map@0.1.5(transitive)
+ Addedes6-set@0.1.6(transitive)
+ Addedes6-symbol@2.0.13.1.4(transitive)
+ Addedes6-weak-map@0.1.4(transitive)
+ Addedescope@2.0.7(transitive)
+ Addedeslint@0.13.0(transitive)
+ Addedesniff@2.0.1(transitive)
+ Addedespree@1.12.3(transitive)
+ Addedesprima@4.0.1(transitive)
+ Addedesrecurse@1.2.0(transitive)
+ Addedestraverse@1.9.3(transitive)
+ Addedestraverse-fb@1.3.2(transitive)
+ Addedesutils@1.1.6(transitive)
+ Addedevent-emitter@0.3.5(transitive)
+ Addedext@1.7.0(transitive)
+ Addedglobals@5.1.0(transitive)
+ Addedjs-yaml@3.14.1(transitive)
+ Addedminimatch@2.0.10(transitive)
+ Addednext-tick@1.1.0(transitive)
+ Addedobject-assign@2.1.1(transitive)
+ Addedoptionator@0.5.0(transitive)
+ Addedtype@2.7.3(transitive)
+ Addedutil-extend@1.0.3(transitive)
- Removeddoctrine@0.5.2(transitive)
- Removedescope@1.0.3(transitive)
- Removedeslint@0.9.2(transitive)
- Removedesprima@1.2.52.0.0(transitive)
- Removedestraverse@1.5.12.0.0(transitive)
- Removedjs-yaml@3.2.7(transitive)
- Removedlru-cache@2.7.3(transitive)
- Removedminimatch@1.0.0(transitive)
- Removedobject-assign@1.0.0(transitive)
- Removedoptionator@0.4.0(transitive)
- Removedsigmund@1.0.1(transitive)
Updatedeslint@^0.13.0