eslint-plugin-ember-template-lint 0.12.0 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/rules/hbs-worker.js +46 -1
- package/lib/rules/lint.js +1 -1
- package/package.json +1 -1
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) {
|
@@ -53,6 +53,14 @@ async function _applyFixes(options, results, columnOffset) {
|
|
53
53
|
fileConfig,
|
54
54
|
});
|
55
55
|
|
56
|
+
if (ruleName === 'prettier') {
|
57
|
+
const getPrettierOptions = rule.getPrettierOptions;
|
58
|
+
rule.getPrettierOptions = function () {
|
59
|
+
const options = getPrettierOptions.call(this);
|
60
|
+
return Object.assign(options, fileConfig.rules[ruleName]?.config || {});
|
61
|
+
};
|
62
|
+
}
|
63
|
+
|
56
64
|
let visitor = await rule.getVisitor();
|
57
65
|
let { code } = transform(templateInfo.template, () => visitor);
|
58
66
|
|
@@ -65,6 +73,43 @@ async function _applyFixes(options, results, columnOffset) {
|
|
65
73
|
diffs.forEach((d) => {
|
66
74
|
d.range = [d.offset - columnOffset, d.offset + (d.deleteText?.length || 0) - columnOffset];
|
67
75
|
});
|
76
|
+
if (ruleName === 'prettier') {
|
77
|
+
const { INSERT, DELETE, REPLACE } = generateDifferences;
|
78
|
+
let message;
|
79
|
+
results.length = 0;
|
80
|
+
diffs.forEach((d) => {
|
81
|
+
switch (d.operation) {
|
82
|
+
case INSERT:
|
83
|
+
message = `Insert \`${showInvisibles(
|
84
|
+
d.insertText
|
85
|
+
)}\``;
|
86
|
+
break;
|
87
|
+
case DELETE:
|
88
|
+
message = `Delete \`${showInvisibles(
|
89
|
+
d.deleteText
|
90
|
+
)}\``;
|
91
|
+
break;
|
92
|
+
case REPLACE:
|
93
|
+
message = `Replace \`${showInvisibles(
|
94
|
+
d.deleteText
|
95
|
+
)}\` with \`${showInvisibles(d.insertText)}\``;
|
96
|
+
break;
|
97
|
+
}
|
98
|
+
const { line, character: column } = origDoc.offsetToPosition(d.offset-columnOffset);
|
99
|
+
const { line: endLine, character: endColumn } = origDoc.offsetToPosition(d.offset + (d.deleteText?.length || 0)-columnOffset);
|
100
|
+
results.push({
|
101
|
+
isFixable: true,
|
102
|
+
rule: ruleName,
|
103
|
+
message,
|
104
|
+
line: line + 1,
|
105
|
+
column,
|
106
|
+
endLine: endLine + 1,
|
107
|
+
endColumn,
|
108
|
+
fix: [d]
|
109
|
+
});
|
110
|
+
});
|
111
|
+
return;
|
112
|
+
}
|
68
113
|
fixableIssues.filter(r => r.rule === ruleName).forEach((r) => {
|
69
114
|
const range = r.range;
|
70
115
|
r.fix = diffs.filter(d => diffContained(d, range) || diffIntersect(d, range));
|
package/lib/rules/lint.js
CHANGED