@depup/angular-eslint__utils 21.3.1-depup.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/LICENSE +21 -0
- package/README.md +25 -0
- package/changes.json +5 -0
- package/dist/eslint-plugin/ast-utils.d.ts +161 -0
- package/dist/eslint-plugin/ast-utils.d.ts.map +1 -0
- package/dist/eslint-plugin/ast-utils.js +465 -0
- package/dist/eslint-plugin/comment-utils.d.ts +11 -0
- package/dist/eslint-plugin/comment-utils.d.ts.map +1 -0
- package/dist/eslint-plugin/comment-utils.js +89 -0
- package/dist/eslint-plugin/get-aria-attribute-keys.d.ts +2 -0
- package/dist/eslint-plugin/get-aria-attribute-keys.d.ts.map +1 -0
- package/dist/eslint-plugin/get-aria-attribute-keys.js +56 -0
- package/dist/eslint-plugin/get-native-event-names.d.ts +12 -0
- package/dist/eslint-plugin/get-native-event-names.d.ts.map +1 -0
- package/dist/eslint-plugin/get-native-event-names.js +200 -0
- package/dist/eslint-plugin/rule-fixes.d.ts +17 -0
- package/dist/eslint-plugin/rule-fixes.d.ts.map +1 -0
- package/dist/eslint-plugin/rule-fixes.js +134 -0
- package/dist/eslint-plugin/selector-utils.d.ts +55 -0
- package/dist/eslint-plugin/selector-utils.d.ts.map +1 -0
- package/dist/eslint-plugin/selector-utils.js +269 -0
- package/dist/eslint-plugin/selectors.d.ts +28 -0
- package/dist/eslint-plugin/selectors.d.ts.map +1 -0
- package/dist/eslint-plugin/selectors.js +48 -0
- package/dist/eslint-plugin-template/parser-services.d.ts +13 -0
- package/dist/eslint-plugin-template/parser-services.d.ts.map +1 -0
- package/dist/eslint-plugin-template/parser-services.js +24 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +56 -0
- package/dist/utils.d.ts +27 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +59 -0
- package/package.json +61 -0
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLifecycleInterfaceByMethodName = exports.getMethodName = exports.getDeclaredMethods = exports.getDecoratorPropertyValue = exports.getDecoratorProperty = exports.getDecoratorProperties = exports.isAngularInnerClassDecorator = exports.isAngularClassDecorator = exports.isAngularLifecycleMethod = exports.isAngularLifecycleInterface = exports.ANGULAR_LIFECYCLE_METHODS = exports.ANGULAR_LIFECYCLE_INTERFACES = exports.getDecoratorName = exports.getDecoratorArgument = exports.getAngularClassDecorator = exports.getDecorator = exports.getClassName = exports.getDeclaredAngularLifecycleMethods = exports.getDeclaredAngularLifecycleInterfaces = exports.getPipeDecorator = exports.ANGULAR_CLASS_DECORATOR_MAPPER = exports.ANGULAR_CLASS_DECORATORS = exports.ANGULAR_INNER_CLASS_DECORATORS = exports.ANGULAR_CLASS_DECORATOR_LIFECYCLE_METHOD_MAPPER = exports.angularLifecycleMethodsOrdered = exports.angularLifecycleMethodKeys = exports.angularLifecycleInterfaceKeys = exports.angularInnerClassDecoratorKeys = exports.angularClassDecoratorKeys = exports.OPTION_STYLE_KEBAB_CASE = exports.OPTION_STYLE_CAMEL_CASE = exports.AngularLifecycleMethods = exports.AngularLifecycleInterfaces = exports.AngularInnerClassDecorators = exports.AngularClassDecorators = void 0;
|
|
4
|
+
exports.getCorrespondentImportClause = getCorrespondentImportClause;
|
|
5
|
+
exports.getImportDeclarations = getImportDeclarations;
|
|
6
|
+
exports.getImportDeclarationSpecifier = getImportDeclarationSpecifier;
|
|
7
|
+
exports.getInterface = getInterface;
|
|
8
|
+
exports.getInterfaceName = getInterfaceName;
|
|
9
|
+
exports.getInterfaces = getInterfaces;
|
|
10
|
+
exports.getDeclaredInterfaceNames = getDeclaredInterfaceNames;
|
|
11
|
+
exports.getNearestNodeFrom = getNearestNodeFrom;
|
|
12
|
+
exports.getPropertyDefinitionName = getPropertyDefinitionName;
|
|
13
|
+
exports.isImportedFrom = isImportedFrom;
|
|
14
|
+
exports.getRawText = getRawText;
|
|
15
|
+
exports.getReplacementText = getReplacementText;
|
|
16
|
+
exports.isCallExpression = isCallExpression;
|
|
17
|
+
exports.isMemberExpression = isMemberExpression;
|
|
18
|
+
exports.isIdentifierOrMemberExpression = isIdentifierOrMemberExpression;
|
|
19
|
+
exports.isClassDeclaration = isClassDeclaration;
|
|
20
|
+
exports.isPropertyDefinition = isPropertyDefinition;
|
|
21
|
+
exports.isPropertyOrMethodDefinition = isPropertyOrMethodDefinition;
|
|
22
|
+
exports.isImportDefaultSpecifier = isImportDefaultSpecifier;
|
|
23
|
+
exports.isImportNamespaceSpecifier = isImportNamespaceSpecifier;
|
|
24
|
+
exports.isObjectExpression = isObjectExpression;
|
|
25
|
+
exports.isArrayExpression = isArrayExpression;
|
|
26
|
+
exports.isProperty = isProperty;
|
|
27
|
+
exports.isLiteral = isLiteral;
|
|
28
|
+
exports.isTemplateElement = isTemplateElement;
|
|
29
|
+
exports.isTemplateLiteral = isTemplateLiteral;
|
|
30
|
+
exports.isImportDeclaration = isImportDeclaration;
|
|
31
|
+
exports.isImportSpecifier = isImportSpecifier;
|
|
32
|
+
exports.isStringLiteral = isStringLiteral;
|
|
33
|
+
exports.isMethodDefinition = isMethodDefinition;
|
|
34
|
+
exports.isSuper = isSuper;
|
|
35
|
+
exports.isImplementsToken = isImplementsToken;
|
|
36
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
37
|
+
const utils_2 = require("../utils");
|
|
38
|
+
var AngularClassDecorators;
|
|
39
|
+
(function (AngularClassDecorators) {
|
|
40
|
+
AngularClassDecorators["Component"] = "Component";
|
|
41
|
+
AngularClassDecorators["Directive"] = "Directive";
|
|
42
|
+
AngularClassDecorators["Injectable"] = "Injectable";
|
|
43
|
+
AngularClassDecorators["NgModule"] = "NgModule";
|
|
44
|
+
AngularClassDecorators["Pipe"] = "Pipe";
|
|
45
|
+
})(AngularClassDecorators || (exports.AngularClassDecorators = AngularClassDecorators = {}));
|
|
46
|
+
var AngularConstructorParameterDecorators;
|
|
47
|
+
(function (AngularConstructorParameterDecorators) {
|
|
48
|
+
AngularConstructorParameterDecorators["Attribute"] = "Attribute";
|
|
49
|
+
AngularConstructorParameterDecorators["Host"] = "Host";
|
|
50
|
+
AngularConstructorParameterDecorators["Inject"] = "Inject";
|
|
51
|
+
AngularConstructorParameterDecorators["Optional"] = "Optional";
|
|
52
|
+
AngularConstructorParameterDecorators["Self"] = "Self";
|
|
53
|
+
AngularConstructorParameterDecorators["SkipSelf"] = "SkipSelf";
|
|
54
|
+
})(AngularConstructorParameterDecorators || (AngularConstructorParameterDecorators = {}));
|
|
55
|
+
var AngularMethodDecorators;
|
|
56
|
+
(function (AngularMethodDecorators) {
|
|
57
|
+
AngularMethodDecorators["HostListener"] = "HostListener";
|
|
58
|
+
})(AngularMethodDecorators || (AngularMethodDecorators = {}));
|
|
59
|
+
var AngularPropertyAccessorDecorators;
|
|
60
|
+
(function (AngularPropertyAccessorDecorators) {
|
|
61
|
+
AngularPropertyAccessorDecorators["ContentChild"] = "ContentChild";
|
|
62
|
+
AngularPropertyAccessorDecorators["ContentChildren"] = "ContentChildren";
|
|
63
|
+
AngularPropertyAccessorDecorators["HostBinding"] = "HostBinding";
|
|
64
|
+
AngularPropertyAccessorDecorators["Input"] = "Input";
|
|
65
|
+
AngularPropertyAccessorDecorators["Output"] = "Output";
|
|
66
|
+
AngularPropertyAccessorDecorators["ViewChild"] = "ViewChild";
|
|
67
|
+
AngularPropertyAccessorDecorators["ViewChildren"] = "ViewChildren";
|
|
68
|
+
})(AngularPropertyAccessorDecorators || (AngularPropertyAccessorDecorators = {}));
|
|
69
|
+
exports.AngularInnerClassDecorators = {
|
|
70
|
+
...AngularConstructorParameterDecorators,
|
|
71
|
+
...AngularMethodDecorators,
|
|
72
|
+
...AngularPropertyAccessorDecorators,
|
|
73
|
+
};
|
|
74
|
+
var AngularLifecycleInterfaces;
|
|
75
|
+
(function (AngularLifecycleInterfaces) {
|
|
76
|
+
AngularLifecycleInterfaces["AfterContentChecked"] = "AfterContentChecked";
|
|
77
|
+
AngularLifecycleInterfaces["AfterContentInit"] = "AfterContentInit";
|
|
78
|
+
AngularLifecycleInterfaces["AfterViewChecked"] = "AfterViewChecked";
|
|
79
|
+
AngularLifecycleInterfaces["AfterViewInit"] = "AfterViewInit";
|
|
80
|
+
AngularLifecycleInterfaces["DoBootstrap"] = "DoBootstrap";
|
|
81
|
+
AngularLifecycleInterfaces["DoCheck"] = "DoCheck";
|
|
82
|
+
AngularLifecycleInterfaces["OnChanges"] = "OnChanges";
|
|
83
|
+
AngularLifecycleInterfaces["OnDestroy"] = "OnDestroy";
|
|
84
|
+
AngularLifecycleInterfaces["OnInit"] = "OnInit";
|
|
85
|
+
})(AngularLifecycleInterfaces || (exports.AngularLifecycleInterfaces = AngularLifecycleInterfaces = {}));
|
|
86
|
+
var AngularLifecycleMethods;
|
|
87
|
+
(function (AngularLifecycleMethods) {
|
|
88
|
+
AngularLifecycleMethods["ngAfterContentChecked"] = "ngAfterContentChecked";
|
|
89
|
+
AngularLifecycleMethods["ngAfterContentInit"] = "ngAfterContentInit";
|
|
90
|
+
AngularLifecycleMethods["ngAfterViewChecked"] = "ngAfterViewChecked";
|
|
91
|
+
AngularLifecycleMethods["ngAfterViewInit"] = "ngAfterViewInit";
|
|
92
|
+
AngularLifecycleMethods["ngDoBootstrap"] = "ngDoBootstrap";
|
|
93
|
+
AngularLifecycleMethods["ngDoCheck"] = "ngDoCheck";
|
|
94
|
+
AngularLifecycleMethods["ngOnChanges"] = "ngOnChanges";
|
|
95
|
+
AngularLifecycleMethods["ngOnDestroy"] = "ngOnDestroy";
|
|
96
|
+
AngularLifecycleMethods["ngOnInit"] = "ngOnInit";
|
|
97
|
+
})(AngularLifecycleMethods || (exports.AngularLifecycleMethods = AngularLifecycleMethods = {}));
|
|
98
|
+
exports.OPTION_STYLE_CAMEL_CASE = 'camelCase';
|
|
99
|
+
exports.OPTION_STYLE_KEBAB_CASE = 'kebab-case';
|
|
100
|
+
exports.angularClassDecoratorKeys = (0, utils_2.objectKeys)(AngularClassDecorators);
|
|
101
|
+
exports.angularInnerClassDecoratorKeys = (0, utils_2.objectKeys)(exports.AngularInnerClassDecorators);
|
|
102
|
+
exports.angularLifecycleInterfaceKeys = (0, utils_2.objectKeys)(AngularLifecycleInterfaces);
|
|
103
|
+
exports.angularLifecycleMethodKeys = (0, utils_2.objectKeys)(AngularLifecycleMethods);
|
|
104
|
+
/**
|
|
105
|
+
* See lifecycle event sequence:
|
|
106
|
+
* https://angular.dev/guide/components/lifecycle
|
|
107
|
+
*/
|
|
108
|
+
exports.angularLifecycleMethodsOrdered = [
|
|
109
|
+
AngularLifecycleMethods.ngOnChanges,
|
|
110
|
+
AngularLifecycleMethods.ngOnInit,
|
|
111
|
+
AngularLifecycleMethods.ngDoCheck,
|
|
112
|
+
AngularLifecycleMethods.ngAfterContentInit,
|
|
113
|
+
AngularLifecycleMethods.ngAfterContentChecked,
|
|
114
|
+
AngularLifecycleMethods.ngAfterViewInit,
|
|
115
|
+
AngularLifecycleMethods.ngAfterViewChecked,
|
|
116
|
+
AngularLifecycleMethods.ngOnDestroy,
|
|
117
|
+
];
|
|
118
|
+
exports.ANGULAR_CLASS_DECORATOR_LIFECYCLE_METHOD_MAPPER = new Map([
|
|
119
|
+
[
|
|
120
|
+
AngularClassDecorators.Component,
|
|
121
|
+
new Set([
|
|
122
|
+
AngularLifecycleMethods.ngAfterContentChecked,
|
|
123
|
+
AngularLifecycleMethods.ngAfterContentInit,
|
|
124
|
+
AngularLifecycleMethods.ngAfterViewChecked,
|
|
125
|
+
AngularLifecycleMethods.ngAfterViewInit,
|
|
126
|
+
AngularLifecycleMethods.ngOnChanges,
|
|
127
|
+
AngularLifecycleMethods.ngOnDestroy,
|
|
128
|
+
AngularLifecycleMethods.ngOnInit,
|
|
129
|
+
AngularLifecycleMethods.ngDoCheck,
|
|
130
|
+
]),
|
|
131
|
+
],
|
|
132
|
+
[
|
|
133
|
+
AngularClassDecorators.Directive,
|
|
134
|
+
new Set([
|
|
135
|
+
AngularLifecycleMethods.ngAfterContentChecked,
|
|
136
|
+
AngularLifecycleMethods.ngAfterContentInit,
|
|
137
|
+
AngularLifecycleMethods.ngAfterViewChecked,
|
|
138
|
+
AngularLifecycleMethods.ngAfterViewInit,
|
|
139
|
+
AngularLifecycleMethods.ngOnChanges,
|
|
140
|
+
AngularLifecycleMethods.ngOnDestroy,
|
|
141
|
+
AngularLifecycleMethods.ngOnInit,
|
|
142
|
+
AngularLifecycleMethods.ngDoCheck,
|
|
143
|
+
]),
|
|
144
|
+
],
|
|
145
|
+
[
|
|
146
|
+
AngularClassDecorators.Injectable,
|
|
147
|
+
new Set([AngularLifecycleMethods.ngOnDestroy]),
|
|
148
|
+
],
|
|
149
|
+
[
|
|
150
|
+
AngularClassDecorators.NgModule,
|
|
151
|
+
new Set([
|
|
152
|
+
AngularLifecycleMethods.ngDoBootstrap,
|
|
153
|
+
]),
|
|
154
|
+
],
|
|
155
|
+
[
|
|
156
|
+
AngularClassDecorators.Pipe,
|
|
157
|
+
new Set([AngularLifecycleMethods.ngOnDestroy]),
|
|
158
|
+
],
|
|
159
|
+
]);
|
|
160
|
+
exports.ANGULAR_INNER_CLASS_DECORATORS = new Set(exports.angularInnerClassDecoratorKeys);
|
|
161
|
+
exports.ANGULAR_CLASS_DECORATORS = new Set(exports.angularClassDecoratorKeys);
|
|
162
|
+
exports.ANGULAR_CLASS_DECORATOR_MAPPER = new Map([
|
|
163
|
+
[AngularClassDecorators.Component, exports.ANGULAR_INNER_CLASS_DECORATORS],
|
|
164
|
+
[AngularClassDecorators.Directive, exports.ANGULAR_INNER_CLASS_DECORATORS],
|
|
165
|
+
[
|
|
166
|
+
AngularClassDecorators.Injectable,
|
|
167
|
+
new Set([
|
|
168
|
+
exports.AngularInnerClassDecorators.Host,
|
|
169
|
+
exports.AngularInnerClassDecorators.Inject,
|
|
170
|
+
exports.AngularInnerClassDecorators.Optional,
|
|
171
|
+
exports.AngularInnerClassDecorators.Self,
|
|
172
|
+
exports.AngularInnerClassDecorators.SkipSelf,
|
|
173
|
+
]),
|
|
174
|
+
],
|
|
175
|
+
[
|
|
176
|
+
AngularClassDecorators.NgModule,
|
|
177
|
+
new Set([
|
|
178
|
+
exports.AngularInnerClassDecorators.Host,
|
|
179
|
+
exports.AngularInnerClassDecorators.Inject,
|
|
180
|
+
exports.AngularInnerClassDecorators.Optional,
|
|
181
|
+
exports.AngularInnerClassDecorators.Self,
|
|
182
|
+
exports.AngularInnerClassDecorators.SkipSelf,
|
|
183
|
+
]),
|
|
184
|
+
],
|
|
185
|
+
[
|
|
186
|
+
AngularClassDecorators.Pipe,
|
|
187
|
+
new Set([
|
|
188
|
+
exports.AngularInnerClassDecorators.Host,
|
|
189
|
+
exports.AngularInnerClassDecorators.Inject,
|
|
190
|
+
exports.AngularInnerClassDecorators.Optional,
|
|
191
|
+
exports.AngularInnerClassDecorators.Self,
|
|
192
|
+
exports.AngularInnerClassDecorators.SkipSelf,
|
|
193
|
+
]),
|
|
194
|
+
],
|
|
195
|
+
]);
|
|
196
|
+
function getCorrespondentImportClause(importDeclarations, compatibleWithTypeOnlyImport = false) {
|
|
197
|
+
let importClause;
|
|
198
|
+
for (const { importKind, specifiers } of importDeclarations) {
|
|
199
|
+
const lastImportSpecifier = (0, utils_2.getLast)(specifiers);
|
|
200
|
+
if ((!compatibleWithTypeOnlyImport && importKind === 'type') ||
|
|
201
|
+
isImportNamespaceSpecifier(lastImportSpecifier)) {
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
importClause = lastImportSpecifier;
|
|
205
|
+
}
|
|
206
|
+
return importClause;
|
|
207
|
+
}
|
|
208
|
+
function getImportDeclarations(node, moduleName) {
|
|
209
|
+
let parentNode = node;
|
|
210
|
+
while ((parentNode = parentNode.parent)) {
|
|
211
|
+
if (!isProgram(parentNode))
|
|
212
|
+
continue;
|
|
213
|
+
return parentNode.body.filter((node) => isImportDeclaration(node) && node.source.value === moduleName);
|
|
214
|
+
}
|
|
215
|
+
return parentNode;
|
|
216
|
+
}
|
|
217
|
+
function getImportDeclarationSpecifier(importDeclarations, importName) {
|
|
218
|
+
for (const importDeclaration of importDeclarations) {
|
|
219
|
+
const importSpecifier = importDeclaration.specifiers.find((importClause) => {
|
|
220
|
+
return (isImportSpecifier(importClause) &&
|
|
221
|
+
((utils_1.ASTUtils.isIdentifier(importClause.imported) &&
|
|
222
|
+
importClause.imported.name === importName) ||
|
|
223
|
+
(isStringLiteral(importClause.imported) &&
|
|
224
|
+
importClause.imported.value === importName)));
|
|
225
|
+
});
|
|
226
|
+
if (importSpecifier) {
|
|
227
|
+
return { importDeclaration, importSpecifier };
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return undefined;
|
|
231
|
+
}
|
|
232
|
+
function getInterface(node, interfaceName) {
|
|
233
|
+
return getInterfaces(node).find((interfaceMember) => getInterfaceName(interfaceMember) === interfaceName);
|
|
234
|
+
}
|
|
235
|
+
function getInterfaceName(interfaceMember) {
|
|
236
|
+
if (utils_1.ASTUtils.isIdentifier(interfaceMember)) {
|
|
237
|
+
return interfaceMember.name;
|
|
238
|
+
}
|
|
239
|
+
return utils_1.ASTUtils.isIdentifier(interfaceMember.property)
|
|
240
|
+
? interfaceMember.property.name
|
|
241
|
+
: undefined;
|
|
242
|
+
}
|
|
243
|
+
const getPipeDecorator = (node) => (0, exports.getDecorator)(node, 'Pipe');
|
|
244
|
+
exports.getPipeDecorator = getPipeDecorator;
|
|
245
|
+
function getInterfaces(node) {
|
|
246
|
+
return (node.implements ?? [])
|
|
247
|
+
.map(({ expression }) => expression)
|
|
248
|
+
.filter(isIdentifierOrMemberExpression);
|
|
249
|
+
}
|
|
250
|
+
function getDeclaredInterfaceNames(node) {
|
|
251
|
+
return getInterfaces(node).map(getInterfaceName).filter(utils_2.isNotNullOrUndefined);
|
|
252
|
+
}
|
|
253
|
+
const getDeclaredAngularLifecycleInterfaces = (node) => getDeclaredInterfaceNames(node).filter(exports.isAngularLifecycleInterface);
|
|
254
|
+
exports.getDeclaredAngularLifecycleInterfaces = getDeclaredAngularLifecycleInterfaces;
|
|
255
|
+
const getDeclaredAngularLifecycleMethods = (node) => (0, exports.getDeclaredMethods)(node)
|
|
256
|
+
.map(exports.getMethodName)
|
|
257
|
+
.filter(utils_2.isNotNullOrUndefined)
|
|
258
|
+
.filter(exports.isAngularLifecycleMethod);
|
|
259
|
+
exports.getDeclaredAngularLifecycleMethods = getDeclaredAngularLifecycleMethods;
|
|
260
|
+
function getNearestNodeFrom({ parent }, predicate) {
|
|
261
|
+
while (parent && !isProgram(parent)) {
|
|
262
|
+
if (predicate(parent)) {
|
|
263
|
+
return parent;
|
|
264
|
+
}
|
|
265
|
+
parent = parent.parent;
|
|
266
|
+
}
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
const getClassName = (node) => {
|
|
270
|
+
if (isClassDeclaration(node)) {
|
|
271
|
+
return node.id?.name;
|
|
272
|
+
}
|
|
273
|
+
if (node.parent) {
|
|
274
|
+
return (0, exports.getClassName)(node.parent);
|
|
275
|
+
}
|
|
276
|
+
return undefined;
|
|
277
|
+
};
|
|
278
|
+
exports.getClassName = getClassName;
|
|
279
|
+
const getDecorator = (node, decoratorName) => {
|
|
280
|
+
return node.decorators?.find((decorator) => (0, exports.getDecoratorName)(decorator) === decoratorName);
|
|
281
|
+
};
|
|
282
|
+
exports.getDecorator = getDecorator;
|
|
283
|
+
const getAngularClassDecorator = ({ decorators, }) => {
|
|
284
|
+
return decorators
|
|
285
|
+
?.map(exports.getDecoratorName)
|
|
286
|
+
.filter(utils_2.isNotNullOrUndefined)
|
|
287
|
+
.find(exports.isAngularClassDecorator);
|
|
288
|
+
};
|
|
289
|
+
exports.getAngularClassDecorator = getAngularClassDecorator;
|
|
290
|
+
const getDecoratorArgument = ({ expression, }) => {
|
|
291
|
+
if (!isCallExpression(expression) || expression.arguments.length === 0) {
|
|
292
|
+
return undefined;
|
|
293
|
+
}
|
|
294
|
+
const [arg] = expression.arguments;
|
|
295
|
+
return isObjectExpression(arg) && arg.properties ? arg : undefined;
|
|
296
|
+
};
|
|
297
|
+
exports.getDecoratorArgument = getDecoratorArgument;
|
|
298
|
+
const getDecoratorName = ({ expression, }) => {
|
|
299
|
+
if (utils_1.ASTUtils.isIdentifier(expression))
|
|
300
|
+
return expression.name;
|
|
301
|
+
return isCallExpression(expression) &&
|
|
302
|
+
utils_1.ASTUtils.isIdentifier(expression.callee)
|
|
303
|
+
? expression.callee.name
|
|
304
|
+
: undefined;
|
|
305
|
+
};
|
|
306
|
+
exports.getDecoratorName = getDecoratorName;
|
|
307
|
+
exports.ANGULAR_LIFECYCLE_INTERFACES = new Set(exports.angularLifecycleInterfaceKeys);
|
|
308
|
+
exports.ANGULAR_LIFECYCLE_METHODS = new Set(exports.angularLifecycleMethodKeys);
|
|
309
|
+
const isAngularLifecycleInterface = (value) => exports.ANGULAR_LIFECYCLE_INTERFACES.has(value);
|
|
310
|
+
exports.isAngularLifecycleInterface = isAngularLifecycleInterface;
|
|
311
|
+
const isAngularLifecycleMethod = (value) => exports.ANGULAR_LIFECYCLE_METHODS.has(value);
|
|
312
|
+
exports.isAngularLifecycleMethod = isAngularLifecycleMethod;
|
|
313
|
+
const isAngularClassDecorator = (value) => exports.ANGULAR_CLASS_DECORATORS.has(value);
|
|
314
|
+
exports.isAngularClassDecorator = isAngularClassDecorator;
|
|
315
|
+
const isAngularInnerClassDecorator = (value) => exports.ANGULAR_INNER_CLASS_DECORATORS.has(value);
|
|
316
|
+
exports.isAngularInnerClassDecorator = isAngularInnerClassDecorator;
|
|
317
|
+
/**
|
|
318
|
+
* `PropertyDefinition` nodes can have different types of `key`s
|
|
319
|
+
*
|
|
320
|
+
* E.g.
|
|
321
|
+
*
|
|
322
|
+
* class Foo {
|
|
323
|
+
* a // Identifier
|
|
324
|
+
* 'b' // Literal
|
|
325
|
+
* ['c'] // Literal
|
|
326
|
+
* }
|
|
327
|
+
*/
|
|
328
|
+
function getPropertyDefinitionName({ computed, key, }) {
|
|
329
|
+
if (utils_1.ASTUtils.isIdentifier(key) && !computed) {
|
|
330
|
+
return key.name;
|
|
331
|
+
}
|
|
332
|
+
if (isLiteral(key)) {
|
|
333
|
+
return key.raw;
|
|
334
|
+
}
|
|
335
|
+
throw new Error(`Unexpected "PropertyDefinition.key.type" provided: ${key.type}`);
|
|
336
|
+
}
|
|
337
|
+
const getDecoratorProperties = (decorator) => {
|
|
338
|
+
return (0, exports.getDecoratorArgument)(decorator)?.properties.filter(isProperty) ?? [];
|
|
339
|
+
};
|
|
340
|
+
exports.getDecoratorProperties = getDecoratorProperties;
|
|
341
|
+
const getDecoratorProperty = (decorator, name) => {
|
|
342
|
+
return (0, exports.getDecoratorProperties)(decorator).find(({ key }) => utils_1.ASTUtils.isIdentifier(key) && key.name === name);
|
|
343
|
+
};
|
|
344
|
+
exports.getDecoratorProperty = getDecoratorProperty;
|
|
345
|
+
const getDecoratorPropertyValue = (decorator, name) => {
|
|
346
|
+
return (0, exports.getDecoratorProperty)(decorator, name)?.value;
|
|
347
|
+
};
|
|
348
|
+
exports.getDecoratorPropertyValue = getDecoratorPropertyValue;
|
|
349
|
+
const getDeclaredMethods = ({ body: { body }, }) => {
|
|
350
|
+
return body.filter(isMethodDefinition);
|
|
351
|
+
};
|
|
352
|
+
exports.getDeclaredMethods = getDeclaredMethods;
|
|
353
|
+
const getMethodName = ({ computed, key, }) => {
|
|
354
|
+
if (isStringLiteral(key)) {
|
|
355
|
+
return key.value;
|
|
356
|
+
}
|
|
357
|
+
return utils_1.ASTUtils.isIdentifier(key) && !computed ? key.name : undefined;
|
|
358
|
+
};
|
|
359
|
+
exports.getMethodName = getMethodName;
|
|
360
|
+
const getLifecycleInterfaceByMethodName = (methodName) => methodName.slice(2);
|
|
361
|
+
exports.getLifecycleInterfaceByMethodName = getLifecycleInterfaceByMethodName;
|
|
362
|
+
function isImportedFrom(identifier, moduleName) {
|
|
363
|
+
const importDeclarations = getImportDeclarations(identifier, moduleName);
|
|
364
|
+
return Boolean(importDeclarations?.some((importDeclaration) => importDeclaration.specifiers.some((specifier) => isImportSpecifier(specifier) &&
|
|
365
|
+
((utils_1.ASTUtils.isIdentifier(specifier.imported) &&
|
|
366
|
+
specifier.imported.name === identifier.name) ||
|
|
367
|
+
(isStringLiteral(specifier.imported) &&
|
|
368
|
+
specifier.imported.value === identifier.name)) &&
|
|
369
|
+
specifier.local.name === identifier.name)));
|
|
370
|
+
}
|
|
371
|
+
function getRawText(node) {
|
|
372
|
+
if (utils_1.ASTUtils.isIdentifier(node)) {
|
|
373
|
+
return node.name;
|
|
374
|
+
}
|
|
375
|
+
if (isPropertyDefinition(node) ||
|
|
376
|
+
isMethodDefinition(node) ||
|
|
377
|
+
isProperty(node)) {
|
|
378
|
+
return getRawText(node.key);
|
|
379
|
+
}
|
|
380
|
+
if (isLiteral(node)) {
|
|
381
|
+
return String(node.value);
|
|
382
|
+
}
|
|
383
|
+
if (isTemplateElement(node)) {
|
|
384
|
+
return node.value.raw;
|
|
385
|
+
}
|
|
386
|
+
if (isTemplateLiteral(node)) {
|
|
387
|
+
return node.quasis[0].value.raw;
|
|
388
|
+
}
|
|
389
|
+
throw Error(`Unexpected \`node.type\` provided: ${node.type}`);
|
|
390
|
+
}
|
|
391
|
+
function getReplacementText(node, text) {
|
|
392
|
+
return isLiteral(node) ? `'${text}'` : `\`${text}\``;
|
|
393
|
+
}
|
|
394
|
+
// SECTION START:
|
|
395
|
+
// Equivalents of utils exported by TypeScript itself for its own AST
|
|
396
|
+
function isCallExpression(node) {
|
|
397
|
+
return node.type === utils_1.AST_NODE_TYPES.CallExpression;
|
|
398
|
+
}
|
|
399
|
+
function isMemberExpression(node) {
|
|
400
|
+
return node.type === utils_1.AST_NODE_TYPES.MemberExpression;
|
|
401
|
+
}
|
|
402
|
+
function isIdentifierOrMemberExpression(node) {
|
|
403
|
+
return utils_1.ASTUtils.isIdentifier(node) || isMemberExpression(node);
|
|
404
|
+
}
|
|
405
|
+
function isClassDeclaration(node) {
|
|
406
|
+
return node.type === utils_1.AST_NODE_TYPES.ClassDeclaration;
|
|
407
|
+
}
|
|
408
|
+
function isPropertyDefinition(node) {
|
|
409
|
+
return node.type === utils_1.AST_NODE_TYPES.PropertyDefinition;
|
|
410
|
+
}
|
|
411
|
+
function isPropertyOrMethodDefinition(node) {
|
|
412
|
+
return isPropertyDefinition(node) || isMethodDefinition(node);
|
|
413
|
+
}
|
|
414
|
+
function isImportDefaultSpecifier(node) {
|
|
415
|
+
return node.type === utils_1.AST_NODE_TYPES.ImportDefaultSpecifier;
|
|
416
|
+
}
|
|
417
|
+
function isImportNamespaceSpecifier(node) {
|
|
418
|
+
return node.type === utils_1.AST_NODE_TYPES.ImportNamespaceSpecifier;
|
|
419
|
+
}
|
|
420
|
+
function isObjectExpression(node) {
|
|
421
|
+
return node.type === utils_1.AST_NODE_TYPES.ObjectExpression;
|
|
422
|
+
}
|
|
423
|
+
function isArrayExpression(node) {
|
|
424
|
+
return node.type === utils_1.AST_NODE_TYPES.ArrayExpression;
|
|
425
|
+
}
|
|
426
|
+
function isProperty(node) {
|
|
427
|
+
return node.type === utils_1.AST_NODE_TYPES.Property;
|
|
428
|
+
}
|
|
429
|
+
function isProgram(node) {
|
|
430
|
+
return node.type === utils_1.AST_NODE_TYPES.Program;
|
|
431
|
+
}
|
|
432
|
+
function isLiteral(node) {
|
|
433
|
+
return node.type === utils_1.AST_NODE_TYPES.Literal;
|
|
434
|
+
}
|
|
435
|
+
function isTemplateElement(node) {
|
|
436
|
+
return node.type === utils_1.AST_NODE_TYPES.TemplateElement;
|
|
437
|
+
}
|
|
438
|
+
function isTemplateLiteral(node) {
|
|
439
|
+
return node.type === utils_1.AST_NODE_TYPES.TemplateLiteral;
|
|
440
|
+
}
|
|
441
|
+
function isImportDeclaration(node) {
|
|
442
|
+
return node.type === utils_1.AST_NODE_TYPES.ImportDeclaration;
|
|
443
|
+
}
|
|
444
|
+
function isImportSpecifier(node) {
|
|
445
|
+
return node.type === utils_1.AST_NODE_TYPES.ImportSpecifier;
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* `ESTree` does not differentiate between different types of `Literals` at the `AST` level,
|
|
449
|
+
* but it is a common thing to need to do, so this utility are here to
|
|
450
|
+
* avoid repeated `typeof` checks on the node's value.
|
|
451
|
+
*/
|
|
452
|
+
function isStringLiteral(node) {
|
|
453
|
+
return isLiteral(node) && typeof node.value === 'string';
|
|
454
|
+
}
|
|
455
|
+
function isMethodDefinition(node) {
|
|
456
|
+
return node.type === utils_1.AST_NODE_TYPES.MethodDefinition;
|
|
457
|
+
}
|
|
458
|
+
function isSuper(node) {
|
|
459
|
+
return node.type === utils_1.AST_NODE_TYPES.Super;
|
|
460
|
+
}
|
|
461
|
+
function isImplementsToken(token) {
|
|
462
|
+
return token.type === utils_1.AST_TOKEN_TYPES.Keyword && token.value === 'implements';
|
|
463
|
+
}
|
|
464
|
+
// SECTION END:
|
|
465
|
+
// Equivalents of utils exported by TypeScript itself for its own AST
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TSESLint, TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
export interface PropInfo {
|
|
3
|
+
name: string;
|
|
4
|
+
leadingComments: string[];
|
|
5
|
+
value: string;
|
|
6
|
+
trailingComments: string[];
|
|
7
|
+
}
|
|
8
|
+
export declare function extractPropertyComments(sourceCode: Readonly<TSESLint.SourceCode>, properties: TSESTree.Property[], objectExpression: TSESTree.Expression, indentation: string): Map<string, PropInfo>;
|
|
9
|
+
export declare function buildSortedPropertiesWithComments(filteredOrder: string[], propInfoMap: Map<string, PropInfo>, indentation: string): string;
|
|
10
|
+
export declare function getObjectIndentation(sourceCode: Readonly<TSESLint.SourceCode>, objectExpression: TSESTree.Expression): string;
|
|
11
|
+
//# sourceMappingURL=comment-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comment-utils.d.ts","sourceRoot":"","sources":["../../src/eslint-plugin/comment-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEnE,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,EAAE,MAAM,EAAE,CAAC;CAC5B;AAED,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,QAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC,EACzC,UAAU,EAAE,QAAQ,CAAC,QAAQ,EAAE,EAC/B,gBAAgB,EAAE,QAAQ,CAAC,UAAU,EACrC,WAAW,EAAE,MAAM,GAClB,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAoEvB;AAED,wBAAgB,iCAAiC,CAC/C,aAAa,EAAE,MAAM,EAAE,EACvB,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,EAClC,WAAW,EAAE,MAAM,GAClB,MAAM,CA8BR;AAED,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,QAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC,EACzC,gBAAgB,EAAE,QAAQ,CAAC,UAAU,GACpC,MAAM,CAIR"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractPropertyComments = extractPropertyComments;
|
|
4
|
+
exports.buildSortedPropertiesWithComments = buildSortedPropertiesWithComments;
|
|
5
|
+
exports.getObjectIndentation = getObjectIndentation;
|
|
6
|
+
function extractPropertyComments(sourceCode, properties, objectExpression, indentation) {
|
|
7
|
+
const allComments = sourceCode.getAllComments();
|
|
8
|
+
const processedCommentRanges = new Set();
|
|
9
|
+
const propInfoMap = new Map();
|
|
10
|
+
const commentLineMap = new Map();
|
|
11
|
+
for (const comment of allComments) {
|
|
12
|
+
const line = sourceCode.getLocFromIndex(comment.range[0]).line;
|
|
13
|
+
if (!commentLineMap.has(line)) {
|
|
14
|
+
commentLineMap.set(line, []);
|
|
15
|
+
}
|
|
16
|
+
commentLineMap.get(line)?.push(comment);
|
|
17
|
+
}
|
|
18
|
+
const makeRangeKey = (start, end) => `${start}-${end}`;
|
|
19
|
+
for (let i = 0; i < properties.length; i++) {
|
|
20
|
+
const prop = properties[i];
|
|
21
|
+
const name = prop.key.name;
|
|
22
|
+
const propRange = prop.range;
|
|
23
|
+
const leadingComments = [];
|
|
24
|
+
const prevPropEnd = i > 0 ? properties[i - 1].range[1] : objectExpression.range[0] + 1;
|
|
25
|
+
for (const comment of allComments) {
|
|
26
|
+
const rangeKey = makeRangeKey(comment.range[0], comment.range[1]);
|
|
27
|
+
if (comment.range[0] > prevPropEnd &&
|
|
28
|
+
comment.range[0] < propRange[0] &&
|
|
29
|
+
!processedCommentRanges.has(rangeKey)) {
|
|
30
|
+
leadingComments.push(indentation + sourceCode.getText(comment));
|
|
31
|
+
processedCommentRanges.add(rangeKey);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const propText = sourceCode.getText(prop).replace(/,\s*$/, '');
|
|
35
|
+
const trailingComments = [];
|
|
36
|
+
const propEndLine = sourceCode.getLocFromIndex(propRange[1]).line;
|
|
37
|
+
if (commentLineMap.has(propEndLine)) {
|
|
38
|
+
const commentsOnLine = commentLineMap.get(propEndLine) || [];
|
|
39
|
+
for (const comment of commentsOnLine) {
|
|
40
|
+
const rangeKey = makeRangeKey(comment.range[0], comment.range[1]);
|
|
41
|
+
if (comment.range[0] > propRange[1] &&
|
|
42
|
+
!processedCommentRanges.has(rangeKey)) {
|
|
43
|
+
const spaceBefore = sourceCode
|
|
44
|
+
.getText()
|
|
45
|
+
.substring(propRange[1], comment.range[0])
|
|
46
|
+
.replace(/,/g, '');
|
|
47
|
+
trailingComments.push(spaceBefore + sourceCode.getText(comment));
|
|
48
|
+
processedCommentRanges.add(rangeKey);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
propInfoMap.set(name, {
|
|
53
|
+
name,
|
|
54
|
+
leadingComments,
|
|
55
|
+
value: propText,
|
|
56
|
+
trailingComments,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return propInfoMap;
|
|
60
|
+
}
|
|
61
|
+
function buildSortedPropertiesWithComments(filteredOrder, propInfoMap, indentation) {
|
|
62
|
+
const sortedParts = [];
|
|
63
|
+
for (let i = 0; i < filteredOrder.length; i++) {
|
|
64
|
+
const propName = filteredOrder[i];
|
|
65
|
+
const info = propInfoMap.get(propName);
|
|
66
|
+
if (info) {
|
|
67
|
+
if (info.leadingComments.length > 0) {
|
|
68
|
+
sortedParts.push(...info.leadingComments);
|
|
69
|
+
}
|
|
70
|
+
const isLast = i === filteredOrder.length - 1;
|
|
71
|
+
let finalPropText = indentation + info.value;
|
|
72
|
+
if (!isLast) {
|
|
73
|
+
finalPropText += ',';
|
|
74
|
+
}
|
|
75
|
+
if (info.trailingComments.length > 0) {
|
|
76
|
+
info.trailingComments.forEach((comment) => {
|
|
77
|
+
finalPropText += comment;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
sortedParts.push(finalPropText);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return sortedParts.join('\n');
|
|
84
|
+
}
|
|
85
|
+
function getObjectIndentation(sourceCode, objectExpression) {
|
|
86
|
+
const objectExpressionText = sourceCode.getText(objectExpression);
|
|
87
|
+
const lines = objectExpressionText.split('\n');
|
|
88
|
+
return lines[1] ? lines[1].match(/^\s*/)?.[0] || '' : '';
|
|
89
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-aria-attribute-keys.d.ts","sourceRoot":"","sources":["../../src/eslint-plugin/get-aria-attribute-keys.ts"],"names":[],"mappings":"AAEA,wBAAgB,oBAAoB,IAAI,WAAW,CAAC,MAAM,CAAC,CAqD1D"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAriaAttributeKeys = getAriaAttributeKeys;
|
|
4
|
+
let ariaAttributeKeys = null;
|
|
5
|
+
function getAriaAttributeKeys() {
|
|
6
|
+
return (ariaAttributeKeys ??
|
|
7
|
+
(ariaAttributeKeys = new Set([
|
|
8
|
+
// Source: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques
|
|
9
|
+
'aria-activedescendant',
|
|
10
|
+
'aria-atomic',
|
|
11
|
+
'aria-autocomplete',
|
|
12
|
+
'aria-busy',
|
|
13
|
+
'aria-checked',
|
|
14
|
+
'aria-colcount',
|
|
15
|
+
'aria-colindex',
|
|
16
|
+
'aria-colspan',
|
|
17
|
+
'aria-controls',
|
|
18
|
+
'aria-current',
|
|
19
|
+
'aria-describedby',
|
|
20
|
+
'aria-details',
|
|
21
|
+
'aria-disabled',
|
|
22
|
+
'aria-dragged',
|
|
23
|
+
'aria-dropeffect',
|
|
24
|
+
'aria-errormessage',
|
|
25
|
+
'aria-expanded',
|
|
26
|
+
'aria-flowto',
|
|
27
|
+
'aria-haspopup',
|
|
28
|
+
'aria-hidden',
|
|
29
|
+
'aria-invalid',
|
|
30
|
+
'aria-label',
|
|
31
|
+
'aria-labelledby',
|
|
32
|
+
'aria-level',
|
|
33
|
+
'aria-live',
|
|
34
|
+
'aria-modal',
|
|
35
|
+
'aria-multiline',
|
|
36
|
+
'aria-multiselectable',
|
|
37
|
+
'aria-orientation',
|
|
38
|
+
'aria-owns',
|
|
39
|
+
'aria-placeholder',
|
|
40
|
+
'aria-posinset',
|
|
41
|
+
'aria-pressed',
|
|
42
|
+
'aria-readonly',
|
|
43
|
+
'aria-relevant',
|
|
44
|
+
'aria-required',
|
|
45
|
+
'aria-rowcount',
|
|
46
|
+
'aria-rowindex',
|
|
47
|
+
'aria-rowspan',
|
|
48
|
+
'aria-selected',
|
|
49
|
+
'aria-setsize',
|
|
50
|
+
'aria-sort',
|
|
51
|
+
'aria-valuemax',
|
|
52
|
+
'aria-valuemin',
|
|
53
|
+
'aria-valuenow',
|
|
54
|
+
'aria-valuetext',
|
|
55
|
+
])));
|
|
56
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DO NOT EDIT THIS FILE
|
|
3
|
+
*
|
|
4
|
+
* In order to update this config, please run `pnpm update-native-event-names`.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Check MDN events page for details https://developer.mozilla.org/en-US/docs/Web/Events
|
|
8
|
+
*
|
|
9
|
+
* Event names sourced from @mdn/browser-compat-data@7.3.6
|
|
10
|
+
*/
|
|
11
|
+
export declare function getNativeEventNames(): ReadonlySet<string>;
|
|
12
|
+
//# sourceMappingURL=get-native-event-names.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-native-event-names.d.ts","sourceRoot":"","sources":["../../src/eslint-plugin/get-native-event-names.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,WAAW,CAAC,MAAM,CAAC,CA2LzD"}
|