From 943d2500a1d1550617dc5bfa85aaf0fbaa508c9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Am=C3=A9rico=20Neto?= Date: Tue, 20 Oct 2015 01:08:26 -0200 Subject: [PATCH 1/2] Change Linter to CLIEngine to use plugins on ESLint --- lib/reporters/eslint/index.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/reporters/eslint/index.js b/lib/reporters/eslint/index.js index c40275db..1017b835 100644 --- a/lib/reporters/eslint/index.js +++ b/lib/reporters/eslint/index.js @@ -35,9 +35,12 @@ function lint(source, config) { // Remove potential Unicode BOM. source = source.replace(/^\uFEFF/, ""); - - var messages = ESLINT.linter.verify(source, config); - results = results.concat(messages); + + var cli = new ESLINT.CLIEngine(); + var messages = cli.executeOnText(source); + + if(messages && messages.results && messages.results.length && messages.results[0].messages) + results = results.concat(messages.results[0].messages); return { results : results, From eb019309dd39a53d5877ff8cc93bf7ee45158f7f Mon Sep 17 00:00:00 2001 From: Conrado Quilles Gomes Date: Sun, 6 Dec 2015 01:21:59 -0200 Subject: [PATCH 2/2] Fixes the pass of eslint config to CLIEngine. Add test to eslint options. Fixes the test of strip comment utility. --- lib/cli.js | 4 +--- lib/reporters/eslint/index.js | 8 +++++--- lib/util.js | 2 +- test/fixtures/.eslintrc.json | 25 +++++++++++++++++++++++++ test/plato_test.js | 18 ++++++++++++++++++ 5 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 test/fixtures/.eslintrc.json diff --git a/lib/cli.js b/lib/cli.js index a88928a6..7b391112 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -45,9 +45,7 @@ exports.exec = function(options, done) { platoOptions.jshint.options = jshintrc; } else if (exports.args.e) { - json = fs.readFileSync(exports.args.e.value).toString(); - jshintrc = JSON.parse(util.stripComments(json)); - platoOptions.eslint = jshintrc; + platoOptions.eslint = exports.args.e.value; } plato.inspect(files, outputDir, platoOptions, done); diff --git a/lib/reporters/eslint/index.js b/lib/reporters/eslint/index.js index 1017b835..24ba101a 100644 --- a/lib/reporters/eslint/index.js +++ b/lib/reporters/eslint/index.js @@ -35,10 +35,12 @@ function lint(source, config) { // Remove potential Unicode BOM. source = source.replace(/^\uFEFF/, ""); - - var cli = new ESLINT.CLIEngine(); + + var cli = new ESLINT.CLIEngine({ + configFile: config + }); var messages = cli.executeOnText(source); - + if(messages && messages.results && messages.results.length && messages.results[0].messages) results = results.concat(messages.results[0].messages); diff --git a/lib/util.js b/lib/util.js index 31e638ae..c823405e 100644 --- a/lib/util.js +++ b/lib/util.js @@ -56,7 +56,7 @@ exports.stripComments = function (str) { /*jshint regexp:false */ str = str || ''; - var multiline = /\/\*(?:(?!\*\/)|.|\n)*?\*\//g; + var multiline = /^[\t\s]*\/\*\*?[^!][\s\S]*?\*\/[\r\n]/gm; var singleline = /\/\/.*/g; return str.replace(multiline, '').replace(singleline, ''); diff --git a/test/fixtures/.eslintrc.json b/test/fixtures/.eslintrc.json new file mode 100644 index 00000000..fada95e4 --- /dev/null +++ b/test/fixtures/.eslintrc.json @@ -0,0 +1,25 @@ +{ + "rules": { + "indent": [ + 2, + 4 + ], + "quotes": [ + 2, + "single" + ], + "linebreak-style": [ + 2, + "windows" + ], + "semi": [ + 2, + "always" + ], + "no-console": 0 + }, + "env": { + "node": true + }, + "extends": "eslint:recommended" +} \ No newline at end of file diff --git a/test/plato_test.js b/test/plato_test.js index c0cfaa0c..f1277498 100644 --- a/test/plato_test.js +++ b/test/plato_test.js @@ -130,5 +130,23 @@ exports['plato'] = { test.ok(overview.summary.total.jshint === 2, 'Should contain total jshint issues'); test.done(); }); + }, + + 'should run eslint with default config' : function(test) { + + var files = [ + 'test/fixtures/a.js', + 'test/fixtures/b.js' + ]; + + test.expect(1); + + plato.inspect(files, null, { + eslint: 'test/fixtures/.eslintrc.json' + }, function(reports) { + var overview = plato.getOverviewReport(reports); + test.ok(overview.summary.total.jshint === 8, 'Should contain total eslint issues'); + test.done(); + }); } };