diff --git a/conf/eslint.json b/conf/eslint.json index 033b2d6..73bdd0e 100644 --- a/conf/eslint.json +++ b/conf/eslint.json @@ -34,7 +34,7 @@ "no-fallthrough": 2, "no-floating-decimal": 0, "no-func-assign": 2, - "no-global-strict": 2, + "strict": [2, "function"], "no-implied-eval": 2, "no-invalid-regexp": 2, "no-iterator": 2, @@ -78,7 +78,7 @@ "no-use-before-define": 2, "no-with": 2, "no-wrap-func": 2, - "no-yoda": 2, + "yoda": [2, "never"], "block-scoped-var": 0, "brace-style": 0, diff --git a/eslint.json b/eslint.json index 9d544f4..d4060b3 100644 --- a/eslint.json +++ b/eslint.json @@ -35,7 +35,7 @@ "no-fallthrough": 2, "no-floating-decimal": 0, "no-func-assign": 2, - "no-global-strict": 2, + "global-strict": [2, "never"], "no-implied-eval": 2, "no-invalid-regexp": 2, "no-iterator": 2, @@ -79,7 +79,7 @@ "no-use-before-define": 2, "no-with": 2, "no-wrap-func": 2, - "no-yoda": 2, + "yoda": [2, "never"], "block-scoped-var": 0, "brace-style": [0, "1tbs"], diff --git a/lib/index.js b/lib/index.js index 288811f..e71e534 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,28 +1,22 @@ var Filter = require('broccoli-filter'), - eslint = require('eslint'), - rules = require('eslint/lib/rules'), - Config = require('eslint/lib/config'); + linter = require('eslint').linter, + CLIEngine = require('eslint').CLIEngine; /** * Calculates the severity of a eslint.linter.verify result * @param {Array} result Eslint verify result array - * @param {Object} config Eslint eslint/lib/config * @return {Number} If the returned number is greater than 0 the result contains errors. */ -function getResultSeverity (result, config) { +function getResultSeverity (result) { 'use strict'; // count all errors return result.reduce(function (previous, message) { - var severity; - if (message.fatal) { return previous + 1; } - severity = config.rules[message.ruleId][0] || config.rules[message.ruleId]; - - if (severity === 2) { + if (message.severity === 2) { return previous + 1; } @@ -46,15 +40,15 @@ var EslintValidationFilter = function(inputTree, options) { // set inputTree this.inputTree = inputTree; - // set options defaults - this.options = { - format: options.format ? options.format : undefined, - rulesdir: options.rulesdir ? options.rulesdir : undefined, - config: options.config ? options.config : './node_modules/eslint/conf/eslint.json' - }; + options = options || {}; // set formatter - this.formatter = require(this.options.format ? this.options.format : 'eslint/lib/formatters/stylish'); + this.formatter = require(options.format || 'eslint/lib/formatters/stylish'); + + this.cli = new CLIEngine({ + configFile: options.config || './node_modules/eslint/conf/eslint.json', + rulePaths: options.rulesdir ? [options.rulesdir] : [] + }); }; module.exports = EslintValidationFilter; @@ -65,22 +59,10 @@ EslintValidationFilter.prototype.targetExtension = 'js'; EslintValidationFilter.prototype.processString = function (content, relativePath) { 'use strict'; - var configHelper = new Config({ - config: this.options.config - }), - config, - result, - messages = []; - - // set rulesdir if given - if (this.options.rulesdir) { - rules.load(this.options.rulesdir); - } - - config = configHelper.getConfig(); + var messages = []; // verify file content - result = eslint.linter.verify(content, config); + var result = this.cli.executeOnText(content).results[0].messages; // if verification has result if (result.length) { @@ -92,9 +74,9 @@ EslintValidationFilter.prototype.processString = function (content, relativePath }); // log formatter output - console.log(this.formatter(messages, config)); + console.log(this.formatter(messages)); - if (getResultSeverity(result, config) > 0) { + if (getResultSeverity(result) > 0) { // throw error if severe messages exist throw 'severe rule errors'; } @@ -102,4 +84,4 @@ EslintValidationFilter.prototype.processString = function (content, relativePath // return unmodified string return content; -}; \ No newline at end of file +}; diff --git a/package.json b/package.json index 0149d1b..c5aa447 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "homepage": "https://github.com/makepanic/broccoli-eslint", "dependencies": { "broccoli-filter": "^0.1.6", - "eslint": "^0.4.5" + "eslint": "^0.14.1" }, "devDependencies": { "mocha": "*", diff --git a/test/fixture/1.js b/test/fixture/1.js index 01d35ab..37ee79a 100644 --- a/test/fixture/1.js +++ b/test/fixture/1.js @@ -1 +1 @@ -alert('broccoli'); \ No newline at end of file +alert('broccoli'); diff --git a/test/fixture/2.js b/test/fixture/2.js index 609b7e5..893d5e6 100644 --- a/test/fixture/2.js +++ b/test/fixture/2.js @@ -1 +1 @@ -var broccoli_conf = 'value'; \ No newline at end of file +var broccoli_conf = 'value';