Skip to content

Commit

Permalink
Add .jshintrc overrides handling to stdin processing
Browse files Browse the repository at this point in the history
The new .jshintrc overrides were not being handled by
SublimeLinter-jshint because the --filename flag was not
being passed to the lint() function.  This has been fixed.

Closes jshint#1880
  • Loading branch information
orichter authored and caitp committed Oct 14, 2014
1 parent 2661dd8 commit 7e5e31c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -596,15 +596,24 @@ var exports = {
if (opts.useStdin) {
cli.withStdin(function (code) {
var config = opts.config;
if (opts.filename && !config) {
var filename = path.resolve(opts.filename);
var filename;

// There is an if(filename) check in the lint() function called below.
// passing a filename of undefined is the same as calling the function
// without a filename. If there is no opts.filename, filename remains
// undefined and lint() is effectively called with 4 parameters.
if (opts.filename) {
filename = path.resolve(opts.filename);
}

if (filename && !config) {
config = loadNpmConfig(filename) ||
exports.loadConfig(findConfig(filename));
}

config = config || {};

lint(extract(code, opts.extract), results, config, data);
lint(extract(code, opts.extract), results, config, data, filename);
(opts.reporter || defReporter)(results, data, { verbose: opts.verbose });
cb(results.length === 0);
});
Expand Down
18 changes: 17 additions & 1 deletion tests/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,7 @@ exports.group = {
},

testFilenameOverridesOptionSTDIN: function (test) {
test.expect(4);
var rep = require("../examples/reporter.js");
var stdin = require('mock-stdin').stdin();
var errors = [];
Expand Down Expand Up @@ -1090,7 +1091,7 @@ exports.group = {

sinon.stub(shjs, "test")
.withArgs("-e", sinon.match(/fake\/\.jshintrc$/)).returns(true)
.withArgs("-e", sinon.match(/\.jshintrc$/)).returns(false);
.withArgs("-e", sinon.match(/\.jshintrc$/)).returns(true);

cli.exit.restore();
sinon.stub(cli, "exit");
Expand All @@ -1111,6 +1112,21 @@ exports.group = {

test.equal(errors.length, 1, "should be a single error.");
test.equal(cli.exit.args[0][0], 2, "status code should be 2 when there is a linting error.");

errors.length = 0;
cli.exit.restore();
sinon.stub(cli, "exit");

stdin = require('mock-stdin').stdin();
cli.interpret([
"node", "jshint", "--filename", "fake2/fakescript.js", "--reporter=reporter.js", "-"
]);

stdin.send(bad);
stdin.end();

test.equal(errors.length, 0, "should be no errors.");
test.equal(cli.exit.args[0][0], 0, "status code should be 0 when there is no linting error.");
rep.reporter.restore();
process.cwd.restore();
shjs.cat.restore();
Expand Down

0 comments on commit 7e5e31c

Please sign in to comment.