Browse files

Merge pull request #436 from goatslacker/GH-435

Fixes GH-435. Call/Apply outside parens now invokes correct warning
  • Loading branch information...
2 parents 020a1fb + 6c23b2b commit efbb3af4f905138df9796ed1b8719bb695d1f93e @valueof valueof committed Feb 7, 2012
Showing with 21 additions and 2 deletions.
  1. +2 −1 jshint.js
  2. +17 −1 tests/unit/fixtures/immed.js
  3. +2 −0 tests/unit/options.js
View
3 jshint.js
@@ -3091,7 +3091,8 @@ loop: for (;;) {
advance(')', this);
nospace(prevtoken, token);
if (option.immed && v.id === 'function') {
- if (nexttoken.id === '(') {
+ if (nexttoken.id === '(' ||
+ (nexttoken.id === '.' && (peek().value === 'call' || peek().value === 'apply'))) {
warning(
"Move the invocation into the parens that contain the function.", nexttoken);
} else {
View
18 tests/unit/fixtures/immed.js
@@ -12,4 +12,20 @@ var c = (function () {
var d = (function () {
return;
-});
+});
+
+var e = (function (a) {
+ return;
+}).call(null, 1);
+
+var f = (function () {
+ return;
+}).apply(null, []);
+
+var g = (function () {
+ return;
+}.apply(null, []));
+
+var h = (function () {
+ return;
+}.call(null, true, undefined));
View
2 tests/unit/options.js
@@ -587,6 +587,8 @@ exports.immed = function () {
.addError(7, "Move the invocation into the parens that contain the function.")
.addError(13, "Do not wrap function literals in parens unless they are to " +
"be immediately invoked.")
+ .addError(19, "Move the invocation into the parens that contain the function.")
+ .addError(23, "Move the invocation into the parens that contain the function.")
.test(src, { immed: true });
};

0 comments on commit efbb3af

Please sign in to comment.