Skip to content

Commit cfcb390

Browse files
committed
Get a higher fidelity for endLine/endColumn
1 parent 041ae72 commit cfcb390

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

lib/rules/prettier.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,12 @@ module.exports = class Prettier extends Rule {
112112

113113
differences.forEach((difference) => {
114114
let message = "";
115-
let { line, column } = getLocFromIndex(
116-
difference.offset,
115+
// `difference.offset` is the offset from the beginning
116+
// of the template, ie. it is the index
117+
let { offset, deleteText = "" } = difference;
118+
let { line, column } = getLocFromIndex(offset, this.source);
119+
let { line: endLine, column: endColumn } = getLocFromIndex(
120+
offset + deleteText.length,
117121
this.source
118122
);
119123

@@ -139,8 +143,8 @@ module.exports = class Prettier extends Rule {
139143
message,
140144
line,
141145
column,
142-
endLine: line,
143-
endColumn: column,
146+
endLine,
147+
endColumn,
144148
source,
145149
isFixable: true,
146150
});

test/unit/rules/lint-prettier-test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ test
3535
line: 1,
3636
column: 34,
3737
endLine: 1,
38-
endColumn: 34,
38+
endColumn: 35,
3939
source: "{{#my-component}}{{/my-component}}\n",
4040
isFixable: true,
4141
},
@@ -52,8 +52,8 @@ test
5252
message: 'Replace `⏎·data-bar="lol"⏎·····` with ` data-bar="lol"`',
5353
line: 1,
5454
column: 13,
55-
endLine: 1,
56-
endColumn: 13,
55+
endLine: 3,
56+
endColumn: 5,
5757
source: `<div data-foo
5858
data-bar="lol"
5959
some-other-thing={{haha-morethaneightychars}}>
@@ -70,7 +70,7 @@ test
7070
line: 1,
7171
column: 4,
7272
endLine: 1,
73-
endColumn: 4,
73+
endColumn: 5,
7474
source: "test\n",
7575
isFixable: true,
7676
},
@@ -112,7 +112,7 @@ test
112112
line: 2,
113113
column: 6,
114114
endLine: 2,
115-
endColumn: 6,
115+
endColumn: 7,
116116
source:
117117
'{{#my-component class="class1 class2"}}\n test \n\n{{/my-component}}',
118118
isFixable: true,

0 commit comments

Comments
 (0)