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

Commit

Permalink
Changed: a file that should be ignored doesn't trigger a warning
Browse files Browse the repository at this point in the history
Close #44
  • Loading branch information
MoOx committed Jun 14, 2015
1 parent 4345151 commit d4e5df6
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 36 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 0.13.0 - 2015-06-14

- Changed: a file that should be ignored doesn't trigger a warning
([#44](https://github.com/MoOx/eslint-loader/issues/44))

# 0.12.0 - 2015-06-04

- Changed: upgrade to eslint 0.22.x
Expand Down
77 changes: 43 additions & 34 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,47 +26,56 @@ function lint(input, config, webpack, callback) {
var res = engine.executeOnText(input, resourcePath)
// executeOnText ensure we will have res.results[0] only

// quiet filter done now
// eslint allow rules to be specified in the input between comments
// so we can found warnings defined in the input itself
if (res.warningCount && config.quiet) {
res.warningCount = 0
res.results[0].warningCount = 0
res.results[0].messages = res.results[0].messages.filter(function(message) {
return message.severity !== 1
})
}
// skip ignored file warning
if (!(
res.warningCount === 1 &&
res.results[0].messages[0] &&
res.results[0].messages[0].message &&
res.results[0].messages[0].message.indexOf(".eslintignore") > -1 &&
res.results[0].messages[0].message.indexOf("--no-ignore") > -1
)) {
// quiet filter done now
// eslint allow rules to be specified in the input between comments
// so we can found warnings defined in the input itself
if (res.warningCount && config.quiet) {
res.warningCount = 0
res.results[0].warningCount = 0
res.results[0].messages = res.results[0].messages.filter(function(message) {
return message.severity !== 1
})
}

if (res.errorCount || res.warningCount) {
// 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)
if (res.errorCount || res.warningCount) {
// 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)

// default behavior: emit error only if we have errors
var emitter = res.errorCount ? webpack.emitError : webpack.emitWarning
// default behavior: emit error only if we have errors
var emitter = res.errorCount ? webpack.emitError : webpack.emitWarning

// force emitError or emitWarning if user want this
if (config.emitError) {
emitter = webpack.emitError
}
else if (config.emitWarning) {
emitter = webpack.emitWarning
}
// force emitError or emitWarning if user want this
if (config.emitError) {
emitter = webpack.emitError
}
else if (config.emitWarning) {
emitter = webpack.emitWarning
}

if (emitter) {
emitter(messages)
if (config.failOnError && res.errorCount) {
throw new Error("Module failed because of a eslint error.")
if (emitter) {
emitter(messages)
if (config.failOnError && res.errorCount) {
throw new Error("Module failed because of a eslint error.")
}
else if (config.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.")
else {
throw new Error("Your module system doesn't support emitWarning. Update available? \n" + messages)
}
}
else {
throw new Error("Your module system doesn't support emitWarning. Update available? \n" + messages)
}
}

if (callback) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-loader",
"version": "0.12.0",
"version": "0.13.0",
"description": "eslint loader (for webpack)",
"keywords": [
"lint",
Expand Down
2 changes: 1 addition & 1 deletion test/eslintignore.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test("eslint-loader ignores files present in .eslintignore", function(t) {
function(err, stats) {
if (err) {throw err}

t.ok(stats.hasWarnings(), "an ignored file gives a warning")
t.notOk(stats.hasWarnings(), "an ignored doesn't give a warning")
t.end()
})
})

0 comments on commit d4e5df6

Please sign in to comment.