@angular-eslint/eslint-plugin-template 16.1.3-alpha.7 → 16.2.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/dist/configs/all.json
CHANGED
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"@angular-eslint/template/no-interpolation-in-attributes": "error",
|
|
25
25
|
"@angular-eslint/template/no-negated-async": "error",
|
|
26
26
|
"@angular-eslint/template/no-positive-tabindex": "error",
|
|
27
|
+
"@angular-eslint/template/prefer-ngsrc": "error",
|
|
27
28
|
"@angular-eslint/template/prefer-self-closing-tags": "error",
|
|
28
29
|
"@angular-eslint/template/role-has-required-aria": "error",
|
|
29
30
|
"@angular-eslint/template/table-scope": "error",
|
package/dist/index.js
CHANGED
|
@@ -52,6 +52,7 @@ const no_inline_styles_1 = __importStar(require("./rules/no-inline-styles"));
|
|
|
52
52
|
const no_interpolation_in_attributes_1 = __importStar(require("./rules/no-interpolation-in-attributes"));
|
|
53
53
|
const no_negated_async_1 = __importStar(require("./rules/no-negated-async"));
|
|
54
54
|
const no_positive_tabindex_1 = __importStar(require("./rules/no-positive-tabindex"));
|
|
55
|
+
const prefer_ngsrc_1 = __importStar(require("./rules/prefer-ngsrc"));
|
|
55
56
|
const prefer_self_closing_tags_1 = __importStar(require("./rules/prefer-self-closing-tags"));
|
|
56
57
|
const role_has_required_aria_1 = __importStar(require("./rules/role-has-required-aria"));
|
|
57
58
|
const table_scope_1 = __importStar(require("./rules/table-scope"));
|
|
@@ -89,6 +90,7 @@ module.exports = {
|
|
|
89
90
|
[no_negated_async_1.RULE_NAME]: no_negated_async_1.default,
|
|
90
91
|
[no_positive_tabindex_1.RULE_NAME]: no_positive_tabindex_1.default,
|
|
91
92
|
[prefer_self_closing_tags_1.RULE_NAME]: prefer_self_closing_tags_1.default,
|
|
93
|
+
[prefer_ngsrc_1.RULE_NAME]: prefer_ngsrc_1.default,
|
|
92
94
|
[role_has_required_aria_1.RULE_NAME]: role_has_required_aria_1.default,
|
|
93
95
|
[table_scope_1.RULE_NAME]: table_scope_1.default,
|
|
94
96
|
[use_track_by_function_1.RULE_NAME]: use_track_by_function_1.default,
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RULE_NAME = void 0;
|
|
4
|
+
const utils_1 = require("@angular-eslint/utils");
|
|
5
|
+
const create_eslint_rule_1 = require("../utils/create-eslint-rule");
|
|
6
|
+
exports.RULE_NAME = 'prefer-ngsrc';
|
|
7
|
+
exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
8
|
+
name: exports.RULE_NAME,
|
|
9
|
+
meta: {
|
|
10
|
+
type: 'suggestion',
|
|
11
|
+
docs: {
|
|
12
|
+
description: 'Ensures ngSrc is used instead of src for img elements',
|
|
13
|
+
recommended: false,
|
|
14
|
+
},
|
|
15
|
+
schema: [],
|
|
16
|
+
messages: {
|
|
17
|
+
missingAttribute: 'The attribute [ngSrc] should be used for img elements instead of [src].',
|
|
18
|
+
invalidDoubleSource: 'Only [ngSrc] should exist on an img element. Delete the [src] attribute.',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
defaultOptions: [],
|
|
22
|
+
create(context) {
|
|
23
|
+
const parserServices = (0, utils_1.getTemplateParserServices)(context);
|
|
24
|
+
return {
|
|
25
|
+
'Element$1[name=img]'(element) {
|
|
26
|
+
const ngSrcAttribute = hasNgSrcAttribute(element);
|
|
27
|
+
const srcAttribute = hasNormalSrcAttribute(element);
|
|
28
|
+
if (!srcAttribute) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const loc = parserServices.convertNodeSourceSpanToLoc(srcAttribute.sourceSpan);
|
|
32
|
+
context.report({
|
|
33
|
+
loc,
|
|
34
|
+
messageId: !ngSrcAttribute
|
|
35
|
+
? 'missingAttribute'
|
|
36
|
+
: 'invalidDoubleSource',
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
function hasNgSrcAttribute({ inputs, attributes, }) {
|
|
43
|
+
return [...inputs, ...attributes].find(({ name }) => name === 'ngSrc');
|
|
44
|
+
}
|
|
45
|
+
function hasNormalSrcAttribute({ inputs, attributes, }) {
|
|
46
|
+
return [...inputs, ...attributes].find(({ name }) => name === 'src');
|
|
47
|
+
}
|
|
@@ -42,10 +42,15 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
|
42
42
|
if (!noContent || noCloseTag) {
|
|
43
43
|
return;
|
|
44
44
|
}
|
|
45
|
+
// HTML tags always have more than two characters
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
47
|
+
const openingTagLastChar = startSourceSpan.toString().at(-2);
|
|
48
|
+
const hasOwnWhitespace = openingTagLastChar.trim() === '';
|
|
49
|
+
const closingTagPrefix = hasOwnWhitespace ? '' : ' ';
|
|
45
50
|
context.report({
|
|
46
51
|
loc: parserServices.convertNodeSourceSpanToLoc(endSourceSpan),
|
|
47
52
|
messageId: exports.MESSAGE_ID,
|
|
48
|
-
fix: (fixer) => fixer.replaceTextRange([startSourceSpan.end.offset - 1, endSourceSpan.end.offset], '
|
|
53
|
+
fix: (fixer) => fixer.replaceTextRange([startSourceSpan.end.offset - 1, endSourceSpan.end.offset], closingTagPrefix + '/>'),
|
|
49
54
|
});
|
|
50
55
|
},
|
|
51
56
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@angular-eslint/eslint-plugin-template",
|
|
3
|
-
"version": "16.
|
|
3
|
+
"version": "16.2.0",
|
|
4
4
|
"description": "ESLint plugin for Angular Templates",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"LICENSE"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@angular-eslint/bundled-angular-compiler": "16.
|
|
21
|
-
"@angular-eslint/utils": "16.
|
|
20
|
+
"@angular-eslint/bundled-angular-compiler": "16.2.0",
|
|
21
|
+
"@angular-eslint/utils": "16.2.0",
|
|
22
22
|
"@typescript-eslint/type-utils": "5.62.0",
|
|
23
23
|
"@typescript-eslint/utils": "5.62.0",
|
|
24
24
|
"aria-query": "5.3.0",
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"eslint": "^7.20.0 || ^8.0.0",
|
|
32
32
|
"typescript": "*"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "038422b3f939f2649375975a95e1417171f38ce0"
|
|
35
35
|
}
|