diff --git a/lib/rules/func-call-spacing.js b/lib/rules/func-call-spacing.js index dccdd0a40c6..5ecb63ecfa7 100644 --- a/lib/rules/func-call-spacing.js +++ b/lib/rules/func-call-spacing.js @@ -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) { @@ -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, " "); @@ -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]], " "); diff --git a/tests/lib/rules/func-call-spacing.js b/tests/lib/rules/func-call-spacing.js index 0774ec4d0c8..f0199fd0a4e 100644 --- a/tests/lib/rules/func-call-spacing.js +++ b/tests/lib/rules/func-call-spacing.js @@ -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() ()", @@ -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() ()", @@ -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 } ] }, @@ -424,7 +464,9 @@ ruleTester.run("func-call-spacing", rule, { messageId: "unexpectedWhitespace", type: "CallExpression", line: 2, - column: 23 + column: 24, + endLine: 3, + endColumn: 0 } ] }, @@ -440,7 +482,9 @@ ruleTester.run("func-call-spacing", rule, { messageId: "unexpectedWhitespace", type: "CallExpression", line: 1, - column: 9 + column: 12, + endLine: 2, + endColumn: 0 } ] }, @@ -456,7 +500,9 @@ ruleTester.run("func-call-spacing", rule, { messageId: "unexpectedWhitespace", type: "CallExpression", line: 1, - column: 9 + column: 12, + endColumn: 0, + endLine: 2 } ] }, @@ -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 ();", @@ -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() ()", @@ -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 ();", @@ -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 + } + ] } ] });