Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support [email protected] #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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"
24 changes: 11 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const CLIEngine = require("eslint").CLIEngine
const join = require("path").join

function createLinter (cli) {
const fmt = cli.getFormatter()
Expand Down Expand Up @@ -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.")
}
})
}
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
77 changes: 43 additions & 34 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -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")
})
})