Skip to content

Commit e0f7d23

Browse files
authored
fix: wrong location reporting in no-invalid-label-refs (#545)
1 parent bae7da7 commit e0f7d23

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

docs/rules/no-invalid-label-refs.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ Examples of **incorrect** code for this rule:
3030
[eslint][ ]
3131

3232
[eslint][
33-
3433
]
3534
```
3635

src/rules/no-invalid-label-refs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function findInvalidLabelReferences(node, sourceCode) {
102102
const startColumn = nodeStartColumn + startColumnOffset;
103103
const endLine = nodeStartLine + endLineOffset;
104104
const endColumn =
105-
(endLine === startLine ? nodeStartColumn : 0) + endColumnOffset;
105+
(endLine === startLine ? nodeStartColumn : 1) + endColumnOffset;
106106

107107
invalid.push({
108108
label: label.trim(),

tests/rules/no-invalid-label-refs.test.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ ruleTester.run("no-invalid-label-refs", rule, {
3131
"[foo][]\n\n[foo]: http://bar.com/image.jpg",
3232
"![foo][]\n\n[foo]: http://bar.com/image.jpg",
3333
"[ foo ][]\n\n[foo]: http://bar.com/image.jpg",
34+
"[eslint][\n\n]",
3435
],
3536
invalid: [
3637
{
@@ -68,7 +69,20 @@ ruleTester.run("no-invalid-label-refs", rule, {
6869
line: 3,
6970
column: 2,
7071
endLine: 4,
71-
endColumn: 1,
72+
endColumn: 2,
73+
},
74+
],
75+
},
76+
{
77+
code: "[\nfoo\n][\n ]\n\n[foo]: http://bar.com/image.jpg",
78+
errors: [
79+
{
80+
messageId: "invalidLabelRef",
81+
data: { label: "foo" },
82+
line: 3,
83+
column: 2,
84+
endLine: 4,
85+
endColumn: 3,
7286
},
7387
],
7488
},
@@ -166,5 +180,31 @@ ruleTester.run("no-invalid-label-refs", rule, {
166180
},
167181
],
168182
},
183+
{
184+
code: "[eslint][ ]",
185+
errors: [
186+
{
187+
messageId: "invalidLabelRef",
188+
data: { label: "eslint" },
189+
line: 1,
190+
column: 9,
191+
endLine: 1,
192+
endColumn: 12,
193+
},
194+
],
195+
},
196+
{
197+
code: "[eslint][\n]",
198+
errors: [
199+
{
200+
messageId: "invalidLabelRef",
201+
data: { label: "eslint" },
202+
line: 1,
203+
column: 9,
204+
endLine: 2,
205+
endColumn: 2,
206+
},
207+
],
208+
},
169209
],
170210
});

0 commit comments

Comments
 (0)