@angular-eslint/eslint-plugin-template 20.0.0-beta.0 → 20.0.0
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.
package/README.md
CHANGED
|
@@ -59,7 +59,7 @@ Please see https://github.com/angular-eslint/angular-eslint for full usage instr
|
|
|
59
59
|
| [`no-call-expression`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin-template/docs/rules/no-call-expression.md) | Disallows calling expressions in templates, except for output handlers | | | | |
|
|
60
60
|
| [`no-distracting-elements`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin-template/docs/rules/no-distracting-elements.md) | [Accessibility] Enforces that no distracting elements are used | | :wrench: | | :accessibility: |
|
|
61
61
|
| [`no-inline-styles`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin-template/docs/rules/no-inline-styles.md) | Disallows the use of inline styles in HTML templates | | | | |
|
|
62
|
-
| [`no-interpolation-in-attributes`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin-template/docs/rules/no-interpolation-in-attributes.md) | Ensures that property-binding is used instead of interpolation in attributes. | |
|
|
62
|
+
| [`no-interpolation-in-attributes`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin-template/docs/rules/no-interpolation-in-attributes.md) | Ensures that property-binding is used instead of interpolation in attributes. | | :wrench: | | |
|
|
63
63
|
| [`no-negated-async`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin-template/docs/rules/no-negated-async.md) | Ensures that async pipe results, as well as values used with the async pipe, are not negated | :white_check_mark: | | :bulb: | |
|
|
64
64
|
| [`no-positive-tabindex`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin-template/docs/rules/no-positive-tabindex.md) | Ensures that the `tabindex` attribute is not positive | | | :bulb: | |
|
|
65
65
|
| [`prefer-at-empty`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin-template/docs/rules/prefer-at-empty.md) | Prefer using `@empty` with `@for` loops instead of a separate `@if` or `@else` block to reduce code and make it easier to read. | | :wrench: | | |
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-interpolation-in-attributes.d.ts","sourceRoot":"","sources":["../../src/rules/no-interpolation-in-attributes.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,OAAO,GAAG,CAAC;IAAE,2BAA2B,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC;AACjE,MAAM,MAAM,UAAU,GAAG,6BAA6B,CAAC;AACvD,eAAO,MAAM,SAAS,mCAAmC,CAAC;;AAY1D,
|
|
1
|
+
{"version":3,"file":"no-interpolation-in-attributes.d.ts","sourceRoot":"","sources":["../../src/rules/no-interpolation-in-attributes.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,OAAO,GAAG,CAAC;IAAE,2BAA2B,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC;AACjE,MAAM,MAAM,UAAU,GAAG,6BAA6B,CAAC;AACvD,eAAO,MAAM,SAAS,mCAAmC,CAAC;;AAY1D,wBA+EG"}
|
|
@@ -34,14 +34,20 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
|
34
34
|
messages: {
|
|
35
35
|
noInterpolationInAttributes: 'Use property binding [attribute]="value" instead of interpolation {{ value }} for an attribute.',
|
|
36
36
|
},
|
|
37
|
+
fixable: 'code',
|
|
37
38
|
},
|
|
38
39
|
defaultOptions: [{ allowSubstringInterpolation: false }],
|
|
39
40
|
create(context, [{ allowSubstringInterpolation }]) {
|
|
40
41
|
const sourceCode = context.sourceCode;
|
|
41
42
|
return {
|
|
42
43
|
['BoundAttribute Interpolation'](interpolation) {
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
const isFullInterpolation = !interpolation.strings.some((str) => str !== '');
|
|
45
|
+
if (allowSubstringInterpolation && !isFullInterpolation) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
// 'parent' is an internal runtime property not declared in the type, hence the 'any' cast.
|
|
49
|
+
const boundAttribute = interpolation.parent?.parent;
|
|
50
|
+
if (!boundAttribute) {
|
|
45
51
|
return;
|
|
46
52
|
}
|
|
47
53
|
const { sourceSpan: { start, end }, } = interpolation;
|
|
@@ -51,6 +57,20 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
|
51
57
|
end: sourceCode.getLocFromIndex(end),
|
|
52
58
|
},
|
|
53
59
|
messageId: 'noInterpolationInAttributes',
|
|
60
|
+
fix: isFullInterpolation
|
|
61
|
+
? (fixer) => {
|
|
62
|
+
const attributeName = boundAttribute.name.trim();
|
|
63
|
+
const exprStart = boundAttribute.valueSpan.start.offset + 2; // +2 to remove '{{'
|
|
64
|
+
const exprEnd = boundAttribute.valueSpan.end.offset - 2; // -2 to remove '}}'
|
|
65
|
+
const expression = sourceCode.text
|
|
66
|
+
.slice(exprStart, exprEnd)
|
|
67
|
+
.trim();
|
|
68
|
+
return fixer.replaceTextRange([
|
|
69
|
+
boundAttribute.keySpan.start.offset,
|
|
70
|
+
boundAttribute.valueSpan.end.offset,
|
|
71
|
+
], `[${attributeName}]="${expression}`);
|
|
72
|
+
}
|
|
73
|
+
: null,
|
|
54
74
|
});
|
|
55
75
|
},
|
|
56
76
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@angular-eslint/eslint-plugin-template",
|
|
3
|
-
"version": "20.0.0
|
|
3
|
+
"version": "20.0.0",
|
|
4
4
|
"description": "ESLint plugin for Angular Templates",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -20,19 +20,19 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"aria-query": "5.3.2",
|
|
22
22
|
"axobject-query": "4.1.0",
|
|
23
|
-
"@angular-eslint/bundled-angular-compiler": "20.0.0
|
|
24
|
-
"@angular-eslint/utils": "20.0.0
|
|
23
|
+
"@angular-eslint/bundled-angular-compiler": "20.0.0",
|
|
24
|
+
"@angular-eslint/utils": "20.0.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/aria-query": "5.0.4",
|
|
28
|
-
"@angular-eslint/test-utils": "20.0.0
|
|
28
|
+
"@angular-eslint/test-utils": "20.0.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"@typescript-eslint/types": "^7.11.0 || ^8.0.0",
|
|
32
32
|
"@typescript-eslint/utils": "^7.11.0 || ^8.0.0",
|
|
33
33
|
"eslint": "^8.57.0 || ^9.0.0",
|
|
34
34
|
"typescript": "*",
|
|
35
|
-
"@angular-eslint/template-parser": "20.0.0
|
|
35
|
+
"@angular-eslint/template-parser": "20.0.0"
|
|
36
36
|
},
|
|
37
37
|
"gitHead": "e2006e5e9c99e5a943d1a999e0efa5247d29ec24"
|
|
38
38
|
}
|