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

Commit 1bf9bf9

Browse files
mgtitimoliMoOx
authored andcommitted
Now filename is passed to CLIEngine instance executeOnText method
1 parent e45d3f6 commit 1bf9bf9

File tree

4 files changed

+47
-10
lines changed

4 files changed

+47
-10
lines changed

index.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@ var loaderUtils = require("loader-utils")
1414
function lint(input, config, webpack, callback) {
1515
var engine = new eslint.CLIEngine(config)
1616

17-
var res = engine.executeOnText(input)
17+
var resourcePath = webpack.resourcePath
18+
var cwd = process.cwd()
19+
20+
// remove cwd from resource path in case webpack has been started from project
21+
// root, to allow having relative paths in .eslintignore
22+
if (resourcePath.indexOf(cwd) === 0) {
23+
resourcePath = resourcePath.substr(cwd.length + 1)
24+
}
25+
26+
var res = engine.executeOnText(input, resourcePath)
1827
// executeOnText ensure we will have res.results[0] only
1928

2029
// quiet filter done now

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"object-assign": "^2.0.0"
3232
},
3333
"devDependencies": {
34-
"eslint": "^0.19.0",
34+
"eslint": "^0.21.2",
3535
"eslint-friendly-formatter": "^1.0.3",
3636
"tape": "^4.0.0",
3737
"webpack": "^1.8.4"

test/fixtures/ignore.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// this file should be totally ignore since it's present in .eslintignore
2+
var -dasdas;

test/index.js

+34-8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ var conf = {
1717
},
1818
],
1919
},
20+
// this disables the use of .eslintignore, since it contains the fixtures
21+
// folder to skip it on the global linting, but here we want the opposite
22+
// (we only use .eslintignore on the test that checks this)
23+
eslint: {
24+
ignore: false,
25+
},
2026
}
2127

2228
test("eslint-loader don't throw error if file is ok", function(t) {
@@ -56,9 +62,9 @@ test("eslint-loader only returns errors and not warnings if quiet is set", funct
5662
conf,
5763
{
5864
entry: "./test/fixtures/warn.js",
59-
eslint: {
65+
eslint: assign({}, conf.eslint, {
6066
quiet: true,
61-
},
67+
}),
6268
}
6369
),
6470
function(err, stats) {
@@ -90,9 +96,9 @@ test("eslint-loader can force to emit error", function(t) {
9096
conf,
9197
{
9298
entry: "./test/fixtures/warn.js",
93-
eslint: {
99+
eslint: assign({}, conf.eslint, {
94100
emitError: true,
95-
},
101+
}),
96102
}
97103
),
98104
function(err, stats) {
@@ -109,9 +115,9 @@ test("eslint-loader can force to emit warning", function(t) {
109115
conf,
110116
{
111117
entry: "./test/fixtures/error.js",
112-
eslint: {
118+
eslint: assign({}, conf.eslint, {
113119
emitWarning: true,
114-
},
120+
}),
115121
}
116122
),
117123
function(err, stats) {
@@ -145,9 +151,9 @@ test("eslint-loader can use custom formatter", function(t) {
145151
conf,
146152
{
147153
entry: "./test/fixtures/error.js",
148-
eslint: {
154+
eslint: assign({}, conf.eslint, {
149155
formatter: require("eslint-friendly-formatter"),
150-
},
156+
}),
151157
}
152158
),
153159
function(err, stats) {
@@ -184,3 +190,23 @@ test("eslint-loader supports query strings parameters", function(t) {
184190
t.end()
185191
})
186192
})
193+
194+
test("eslint-loader ignores files present in .eslintignore", function(t) {
195+
webpack(assign({},
196+
conf,
197+
{
198+
entry: "./test/fixtures/ignore.js",
199+
eslint: assign({}, conf.eslint, {
200+
// we want to enable ignore, so eslint will parse .eslintignore and
201+
// should skip the file specified above
202+
ignore: true,
203+
}),
204+
}
205+
),
206+
function(err, stats) {
207+
if (err) {throw err}
208+
209+
t.ok(stats.hasWarnings(), "an ignored file gives a warning")
210+
t.end()
211+
})
212+
})

0 commit comments

Comments
 (0)