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

Change Linter to CLIEngine to use plugins on ESLint #166

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
4 changes: 1 addition & 3 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 7 additions & 2 deletions lib/reporters/eslint/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@ 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({
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);

return {
results : results,
Expand Down
2 changes: 1 addition & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, '');
Expand Down
25 changes: 25 additions & 0 deletions test/fixtures/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -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"
}
18 changes: 18 additions & 0 deletions test/plato_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}
};