diff --git a/.travis.yml b/.travis.yml index aaae543..1b81aa5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: node_js node_js: - - "0.11" - - "0.12" - - "iojs" + - "4" + - "6" + - "7" -script: "npm run test-harmony" +script: "npm run test" diff --git a/index.js b/index.js index 4294963..fdb3f54 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,5 @@ const CLIEngine = require("eslint").CLIEngine +const join = require("path").join function createLinter (cli) { const fmt = cli.getFormatter() @@ -28,20 +29,17 @@ function LinterError(message) { LinterError.prototype = Object.create(Error.prototype) -module.exports = function () { - this.eslint = function (opts) { +module.exports = function (fly) { + fly.plugin("eslint", {every: 0}, function * (files, opts) { const lint = createLinter(new CLIEngine(opts)) - return this.unwrap((files) => { - const problems = files.map(file => lint(file)) - .filter((problem) => problem.errorCount > 0 || problem.warningCount > 0) + const problems = files.map(file => lint(join(file.dir, file.base))) + .filter(problem => problem.errorCount > 0 || problem.warningCount > 0) + const errorCount = problems.reduce(sumProperty("errorCount"), 0) + const warningCount = problems.reduce(sumProperty("warningCount"), 0) - const errorCount = problems.reduce(sumProperty("errorCount"), 0) - const warningCount = problems.reduce(sumProperty("warningCount"), 0) - - if (errorCount > 0 || warningCount > 0) { - throw new LinterError(errorCount + " errors and " + warningCount + " warnings in " + problems.length + " files.") - } - }) - } + if (errorCount > 0 || warningCount > 0) { + throw new LinterError(errorCount + " errors and " + warningCount + " warnings in " + problems.length + " files.") + } + }) } diff --git a/package.json b/package.json index d1787e3..092e3ef 100644 --- a/package.json +++ b/package.json @@ -9,22 +9,21 @@ "lint": "eslint *.js", "setup": "npm i && npm test", "spec": "npm run test | tspec", - "test": "npm run lint && npm run test-harmony", + "test": "npm run lint && tape test/*.js", "build": "echo No build task specified.", - "deploy": "npm run test && git push origin master && npm publish", - "test-harmony": "node --harmony --harmony_arrow_functions ./node_modules/tape/bin/tape test/*.js" + "deploy": "npm run test && git push origin master && npm publish" }, "author": "Jorge Bucaran", "dependencies": { "eslint": ">=0.24.0" }, "devDependencies": { + "fly": "^2.0.5", "tap-spec": "^4.0.2", "tape": "^4.0.0" }, "engines": { - "iojs": ">= 1.0.0", - "node": ">= 0.11.0" + "node": ">= 4.6" }, "keywords": [ "fly", diff --git a/test/index.js b/test/index.js index 5db95e3..ed59abe 100644 --- a/test/index.js +++ b/test/index.js @@ -1,41 +1,50 @@ const test = require("tape").test const join = require("path").join -const fly = {} -const state = { - pass: { - msg: "pass lint", - spec: [join("test", "fixtures", "pass.js")] - }, - fail: { - msg: "fail lint", - spec: [join("test", "fixtures", "fail.js")] - }, - nobleed: { - msg: "pass lint after failed one", - spec: [join("test", "fixtures", "pass.js")] - } + +const Fly = require("fly") +const fixtureDir = join(__dirname,'fixtures') +const eslintOpt = { + configFile: join(fixtureDir, '.eslintrc') } -const unwrap = function (f) { return f(this.spec) } -test("fly-eslint", function (t) { - require("../").call(fly) - t.ok(fly.eslint !== undefined, "inject eslint in fly instance") - run.call(fly, t, state.pass, true) - run.call(fly, t, state.fail, false) - run.call(fly, t, state.nobleed, true) - t.end() +test("pass", t => { + t.plan(2) + const fly = new Fly({ + plugins: [ + require("../") + ], + tasks : { + *foo (f) { + yield f.source(join(fixtureDir, "pass.js")) + .eslint(eslintOpt) + } + } + }) + const message = "should pass lint" + t.true("eslint" in fly.plugins, "attach `eslint()` plugin to fly") + fly.start("foo") + .then(() => t.ok(true, message)) + .catch(() => t.ok(false, message)) }) -function run (t, state, pass) { - try { - this.unwrap = unwrap.bind(state) - this.eslint() - t.ok(pass, state.msg) - } catch (e) { - if (e.name === 'LinterError') { - t.ok(!pass, state.msg) - } else { - throw e +test("fail", t => { + t.plan(2) + const fly = new Fly({ + plugins: [ + require("../") + ], + tasks : { + *foo (f) { + yield f.source(join(fixtureDir, "fail.js")) + .eslint(eslintOpt) + } } - } -} + }) + t.true("eslint" in fly.plugins, "attach `eslint()` plugin to fly") + const message = "should fail lint" + fly.start("foo") + .then(() => t.ok(false, message)) + .catch((e) => { + t.equal(e.name, "LinterError", "should throw LinterError") + }) +})