Skip to content

Commit d104fdf

Browse files
authored
Merge pull request #178 from ember-template-lint/fix-deprecated-log
2 parents 6c4cc03 + cfcb390 commit d104fdf

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

lib/rules/prettier.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,12 @@ module.exports = class Prettier extends Rule {
9090

9191
this.log({
9292
message,
93+
// As of [email protected], passing line and column whose values match the
94+
// reference node's line and column isn't required (it uses the node's line/column).
95+
// In order to support older versions (> 3.8.0), we're keeping these properties here.
9396
line: node.loc && node.loc.start.line,
9497
column: node.loc && node.loc.start.column,
98+
node,
9599
source,
96100
});
97101

@@ -108,8 +112,12 @@ module.exports = class Prettier extends Rule {
108112

109113
differences.forEach((difference) => {
110114
let message = "";
111-
let { line, column } = getLocFromIndex(
112-
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,
113121
this.source
114122
);
115123

@@ -131,7 +139,15 @@ module.exports = class Prettier extends Rule {
131139
break;
132140
}
133141

134-
this.log({ message, line, column, source, isFixable: true });
142+
this.log({
143+
message,
144+
line,
145+
column,
146+
endLine,
147+
endColumn,
148+
source,
149+
isFixable: true,
150+
});
135151
});
136152
}
137153
},

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ test
3434
message: "Delete `⏎`",
3535
line: 1,
3636
column: 34,
37+
endLine: 1,
38+
endColumn: 35,
3739
source: "{{#my-component}}{{/my-component}}\n",
3840
isFixable: true,
3941
},
@@ -50,6 +52,8 @@ test
5052
message: 'Replace `⏎·data-bar="lol"⏎·····` with ` data-bar="lol"`',
5153
line: 1,
5254
column: 13,
55+
endLine: 3,
56+
endColumn: 5,
5357
source: `<div data-foo
5458
data-bar="lol"
5559
some-other-thing={{haha-morethaneightychars}}>
@@ -65,6 +69,8 @@ test
6569
message: "Delete `⏎`",
6670
line: 1,
6771
column: 4,
72+
endLine: 1,
73+
endColumn: 5,
6874
source: "test\n",
6975
isFixable: true,
7076
},
@@ -85,6 +91,8 @@ test
8591
message: "Insert `··`",
8692
line: 2,
8793
column: 1,
94+
endLine: 2,
95+
endColumn: 1,
8896
source: "{{#my-component}}\n\ntest\n\n{{/my-component}}",
8997
isFixable: true,
9098
},
@@ -103,6 +111,8 @@ test
103111
message: "Delete `·`",
104112
line: 2,
105113
column: 6,
114+
endLine: 2,
115+
endColumn: 7,
106116
source:
107117
'{{#my-component class="class1 class2"}}\n test \n\n{{/my-component}}',
108118
isFixable: true,

0 commit comments

Comments
 (0)