Skip to content

Commit

Permalink
Bumping up eslint to latest and changing Linter to CLIEngine
Browse files Browse the repository at this point in the history
### REASON
solve several eslint issues (es-analysis#166, es-analysis#211)
  • Loading branch information
kyungilpark committed Jun 28, 2019
1 parent 5baa923 commit fb8e298
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 12 deletions.
8 changes: 2 additions & 6 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ exports.exec = function(options, done) {
q: !!exports.args.q,
title : exports.args.t && exports.args.t.value,
exclude : exports.args.x && new RegExp(exports.args.x.value),
date : exports.args.D && exports.args.D.value
date : exports.args.D && exports.args.D.value,
eslint: exports.args.e && exports.args.e.value
};
var json;
var jshintrc = {};
Expand All @@ -43,11 +44,6 @@ exports.exec = function(options, done) {
platoOptions.jshint = { globals : jshintrc.globals || {} };
delete jshintrc.globals;
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;
}

plato.inspect(files, outputDir, platoOptions, done);
Expand Down
20 changes: 17 additions & 3 deletions lib/plato.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,25 @@ exports.inspect = function(files, outputDir, options, done) {
jshint : {} // use jshint defaults
};

// TODO: separate jshint and eslint on running `runReports`
if (options.eslint) {
options.jshint = options.eslint;
reporters.jshint = reporters.eslint;
if (typeof options.eslint === "string") {
options.jshint = {
configFile: path.resolve(options.eslint)
};
} else {
options.eslint.baseConfig = options.eslint.baseConfig || {};
["extends", "overrides", "settings"].forEach(function(configKey){
if (options.eslint[configKey]) {
options.eslint.baseConfig[configKey] = options.eslint[configKey];
delete options.eslint[configKey];
}
});
options.jshint = options.eslint;
}
delete options.eslint;
delete reporters.eslint;
reporters.jshint = reporters.eslint;
// delete reporters.eslint; // NOTE: don't delete because can't reuse `inspect`
}

Object.keys(flags).forEach(function(flag){
Expand Down
7 changes: 5 additions & 2 deletions lib/reporters/eslint/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"use strict";

var ESLINT = require("eslint");
// @see http://www.phpied.com/using-eslint-in-a-script/
// @see https://eslint.org/docs/developer-guide/nodejs-api#cliengine
var CLIEngine = require("eslint").CLIEngine;

exports.process = function (source, options/*, reportInfo */) {
var results = lint(source, options);
Expand Down Expand Up @@ -36,7 +38,8 @@ function lint(source, config) {
// Remove potential Unicode BOM.
source = source.replace(/^\uFEFF/, "");

var messages = ESLINT.linter.verify(source, config);
var cli = new CLIEngine(config);
var messages = cli.executeOnText(source).results[0].messages;
results = results.concat(messages);

return {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"analyze"
],
"dependencies": {
"eslint": "~3.0.1",
"eslint": "6.0.1",
"fs-extra": "~0.30.0",
"glob": "~7.0.5",
"jshint": "~2.9.2",
Expand Down
24 changes: 24 additions & 0 deletions test/fixtures/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"rules": {
"indent": [
2,
4
],
"quotes": [
2,
"single"
],
"linebreak-style": [
2
],
"semi": [
2,
"always"
],
"no-console": 0
},
"env": {
"node": true
},
"extends": "eslint:recommended"
}
38 changes: 38 additions & 0 deletions test/plato_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,43 @@ exports['plato'] = {
test.ok(overview.summary.total.jshint === 4, 'Should contain total jshint issues');
test.done();
});
},

'should run eslint with config file' : function(test) {
// #166 test-case
var options = {
eslint: 'test/fixtures/.eslintrc.json'
};
var files = [
'test/fixtures/a.js',
'test/fixtures/b.js'
];

test.expect(1);

plato.inspect(files, null, options, function(reports) {
var overview = plato.getOverviewReport(reports);
test.ok(overview.summary.total.jshint === 8, 'Should contain total eslint issues');
test.done();
});
},

'should run eslint with config object' : function(test) {
// #211 test-case
var options = {
eslint: require('./fixtures/.eslintrc.json')
};
var files = [
'test/fixtures/a.js',
'test/fixtures/b.js'
];

test.expect(1);

plato.inspect(files, null, options, function(reports) {
var overview = plato.getOverviewReport(reports);
test.ok(overview.summary.total.jshint === 8, 'Should contain total eslint issues');
test.done();
});
}
};

0 comments on commit fb8e298

Please sign in to comment.