Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update: reporter locr of func-call-spacing (refs #12334) (#13311)
  • Loading branch information
anikethsaha committed Jun 5, 2020
1 parent 353bfe9 commit 27ef73f
Show file tree
Hide file tree
Showing 2 changed files with 168 additions and 16 deletions.
21 changes: 18 additions & 3 deletions lib/rules/func-call-spacing.js
Expand Up @@ -116,7 +116,13 @@ module.exports = {
if (never && hasWhitespace) {
context.report({
node,
loc: leftToken.loc.start,
loc: {
start: leftToken.loc.end,
end: {
line: rightToken.loc.start.line,
column: rightToken.loc.start.column - 1
}
},
messageId: "unexpectedWhitespace",
fix(fixer) {

Expand All @@ -134,7 +140,13 @@ module.exports = {
} else if (!never && !hasWhitespace) {
context.report({
node,
loc: leftToken.loc.start,
loc: {
start: {
line: leftToken.loc.end.line,
column: leftToken.loc.end.column - 1
},
end: rightToken.loc.start
},
messageId: "missing",
fix(fixer) {
return fixer.insertTextBefore(rightToken, " ");
Expand All @@ -143,7 +155,10 @@ module.exports = {
} else if (!never && !allowNewlines && hasNewline) {
context.report({
node,
loc: leftToken.loc.start,
loc: {
start: leftToken.loc.end,
end: rightToken.loc.start
},
messageId: "unexpectedNewline",
fix(fixer) {
return fixer.replaceTextRange([leftToken.range[1], rightToken.range[0]], " ");
Expand Down
163 changes: 150 additions & 13 deletions tests/lib/rules/func-call-spacing.js
Expand Up @@ -236,12 +236,30 @@ ruleTester.run("func-call-spacing", rule, {
{
code: "f.b ();",
output: "f.b();",
errors: [{ messageId: "unexpectedWhitespace", type: "CallExpression", column: 3 }]
errors: [
{
messageId: "unexpectedWhitespace",
type: "CallExpression",
column: 4,
line: 1,
endColumn: 4,
endLine: 1
}
]
},
{
code: "f.b().c ();",
output: "f.b().c();",
errors: [{ messageId: "unexpectedWhitespace", type: "CallExpression", column: 7 }]
errors: [
{
messageId: "unexpectedWhitespace",
type: "CallExpression",
column: 8,
line: 1,
endColumn: 8,
endLine: 1
}
]
},
{
code: "f() ()",
Expand Down Expand Up @@ -335,16 +353,34 @@ ruleTester.run("func-call-spacing", rule, {
errors: [{ messageId: "unexpectedWhitespace", type: "CallExpression" }]
},
{
code: "f.b ();",
code: "f.b ();",
output: "f.b();",
options: ["never"],
errors: [{ messageId: "unexpectedWhitespace", type: "CallExpression", column: 3 }]
errors: [
{
messageId: "unexpectedWhitespace",
type: "CallExpression",
column: 4,
line: 1,
endColumn: 5,
endLine: 1
}
]
},
{
code: "f.b().c ();",
output: "f.b().c();",
options: ["never"],
errors: [{ messageId: "unexpectedWhitespace", type: "CallExpression", column: 7 }]
errors: [
{
messageId: "unexpectedWhitespace",
type: "CallExpression",
column: 8,
line: 1,
endColumn: 8,
endLine: 1
}
]
},
{
code: "f() ()",
Expand Down Expand Up @@ -407,7 +443,11 @@ ruleTester.run("func-call-spacing", rule, {
errors: [
{
messageId: "unexpectedWhitespace",
type: "CallExpression"
type: "CallExpression",
line: 1,
column: 2,
endLine: 2,
endColumn: 0
}
]
},
Expand All @@ -424,7 +464,9 @@ ruleTester.run("func-call-spacing", rule, {
messageId: "unexpectedWhitespace",
type: "CallExpression",
line: 2,
column: 23
column: 24,
endLine: 3,
endColumn: 0
}
]
},
Expand All @@ -440,7 +482,9 @@ ruleTester.run("func-call-spacing", rule, {
messageId: "unexpectedWhitespace",
type: "CallExpression",
line: 1,
column: 9
column: 12,
endLine: 2,
endColumn: 0
}
]
},
Expand All @@ -456,7 +500,9 @@ ruleTester.run("func-call-spacing", rule, {
messageId: "unexpectedWhitespace",
type: "CallExpression",
line: 1,
column: 9
column: 12,
endColumn: 0,
endLine: 2
}
]
},
Expand Down Expand Up @@ -534,13 +580,31 @@ ruleTester.run("func-call-spacing", rule, {
code: "f.b();",
output: "f.b ();",
options: ["always"],
errors: [{ messageId: "missing", type: "CallExpression", column: 3 }]
errors: [
{
messageId: "missing",
type: "CallExpression",
column: 3,
line: 1,
endLine: 1,
endColumn: 4
}
]
},
{
code: "f.b\n();",
output: "f.b ();",
options: ["always"],
errors: [{ messageId: "unexpectedNewline", type: "CallExpression", column: 3 }]
errors: [
{
messageId: "unexpectedNewline",
type: "CallExpression",
column: 4,
line: 1,
endColumn: 1,
endLine: 2
}
]
},
{
code: "f.b().c ();",
Expand All @@ -552,7 +616,16 @@ ruleTester.run("func-call-spacing", rule, {
code: "f.b\n().c ();",
output: "f.b ().c ();",
options: ["always"],
errors: [{ messageId: "unexpectedNewline", type: "CallExpression", column: 3 }]
errors: [
{
messageId: "unexpectedNewline",
type: "CallExpression",
column: 4,
line: 1,
endColumn: 1,
endLine: 2
}
]
},
{
code: "f() ()",
Expand Down Expand Up @@ -664,7 +737,13 @@ ruleTester.run("func-call-spacing", rule, {
code: "f.b();",
output: "f.b ();",
options: ["always", { allowNewlines: true }],
errors: [{ messageId: "missing", type: "CallExpression", column: 3 }]
errors: [
{
messageId: "missing",
type: "CallExpression",
column: 3
}
]
},
{
code: "f.b().c ();",
Expand Down Expand Up @@ -716,6 +795,64 @@ ruleTester.run("func-call-spacing", rule, {
{ messageId: "missing", type: "CallExpression" },
{ messageId: "missing", type: "CallExpression" }
]
},
{
code: "f ();",
output: "f();",
errors: [
{
messageId: "unexpectedWhitespace",
type: "CallExpression",
line: 1,
column: 2,
endLine: 1,
endColumn: 5
}
]
},
{
code: "f\n ();",
output: null,
errors: [
{
messageId: "unexpectedWhitespace",
type: "CallExpression",
line: 1,
column: 2,
endLine: 2,
endColumn: 1
}
]
},
{
code: "fn();",
output: "fn ();",
options: ["always"],
errors: [
{
messageId: "missing",
type: "CallExpression",
line: 1,
column: 2,
endLine: 1,
endColumn: 3
}
]
},
{
code: "fnn\n (a, b);",
output: "fnn (a, b);",
options: ["always"],
errors: [
{
messageId: "unexpectedNewline",
type: "CallExpression",
line: 1,
column: 4,
endLine: 2,
endColumn: 2
}
]
}
]
});

0 comments on commit 27ef73f

Please sign in to comment.