@angular-eslint/eslint-plugin-template 19.4.1-alpha.3 → 19.4.1-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prefer-template-literal.d.ts","sourceRoot":"","sources":["../../src/rules/prefer-template-literal.ts"],"names":[],"mappings":"AAeA,QAAA,MAAM,SAAS,0BAA0B,CAAC;AAE1C,MAAM,MAAM,OAAO,GAAG,EAAE,CAAC;AACzB,MAAM,MAAM,UAAU,GAAG,OAAO,SAAS,CAAC;AAC1C,eAAO,MAAM,SAAS,4BAA4B,CAAC;;AAEnD,
|
|
1
|
+
{"version":3,"file":"prefer-template-literal.d.ts","sourceRoot":"","sources":["../../src/rules/prefer-template-literal.ts"],"names":[],"mappings":"AAeA,QAAA,MAAM,SAAS,0BAA0B,CAAC;AAE1C,MAAM,MAAM,OAAO,GAAG,EAAE,CAAC;AACzB,MAAM,MAAM,UAAU,GAAG,OAAO,SAAS,CAAC;AAC1C,eAAO,MAAM,SAAS,4BAA4B,CAAC;;AAEnD,wBAiJG"}
|
|
@@ -45,6 +45,11 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
|
45
45
|
}
|
|
46
46
|
return '`';
|
|
47
47
|
}
|
|
48
|
+
function hasParentheses(node) {
|
|
49
|
+
const { start, end } = node.sourceSpan;
|
|
50
|
+
const text = sourceCode.text.slice(start - 1, end + 1);
|
|
51
|
+
return text.startsWith('(') && text.endsWith(')');
|
|
52
|
+
}
|
|
48
53
|
context.report({
|
|
49
54
|
loc: {
|
|
50
55
|
start: sourceCode.getLocFromIndex(start),
|
|
@@ -58,13 +63,50 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
|
58
63
|
const quote = getQuote();
|
|
59
64
|
return fixer.replaceTextRange([start, end], `${quote}${(0, literal_primitive_1.getLiteralPrimitiveStringValue)(left, quote)}${(0, literal_primitive_1.getLiteralPrimitiveStringValue)(right, quote)}${quote}`);
|
|
60
65
|
}
|
|
61
|
-
const fixes =
|
|
66
|
+
const fixes = Array();
|
|
67
|
+
const leftHasParentheses = hasParentheses(left);
|
|
68
|
+
const rightHasParentheses = hasParentheses(right);
|
|
69
|
+
// Remove the left first parenthesis if it exists
|
|
70
|
+
if (leftHasParentheses) {
|
|
71
|
+
fixes.push(fixer.removeRange([
|
|
72
|
+
left.sourceSpan.start - 1,
|
|
73
|
+
left.sourceSpan.start,
|
|
74
|
+
]));
|
|
75
|
+
}
|
|
62
76
|
// Fix the left side
|
|
63
77
|
fixes.push(...getLeftSideFixes(fixer, left));
|
|
78
|
+
// Remove the left last parenthesis if it exists
|
|
79
|
+
if (leftHasParentheses) {
|
|
80
|
+
fixes.push(fixer.removeRange([
|
|
81
|
+
left.sourceSpan.end,
|
|
82
|
+
left.sourceSpan.end + 1,
|
|
83
|
+
]));
|
|
84
|
+
}
|
|
64
85
|
// Remove the `+` sign
|
|
65
|
-
fixes.push(fixer.removeRange([
|
|
86
|
+
fixes.push(fixer.removeRange([
|
|
87
|
+
leftHasParentheses
|
|
88
|
+
? left.sourceSpan.end + 1
|
|
89
|
+
: left.sourceSpan.end,
|
|
90
|
+
rightHasParentheses
|
|
91
|
+
? right.sourceSpan.start - 1
|
|
92
|
+
: right.sourceSpan.start,
|
|
93
|
+
]));
|
|
94
|
+
// Remove the right first parenthesis if it exists
|
|
95
|
+
if (rightHasParentheses) {
|
|
96
|
+
fixes.push(fixer.removeRange([
|
|
97
|
+
right.sourceSpan.start - 1,
|
|
98
|
+
right.sourceSpan.start,
|
|
99
|
+
]));
|
|
100
|
+
}
|
|
66
101
|
// Fix the right side
|
|
67
102
|
fixes.push(...getRightSideFixes(fixer, right));
|
|
103
|
+
// Remove the right last parenthesis if it exists
|
|
104
|
+
if (rightHasParentheses) {
|
|
105
|
+
fixes.push(fixer.removeRange([
|
|
106
|
+
right.sourceSpan.end,
|
|
107
|
+
right.sourceSpan.end + 1,
|
|
108
|
+
]));
|
|
109
|
+
}
|
|
68
110
|
return fixes;
|
|
69
111
|
},
|
|
70
112
|
});
|
|
@@ -78,19 +120,17 @@ function getLeftSideFixes(fixer, left) {
|
|
|
78
120
|
// Remove the end ` sign from the left side
|
|
79
121
|
return [fixer.removeRange([end - 1, end])];
|
|
80
122
|
}
|
|
81
|
-
|
|
123
|
+
if ((0, literal_primitive_1.isLiteralPrimitive)(left)) {
|
|
82
124
|
// Transform left side to template literal
|
|
83
125
|
return [
|
|
84
126
|
fixer.replaceTextRange([start, end], `\`${(0, literal_primitive_1.getLiteralPrimitiveStringValue)(left, '`')}`),
|
|
85
127
|
];
|
|
86
128
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
];
|
|
93
|
-
}
|
|
129
|
+
// Transform left side to template literal
|
|
130
|
+
return [
|
|
131
|
+
fixer.insertTextBeforeRange([start, end], '`${'),
|
|
132
|
+
fixer.insertTextAfterRange([start, end], '}'),
|
|
133
|
+
];
|
|
94
134
|
}
|
|
95
135
|
function getRightSideFixes(fixer, right) {
|
|
96
136
|
const { start, end } = right.sourceSpan;
|
|
@@ -98,17 +138,15 @@ function getRightSideFixes(fixer, right) {
|
|
|
98
138
|
// Remove the start ` sign from the right side
|
|
99
139
|
return [fixer.removeRange([start, start + 1])];
|
|
100
140
|
}
|
|
101
|
-
|
|
141
|
+
if ((0, literal_primitive_1.isLiteralPrimitive)(right)) {
|
|
102
142
|
// Transform right side to template literal if it's a string
|
|
103
143
|
return [
|
|
104
144
|
fixer.replaceTextRange([start, end], `${(0, literal_primitive_1.getLiteralPrimitiveStringValue)(right, '`')}\``),
|
|
105
145
|
];
|
|
106
146
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
];
|
|
113
|
-
}
|
|
147
|
+
// Transform right side to template literal
|
|
148
|
+
return [
|
|
149
|
+
fixer.insertTextBeforeRange([start, end], '${'),
|
|
150
|
+
fixer.insertTextAfterRange([start, end], '}`'),
|
|
151
|
+
];
|
|
114
152
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@angular-eslint/eslint-plugin-template",
|
|
3
|
-
"version": "19.4.1-alpha.
|
|
3
|
+
"version": "19.4.1-alpha.5",
|
|
4
4
|
"description": "ESLint plugin for Angular Templates",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -20,13 +20,13 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"aria-query": "5.3.2",
|
|
22
22
|
"axobject-query": "4.1.0",
|
|
23
|
-
"@angular-eslint/bundled-angular-compiler": "19.4.1-alpha.
|
|
24
|
-
"@angular-eslint/utils": "19.4.1-alpha.
|
|
23
|
+
"@angular-eslint/bundled-angular-compiler": "19.4.1-alpha.5",
|
|
24
|
+
"@angular-eslint/utils": "19.4.1-alpha.5"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/aria-query": "5.0.4",
|
|
28
|
-
"@angular-eslint/template-parser": "19.4.1-alpha.
|
|
29
|
-
"@angular-eslint/test-utils": "19.4.1-alpha.
|
|
28
|
+
"@angular-eslint/template-parser": "19.4.1-alpha.5",
|
|
29
|
+
"@angular-eslint/test-utils": "19.4.1-alpha.5"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"@typescript-eslint/types": "^7.11.0 || ^8.0.0",
|