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

Commit

Permalink
Merge pull request #65 from JamesHenry/master
Browse files Browse the repository at this point in the history
Update ESLint peerDependency and add support for auto-fixing

Close #64
  • Loading branch information
MoOx committed Oct 8, 2015
2 parents 10e664e + 74ff4c8 commit fe762b2
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ function lint(input, config, webpack, callback) {
})
}

// if enabled, use eslint auto-fixing where possible
if (config.fix && res.results[0].output) {
eslint.CLIEngine.outputFixes(res)
}

if (res.errorCount || res.warningCount) {
// add filename for each results so formatter can have relevant filename
res.results.forEach(function(r) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"index.js"
],
"peerDependencies": {
"eslint": "^1.0.0"
"eslint": "^1.6.0"
},
"dependencies": {
"loader-utils": "^0.2.7",
Expand Down
49 changes: 49 additions & 0 deletions test/autofix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
var test = require("tape")
var webpack = require("webpack")
var assign = require("object-assign")
var conf = require("./utils/conf")
var fs = require("fs")

// clone the "fixable" file, so that we do not lose the original contents
// when the fixes are applied to disk
test("setup", function(t) {
fs
.createReadStream("./test/fixtures/fixable.js")
.pipe(fs.createWriteStream("./test/fixtures/fixable-clone.js"))

t.end()
})

test("loader doesn't throw error if file ok after auto-fixing", function(t) {
webpack(assign({},
conf,
{
entry: "./test/fixtures/fixable-clone.js",
module: {
loaders: [
{
test: /\.js$/,
loader: "./index?fix=true",
exclude: /node_modules/,
},
],
},
}
),
function(err, stats) {
if (err) {
throw err
}
// console.log(stats.compilation.errors)
t.notOk(stats.hasErrors(), "a good file doesn't give any error")
// console.log(stats.compilation.warnings)
t.notOk(stats.hasWarnings(), "a good file doesn't give any warning")
t.end()
})
})

// remove the clone
test("teardown", function(t) {
fs.unlinkSync("./test/fixtures/fixable-clone.js")
t.end()
})
7 changes: 7 additions & 0 deletions test/fixtures/fixable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

function foo() {
return true;
}

foo();

0 comments on commit fe762b2

Please sign in to comment.