From 7e5e31cc9af7f4240977dc875c209743be3a6dfb Mon Sep 17 00:00:00 2001 From: orichter Date: Mon, 29 Sep 2014 15:35:58 -0700 Subject: [PATCH] Add .jshintrc overrides handling to stdin processing 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 #1880 --- src/cli.js | 15 ++++++++++++--- tests/cli.js | 18 +++++++++++++++++- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/cli.js b/src/cli.js index 00f962875b..ed94b08045 100644 --- a/src/cli.js +++ b/src/cli.js @@ -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); }); diff --git a/tests/cli.js b/tests/cli.js index 5f61e92b55..f0e4a7b942 100644 --- a/tests/cli.js +++ b/tests/cli.js @@ -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 = []; @@ -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"); @@ -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();