Skip to content

Commit

Permalink
Fix: no-spaced-func had been crashed (fixes #4508)
Browse files Browse the repository at this point in the history
If the `callee` is enclosed with parentheses and arguments parentheses
are omitted, `no-spaced-func` had been crashed.
  • Loading branch information
mysticatea committed Nov 23, 2015
1 parent ff21d33 commit 828f4cb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
16 changes: 10 additions & 6 deletions lib/rules/no-spaced-func.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,21 @@ module.exports = function(context) {
prevToken = lastCalleeToken,
parenToken = sourceCode.getTokenAfter(lastCalleeToken);

if (sourceCode.getLastToken(node).value !== ")") {
return;
}

while (parenToken.value !== "(") {
// advances to an open parenthesis.
while (
parenToken &&
parenToken.range[1] < node.range[1] &&
parenToken.value !== "("
) {
prevToken = parenToken;
parenToken = sourceCode.getTokenAfter(parenToken);
}

// look for a space between the callee and the open paren
if (sourceCode.isSpaceBetweenTokens(prevToken, parenToken)) {
if (parenToken &&
parenToken.range[1] < node.range[1] &&
sourceCode.isSpaceBetweenTokens(prevToken, parenToken)
) {
context.report({
node: node,
loc: lastCalleeToken.loc.start,
Expand Down
3 changes: 2 additions & 1 deletion tests/lib/rules/no-spaced-func.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ ruleTester.run("no-spaced-func", rule, {
"( f()() )(0)",
"(function(){ if (foo) { bar(); } }());",
"f(0, (1))",
"describe/*.only*/('foo', function () {});"
"describe/**/('foo', function () {});",
"new (foo())"
],
invalid: [
{
Expand Down

0 comments on commit 828f4cb

Please sign in to comment.