eslint-loader
Advanced tools
Comparing version 0.7.0 to 0.8.0
@@ -0,1 +1,7 @@ | ||
# 0.8.0 - 2015-03-27 | ||
- Changed: `reporter` is now `formatter` option to fit eslint name | ||
- Changed: plugin is now async as it don't need to be sync | ||
- Added: options are supported as query strings | ||
# 0.7.0 - 2015-03-15 | ||
@@ -2,0 +8,0 @@ |
85
index.js
@@ -1,18 +0,18 @@ | ||
"use strict"; | ||
var eslint = require("eslint") | ||
var assign = require("object-assign") | ||
var loaderUtils = require("loader-utils") | ||
// eslint empty filename | ||
var TEXT = "<text>" | ||
/** | ||
* linter | ||
* | ||
* @param {String|Buffer} input JavaScript string | ||
* @param {Object} config eslint configuration | ||
* @param {Object} webpack webpack instance | ||
* @returns {void} | ||
* @param {String|Buffer} input JavaScript string | ||
* @param {Object} config eslint configuration | ||
* @param {Object} webpack webpack instance | ||
* @param {Function} callback optional callback for async loader | ||
* @return {void} | ||
*/ | ||
function lint(input, config, webpack) { | ||
var res = config.executeOnText(input) | ||
function lint(input, config, webpack, callback) { | ||
var engine = new eslint.CLIEngine(config) | ||
var res = engine.executeOnText(input) | ||
// executeOnText ensure we will have res.results[0] only | ||
@@ -23,3 +23,3 @@ | ||
// so we can found warnings defined in the input itself | ||
if (res.warningCount && webpack.options.eslint.quiet) { | ||
if (res.warningCount && config.quiet) { | ||
res.warningCount = 0 | ||
@@ -33,9 +33,7 @@ res.results[0].warningCount = 0 | ||
if (res.errorCount || res.warningCount) { | ||
var messages = webpack.options.eslint.reporter(res.results) | ||
if (messages.indexOf(TEXT) > -1) { | ||
messages = messages.split("\n").filter(function(line) { | ||
// drop the line that should contains filepath we do not have | ||
return !line.match(TEXT) | ||
}).join("\n") | ||
} | ||
// add filename for each results so formatter can have relevant filename | ||
res.results.forEach(function(r) { | ||
r.filePath = webpack.resourcePath | ||
}) | ||
var messages = config.formatter(res.results) | ||
@@ -46,6 +44,6 @@ // default behavior: emit error only if we have errors | ||
// force emitError or emitWarning if user want this | ||
if (webpack.options.eslint.emitError) { | ||
if (config.emitError) { | ||
emitter = webpack.emitError | ||
} | ||
else if (webpack.options.eslint.emitWarning) { | ||
else if (config.emitWarning) { | ||
emitter = webpack.emitWarning | ||
@@ -56,7 +54,7 @@ } | ||
emitter(messages) | ||
if (webpack.options.eslint.failOnError && res.errorCount) { | ||
throw new Error("Module failed because of a eslint error."); | ||
if (config.failOnError && res.errorCount) { | ||
throw new Error("Module failed because of a eslint error.") | ||
} | ||
else if (webpack.options.eslint.failOnWarning && res.warningCount) { | ||
throw new Error("Module failed because of a eslint warning."); | ||
else if (config.failOnWarning && res.warningCount) { | ||
throw new Error("Module failed because of a eslint warning.") | ||
} | ||
@@ -68,2 +66,6 @@ } | ||
} | ||
if (callback) { | ||
callback(null, input) | ||
} | ||
} | ||
@@ -78,13 +80,30 @@ | ||
module.exports = function(input) { | ||
this.options.eslint = this.options.eslint || {} | ||
this.options.eslint.reporter = this.options.eslint.reporter || require("eslint/lib/formatters/stylish") | ||
var config = assign( | ||
// loader defaults | ||
{ | ||
formatter: require("eslint/lib/formatters/stylish"), | ||
}, | ||
// user defaults | ||
this.options.eslint || {}, | ||
// loader query string | ||
loaderUtils.parseQuery(this.query) | ||
) | ||
this.cacheable() | ||
// sync loader | ||
var config = new eslint.CLIEngine(this.options.eslint) | ||
var callback = this.async() | ||
// sync | ||
if (!callback) { | ||
lint(input, config, this) | ||
lint(input, config, this) | ||
// this loader do nothing | ||
return input | ||
return input | ||
} | ||
// async | ||
else { | ||
try { | ||
lint(input, config, this, callback) | ||
} | ||
catch(e) { | ||
callback(e) | ||
} | ||
} | ||
} |
{ | ||
"name": "eslint-loader", | ||
"version": "0.7.0", | ||
"version": "0.8.0", | ||
"description": "eslint loader (for webpack)", | ||
@@ -30,2 +30,3 @@ "keywords": [ | ||
"dependencies": { | ||
"loader-utils": "^0.2.6", | ||
"object-assign": "^2.0.0" | ||
@@ -32,0 +33,0 @@ }, |
@@ -29,5 +29,23 @@ # eslint-loader [![Build Status](http://img.shields.io/travis/MoOx/eslint-loader.svg)](https://travis-ci.org/MoOx/eslint-loader) | ||
You can pass directly some [eslint options](http://eslint.org/docs/configuring/) by adding an `eslint` entry in you webpack config: | ||
You can pass directly some [eslint options](http://eslint.org/docs/user-guide/command-line-interface) by | ||
- Adding a query string to the loader for this loader usabe only | ||
```js | ||
{ | ||
module: { | ||
loaders: [ | ||
{ | ||
test: /\.js$/, | ||
loader: "eslint-loader?{rules:[{semi:0}]}", | ||
exclude: /node_modules/, | ||
}, | ||
], | ||
}, | ||
} | ||
``` | ||
- Adding an `eslint` entry in you webpack config for global options: | ||
```js | ||
module.exports = { | ||
@@ -40,9 +58,9 @@ eslint: { | ||
#### `reporter` (default: eslint stylish reporter) | ||
**Note that you can use both method in order to benefit from global & specific options** | ||
#### `formatter` (default: eslint stylish formatter) | ||
Loader accepts a function that will have one argument: an array of eslint messages (object). | ||
The function must return the output as a string. | ||
You can use official eslint reporters. | ||
**Please note that every lines with the filename will be skipped from output** | ||
because of the way the loader use eslint (just with a string of text, not a file - so no filename available) | ||
You can use official eslint formatters. | ||
@@ -59,9 +77,9 @@ ```js | ||
// default value | ||
reporter: require("eslint/lib/formatters/stylish"), | ||
formatter: require("eslint/lib/formatters/stylish"), | ||
// community reporter | ||
reporter: require("eslint-friendly-formatter"), | ||
// community formatter | ||
formatter: require("eslint-friendly-formatter"), | ||
// custom reporter | ||
reporter: function(results) { | ||
// custom formatter | ||
formatter: function(results) { | ||
// `results` format is available here | ||
@@ -68,0 +86,0 @@ // http://eslint.org/docs/developer-guide/nodejs-api.html#executeonfiles() |
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
9276
92
170
3
+ Addedloader-utils@^0.2.6
+ Addedbig.js@3.2.0(transitive)
+ Addedemojis-list@2.1.0(transitive)
+ Addedjson5@0.5.1(transitive)
+ Addedloader-utils@0.2.17(transitive)
+ Addedobject-assign@4.1.1(transitive)