🌐 AI搜索 & 代理 主页
Skip to content

Commit 27ef73f

Browse files
authored
Update: reporter locr of func-call-spacing (refs #12334) (#13311)
1 parent 353bfe9 commit 27ef73f

File tree

2 files changed

+168
-16
lines changed

2 files changed

+168
-16
lines changed

lib/rules/func-call-spacing.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,13 @@ module.exports = {
116116
if (never && hasWhitespace) {
117117
context.report({
118118
node,
119-
loc: leftToken.loc.start,
119+
loc: {
120+
start: leftToken.loc.end,
121+
end: {
122+
line: rightToken.loc.start.line,
123+
column: rightToken.loc.start.column - 1
124+
}
125+
},
120126
messageId: "unexpectedWhitespace",
121127
fix(fixer) {
122128

@@ -134,7 +140,13 @@ module.exports = {
134140
} else if (!never && !hasWhitespace) {
135141
context.report({
136142
node,
137-
loc: leftToken.loc.start,
143+
loc: {
144+
start: {
145+
line: leftToken.loc.end.line,
146+
column: leftToken.loc.end.column - 1
147+
},
148+
end: rightToken.loc.start
149+
},
138150
messageId: "missing",
139151
fix(fixer) {
140152
return fixer.insertTextBefore(rightToken, " ");
@@ -143,7 +155,10 @@ module.exports = {
143155
} else if (!never && !allowNewlines && hasNewline) {
144156
context.report({
145157
node,
146-
loc: leftToken.loc.start,
158+
loc: {
159+
start: leftToken.loc.end,
160+
end: rightToken.loc.start
161+
},
147162
messageId: "unexpectedNewline",
148163
fix(fixer) {
149164
return fixer.replaceTextRange([leftToken.range[1], rightToken.range[0]], " ");

tests/lib/rules/func-call-spacing.js

Lines changed: 150 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,30 @@ ruleTester.run("func-call-spacing", rule, {
236236
{
237237
code: "f.b ();",
238238
output: "f.b();",
239-
errors: [{ messageId: "unexpectedWhitespace", type: "CallExpression", column: 3 }]
239+
errors: [
240+
{
241+
messageId: "unexpectedWhitespace",
242+
type: "CallExpression",
243+
column: 4,
244+
line: 1,
245+
endColumn: 4,
246+
endLine: 1
247+
}
248+
]
240249
},
241250
{
242251
code: "f.b().c ();",
243252
output: "f.b().c();",
244-
errors: [{ messageId: "unexpectedWhitespace", type: "CallExpression", column: 7 }]
253+
errors: [
254+
{
255+
messageId: "unexpectedWhitespace",
256+
type: "CallExpression",
257+
column: 8,
258+
line: 1,
259+
endColumn: 8,
260+
endLine: 1
261+
}
262+
]
245263
},
246264
{
247265
code: "f() ()",
@@ -335,16 +353,34 @@ ruleTester.run("func-call-spacing", rule, {
335353
errors: [{ messageId: "unexpectedWhitespace", type: "CallExpression" }]
336354
},
337355
{
338-
code: "f.b ();",
356+
code: "f.b ();",
339357
output: "f.b();",
340358
options: ["never"],
341-
errors: [{ messageId: "unexpectedWhitespace", type: "CallExpression", column: 3 }]
359+
errors: [
360+
{
361+
messageId: "unexpectedWhitespace",
362+
type: "CallExpression",
363+
column: 4,
364+
line: 1,
365+
endColumn: 5,
366+
endLine: 1
367+
}
368+
]
342369
},
343370
{
344371
code: "f.b().c ();",
345372
output: "f.b().c();",
346373
options: ["never"],
347-
errors: [{ messageId: "unexpectedWhitespace", type: "CallExpression", column: 7 }]
374+
errors: [
375+
{
376+
messageId: "unexpectedWhitespace",
377+
type: "CallExpression",
378+
column: 8,
379+
line: 1,
380+
endColumn: 8,
381+
endLine: 1
382+
}
383+
]
348384
},
349385
{
350386
code: "f() ()",
@@ -407,7 +443,11 @@ ruleTester.run("func-call-spacing", rule, {
407443
errors: [
408444
{
409445
messageId: "unexpectedWhitespace",
410-
type: "CallExpression"
446+
type: "CallExpression",
447+
line: 1,
448+
column: 2,
449+
endLine: 2,
450+
endColumn: 0
411451
}
412452
]
413453
},
@@ -424,7 +464,9 @@ ruleTester.run("func-call-spacing", rule, {
424464
messageId: "unexpectedWhitespace",
425465
type: "CallExpression",
426466
line: 2,
427-
column: 23
467+
column: 24,
468+
endLine: 3,
469+
endColumn: 0
428470
}
429471
]
430472
},
@@ -440,7 +482,9 @@ ruleTester.run("func-call-spacing", rule, {
440482
messageId: "unexpectedWhitespace",
441483
type: "CallExpression",
442484
line: 1,
443-
column: 9
485+
column: 12,
486+
endLine: 2,
487+
endColumn: 0
444488
}
445489
]
446490
},
@@ -456,7 +500,9 @@ ruleTester.run("func-call-spacing", rule, {
456500
messageId: "unexpectedWhitespace",
457501
type: "CallExpression",
458502
line: 1,
459-
column: 9
503+
column: 12,
504+
endColumn: 0,
505+
endLine: 2
460506
}
461507
]
462508
},
@@ -534,13 +580,31 @@ ruleTester.run("func-call-spacing", rule, {
534580
code: "f.b();",
535581
output: "f.b ();",
536582
options: ["always"],
537-
errors: [{ messageId: "missing", type: "CallExpression", column: 3 }]
583+
errors: [
584+
{
585+
messageId: "missing",
586+
type: "CallExpression",
587+
column: 3,
588+
line: 1,
589+
endLine: 1,
590+
endColumn: 4
591+
}
592+
]
538593
},
539594
{
540595
code: "f.b\n();",
541596
output: "f.b ();",
542597
options: ["always"],
543-
errors: [{ messageId: "unexpectedNewline", type: "CallExpression", column: 3 }]
598+
errors: [
599+
{
600+
messageId: "unexpectedNewline",
601+
type: "CallExpression",
602+
column: 4,
603+
line: 1,
604+
endColumn: 1,
605+
endLine: 2
606+
}
607+
]
544608
},
545609
{
546610
code: "f.b().c ();",
@@ -552,7 +616,16 @@ ruleTester.run("func-call-spacing", rule, {
552616
code: "f.b\n().c ();",
553617
output: "f.b ().c ();",
554618
options: ["always"],
555-
errors: [{ messageId: "unexpectedNewline", type: "CallExpression", column: 3 }]
619+
errors: [
620+
{
621+
messageId: "unexpectedNewline",
622+
type: "CallExpression",
623+
column: 4,
624+
line: 1,
625+
endColumn: 1,
626+
endLine: 2
627+
}
628+
]
556629
},
557630
{
558631
code: "f() ()",
@@ -664,7 +737,13 @@ ruleTester.run("func-call-spacing", rule, {
664737
code: "f.b();",
665738
output: "f.b ();",
666739
options: ["always", { allowNewlines: true }],
667-
errors: [{ messageId: "missing", type: "CallExpression", column: 3 }]
740+
errors: [
741+
{
742+
messageId: "missing",
743+
type: "CallExpression",
744+
column: 3
745+
}
746+
]
668747
},
669748
{
670749
code: "f.b().c ();",
@@ -716,6 +795,64 @@ ruleTester.run("func-call-spacing", rule, {
716795
{ messageId: "missing", type: "CallExpression" },
717796
{ messageId: "missing", type: "CallExpression" }
718797
]
798+
},
799+
{
800+
code: "f ();",
801+
output: "f();",
802+
errors: [
803+
{
804+
messageId: "unexpectedWhitespace",
805+
type: "CallExpression",
806+
line: 1,
807+
column: 2,
808+
endLine: 1,
809+
endColumn: 5
810+
}
811+
]
812+
},
813+
{
814+
code: "f\n ();",
815+
output: null,
816+
errors: [
817+
{
818+
messageId: "unexpectedWhitespace",
819+
type: "CallExpression",
820+
line: 1,
821+
column: 2,
822+
endLine: 2,
823+
endColumn: 1
824+
}
825+
]
826+
},
827+
{
828+
code: "fn();",
829+
output: "fn ();",
830+
options: ["always"],
831+
errors: [
832+
{
833+
messageId: "missing",
834+
type: "CallExpression",
835+
line: 1,
836+
column: 2,
837+
endLine: 1,
838+
endColumn: 3
839+
}
840+
]
841+
},
842+
{
843+
code: "fnn\n (a, b);",
844+
output: "fnn (a, b);",
845+
options: ["always"],
846+
errors: [
847+
{
848+
messageId: "unexpectedNewline",
849+
type: "CallExpression",
850+
line: 1,
851+
column: 4,
852+
endLine: 2,
853+
endColumn: 2
854+
}
855+
]
719856
}
720857
]
721858
});

0 commit comments

Comments
 (0)