@angular-eslint/eslint-plugin-template 16.0.4-alpha.9 → 16.1.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.
|
@@ -146,9 +146,13 @@ function byLocation(one, other) {
|
|
|
146
146
|
}
|
|
147
147
|
function byOrder(order, alphabetical) {
|
|
148
148
|
return function (one, other) {
|
|
149
|
+
var _a, _b, _c, _d;
|
|
149
150
|
const orderComparison = getOrderIndex(one, order) - getOrderIndex(other, order);
|
|
150
151
|
if (alphabetical && orderComparison === 0) {
|
|
151
|
-
return one.
|
|
152
|
+
return ((_b = (_a = one.keySpan) === null || _a === void 0 ? void 0 : _a.details) !== null && _b !== void 0 ? _b : one.name) >
|
|
153
|
+
((_d = (_c = other.keySpan) === null || _c === void 0 ? void 0 : _c.details) !== null && _d !== void 0 ? _d : other.name)
|
|
154
|
+
? 1
|
|
155
|
+
: -1;
|
|
152
156
|
}
|
|
153
157
|
return orderComparison;
|
|
154
158
|
};
|
|
@@ -175,9 +179,27 @@ function toTemplateReferenceVariableOrderType(reference) {
|
|
|
175
179
|
return Object.assign(Object.assign({}, reference), { orderType: "TEMPLATE_REFERENCE" /* OrderType.TemplateReferenceVariable */ });
|
|
176
180
|
}
|
|
177
181
|
function extractTemplateAttrs(node) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
182
|
+
if (!isTmplAstTemplate(node.parent)) {
|
|
183
|
+
return [];
|
|
184
|
+
}
|
|
185
|
+
/*
|
|
186
|
+
* There may be multiple "attributes" for a structural directive even though
|
|
187
|
+
* there is only a single HTML attribute:
|
|
188
|
+
* e.g. `<ng-container *ngFor="let foo of bar"></ng-container>`
|
|
189
|
+
* will parsed as two attributes (`ngFor` and `ngForOf`)
|
|
190
|
+
*/
|
|
191
|
+
const attrs = node.parent.templateAttrs.map(toStructuralDirectiveOrderType);
|
|
192
|
+
// Pick up on any subsequent `let` bindings, e.g. `index as i`
|
|
193
|
+
let sourceEnd = attrs[attrs.length - 1].sourceSpan.end;
|
|
194
|
+
node.parent.variables.forEach((v) => {
|
|
195
|
+
if (v.sourceSpan.start.offset <= sourceEnd.offset &&
|
|
196
|
+
sourceEnd.offset < v.sourceSpan.end.offset) {
|
|
197
|
+
sourceEnd = v.sourceSpan.end;
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
return [
|
|
201
|
+
Object.assign(Object.assign({}, attrs[0]), { sourceSpan: new bundled_angular_compiler_1.ParseSourceSpan(attrs[0].sourceSpan.start, sourceEnd) }),
|
|
202
|
+
];
|
|
181
203
|
}
|
|
182
204
|
function normalizeInputsOutputs(inputs, outputs) {
|
|
183
205
|
const extractedInputs = inputs
|
|
@@ -200,19 +222,21 @@ function isOnSameLocation(input, output) {
|
|
|
200
222
|
input.sourceSpan.end === output.sourceSpan.end);
|
|
201
223
|
}
|
|
202
224
|
function getMessageName(expected) {
|
|
225
|
+
var _a, _b;
|
|
226
|
+
const fullName = (_b = (_a = expected.keySpan) === null || _a === void 0 ? void 0 : _a.details) !== null && _b !== void 0 ? _b : expected.name;
|
|
203
227
|
switch (expected.orderType) {
|
|
204
228
|
case "STRUCTURAL_DIRECTIVE" /* OrderType.StructuralDirective */:
|
|
205
|
-
return `*${
|
|
229
|
+
return `*${fullName}`;
|
|
206
230
|
case "TEMPLATE_REFERENCE" /* OrderType.TemplateReferenceVariable */:
|
|
207
|
-
return `#${
|
|
231
|
+
return `#${fullName}`;
|
|
208
232
|
case "INPUT_BINDING" /* OrderType.InputBinding */:
|
|
209
|
-
return `[${
|
|
233
|
+
return `[${fullName}]`;
|
|
210
234
|
case "OUTPUT_BINDING" /* OrderType.OutputBinding */:
|
|
211
|
-
return `(${
|
|
235
|
+
return `(${fullName})`;
|
|
212
236
|
case "TWO_WAY_BINDING" /* OrderType.TwoWayBinding */:
|
|
213
|
-
return `[(${
|
|
237
|
+
return `[(${fullName})]`;
|
|
214
238
|
default:
|
|
215
|
-
return
|
|
239
|
+
return fullName;
|
|
216
240
|
}
|
|
217
241
|
}
|
|
218
242
|
function getStartPos(expected) {
|
|
@@ -7,6 +7,7 @@ const get_original_attribute_name_1 = require("../utils/get-original-attribute-n
|
|
|
7
7
|
exports.RULE_NAME = 'no-duplicate-attributes';
|
|
8
8
|
const DEFAULT_OPTIONS = {
|
|
9
9
|
allowTwoWayDataBinding: true,
|
|
10
|
+
allowStylePrecedenceDuplicates: false,
|
|
10
11
|
ignore: [],
|
|
11
12
|
};
|
|
12
13
|
exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
@@ -27,6 +28,11 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
|
27
28
|
default: DEFAULT_OPTIONS.allowTwoWayDataBinding,
|
|
28
29
|
description: `Whether or not two-way data binding is allowed as an exception to the rule.`,
|
|
29
30
|
},
|
|
31
|
+
allowStylePrecedenceDuplicates: {
|
|
32
|
+
type: 'boolean',
|
|
33
|
+
default: DEFAULT_OPTIONS.allowStylePrecedenceDuplicates,
|
|
34
|
+
description: `Whether or not Angular style precedence is allowed as an exception to the rule. See https://angular.io/guide/style-precedence#style-precedence`,
|
|
35
|
+
},
|
|
30
36
|
ignore: {
|
|
31
37
|
type: 'array',
|
|
32
38
|
items: { type: 'string' },
|
|
@@ -44,14 +50,37 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
|
44
50
|
},
|
|
45
51
|
},
|
|
46
52
|
defaultOptions: [DEFAULT_OPTIONS],
|
|
47
|
-
create(context, [{ allowTwoWayDataBinding, ignore }]) {
|
|
53
|
+
create(context, [{ allowTwoWayDataBinding, allowStylePrecedenceDuplicates, ignore }]) {
|
|
48
54
|
const parserServices = (0, utils_1.getTemplateParserServices)(context);
|
|
49
55
|
return {
|
|
50
56
|
Element$1({ inputs, outputs, attributes }) {
|
|
51
|
-
|
|
57
|
+
// According to the Angular documentation (https://angular.io/guide/style-precedence#style-precedence)
|
|
58
|
+
// Angular merges both attributes which means their combined use can be seen as valid
|
|
59
|
+
const angularStylePrecedenceDuplicatesAllowed = ['class', 'style'];
|
|
60
|
+
let duplicateInputsAndAttributes = findDuplicates([
|
|
52
61
|
...inputs,
|
|
53
62
|
...attributes,
|
|
54
63
|
]);
|
|
64
|
+
if (allowStylePrecedenceDuplicates) {
|
|
65
|
+
const inputsIgnored = inputs.filter((input) => angularStylePrecedenceDuplicatesAllowed.includes((0, get_original_attribute_name_1.getOriginalAttributeName)(input)));
|
|
66
|
+
if ((inputsIgnored === null || inputsIgnored === void 0 ? void 0 : inputsIgnored.length) > 0) {
|
|
67
|
+
const attributesIgnored = attributes.filter((attr) => angularStylePrecedenceDuplicatesAllowed.includes((0, get_original_attribute_name_1.getOriginalAttributeName)(attr)));
|
|
68
|
+
const inputsNotIgnored = inputs.filter((input) => !inputsIgnored.includes(input));
|
|
69
|
+
const attributesNotIgnored = attributes.filter((attr) => !attributesIgnored.includes(attr));
|
|
70
|
+
const ignoreDuplicated = [
|
|
71
|
+
...findDuplicates(inputsIgnored),
|
|
72
|
+
...findDuplicates(attributesIgnored),
|
|
73
|
+
];
|
|
74
|
+
const notIgnoredDuplicates = [
|
|
75
|
+
...findDuplicates(inputsNotIgnored),
|
|
76
|
+
...findDuplicates(attributesNotIgnored),
|
|
77
|
+
];
|
|
78
|
+
duplicateInputsAndAttributes = [
|
|
79
|
+
...ignoreDuplicated,
|
|
80
|
+
...notIgnoredDuplicates,
|
|
81
|
+
];
|
|
82
|
+
}
|
|
83
|
+
}
|
|
55
84
|
const filteredOutputs = allowTwoWayDataBinding
|
|
56
85
|
? outputs.filter((output) => {
|
|
57
86
|
return !inputs.some((input) => input.sourceSpan.start === output.sourceSpan.start &&
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@angular-eslint/eslint-plugin-template",
|
|
3
|
-
"version": "16.0
|
|
3
|
+
"version": "16.1.0",
|
|
4
4
|
"description": "ESLint plugin for Angular Templates",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
"LICENSE"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@angular-eslint/bundled-angular-compiler": "16.0
|
|
21
|
-
"@angular-eslint/utils": "16.0
|
|
22
|
-
"@typescript-eslint/type-utils": "5.
|
|
23
|
-
"@typescript-eslint/utils": "5.
|
|
24
|
-
"aria-query": "5.
|
|
20
|
+
"@angular-eslint/bundled-angular-compiler": "16.1.0",
|
|
21
|
+
"@angular-eslint/utils": "16.1.0",
|
|
22
|
+
"@typescript-eslint/type-utils": "5.62.0",
|
|
23
|
+
"@typescript-eslint/utils": "5.62.0",
|
|
24
|
+
"aria-query": "5.3.0",
|
|
25
25
|
"axobject-query": "3.1.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"eslint": "^7.20.0 || ^8.0.0",
|
|
32
32
|
"typescript": "*"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "dce6381cafcbe2de109d0a53b4c9c3e3bf1ae569"
|
|
35
35
|
}
|