Skip to content

Commit

Permalink
fix problem of not loading jshintrc file when not supplied options.
Browse files Browse the repository at this point in the history
- cherry-pick of #187 by @sassy
- solved #182
- added test-case for #182
  • Loading branch information
sassy authored and kyungilpark committed Jun 29, 2019
1 parent 597c9a6 commit cdc5d5d
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/reporters/jshint/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ var jsHintCli = require("jshint/src/cli.js");
// Provides a regexp to test for ES6 / ES Modules. If the pass tests then esversion is set to 6 if not already specified.
var esmRegex = /(^\s*|[}\);\n]\s*)(import\s*(['"]|(\*\s+as\s+)?[^"'\(\)\n;]+\s*from\s*['"]|\{)|export\s+\*\s+from\s+["']|export\s* (\{|default|function|class|var|const|let|async\s+function))/;

exports.process = function (source, options/*, reportInfo */) {
exports.process = function (source, options, reportInfo) {
if (options == null || Object.getOwnPropertyNames(options).length === 0) {
options = { options : {}, globals : {}};
var jsHintOptions = jsHintCli.getConfig(source);
var jsHintOptions = jsHintCli.getConfig(reportInfo.file || "");

delete jsHintOptions.dirname;
if (jsHintOptions != null && Object.getOwnPropertyNames(jsHintOptions).length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"boss": true,
"eqnull": true,
"node": true,
"es5": true
"maxparams": 3
}

/* foo */
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/issue_182.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* exceeded maxparams(3)
*/
function foo(a, b, c, d) {
return a + b + c + d;
}

foo();
5 changes: 2 additions & 3 deletions test/issues/issue_16_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ exports['issue_16'] = {

var file = "test/fixtures/issue_16.js",
source = fs.readFileSync(file).toString().trim(),
config = {},
globals = [],
report = linter.process(source, config, globals);
options = {},
report = linter.process(source, options, {});

test.equal(report.messages.length, 0, "Report returned with messages");
test.done();
Expand Down
36 changes: 36 additions & 0 deletions test/issues/issue_182_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';
/**
* #182 the default behavior of JSHint is to look for ".jshintsrc" up the processed file's hierarchy.
* The difference between `.jshintrc` and `test/fixtures/.jshintrc` is maxparams.
* if jshint finds `test/fixtures/.jshintrc` then a maxparams error should occur.
*/
var fs = require('fs-extra'),
linter = require('../../lib/reporters/jshint');

exports['issue_182'] = {
setUp: function(done) {
done();
},

'look for ".jshintsrc" up the processed file hierarchy': function(test) {

var file = "test/fixtures/issue_182.js",
source = fs.readFileSync(file).toString().trim(),
options = {},
reportInfo = {
file : 'test/fixtures/issue_182.js',
fileShort : '',
fileSafe : '',
link : ''
},
report;

report = linter.process(source, options, reportInfo);
test.equal(report.messages.length, 1, "a maxparams error should occur");

report = linter.process(source, options, {});
test.equal(report.messages.length, 0, "no error");

test.done();
}
};
3 changes: 1 addition & 2 deletions test/issues/issue_217_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ exports['issue_217'] = {
"unused": false
})
},
globals = [],
report = linter.process(source, config, globals);
report = linter.process(source, config, {});

test.equal(report.messages.length, 0, "Report returned with messages");
test.done();
Expand Down
2 changes: 1 addition & 1 deletion test/plato_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ exports['plato'] = {
var files = './test/fixtures/*.js';

plato.inspect(files, null, {}, function(reports) {
test.equal(reports.length, 8, 'Should properly test against the array produced by the glob');
test.equal(reports.length, 9, 'Should properly test against the array produced by the glob');
test.done();
});
},
Expand Down

0 comments on commit cdc5d5d

Please sign in to comment.