eslint-plugin-ember-template-lint 0.11.0 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +1 -1
- package/lib/rules/hbs-worker.js +39 -2
- package/lib/rules/lint.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# eslint-plugin-hbs-template
|
2
2
|
|
3
|
-
Provide linting (via [ember-template-lint](https://github.com/ember-template-lint/ember-template-lint)) for hbs templates files, template string literals and gts,gjs
|
3
|
+
Provide linting (via [ember-template-lint](https://github.com/ember-template-lint/ember-template-lint)) for hbs templates files, template string literals and gts,gjs (also enables eslint to run its other rules in gts/gjs)
|
4
4
|
* no extra config file needed
|
5
5
|
|
6
6
|
* no need to run extra tool for linting
|
package/lib/rules/hbs-worker.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
const { runAsWorker } = require('synckit');
|
2
|
-
const { generateDifferences } = require('prettier-linter-helpers');
|
2
|
+
const { generateDifferences, showInvisibles } = require('prettier-linter-helpers');
|
3
3
|
const Document = require('../utils/document');
|
4
4
|
|
5
5
|
async function _applyFixes(options, results, columnOffset) {
|
@@ -19,7 +19,7 @@ async function _applyFixes(options, results, columnOffset) {
|
|
19
19
|
|
20
20
|
let template = currentSource;
|
21
21
|
if (columnOffset) {
|
22
|
-
template = spaces + template.
|
22
|
+
template = spaces + template.replace(/\n([^\n])/g, '\n' + spaces + '$1');
|
23
23
|
}
|
24
24
|
const origDoc = new Document(template);
|
25
25
|
fixableIssues.forEach((r) => {
|
@@ -65,6 +65,43 @@ async function _applyFixes(options, results, columnOffset) {
|
|
65
65
|
diffs.forEach((d) => {
|
66
66
|
d.range = [d.offset - columnOffset, d.offset + (d.deleteText?.length || 0) - columnOffset];
|
67
67
|
});
|
68
|
+
if (ruleName === 'prettier') {
|
69
|
+
const { INSERT, DELETE, REPLACE } = generateDifferences;
|
70
|
+
let message;
|
71
|
+
results.length = 0;
|
72
|
+
diffs.forEach((d) => {
|
73
|
+
switch (d.operation) {
|
74
|
+
case INSERT:
|
75
|
+
message = `Insert \`${showInvisibles(
|
76
|
+
d.insertText
|
77
|
+
)}\``;
|
78
|
+
break;
|
79
|
+
case DELETE:
|
80
|
+
message = `Delete \`${showInvisibles(
|
81
|
+
d.deleteText
|
82
|
+
)}\``;
|
83
|
+
break;
|
84
|
+
case REPLACE:
|
85
|
+
message = `Replace \`${showInvisibles(
|
86
|
+
d.deleteText
|
87
|
+
)}\` with \`${showInvisibles(d.insertText)}\``;
|
88
|
+
break;
|
89
|
+
}
|
90
|
+
const { line, character: column } = origDoc.offsetToPosition(d.offset-columnOffset);
|
91
|
+
const { line: endLine, character: endColumn } = origDoc.offsetToPosition(d.offset + (d.deleteText?.length || 0)-columnOffset);
|
92
|
+
results.push({
|
93
|
+
isFixable: true,
|
94
|
+
rule: ruleName,
|
95
|
+
message,
|
96
|
+
line: line + 1,
|
97
|
+
column,
|
98
|
+
endLine: endLine + 1,
|
99
|
+
endColumn,
|
100
|
+
fix: [d]
|
101
|
+
});
|
102
|
+
});
|
103
|
+
return;
|
104
|
+
}
|
68
105
|
fixableIssues.filter(r => r.rule === ruleName).forEach((r) => {
|
69
106
|
const range = r.range;
|
70
107
|
r.fix = diffs.filter(d => diffContained(d, range) || diffIntersect(d, range));
|
package/lib/rules/lint.js
CHANGED