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

Commit

Permalink
Remove duplicate output.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaridmargolin committed Mar 29, 2017
1 parent fd40172 commit c5b3078
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 24 deletions.
36 changes: 33 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict"

var eslint = require("eslint")
var assign = require("object-assign")
var loaderUtils = require("loader-utils")
Expand All @@ -8,6 +10,33 @@ var cache = createCache("eslint-loader")

var engines = {}

/**
* Class representing an ESLintError.
* @extends Error
*/
class ESLintError extends Error {
/**
* Create an ESLintError.
* @param {string} messages - Formatted eslint errors.
*/
constructor(messages) {
super()
this.name = "ESLintError"
this.message = messages
this.stack = ""
}

/**
* Returns a stringified representation of our error. This method is called
* when an error is consumed by console methods
* ex: console.error(new ESLintError(formattedMessage))
* @return {string} error - A stringified representation of the error.
*/
inspect() {
return this.message
}
}

/**
* printLinterOutput
*
Expand Down Expand Up @@ -80,17 +109,18 @@ function printLinterOutput(res, config, webpack) {
}

if (emitter) {
emitter(messages)
if (config.failOnError && res.errorCount) {
throw new Error(
throw new ESLintError(
"Module failed because of a eslint error.\n" + messages
)
}
else if (config.failOnWarning && res.warningCount) {
throw new Error(
throw new ESLintError(
"Module failed because of a eslint warning.\n" + messages
)
}

emitter(webpack.version === 2 ? new ESLintError(messages) : messages)
}
else {
throw new Error(
Expand Down
20 changes: 8 additions & 12 deletions test/formatter-multiple-entries.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
var test = require("ava")
var webpack = require("webpack")
var conf = require("./utils/conf")
var webpackWeirdPrefix = require("./utils/weird-prefix.js")
var fs = require("fs")
var path = require("path")

test.cb("eslint-loader can be configured to write multiple eslint result files",
function(t) {
var outputFilename = "outputReport-[name].txt"
var outputFilenamesArr = [
"outputReport-error-multi-two.txt",
"outputReport-error-multi-one.txt",
"outputReport-error-multi.txt",
]
var config = conf(
{
entry: [
Expand All @@ -30,31 +25,32 @@ function(t) {

/* Plan for the success count. Failure cases are going to fail anyway so the
* count being off for those cases doesn't matter. */
t.plan(outputFilenamesArr.length * 2)
t.plan(config.entry.length * 2)

webpack(config,
function(err, stats) {
if (err) {
throw err
}

for (var i = 0; i < outputFilenamesArr.length; i++) {
var filename = config.output.path + outputFilenamesArr[i]
stats.compilation.errors.forEach(function(error) {
var basename = path.basename(error.module.resource, ".js")
var filename = config.output.path + "outputReport-" + basename + ".txt"

try {
var contents = fs.readFileSync(filename, "utf8")

t.pass("File '" + filename + "' has been created")
t.is(
stats.compilation.errors[i].message,
webpackWeirdPrefix + contents,
error.message,
contents,
"File '" + filename + "' Contents should equal output"
)
}
catch (e) {
t.fail("Expected file '" + filename + "' to have been created:" + e)
}
}
})

t.end()
})
Expand Down
3 changes: 1 addition & 2 deletions test/formatter-write.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
var test = require("ava")
var webpack = require("webpack")
var conf = require("./utils/conf")
var webpackWeirdPrefix = require("./utils/weird-prefix.js")
var fs = require("fs")

test.cb("eslint-loader can be configured to write eslint results to a file",
Expand Down Expand Up @@ -46,7 +45,7 @@ function(t) {

t.is(
stats.compilation.errors[0].message,
webpackWeirdPrefix + contents,
contents,
"File Contents should equal output"
)
}
Expand Down
7 changes: 0 additions & 7 deletions test/utils/weird-prefix.js

This file was deleted.

0 comments on commit c5b3078

Please sign in to comment.