@angular-eslint/utils 20.7.1-alpha.0 → 21.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.
|
@@ -7,9 +7,10 @@ export declare const OPTION_TYPE_ELEMENT = "element";
|
|
|
7
7
|
export type SelectorStyleOption = SelectorStyle | string;
|
|
8
8
|
export type SelectorTypeOption = typeof OPTION_TYPE_ATTRIBUTE | typeof OPTION_TYPE_ELEMENT | string;
|
|
9
9
|
export type SelectorTypeInternal = typeof OPTION_TYPE_ATTRS | typeof OPTION_TYPE_ELEMENT;
|
|
10
|
+
export type SelectorPrefixOption = undefined | string | readonly string[];
|
|
10
11
|
export type SelectorConfig = {
|
|
11
12
|
readonly type: SelectorTypeOption;
|
|
12
|
-
readonly prefix:
|
|
13
|
+
readonly prefix: SelectorPrefixOption;
|
|
13
14
|
readonly style: SelectorStyleOption;
|
|
14
15
|
};
|
|
15
16
|
export type SingleConfigOption = Options[number];
|
|
@@ -18,7 +19,7 @@ export type RuleOptions = readonly [SingleConfigOption | MultipleConfigOption];
|
|
|
18
19
|
export type Options = [
|
|
19
20
|
{
|
|
20
21
|
readonly type: SelectorTypeOption | readonly SelectorTypeOption[];
|
|
21
|
-
readonly prefix:
|
|
22
|
+
readonly prefix: SelectorPrefixOption;
|
|
22
23
|
readonly style: SelectorTypeOption;
|
|
23
24
|
}
|
|
24
25
|
];
|
|
@@ -31,15 +32,15 @@ export declare const SelectorValidator: {
|
|
|
31
32
|
prefix(prefix: string, selectorStyle: string): (selector: string) => boolean;
|
|
32
33
|
selectorAfterPrefix(prefix: string): (selector: string) => boolean;
|
|
33
34
|
};
|
|
34
|
-
export declare const reportPrefixError: (node: TSESTree.Node, prefix:
|
|
35
|
-
export declare const reportSelectorAfterPrefixError: (node: TSESTree.Node, prefix:
|
|
35
|
+
export declare const reportPrefixError: (node: TSESTree.Node, prefix: SelectorPrefixOption, context: Readonly<TSESLint.RuleContext<string, readonly unknown[]>>) => void;
|
|
36
|
+
export declare const reportSelectorAfterPrefixError: (node: TSESTree.Node, prefix: SelectorPrefixOption, context: Readonly<TSESLint.RuleContext<string, readonly unknown[]>>) => void;
|
|
36
37
|
export declare const reportStyleError: (node: TSESTree.Node, style: SelectorStyleOption, context: Readonly<TSESLint.RuleContext<string, readonly unknown[]>>) => void;
|
|
37
|
-
export declare const reportStyleAndPrefixError: (node: TSESTree.Node, style: SelectorStyleOption, prefix:
|
|
38
|
+
export declare const reportStyleAndPrefixError: (node: TSESTree.Node, style: SelectorStyleOption, prefix: SelectorPrefixOption, context: Readonly<TSESLint.RuleContext<string, readonly unknown[]>>) => void;
|
|
38
39
|
export declare const reportTypeError: (node: TSESTree.Node, type: SelectorTypeOption | readonly SelectorTypeOption[], context: Readonly<TSESLint.RuleContext<string, readonly unknown[]>>) => void;
|
|
39
40
|
export declare const parseSelectorNode: (node: TSESTree.Node) => readonly CssSelector[] | null;
|
|
40
41
|
export declare const getActualSelectorType: (node: TSESTree.Node) => SelectorTypeOption | null;
|
|
41
|
-
export declare const checkValidOptions: (type: SelectorTypeOption | readonly SelectorTypeOption[], prefix:
|
|
42
|
-
export declare const checkSelector: (node: TSESTree.Node, typeOption: SelectorTypeOption | readonly SelectorTypeOption[], prefixOption:
|
|
42
|
+
export declare const checkValidOptions: (type: SelectorTypeOption | readonly SelectorTypeOption[], prefix: SelectorPrefixOption, style: SelectorStyleOption) => boolean;
|
|
43
|
+
export declare const checkSelector: (node: TSESTree.Node, typeOption: SelectorTypeOption | readonly SelectorTypeOption[], prefixOption: SelectorPrefixOption, styleOption: SelectorStyle, parsedSelectors?: readonly CssSelector[] | null) => {
|
|
43
44
|
readonly hasExpectedPrefix: boolean;
|
|
44
45
|
readonly hasExpectedType: boolean;
|
|
45
46
|
readonly hasExpectedStyle: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selector-utils.d.ts","sourceRoot":"","sources":["../../src/eslint-plugin/selector-utils.ts"],"names":[],"mappings":"A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AO,CAAC;IAClC,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;IACnC,QAAQ,CAAC,sBAAsB,EAAE,OAAO,CAAC;CAC1C,GAAG,IA0DH,CAAC;AAGF,eAAO,MAAM,sBAAsB,GACjC,QAAQ,kBAAkB,GAAG,oBAAoB,KAChD,MAAM,IAAI,oBAOZ,CAAC;AAGF,eAAO,MAAM,yBAAyB,GACpC,QAAQ,kBAAkB,GAAG,oBAAoB,KAChD,GAAG,CAAC,MAAM,EAAE,cAAc,CA8B5B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAC9B,cAAc,QAAQ,CAAC,IAAI,EAC3B,cAAc,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,KACxC,cAAc,GAAG,IA0BnB,CAAC"}
|
|
@@ -22,7 +22,7 @@ exports.SelectorValidator = {
|
|
|
22
22
|
return selector !== null;
|
|
23
23
|
},
|
|
24
24
|
kebabCase(selector) {
|
|
25
|
-
return /^[a-z0-9-
|
|
25
|
+
return /^[a-z0-9]+(-[a-z0-9]+)*$/.test(selector);
|
|
26
26
|
},
|
|
27
27
|
prefixRegex(prefix) {
|
|
28
28
|
return new RegExp(`^\\[?(${prefix})`);
|
|
@@ -63,21 +63,23 @@ const getValidSelectors = (selectors, types) => {
|
|
|
63
63
|
}, []);
|
|
64
64
|
};
|
|
65
65
|
const reportPrefixError = (node, prefix, context) => {
|
|
66
|
+
const prefixArray = prefix ? (0, utils_1.arrayify)(prefix) : [];
|
|
66
67
|
context.report({
|
|
67
68
|
node,
|
|
68
69
|
messageId: 'prefixFailure',
|
|
69
70
|
data: {
|
|
70
|
-
prefix: (0, utils_1.toHumanReadableText)(
|
|
71
|
+
prefix: (0, utils_1.toHumanReadableText)(prefixArray),
|
|
71
72
|
},
|
|
72
73
|
});
|
|
73
74
|
};
|
|
74
75
|
exports.reportPrefixError = reportPrefixError;
|
|
75
76
|
const reportSelectorAfterPrefixError = (node, prefix, context) => {
|
|
77
|
+
const prefixArray = prefix ? (0, utils_1.arrayify)(prefix) : [];
|
|
76
78
|
context.report({
|
|
77
79
|
node,
|
|
78
80
|
messageId: 'selectorAfterPrefixFailure',
|
|
79
81
|
data: {
|
|
80
|
-
prefix: (0, utils_1.toHumanReadableText)(
|
|
82
|
+
prefix: (0, utils_1.toHumanReadableText)(prefixArray),
|
|
81
83
|
},
|
|
82
84
|
});
|
|
83
85
|
};
|
|
@@ -93,12 +95,13 @@ const reportStyleError = (node, style, context) => {
|
|
|
93
95
|
};
|
|
94
96
|
exports.reportStyleError = reportStyleError;
|
|
95
97
|
const reportStyleAndPrefixError = (node, style, prefix, context) => {
|
|
98
|
+
const prefixArray = prefix ? (0, utils_1.arrayify)(prefix) : [];
|
|
96
99
|
context.report({
|
|
97
100
|
node,
|
|
98
101
|
messageId: 'styleAndPrefixFailure',
|
|
99
102
|
data: {
|
|
100
103
|
style,
|
|
101
|
-
prefix: (0, utils_1.toHumanReadableText)(
|
|
104
|
+
prefix: (0, utils_1.toHumanReadableText)(prefixArray),
|
|
102
105
|
},
|
|
103
106
|
});
|
|
104
107
|
};
|
|
@@ -151,7 +154,12 @@ const checkValidOptions = (type, prefix, style) => {
|
|
|
151
154
|
// Check if options are valid
|
|
152
155
|
const isTypeOptionValid = typeOption.length > 0 &&
|
|
153
156
|
typeOption.every((argument) => [exports.OPTION_TYPE_ELEMENT, exports.OPTION_TYPE_ATTRIBUTE].indexOf(argument) !== -1);
|
|
154
|
-
|
|
157
|
+
// Prefix is optional - allow undefined, empty string, or empty array
|
|
158
|
+
// If provided, it should be non-empty
|
|
159
|
+
const isPrefixOptionValid = prefix === undefined ||
|
|
160
|
+
prefix === '' ||
|
|
161
|
+
(Array.isArray(prefix) && prefix.length === 0) ||
|
|
162
|
+
prefix.length > 0;
|
|
155
163
|
const isStyleOptionValid = [ast_utils_1.OPTION_STYLE_CAMEL_CASE, ast_utils_1.OPTION_STYLE_KEBAB_CASE].indexOf(styleOption) !==
|
|
156
164
|
-1;
|
|
157
165
|
return isTypeOptionValid && isPrefixOptionValid && isStyleOptionValid;
|
|
@@ -169,14 +177,22 @@ const checkSelector = (node, typeOption, prefixOption, styleOption, parsedSelect
|
|
|
169
177
|
return null;
|
|
170
178
|
}
|
|
171
179
|
const validSelectors = getValidSelectors(listSelectors, types);
|
|
172
|
-
|
|
180
|
+
// If no prefix is required (empty or undefined), consider prefix check as passed
|
|
181
|
+
const prefixArray = prefixOption ? (0, utils_1.arrayify)(prefixOption) : [];
|
|
182
|
+
const hasExpectedPrefix = !prefixOption ||
|
|
183
|
+
prefixArray.length === 0 ||
|
|
184
|
+
validSelectors.some((selector) => prefixArray.some((prefix) => exports.SelectorValidator.prefix(prefix, styleOption)(selector)));
|
|
185
|
+
// Style validation should ONLY check if the selector matches the style pattern
|
|
173
186
|
const hasExpectedStyle = validSelectors.some((selector) => styleValidator(selector));
|
|
174
187
|
const hasExpectedType = validSelectors.length > 0;
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
188
|
+
// Only check for selector after prefix if prefix is actually required
|
|
189
|
+
const hasSelectorAfterPrefix = !prefixOption ||
|
|
190
|
+
prefixArray.length === 0 ||
|
|
191
|
+
validSelectors.some((selector) => {
|
|
192
|
+
return prefixArray.some((prefix) => {
|
|
193
|
+
return exports.SelectorValidator.selectorAfterPrefix(prefix)(selector);
|
|
194
|
+
});
|
|
178
195
|
});
|
|
179
|
-
});
|
|
180
196
|
return {
|
|
181
197
|
hasExpectedPrefix,
|
|
182
198
|
hasExpectedType,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@angular-eslint/utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "21.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"typescript": "*"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@angular-eslint/bundled-angular-compiler": "
|
|
25
|
+
"@angular-eslint/bundled-angular-compiler": "21.0.0"
|
|
26
26
|
},
|
|
27
27
|
"nx": {
|
|
28
28
|
"namedInputs": {
|