├── .gitignore ├── test ├── fixtures │ ├── fail.js │ ├── pass.js │ └── .eslintrc └── index.js ├── .travis.yml ├── .editorconfig ├── .eslintrc ├── package.json ├── LICENSE ├── index.js └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | node_modules/ 3 | -------------------------------------------------------------------------------- /test/fixtures/fail.js: -------------------------------------------------------------------------------- 1 | var a = 1 2 | a++ 3 | -------------------------------------------------------------------------------- /test/fixtures/pass.js: -------------------------------------------------------------------------------- 1 | var a = 1; 2 | a++; 3 | -------------------------------------------------------------------------------- /test/fixtures/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "semi": [2, "always"] 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.11" 4 | - "0.12" 5 | - "iojs" 6 | 7 | script: "npm run test-harmony" 8 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 2 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "node": true 4 | }, 5 | "rules": { 6 | "semi": [2, "never"], 7 | "curly": 0, 8 | "strict": 0, 9 | "no-shadow": 0, 10 | "no-use-before-define": 0 11 | }, 12 | "parserOptions": { 13 | "ecmaVersion": 6, 14 | "ecmaFeatures": { 15 | "arrowFunctions": true, 16 | "blockBindings": true 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fly-eslint", 3 | "version": "1.0.0", 4 | "description": "ESLint plugin for Fly", 5 | "license": "MIT", 6 | "repository": "https://github.com/bucaran/fly-eslint", 7 | "main": "index.js", 8 | "scripts": { 9 | "lint": "eslint *.js", 10 | "setup": "npm i && npm test", 11 | "spec": "npm run test | tspec", 12 | "test": "npm run lint && npm run test-harmony", 13 | "build": "echo No build task specified.", 14 | "deploy": "npm run test && git push origin master && npm publish", 15 | "test-harmony": "node --harmony --harmony_arrow_functions ./node_modules/tape/bin/tape test/*.js" 16 | }, 17 | "author": "Jorge Bucaran", 18 | "dependencies": { 19 | "eslint": ">=0.24.0" 20 | }, 21 | "devDependencies": { 22 | "tap-spec": "^4.0.2", 23 | "tape": "^4.0.0" 24 | }, 25 | "engines": { 26 | "iojs": ">= 1.0.0", 27 | "node": ">= 0.11.0" 28 | }, 29 | "keywords": [ 30 | "fly", 31 | "fly-plugin", 32 | "eslint" 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | const test = require("tape").test 2 | const join = require("path").join 3 | const fly = {} 4 | const state = { 5 | pass: { 6 | msg: "pass lint", 7 | spec: [join("test", "fixtures", "pass.js")] 8 | }, 9 | fail: { 10 | msg: "fail lint", 11 | spec: [join("test", "fixtures", "fail.js")] 12 | }, 13 | nobleed: { 14 | msg: "pass lint after failed one", 15 | spec: [join("test", "fixtures", "pass.js")] 16 | } 17 | } 18 | const unwrap = function (f) { return f(this.spec) } 19 | 20 | test("fly-eslint", function (t) { 21 | require("../").call(fly) 22 | t.ok(fly.eslint !== undefined, "inject eslint in fly instance") 23 | run.call(fly, t, state.pass, true) 24 | run.call(fly, t, state.fail, false) 25 | run.call(fly, t, state.nobleed, true) 26 | t.end() 27 | }) 28 | 29 | function run (t, state, pass) { 30 | try { 31 | this.unwrap = unwrap.bind(state) 32 | this.eslint() 33 | t.ok(pass, state.msg) 34 | } catch (e) { 35 | if (e.name === 'LinterError') { 36 | t.ok(!pass, state.msg) 37 | } else { 38 | throw e 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Jorge Bucaran 4 | 5 | Permission is hereby granted, free of charge, to any person 6 | obtaining a copy of this software and associated documentation 7 | files (the "Software"), to deal in the Software without 8 | restriction, including without limitation the rights to use, 9 | copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the 11 | Software is furnished to do so, subject to the following 12 | conditions: 13 | 14 | The above copyright notice and this permission notice shall be 15 | included in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | OTHER DEALINGS IN THE SOFTWARE. 25 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const CLIEngine = require("eslint").CLIEngine 2 | 3 | function createLinter (cli) { 4 | const fmt = cli.getFormatter() 5 | return (file) => { 6 | const report = cli.executeOnFiles([file]) 7 | const msg = fmt(report.results) 8 | 9 | if (msg.length > 0) { 10 | console.warn(msg) 11 | } 12 | 13 | return { 14 | errorCount: parseInt(report.errorCount), 15 | warningCount: parseInt(report.warningCount) 16 | } 17 | } 18 | } 19 | 20 | function sumProperty(key) { 21 | return (count, obj) => count += obj[key] 22 | } 23 | 24 | function LinterError(message) { 25 | this.name = "LinterError" 26 | this.message = message || "" 27 | } 28 | 29 | LinterError.prototype = Object.create(Error.prototype) 30 | 31 | module.exports = function () { 32 | this.eslint = function (opts) { 33 | const lint = createLinter(new CLIEngine(opts)) 34 | 35 | return this.unwrap((files) => { 36 | const problems = files.map(file => lint(file)) 37 | .filter((problem) => problem.errorCount > 0 || problem.warningCount > 0) 38 | 39 | const errorCount = problems.reduce(sumProperty("errorCount"), 0) 40 | const warningCount = problems.reduce(sumProperty("warningCount"), 0) 41 | 42 | if (errorCount > 0 || warningCount > 0) { 43 | throw new LinterError(errorCount + " errors and " + warningCount + " warnings in " + problems.length + " files.") 44 | } 45 | }) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 | 5 |
6 | 7 | > [ESLint](http://eslint.org/) plugin for _[Fly][fly]_. 8 | 9 | [![][fly-badge]][fly] 10 | [![npm package][npm-ver-link]][releases] 11 | [![][dl-badge]][npm-pkg-link] 12 | [![][travis-badge]][travis-link] 13 | [![][mit-badge]][mit] 14 | 15 | ## Usage 16 | > Check out the [documentation](http://eslint.org/docs/user-guide/command-line-interface) to see the available options. 17 | 18 | ### Install 19 | 20 | ```a 21 | npm install -D fly-eslint 22 | ``` 23 | 24 | ### Example 25 | 26 | ```js 27 | export function* test () { 28 | yield this.source("src/**/*.js").eslint() 29 | } 30 | ``` 31 | 32 | # License 33 | 34 | [MIT][mit] © [Jorge Bucaran][author] et [al][contributors] 35 | 36 | 37 | [mit]: http://opensource.org/licenses/MIT 38 | [author]: http://about.bucaran.me 39 | [contributors]: https://github.com/bucaran/fly-eslint/graphs/contributors 40 | [releases]: https://github.com/bucaran/fly-eslint/releases 41 | [fly]: https://www.github.com/flyjs/fly 42 | [fly-badge]: https://img.shields.io/badge/fly-JS-05B3E1.svg?style=flat-square 43 | [mit-badge]: https://img.shields.io/badge/license-MIT-444444.svg?style=flat-square 44 | [npm-pkg-link]: https://www.npmjs.org/package/fly-eslint 45 | [npm-ver-link]: https://img.shields.io/npm/v/fly-eslint.svg?style=flat-square 46 | [dl-badge]: http://img.shields.io/npm/dm/fly-eslint.svg?style=flat-square 47 | [travis-link]: https://travis-ci.org/bucaran/fly-eslint 48 | [travis-badge]: http://img.shields.io/travis/bucaran/fly-eslint.svg?style=flat-square 49 | --------------------------------------------------------------------------------