Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix: func-call-spacing "never" reports wrong message (fixes #13190) (#…
  • Loading branch information
mdjermanovic committed Apr 24, 2020
1 parent bcafd0f commit 8e7a2d9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 53 deletions.
7 changes: 4 additions & 3 deletions lib/rules/func-call-spacing.js
Expand Up @@ -63,7 +63,8 @@ module.exports = {
},

messages: {
unexpected: "Unexpected newline between function name and paren.",
unexpectedWhitespace: "Unexpected whitespace between function name and paren.",
unexpectedNewline: "Unexpected newline between function name and paren.",
missing: "Missing space between function name and paren."
}
},
Expand Down Expand Up @@ -116,7 +117,7 @@ module.exports = {
context.report({
node,
loc: leftToken.loc.start,
messageId: "unexpected",
messageId: "unexpectedWhitespace",
fix(fixer) {

/*
Expand All @@ -143,7 +144,7 @@ module.exports = {
context.report({
node,
loc: leftToken.loc.start,
messageId: "unexpected",
messageId: "unexpectedNewline",
fix(fixer) {
return fixer.replaceTextRange([leftToken.range[1], rightToken.range[0]], " ");
}
Expand Down
100 changes: 50 additions & 50 deletions tests/lib/rules/func-call-spacing.js
Expand Up @@ -226,177 +226,177 @@ ruleTester.run("func-call-spacing", rule, {
{
code: "f ();",
output: "f();",
errors: [{ messageId: "unexpected", type: "CallExpression" }]
errors: [{ messageId: "unexpectedWhitespace", type: "CallExpression" }]
},
{
code: "f (a, b);",
output: "f(a, b);",
errors: [{ messageId: "unexpected", type: "CallExpression" }]
errors: [{ messageId: "unexpectedWhitespace", type: "CallExpression" }]
},
{
code: "f.b ();",
output: "f.b();",
errors: [{ messageId: "unexpected", type: "CallExpression", column: 3 }]
errors: [{ messageId: "unexpectedWhitespace", type: "CallExpression", column: 3 }]
},
{
code: "f.b().c ();",
output: "f.b().c();",
errors: [{ messageId: "unexpected", type: "CallExpression", column: 7 }]
errors: [{ messageId: "unexpectedWhitespace", type: "CallExpression", column: 7 }]
},
{
code: "f() ()",
output: "f()()",
errors: [{ messageId: "unexpected", type: "CallExpression" }]
errors: [{ messageId: "unexpectedWhitespace", type: "CallExpression" }]
},
{
code: "(function() {} ())",
output: "(function() {}())",
errors: [{ messageId: "unexpected", type: "CallExpression" }]
errors: [{ messageId: "unexpectedWhitespace", type: "CallExpression" }]
},
{
code: "var f = new Foo ()",
output: "var f = new Foo()",
errors: [{ messageId: "unexpected", type: "NewExpression" }]
errors: [{ messageId: "unexpectedWhitespace", type: "NewExpression" }]
},
{
code: "f ( (0) )",
output: "f( (0) )",
errors: [{ messageId: "unexpected", type: "CallExpression" }]
errors: [{ messageId: "unexpectedWhitespace", type: "CallExpression" }]
},
{
code: "f(0) (1)",
output: "f(0)(1)",
errors: [{ messageId: "unexpected", type: "CallExpression" }]
errors: [{ messageId: "unexpectedWhitespace", type: "CallExpression" }]
},
{
code: "(f) (0)",
output: "(f)(0)",
errors: [{ messageId: "unexpected", type: "CallExpression" }]
errors: [{ messageId: "unexpectedWhitespace", type: "CallExpression" }]
},
{
code: "f ();\n t ();",
output: "f();\n t();",
errors: [
{ messageId: "unexpected", type: "CallExpression" },
{ messageId: "unexpected", type: "CallExpression" }
{ messageId: "unexpectedWhitespace", type: "CallExpression" },
{ messageId: "unexpectedWhitespace", type: "CallExpression" }
]
},
{
code: "import (source);",
output: "import(source);",
parserOptions: { ecmaVersion: 2020 },
errors: [{ messageId: "unexpected", type: "ImportExpression" }]
errors: [{ messageId: "unexpectedWhitespace", type: "ImportExpression" }]
},

// https://github.com/eslint/eslint/issues/7787
{
code: "f\n();",
output: null, // no change
errors: [{ messageId: "unexpected", type: "CallExpression" }]
errors: [{ messageId: "unexpectedWhitespace", type: "CallExpression" }]
},
{
code: "f\r();",
output: null, // no change
errors: [{ messageId: "unexpected", type: "CallExpression" }]
errors: [{ messageId: "unexpectedWhitespace", type: "CallExpression" }]
},
{
code: "f\u2028();",
output: null, // no change
errors: [{ messageId: "unexpected", type: "CallExpression" }]
errors: [{ messageId: "unexpectedWhitespace", type: "CallExpression" }]
},
{
code: "f\u2029();",
output: null, // no change
errors: [{ messageId: "unexpected", type: "CallExpression" }]
errors: [{ messageId: "unexpectedWhitespace", type: "CallExpression" }]
},
{
code: "f\r\n();",
output: null, // no change
errors: [{ messageId: "unexpected", type: "CallExpression" }]
errors: [{ messageId: "unexpectedWhitespace", type: "CallExpression" }]
},
{
code: "import\n(source);",
output: null,
parserOptions: { ecmaVersion: 2020 },
errors: [{ messageId: "unexpected", type: "ImportExpression" }]
errors: [{ messageId: "unexpectedWhitespace", type: "ImportExpression" }]
},

// "never"
{
code: "f ();",
output: "f();",
options: ["never"],
errors: [{ messageId: "unexpected", type: "CallExpression" }]
errors: [{ messageId: "unexpectedWhitespace", type: "CallExpression" }]
},
{
code: "f (a, b);",
output: "f(a, b);",
options: ["never"],
errors: [{ messageId: "unexpected", type: "CallExpression" }]
errors: [{ messageId: "unexpectedWhitespace", type: "CallExpression" }]
},
{
code: "f.b ();",
output: "f.b();",
options: ["never"],
errors: [{ messageId: "unexpected", type: "CallExpression", column: 3 }]
errors: [{ messageId: "unexpectedWhitespace", type: "CallExpression", column: 3 }]
},
{
code: "f.b().c ();",
output: "f.b().c();",
options: ["never"],
errors: [{ messageId: "unexpected", type: "CallExpression", column: 7 }]
errors: [{ messageId: "unexpectedWhitespace", type: "CallExpression", column: 7 }]
},
{
code: "f() ()",
output: "f()()",
options: ["never"],
errors: [{ messageId: "unexpected", type: "CallExpression" }]
errors: [{ messageId: "unexpectedWhitespace", type: "CallExpression" }]
},
{
code: "(function() {} ())",
output: "(function() {}())",
options: ["never"],
errors: [{ messageId: "unexpected", type: "CallExpression" }]
errors: [{ messageId: "unexpectedWhitespace", type: "CallExpression" }]
},
{
code: "var f = new Foo ()",
output: "var f = new Foo()",
options: ["never"],
errors: [{ messageId: "unexpected", type: "NewExpression" }]
errors: [{ messageId: "unexpectedWhitespace", type: "NewExpression" }]
},
{
code: "f ( (0) )",
output: "f( (0) )",
options: ["never"],
errors: [{ messageId: "unexpected", type: "CallExpression" }]
errors: [{ messageId: "unexpectedWhitespace", type: "CallExpression" }]
},
{
code: "f(0) (1)",
output: "f(0)(1)",
options: ["never"],
errors: [{ messageId: "unexpected", type: "CallExpression" }]
errors: [{ messageId: "unexpectedWhitespace", type: "CallExpression" }]
},
{
code: "(f) (0)",
output: "(f)(0)",
options: ["never"],
errors: [{ messageId: "unexpected", type: "CallExpression" }]
errors: [{ messageId: "unexpectedWhitespace", type: "CallExpression" }]
},
{
code: "f ();\n t ();",
output: "f();\n t();",
options: ["never"],
errors: [
{ messageId: "unexpected", type: "CallExpression" },
{ messageId: "unexpected", type: "CallExpression" }
{ messageId: "unexpectedWhitespace", type: "CallExpression" },
{ messageId: "unexpectedWhitespace", type: "CallExpression" }
]
},
{
code: "import (source);",
output: "import(source);",
options: ["never"],
parserOptions: { ecmaVersion: 2020 },
errors: [{ messageId: "unexpected", type: "ImportExpression" }]
errors: [{ messageId: "unexpectedWhitespace", type: "ImportExpression" }]
},

// https://github.com/eslint/eslint/issues/7787
Expand All @@ -406,7 +406,7 @@ ruleTester.run("func-call-spacing", rule, {
options: ["never"],
errors: [
{
messageId: "unexpected",
messageId: "unexpectedWhitespace",
type: "CallExpression"
}
]
Expand All @@ -421,7 +421,7 @@ ruleTester.run("func-call-spacing", rule, {
options: ["never"],
errors: [
{
messageId: "unexpected",
messageId: "unexpectedWhitespace",
type: "CallExpression",
line: 2,
column: 23
Expand All @@ -437,7 +437,7 @@ ruleTester.run("func-call-spacing", rule, {
options: ["never"],
errors: [
{
messageId: "unexpected",
messageId: "unexpectedWhitespace",
type: "CallExpression",
line: 1,
column: 9
Expand All @@ -453,7 +453,7 @@ ruleTester.run("func-call-spacing", rule, {
options: ["never"],
errors: [
{
messageId: "unexpected",
messageId: "unexpectedWhitespace",
type: "CallExpression",
line: 1,
column: 9
Expand All @@ -466,7 +466,7 @@ ruleTester.run("func-call-spacing", rule, {
options: ["never"],
errors: [
{
messageId: "unexpected",
messageId: "unexpectedWhitespace",
type: "CallExpression"
}
]
Expand All @@ -477,7 +477,7 @@ ruleTester.run("func-call-spacing", rule, {
options: ["never"],
errors: [
{
messageId: "unexpected",
messageId: "unexpectedWhitespace",
type: "CallExpression"
}
]
Expand All @@ -488,7 +488,7 @@ ruleTester.run("func-call-spacing", rule, {
options: ["never"],
errors: [
{
messageId: "unexpected",
messageId: "unexpectedWhitespace",
type: "CallExpression"
}
]
Expand All @@ -499,7 +499,7 @@ ruleTester.run("func-call-spacing", rule, {
options: ["never"],
errors: [
{
messageId: "unexpected",
messageId: "unexpectedWhitespace",
type: "CallExpression"
}
]
Expand All @@ -516,7 +516,7 @@ ruleTester.run("func-call-spacing", rule, {
code: "f\n();",
output: "f ();",
options: ["always"],
errors: [{ messageId: "unexpected", type: "CallExpression" }]
errors: [{ messageId: "unexpectedNewline", type: "CallExpression" }]
},
{
code: "f(a, b);",
Expand All @@ -528,7 +528,7 @@ ruleTester.run("func-call-spacing", rule, {
code: "f\n(a, b);",
output: "f (a, b);",
options: ["always"],
errors: [{ messageId: "unexpected", type: "CallExpression" }]
errors: [{ messageId: "unexpectedNewline", type: "CallExpression" }]
},
{
code: "f.b();",
Expand All @@ -540,7 +540,7 @@ ruleTester.run("func-call-spacing", rule, {
code: "f.b\n();",
output: "f.b ();",
options: ["always"],
errors: [{ messageId: "unexpected", type: "CallExpression", column: 3 }]
errors: [{ messageId: "unexpectedNewline", type: "CallExpression", column: 3 }]
},
{
code: "f.b().c ();",
Expand All @@ -552,7 +552,7 @@ ruleTester.run("func-call-spacing", rule, {
code: "f.b\n().c ();",
output: "f.b ().c ();",
options: ["always"],
errors: [{ messageId: "unexpected", type: "CallExpression", column: 3 }]
errors: [{ messageId: "unexpectedNewline", type: "CallExpression", column: 3 }]
},
{
code: "f() ()",
Expand All @@ -564,14 +564,14 @@ ruleTester.run("func-call-spacing", rule, {
code: "f\n() ()",
output: "f () ()",
options: ["always"],
errors: [{ messageId: "unexpected", type: "CallExpression" }]
errors: [{ messageId: "unexpectedNewline", type: "CallExpression" }]
},
{
code: "f\n()()",
output: "f () ()",
options: ["always"],
errors: [
{ messageId: "unexpected", type: "CallExpression" },
{ messageId: "unexpectedNewline", type: "CallExpression" },
{ messageId: "missing", type: "CallExpression" }
]
},
Expand Down Expand Up @@ -625,25 +625,25 @@ ruleTester.run("func-call-spacing", rule, {
code: "f\r();",
output: "f ();",
options: ["always"],
errors: [{ messageId: "unexpected", type: "CallExpression" }]
errors: [{ messageId: "unexpectedNewline", type: "CallExpression" }]
},
{
code: "f\u2028();",
output: "f ();",
options: ["always"],
errors: [{ messageId: "unexpected", type: "CallExpression" }]
errors: [{ messageId: "unexpectedNewline", type: "CallExpression" }]
},
{
code: "f\u2029();",
output: "f ();",
options: ["always"],
errors: [{ messageId: "unexpected", type: "CallExpression" }]
errors: [{ messageId: "unexpectedNewline", type: "CallExpression" }]
},
{
code: "f\r\n();",
output: "f ();",
options: ["always"],
errors: [{ messageId: "unexpected", type: "CallExpression" }]
errors: [{ messageId: "unexpectedNewline", type: "CallExpression" }]
},

// "always", "allowNewlines": true
Expand Down

0 comments on commit 8e7a2d9

Please sign in to comment.