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

Commit 1697b94

Browse files
deryniMoOx
authored andcommitted
Fixed: outputReport option writes report for last file checked only (#160)
* Interpolate outputReport file placeholders. Fixes #121 Original work by Tomasz Sterna (smokku). * Use outputReport.filePath in the output conditional. Without this a config that used eslint: { outputReport: { formatter: require("eslint/lib/formatters/stylish") } } would create an file named "undefined" in the output path. * Add tests for interpolated outputReport filenames. * Include caught error in failure log. * Add a working test for multiple files in entries.
1 parent 87cec0d commit 1697b94

File tree

5 files changed

+70
-2
lines changed

5 files changed

+70
-2
lines changed

index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function lint(input, config, webpack) {
102102
})
103103
var messages = config.formatter(res.results)
104104

105-
if (config.outputReport) {
105+
if (config.outputReport && config.outputReport.filePath) {
106106
var reportOutput
107107
// if a different formatter is passed in as an option use that
108108
if (config.outputReport.formatter) {
@@ -111,7 +111,14 @@ function lint(input, config, webpack) {
111111
else {
112112
reportOutput = messages
113113
}
114-
webpack.emitFile(config.outputReport.filePath, reportOutput)
114+
var filePath = loaderUtils.interpolateName(webpack,
115+
config.outputReport.filePath, {
116+
content: res.results.map(function(r) {
117+
return r.source
118+
}).join("\n"),
119+
}
120+
)
121+
webpack.emitFile(filePath, reportOutput)
115122
}
116123

117124
// default behavior: emit error only if we have errors

test/fixtures/error-multi-one.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var inone = stuff

test/fixtures/error-multi-two.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var intwo = stuff

test/fixtures/error-multi.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var foo = stuff

test/formatter-multiple-entries.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
var test = require("ava")
2+
var webpack = require("webpack")
3+
var conf = require("./utils/conf")
4+
var fs = require("fs")
5+
6+
test.cb("eslint-loader can be configured to write multiple eslint result files",
7+
function(t) {
8+
var outputFilename = "outputReport-[name].txt"
9+
var outputFilenamesArr = [
10+
"outputReport-error-multi-two.txt",
11+
"outputReport-error-multi-one.txt",
12+
"outputReport-error-multi.txt",
13+
]
14+
var config = conf(
15+
{
16+
entry: [
17+
"./test/fixtures/error-multi-two.js",
18+
"./test/fixtures/error-multi-one.js",
19+
"./test/fixtures/error-multi.js",
20+
],
21+
},
22+
{
23+
formatter: require("eslint/lib/formatters/checkstyle"),
24+
outputReport: {
25+
filePath: outputFilename,
26+
},
27+
}
28+
)
29+
30+
/* Plan for the success count. Failure cases are going to fail anyway so the
31+
* count being off for those cases doesn't matter. */
32+
t.plan(outputFilenamesArr.length * 2)
33+
34+
webpack(config,
35+
function(err, stats) {
36+
if (err) {
37+
throw err
38+
}
39+
40+
for (var i = 0; i < outputFilenamesArr.length; i++) {
41+
var filename = config.output.path + outputFilenamesArr[i]
42+
43+
try {
44+
var contents = fs.readFileSync(filename, "utf8")
45+
46+
t.pass("File '" + filename + "' has been created")
47+
48+
t.is(stats.compilation.errors[i].message, contents,
49+
"File '" + filename + "' Contents should equal output")
50+
}
51+
catch (e) {
52+
t.fail("Expected file '" + filename + "' to have been created:" + e)
53+
}
54+
}
55+
56+
t.end()
57+
})
58+
})

0 commit comments

Comments
 (0)