Skip to content
This repository was archived by the owner on Sep 28, 2020. It is now read-only.

fix #204 | get this.options.eslint without error #212

Merged
merged 6 commits into from
Feb 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ language: node_js
node_js:
- 8
- 6
- 4

env:
- WEBPACK_VERSION=4
- WEBPACK_VERSION=3
- WEBPACK_VERSION=2
- WEBPACK_VERSION=1

matrix:
fast_finish: true
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ module.exports = function(input, map) {

var userOptions = assign(
// user defaults
webpack.options.eslint || {},
(webpack.options && webpack.options.eslint) || webpack.query || {},
// loader query string
loaderUtils.getOptions(webpack)
)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"eslint": "^4.0.0",
"eslint-friendly-formatter": "^2.0.4",
"npmpub": "^3.0.1",
"webpack": "^3.3.0"
"webpack": "^4.0.0"
},
"scripts": {
"lint": "eslint .",
Expand Down
4 changes: 2 additions & 2 deletions test/autofix.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ test.cb("loader doesn't throw error if file ok after auto-fixing",
{
entry: "./test/fixtures/fixable-clone.js",
module: {
loaders: [
rules: [
{
test: /\.js$/,
loader: "./index?fix=true",
use: "./index?fix=true",
exclude: /node_modules/,
},
],
Expand Down
62 changes: 21 additions & 41 deletions test/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var rimraf = require("rimraf")
var webpack = require("webpack")

var defaultCacheDir = path.join(
__dirname,
__dirname,
"../node_modules/.cache/eslint-loader"
)
var cacheDir = path.join(__dirname, "output/cache/cachefiles")
Expand All @@ -16,10 +16,10 @@ var eslintLoader = path.join(__dirname, "../index")
var globalConfig = {
entry: path.join(__dirname, "fixtures/cache.js"),
module: {
loaders: [
rules: [
{
test: /\.js$/,
loader: eslintLoader,
use: eslintLoader,
exclude: /node_modules/,
},
],
Expand Down Expand Up @@ -53,14 +53,11 @@ test.cb("should output files to cache directory", (t) => {
path: t.context.directory,
},
module: {
loaders: [
rules: [
{
test: /\.js$/,
loader: eslintLoader,
use: `${eslintLoader}?cache=${t.context.cache}`,
exclude: /node_modules/,
query: {
cache: t.context.cache,
},
},
],
},
Expand All @@ -78,21 +75,18 @@ test.cb("should output files to cache directory", (t) => {
})
})

test.cb.serial("should output json.gz files to standard cache dir by default",
test.cb.serial("should output json.gz files to standard cache dir by default",
(t) => {
var config = assign({}, globalConfig, {
output: {
path: t.context.directory,
},
module: {
loaders: [
rules: [
{
test: /\.jsx?/,
loader: eslintLoader,
use: `${eslintLoader}?cache=true`,
exclude: /node_modules/,
query: {
cache: true,
},
},
],
},
Expand All @@ -112,17 +106,17 @@ test.cb.serial("should output json.gz files to standard cache dir by default",
})

test.cb.serial(
"should output files to standard cache dir if set to true in query",
"should output files to standard cache dir if set to true in query",
(t) => {
var config = assign({}, globalConfig, {
output: {
path: t.context.directory,
},
module: {
loaders: [
rules: [
{
test: /\.jsx?/,
loader: `${eslintLoader}?cache=true`,
use: `${eslintLoader}?cache=true`,
exclude: /node_modules/,
},
],
Expand All @@ -143,21 +137,18 @@ test.cb.serial(
})
})

test.cb.serial("should read from cache directory if cached file exists",
test.cb.serial("should read from cache directory if cached file exists",
(t) => {
var config = assign({}, globalConfig, {
output: {
path: t.context.directory,
},
module: {
loaders: [
rules: [
{
test: /\.jsx?/,
loader: eslintLoader,
use: `${eslintLoader}?cache=${t.context.cache}`,
exclude: /node_modules/,
query: {
cache: t.context.cache,
},
},
],
},
Expand Down Expand Up @@ -186,14 +177,11 @@ test.cb.serial("should have one file per module", (t) => {
path: t.context.directory,
},
module: {
loaders: [
rules: [
{
test: /\.jsx?/,
loader: eslintLoader,
use: `${eslintLoader}?cache=${t.context.cache}`,
exclude: /node_modules/,
query: {
cache: t.context.cache,
},
},
],
},
Expand All @@ -218,15 +206,11 @@ test.cb.serial("should generate a new file if the identifier changes", (t) => {
path: t.context.directory,
},
module: {
loaders: [
rules: [
{
test: /\.jsx?/,
loader: eslintLoader,
use: `${eslintLoader}?cache=${t.context.cache}&cacheIdentifier=a`,
exclude: /node_modules/,
query: {
cache: t.context.cache,
cacheIdentifier: "a",
},
},
],
},
Expand All @@ -236,15 +220,11 @@ test.cb.serial("should generate a new file if the identifier changes", (t) => {
path: t.context.directory,
},
module: {
loaders: [
rules: [
{
test: /\.jsx?/,
loader: eslintLoader,
use: `${eslintLoader}?cache=${t.context.cache}&cacheIdentifier=b`,
exclude: /node_modules/,
query: {
cache: t.context.cache,
cacheIdentifier: "b",
},
},
],
},
Expand Down Expand Up @@ -284,4 +264,4 @@ function createTestDirectory(baseDirectory, testTitle, cb) {

function escapeDirectory(directory) {
return directory.replace(/[/?<>\\:*|"\s]/g, "_")
}
}
16 changes: 3 additions & 13 deletions test/multiple-engines.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,15 @@ test.cb("eslint-loader will create an engine for each unique config", function(t
{
entry: "./test/fixtures/good.js",
module: {
loaders: [
rules: [
{
test: /\.js$/,
loader: "./index",
query: {
rules: {
quotes: [1, "single"],
},
},
use: "./index?{rules:{quotes:[1,'single']}}",
exclude: /node_modules/,
},
{
test: /\.js$/,
loader: "./index",
query: {
rules: {
semi: [1, "always"],
},
},
use: "./index?{rules:{semi:[1,'always']}}",
exclude: /node_modules/,
},
],
Expand Down
4 changes: 2 additions & 2 deletions test/parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ test.cb("eslint-loader supports query strings parameters", function(t) {
{
entry: "./test/fixtures/good-semi.js",
module: {
loaders: [
rules: [
{
test: /\.js$/,
loader: "./index?{rules:{semi:0}}",
use: "./index?{rules:{semi:0}}",
exclude: /node_modules/,
},
],
Expand Down
30 changes: 16 additions & 14 deletions test/utils/conf.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
var path = require("path")
var assign = require("object-assign")

var webpack = require("webpack")
var webpackVersion = require("./version.js")
var assign = require("object-assign")

var DEFAULT_CONFIG = {
output: {
path: path.join(__dirname, "..", "output") + path.sep,
filename: "bundle.js",
},
module: {
loaders: [
rules: [
{
test: /\.js$/,
loader: "./index",
use: "./index",
exclude: /node_modules/,
},
],
Expand All @@ -27,6 +27,7 @@ var DEFAULT_CONFIG = {
* @returns {Object}
*/
module.exports = function conf(webpackConf, loaderConf) {
var mode = webpackVersion < 4 ? {} : {mode: "development"}

loaderConf = {
eslint: assign({
Expand All @@ -40,16 +41,17 @@ module.exports = function conf(webpackConf, loaderConf) {
// webpack v1 allows loader option to be added directly to the root webpack
// config object
// webpack v2 requires them to be added via the LoaderOptionsPlugin
return assign(DEFAULT_CONFIG, webpackConf,
webpackVersion === "1" ?
loaderConf : {
plugins: [
new webpack.LoaderOptionsPlugin({
exclude: /node_modules/,
options: loaderConf,
}),
],
}
// webpack v4 needs mode option
return assign(DEFAULT_CONFIG,
mode,
webpackConf,
{
plugins: [
new webpack.LoaderOptionsPlugin({
exclude: /node_modules/,
options: loaderConf,
}),
],
}
)

}
Loading