Brunobkr commited on
Commit
7c0069c
·
verified ·
1 Parent(s): 8b33cd2

Upload folder using huggingface_hub (part 23)

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-inferrable-types.d.ts +11 -0
  2. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-inferrable-types.js +182 -0
  3. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-invalid-this.d.ts +15 -0
  4. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-invalid-this.js +75 -0
  5. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-invalid-void-type.d.ts +9 -0
  6. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-invalid-void-type.js +210 -0
  7. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-loop-func.d.ts +13 -0
  8. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-loop-func.js +187 -0
  9. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-loss-of-precision.d.ts +9 -0
  10. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-loss-of-precision.js +35 -0
  11. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-magic-numbers.d.ts +29 -0
  12. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-magic-numbers.js +249 -0
  13. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-meaningless-void-operator.d.ts +10 -0
  14. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-meaningless-void-operator.js +102 -0
  15. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-misused-new.d.ts +4 -0
  16. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-misused-new.js +81 -0
  17. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-misused-promises.d.ts +21 -0
  18. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-misused-promises.js +765 -0
  19. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-misused-spread.d.ts +12 -0
  20. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-misused-spread.js +260 -0
  21. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-mixed-enums.d.ts +4 -0
  22. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-mixed-enums.js +200 -0
  23. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-namespace.d.ts +11 -0
  24. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-namespace.js +60 -0
  25. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-non-null-asserted-nullish-coalescing.d.ts +5 -0
  26. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-non-null-asserted-nullish-coalescing.js +73 -0
  27. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-non-null-asserted-optional-chain.d.ts +5 -0
  28. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-non-null-asserted-optional-chain.js +65 -0
  29. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-non-null-assertion.d.ts +6 -0
  30. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-non-null-assertion.js +93 -0
  31. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-redeclare.d.ts +12 -0
  32. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-redeclare.js +199 -0
  33. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-redundant-type-constituents.d.ts +4 -0
  34. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-redundant-type-constituents.js +431 -0
  35. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-require-imports.d.ts +11 -0
  36. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-require-imports.js +115 -0
  37. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-restricted-imports.d.ts +9 -0
  38. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-restricted-imports.js +243 -0
  39. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-restricted-types.d.ts +16 -0
  40. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-restricted-types.js +171 -0
  41. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-shadow.d.ts +16 -0
  42. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-shadow.js +551 -0
  43. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-this-alias.d.ts +11 -0
  44. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-this-alias.js +66 -0
  45. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-type-alias.d.ts +18 -0
  46. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-type-alias.js +268 -0
  47. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-unnecessary-boolean-literal-compare.d.ts +12 -0
  48. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-unnecessary-boolean-literal-compare.js +263 -0
  49. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-unnecessary-condition.d.ts +14 -0
  50. tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-unnecessary-condition.js +689 -0
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-inferrable-types.d.ts ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export type Options = [
2
+ {
3
+ ignoreParameters?: boolean;
4
+ ignoreProperties?: boolean;
5
+ }
6
+ ];
7
+ export type MessageIds = 'noInferrableType';
8
+ declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<"noInferrableType", Options, import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
9
+ name: string;
10
+ };
11
+ export default _default;
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-inferrable-types.js ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@typescript-eslint/utils");
4
+ const util_1 = require("../util");
5
+ exports.default = (0, util_1.createRule)({
6
+ name: 'no-inferrable-types',
7
+ meta: {
8
+ type: 'suggestion',
9
+ docs: {
10
+ description: 'Disallow explicit type declarations for variables or parameters initialized to a number, string, or boolean',
11
+ recommended: 'stylistic',
12
+ },
13
+ fixable: 'code',
14
+ messages: {
15
+ noInferrableType: 'Type {{type}} trivially inferred from a {{type}} literal, remove type annotation.',
16
+ },
17
+ schema: [
18
+ {
19
+ type: 'object',
20
+ additionalProperties: false,
21
+ properties: {
22
+ ignoreParameters: {
23
+ type: 'boolean',
24
+ description: 'Whether to ignore function parameters.',
25
+ },
26
+ ignoreProperties: {
27
+ type: 'boolean',
28
+ description: 'Whether to ignore class properties.',
29
+ },
30
+ },
31
+ },
32
+ ],
33
+ },
34
+ defaultOptions: [
35
+ {
36
+ ignoreParameters: false,
37
+ ignoreProperties: false,
38
+ },
39
+ ],
40
+ create(context, [{ ignoreParameters, ignoreProperties }]) {
41
+ function isFunctionCall(init, callName) {
42
+ const node = (0, util_1.skipChainExpression)(init);
43
+ return (node.type === utils_1.AST_NODE_TYPES.CallExpression &&
44
+ node.callee.type === utils_1.AST_NODE_TYPES.Identifier &&
45
+ node.callee.name === callName);
46
+ }
47
+ function isLiteral(init, typeName) {
48
+ return (init.type === utils_1.AST_NODE_TYPES.Literal && typeof init.value === typeName);
49
+ }
50
+ function isIdentifier(init, ...names) {
51
+ return (init.type === utils_1.AST_NODE_TYPES.Identifier && names.includes(init.name));
52
+ }
53
+ function hasUnaryPrefix(init, ...operators) {
54
+ return (init.type === utils_1.AST_NODE_TYPES.UnaryExpression &&
55
+ operators.includes(init.operator));
56
+ }
57
+ const keywordMap = {
58
+ [utils_1.AST_NODE_TYPES.TSBigIntKeyword]: 'bigint',
59
+ [utils_1.AST_NODE_TYPES.TSBooleanKeyword]: 'boolean',
60
+ [utils_1.AST_NODE_TYPES.TSNullKeyword]: 'null',
61
+ [utils_1.AST_NODE_TYPES.TSNumberKeyword]: 'number',
62
+ [utils_1.AST_NODE_TYPES.TSStringKeyword]: 'string',
63
+ [utils_1.AST_NODE_TYPES.TSSymbolKeyword]: 'symbol',
64
+ [utils_1.AST_NODE_TYPES.TSUndefinedKeyword]: 'undefined',
65
+ };
66
+ /**
67
+ * Returns whether a node has an inferrable value or not
68
+ */
69
+ function isInferrable(annotation, init) {
70
+ switch (annotation.type) {
71
+ case utils_1.AST_NODE_TYPES.TSBigIntKeyword: {
72
+ // note that bigint cannot have + prefixed to it
73
+ const unwrappedInit = hasUnaryPrefix(init, '-')
74
+ ? init.argument
75
+ : init;
76
+ return (isFunctionCall(unwrappedInit, 'BigInt') ||
77
+ unwrappedInit.type === utils_1.AST_NODE_TYPES.Literal);
78
+ }
79
+ case utils_1.AST_NODE_TYPES.TSBooleanKeyword:
80
+ return (hasUnaryPrefix(init, '!') ||
81
+ isFunctionCall(init, 'Boolean') ||
82
+ isLiteral(init, 'boolean'));
83
+ case utils_1.AST_NODE_TYPES.TSNumberKeyword: {
84
+ const unwrappedInit = hasUnaryPrefix(init, '+', '-')
85
+ ? init.argument
86
+ : init;
87
+ return (isIdentifier(unwrappedInit, 'Infinity', 'NaN') ||
88
+ isFunctionCall(unwrappedInit, 'Number') ||
89
+ isLiteral(unwrappedInit, 'number'));
90
+ }
91
+ case utils_1.AST_NODE_TYPES.TSNullKeyword:
92
+ return init.type === utils_1.AST_NODE_TYPES.Literal && init.value == null;
93
+ case utils_1.AST_NODE_TYPES.TSStringKeyword:
94
+ return (isFunctionCall(init, 'String') ||
95
+ isLiteral(init, 'string') ||
96
+ init.type === utils_1.AST_NODE_TYPES.TemplateLiteral);
97
+ case utils_1.AST_NODE_TYPES.TSSymbolKeyword:
98
+ return isFunctionCall(init, 'Symbol');
99
+ case utils_1.AST_NODE_TYPES.TSTypeReference: {
100
+ if (annotation.typeName.type === utils_1.AST_NODE_TYPES.Identifier &&
101
+ annotation.typeName.name === 'RegExp') {
102
+ const isRegExpLiteral = init.type === utils_1.AST_NODE_TYPES.Literal &&
103
+ init.value instanceof RegExp;
104
+ const isRegExpNewCall = init.type === utils_1.AST_NODE_TYPES.NewExpression &&
105
+ init.callee.type === utils_1.AST_NODE_TYPES.Identifier &&
106
+ init.callee.name === 'RegExp';
107
+ const isRegExpCall = isFunctionCall(init, 'RegExp');
108
+ return isRegExpLiteral || isRegExpCall || isRegExpNewCall;
109
+ }
110
+ return false;
111
+ }
112
+ case utils_1.AST_NODE_TYPES.TSUndefinedKeyword:
113
+ return (hasUnaryPrefix(init, 'void') || isIdentifier(init, 'undefined'));
114
+ }
115
+ return false;
116
+ }
117
+ /**
118
+ * Reports an inferrable type declaration, if any
119
+ */
120
+ function reportInferrableType(node, typeNode, initNode) {
121
+ if (!typeNode || !initNode) {
122
+ return;
123
+ }
124
+ if (!isInferrable(typeNode.typeAnnotation, initNode)) {
125
+ return;
126
+ }
127
+ const type = typeNode.typeAnnotation.type === utils_1.AST_NODE_TYPES.TSTypeReference
128
+ ? // TODO - if we add more references
129
+ 'RegExp'
130
+ : keywordMap[typeNode.typeAnnotation.type];
131
+ context.report({
132
+ node,
133
+ messageId: 'noInferrableType',
134
+ data: {
135
+ type,
136
+ },
137
+ *fix(fixer) {
138
+ if ((node.type === utils_1.AST_NODE_TYPES.AssignmentPattern &&
139
+ node.left.optional) ||
140
+ (node.type === utils_1.AST_NODE_TYPES.PropertyDefinition && node.definite)) {
141
+ yield fixer.remove((0, util_1.nullThrows)(context.sourceCode.getTokenBefore(typeNode), util_1.NullThrowsReasons.MissingToken('token before', 'type node')));
142
+ }
143
+ yield fixer.remove(typeNode);
144
+ },
145
+ });
146
+ }
147
+ function inferrableVariableVisitor(node) {
148
+ reportInferrableType(node, node.id.typeAnnotation, node.init);
149
+ }
150
+ function inferrableParameterVisitor(node) {
151
+ if (ignoreParameters) {
152
+ return;
153
+ }
154
+ node.params.forEach(param => {
155
+ if (param.type === utils_1.AST_NODE_TYPES.TSParameterProperty) {
156
+ param = param.parameter;
157
+ }
158
+ if (param.type === utils_1.AST_NODE_TYPES.AssignmentPattern) {
159
+ reportInferrableType(param, param.left.typeAnnotation, param.right);
160
+ }
161
+ });
162
+ }
163
+ function inferrablePropertyVisitor(node) {
164
+ // We ignore `readonly` because of Microsoft/TypeScript#14416
165
+ // Essentially a readonly property without a type
166
+ // will result in its value being the type, leading to
167
+ // compile errors if the type is stripped.
168
+ if (ignoreProperties || node.readonly || node.optional) {
169
+ return;
170
+ }
171
+ reportInferrableType(node, node.typeAnnotation, node.value);
172
+ }
173
+ return {
174
+ AccessorProperty: inferrablePropertyVisitor,
175
+ ArrowFunctionExpression: inferrableParameterVisitor,
176
+ FunctionDeclaration: inferrableParameterVisitor,
177
+ FunctionExpression: inferrableParameterVisitor,
178
+ PropertyDefinition: inferrablePropertyVisitor,
179
+ VariableDeclarator: inferrableVariableVisitor,
180
+ };
181
+ },
182
+ });
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-invalid-this.d.ts ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { TSESTree } from '@typescript-eslint/utils';
2
+ import type { InferMessageIdsTypeFromRule, InferOptionsTypeFromRule } from '../util';
3
+ declare const baseRule: import("@typescript-eslint/utils/ts-eslint").RuleModule<"unexpectedThis", [({
4
+ capIsConstructor?: boolean;
5
+ } | undefined)?], unknown, {
6
+ ThisExpression(node: TSESTree.ThisExpression): void;
7
+ }>;
8
+ export type Options = InferOptionsTypeFromRule<typeof baseRule>;
9
+ export type MessageIds = InferMessageIdsTypeFromRule<typeof baseRule>;
10
+ declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<"unexpectedThis", [({
11
+ capIsConstructor?: boolean;
12
+ } | undefined)?], import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
13
+ name: string;
14
+ };
15
+ export default _default;
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-invalid-this.js ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@typescript-eslint/utils");
4
+ const util_1 = require("../util");
5
+ const getESLintCoreRule_1 = require("../util/getESLintCoreRule");
6
+ const baseRule = (0, getESLintCoreRule_1.getESLintCoreRule)('no-invalid-this');
7
+ const defaultOptions = [{ capIsConstructor: true }];
8
+ exports.default = (0, util_1.createRule)({
9
+ name: 'no-invalid-this',
10
+ meta: {
11
+ type: 'suggestion',
12
+ defaultOptions,
13
+ docs: {
14
+ description: 'Disallow `this` keywords outside of classes or class-like objects',
15
+ extendsBaseRule: true,
16
+ },
17
+ hasSuggestions: baseRule.meta.hasSuggestions,
18
+ messages: baseRule.meta.messages,
19
+ schema: baseRule.meta.schema,
20
+ },
21
+ defaultOptions,
22
+ create(context) {
23
+ const rules = baseRule.create(context);
24
+ /**
25
+ * Since function definitions can be nested we use a stack storing if "this" is valid in the current context.
26
+ *
27
+ * Example:
28
+ *
29
+ * function a(this: number) { // valid "this"
30
+ * function b() {
31
+ * console.log(this); // invalid "this"
32
+ * }
33
+ * }
34
+ *
35
+ * When parsing the function declaration of "a" the stack will be: [true]
36
+ * When parsing the function declaration of "b" the stack will be: [true, false]
37
+ */
38
+ const thisIsValidStack = [];
39
+ return {
40
+ ...rules,
41
+ AccessorProperty() {
42
+ thisIsValidStack.push(true);
43
+ },
44
+ 'AccessorProperty:exit'() {
45
+ thisIsValidStack.pop();
46
+ },
47
+ FunctionDeclaration(node) {
48
+ thisIsValidStack.push(node.params.some(param => param.type === utils_1.AST_NODE_TYPES.Identifier && param.name === 'this'));
49
+ },
50
+ 'FunctionDeclaration:exit'() {
51
+ thisIsValidStack.pop();
52
+ },
53
+ FunctionExpression(node) {
54
+ thisIsValidStack.push(node.params.some(param => param.type === utils_1.AST_NODE_TYPES.Identifier && param.name === 'this'));
55
+ },
56
+ 'FunctionExpression:exit'() {
57
+ thisIsValidStack.pop();
58
+ },
59
+ PropertyDefinition() {
60
+ thisIsValidStack.push(true);
61
+ },
62
+ 'PropertyDefinition:exit'() {
63
+ thisIsValidStack.pop();
64
+ },
65
+ ThisExpression(node) {
66
+ const thisIsValidHere = thisIsValidStack[thisIsValidStack.length - 1];
67
+ if (thisIsValidHere) {
68
+ return;
69
+ }
70
+ // baseRule's work
71
+ rules.ThisExpression(node);
72
+ },
73
+ };
74
+ },
75
+ });
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-invalid-void-type.d.ts ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ export interface Options {
2
+ allowAsThisParameter?: boolean;
3
+ allowInGenericTypeArguments?: boolean | [string, ...string[]];
4
+ }
5
+ export type MessageIds = 'invalidVoidForGeneric' | 'invalidVoidNotReturn' | 'invalidVoidNotReturnOrGeneric' | 'invalidVoidNotReturnOrThisParam' | 'invalidVoidNotReturnOrThisParamOrGeneric' | 'invalidVoidUnionConstituent';
6
+ declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<MessageIds, [Options], import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
7
+ name: string;
8
+ };
9
+ export default _default;
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-invalid-void-type.js ADDED
@@ -0,0 +1,210 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@typescript-eslint/utils");
4
+ const util_1 = require("../util");
5
+ exports.default = (0, util_1.createRule)({
6
+ name: 'no-invalid-void-type',
7
+ meta: {
8
+ type: 'problem',
9
+ docs: {
10
+ description: 'Disallow `void` type outside of generic or return types',
11
+ recommended: 'strict',
12
+ },
13
+ messages: {
14
+ invalidVoidForGeneric: '{{ generic }} may not have void as a type argument.',
15
+ invalidVoidNotReturn: 'void is only valid as a return type.',
16
+ invalidVoidNotReturnOrGeneric: 'void is only valid as a return type or generic type argument.',
17
+ invalidVoidNotReturnOrThisParam: 'void is only valid as return type or type of `this` parameter.',
18
+ invalidVoidNotReturnOrThisParamOrGeneric: 'void is only valid as a return type or generic type argument or the type of a `this` parameter.',
19
+ invalidVoidUnionConstituent: 'void is not valid as a constituent in a union type',
20
+ },
21
+ schema: [
22
+ {
23
+ type: 'object',
24
+ additionalProperties: false,
25
+ properties: {
26
+ allowAsThisParameter: {
27
+ type: 'boolean',
28
+ description: 'Whether a `this` parameter of a function may be `void`.',
29
+ },
30
+ allowInGenericTypeArguments: {
31
+ description: 'Whether `void` can be used as a valid value for generic type parameters.',
32
+ oneOf: [
33
+ {
34
+ type: 'boolean',
35
+ description: 'Whether `void` can be used as a valid value for all generic type parameters.',
36
+ },
37
+ {
38
+ type: 'array',
39
+ description: 'Allowlist of types that may accept `void` as a generic type parameter.',
40
+ items: { type: 'string' },
41
+ minItems: 1,
42
+ },
43
+ ],
44
+ },
45
+ },
46
+ },
47
+ ],
48
+ },
49
+ defaultOptions: [
50
+ { allowAsThisParameter: false, allowInGenericTypeArguments: true },
51
+ ],
52
+ create(context, [{ allowAsThisParameter, allowInGenericTypeArguments }]) {
53
+ const validParents = [
54
+ utils_1.AST_NODE_TYPES.TSTypeAnnotation, //
55
+ ];
56
+ const invalidGrandParents = [
57
+ utils_1.AST_NODE_TYPES.TSPropertySignature,
58
+ utils_1.AST_NODE_TYPES.CallExpression,
59
+ utils_1.AST_NODE_TYPES.PropertyDefinition,
60
+ utils_1.AST_NODE_TYPES.AccessorProperty,
61
+ utils_1.AST_NODE_TYPES.Identifier,
62
+ ];
63
+ const validUnionMembers = [
64
+ utils_1.AST_NODE_TYPES.TSVoidKeyword,
65
+ utils_1.AST_NODE_TYPES.TSNeverKeyword,
66
+ ];
67
+ if (allowInGenericTypeArguments === true) {
68
+ validParents.push(utils_1.AST_NODE_TYPES.TSTypeParameterInstantiation);
69
+ }
70
+ /**
71
+ * @brief check if the given void keyword is used as a valid generic type
72
+ *
73
+ * reports if the type parametrized by void is not in the allowlist, or
74
+ * allowInGenericTypeArguments is false.
75
+ * no-op if the given void keyword is not used as generic type
76
+ */
77
+ function checkGenericTypeArgument(node) {
78
+ // only matches T<..., void, ...>
79
+ // extra check for precaution
80
+ /* istanbul ignore next */
81
+ if (node.parent.type !== utils_1.AST_NODE_TYPES.TSTypeParameterInstantiation ||
82
+ node.parent.parent.type !== utils_1.AST_NODE_TYPES.TSTypeReference) {
83
+ return;
84
+ }
85
+ // check allowlist
86
+ if (Array.isArray(allowInGenericTypeArguments)) {
87
+ const fullyQualifiedName = context.sourceCode
88
+ .getText(node.parent.parent.typeName)
89
+ .replaceAll(' ', '');
90
+ if (!allowInGenericTypeArguments
91
+ .map(s => s.replaceAll(' ', ''))
92
+ .includes(fullyQualifiedName)) {
93
+ context.report({
94
+ node,
95
+ messageId: 'invalidVoidForGeneric',
96
+ data: { generic: fullyQualifiedName },
97
+ });
98
+ }
99
+ return;
100
+ }
101
+ if (!allowInGenericTypeArguments) {
102
+ context.report({
103
+ node,
104
+ messageId: allowAsThisParameter
105
+ ? 'invalidVoidNotReturnOrThisParam'
106
+ : 'invalidVoidNotReturn',
107
+ });
108
+ }
109
+ }
110
+ /**
111
+ * @brief checks if the generic type parameter defaults to void
112
+ */
113
+ function checkDefaultVoid(node, parentNode) {
114
+ if (parentNode.default !== node) {
115
+ context.report({
116
+ node,
117
+ messageId: getNotReturnOrGenericMessageId(node),
118
+ });
119
+ }
120
+ }
121
+ /**
122
+ * @brief checks that a union containing void is valid
123
+ * @return true if every member of the union is specified as a valid type in
124
+ * validUnionMembers, or is a valid generic type parametrized by void
125
+ */
126
+ function isValidUnionType(node) {
127
+ return node.types.every(member => validUnionMembers.includes(member.type) ||
128
+ // allows any T<..., void, ...> here, checked by checkGenericTypeArgument
129
+ (member.type === utils_1.AST_NODE_TYPES.TSTypeReference &&
130
+ member.typeArguments?.type ===
131
+ utils_1.AST_NODE_TYPES.TSTypeParameterInstantiation &&
132
+ member.typeArguments.params
133
+ .map(param => param.type)
134
+ .includes(utils_1.AST_NODE_TYPES.TSVoidKeyword)));
135
+ }
136
+ return {
137
+ TSVoidKeyword(node) {
138
+ // checks T<..., void, ...> against specification of allowInGenericArguments option
139
+ if (node.parent.type === utils_1.AST_NODE_TYPES.TSTypeParameterInstantiation &&
140
+ node.parent.parent.type === utils_1.AST_NODE_TYPES.TSTypeReference) {
141
+ checkGenericTypeArgument(node);
142
+ return;
143
+ }
144
+ // allow <T = void> if allowInGenericTypeArguments is specified, and report if the generic type parameter extends void
145
+ if (allowInGenericTypeArguments &&
146
+ node.parent.type === utils_1.AST_NODE_TYPES.TSTypeParameter &&
147
+ node.parent.default?.type === utils_1.AST_NODE_TYPES.TSVoidKeyword) {
148
+ checkDefaultVoid(node, node.parent);
149
+ return;
150
+ }
151
+ // union w/ void must contain types from validUnionMembers, or a valid generic void type
152
+ if (node.parent.type === utils_1.AST_NODE_TYPES.TSUnionType &&
153
+ isValidUnionType(node.parent)) {
154
+ return;
155
+ }
156
+ // using `void` as part of the return type of function overloading implementation
157
+ if (node.parent.type === utils_1.AST_NODE_TYPES.TSUnionType) {
158
+ const declaringFunction = getParentFunctionDeclarationNode(node.parent);
159
+ if (declaringFunction &&
160
+ (0, util_1.hasOverloadSignatures)(declaringFunction, context)) {
161
+ return;
162
+ }
163
+ }
164
+ // this parameter is ok to be void.
165
+ if (allowAsThisParameter &&
166
+ node.parent.type === utils_1.AST_NODE_TYPES.TSTypeAnnotation &&
167
+ node.parent.parent.type === utils_1.AST_NODE_TYPES.Identifier &&
168
+ node.parent.parent.name === 'this') {
169
+ return;
170
+ }
171
+ // default cases
172
+ if (validParents.includes(node.parent.type) &&
173
+ // https://github.com/typescript-eslint/typescript-eslint/issues/6225
174
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
175
+ !invalidGrandParents.includes(node.parent.parent.type)) {
176
+ return;
177
+ }
178
+ context.report({
179
+ node,
180
+ messageId: allowInGenericTypeArguments && allowAsThisParameter
181
+ ? 'invalidVoidNotReturnOrThisParamOrGeneric'
182
+ : allowInGenericTypeArguments
183
+ ? getNotReturnOrGenericMessageId(node)
184
+ : allowAsThisParameter
185
+ ? 'invalidVoidNotReturnOrThisParam'
186
+ : 'invalidVoidNotReturn',
187
+ });
188
+ },
189
+ };
190
+ },
191
+ });
192
+ function getNotReturnOrGenericMessageId(node) {
193
+ return node.parent.type === utils_1.AST_NODE_TYPES.TSUnionType
194
+ ? 'invalidVoidUnionConstituent'
195
+ : 'invalidVoidNotReturnOrGeneric';
196
+ }
197
+ function getParentFunctionDeclarationNode(node) {
198
+ let current = node.parent;
199
+ while (current) {
200
+ if (current.type === utils_1.AST_NODE_TYPES.FunctionDeclaration) {
201
+ return current;
202
+ }
203
+ if (current.type === utils_1.AST_NODE_TYPES.MethodDefinition &&
204
+ current.value.body != null) {
205
+ return current;
206
+ }
207
+ current = current.parent;
208
+ }
209
+ return null;
210
+ }
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-loop-func.d.ts ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { TSESLint, TSESTree } from '@typescript-eslint/utils';
2
+ import type { InferMessageIdsTypeFromRule, InferOptionsTypeFromRule } from '../util';
3
+ declare const baseRule: TSESLint.RuleModule<"unsafeRefs", [], unknown, {
4
+ ArrowFunctionExpression(node: TSESTree.ArrowFunctionExpression): void;
5
+ FunctionDeclaration(node: TSESTree.FunctionDeclaration): void;
6
+ FunctionExpression(node: TSESTree.FunctionExpression): void;
7
+ }>;
8
+ export type Options = InferOptionsTypeFromRule<typeof baseRule>;
9
+ export type MessageIds = InferMessageIdsTypeFromRule<typeof baseRule>;
10
+ declare const _default: TSESLint.RuleModule<"unsafeRefs", [], import("../../rules").ESLintPluginDocs, TSESLint.RuleListener> & {
11
+ name: string;
12
+ };
13
+ export default _default;
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-loop-func.js ADDED
@@ -0,0 +1,187 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@typescript-eslint/utils");
4
+ const util_1 = require("../util");
5
+ const getESLintCoreRule_1 = require("../util/getESLintCoreRule");
6
+ const baseRule = (0, getESLintCoreRule_1.getESLintCoreRule)('no-loop-func');
7
+ exports.default = (0, util_1.createRule)({
8
+ name: 'no-loop-func',
9
+ meta: {
10
+ type: 'suggestion',
11
+ // defaultOptions, -- base rule does not use defaultOptions
12
+ docs: {
13
+ description: 'Disallow function declarations that contain unsafe references inside loop statements',
14
+ extendsBaseRule: true,
15
+ },
16
+ hasSuggestions: baseRule.meta.hasSuggestions,
17
+ messages: baseRule.meta.messages,
18
+ schema: [],
19
+ },
20
+ defaultOptions: [],
21
+ create(context) {
22
+ const SKIPPED_IIFE_NODES = new Set();
23
+ /**
24
+ * Gets the containing loop node of a specified node.
25
+ *
26
+ * We don't need to check nested functions, so this ignores those.
27
+ * `Scope.through` contains references of nested functions.
28
+ *
29
+ * @param node An AST node to get.
30
+ * @returns The containing loop node of the specified node, or `null`.
31
+ */
32
+ function getContainingLoopNode(node) {
33
+ for (let currentNode = node; currentNode.parent; currentNode = currentNode.parent) {
34
+ const parent = currentNode.parent;
35
+ switch (parent.type) {
36
+ case utils_1.AST_NODE_TYPES.WhileStatement:
37
+ case utils_1.AST_NODE_TYPES.DoWhileStatement:
38
+ return parent;
39
+ case utils_1.AST_NODE_TYPES.ForStatement:
40
+ // `init` is outside of the loop.
41
+ if (parent.init !== currentNode) {
42
+ return parent;
43
+ }
44
+ break;
45
+ case utils_1.AST_NODE_TYPES.ForInStatement:
46
+ case utils_1.AST_NODE_TYPES.ForOfStatement:
47
+ // `right` is outside of the loop.
48
+ if (parent.right !== currentNode) {
49
+ return parent;
50
+ }
51
+ break;
52
+ case utils_1.AST_NODE_TYPES.ArrowFunctionExpression:
53
+ case utils_1.AST_NODE_TYPES.FunctionExpression:
54
+ case utils_1.AST_NODE_TYPES.FunctionDeclaration:
55
+ // We don't need to check nested functions.
56
+ // We need to check nested functions only in case of IIFE.
57
+ if (SKIPPED_IIFE_NODES.has(parent)) {
58
+ break;
59
+ }
60
+ return null;
61
+ default:
62
+ break;
63
+ }
64
+ }
65
+ return null;
66
+ }
67
+ /**
68
+ * Gets the containing loop node of a given node.
69
+ * If the loop was nested, this returns the most outer loop.
70
+ * @param node A node to get. This is a loop node.
71
+ * @param excludedNode A node that the result node should not include.
72
+ * @returns The most outer loop node.
73
+ */
74
+ function getTopLoopNode(node, excludedNode) {
75
+ const border = excludedNode ? excludedNode.range[1] : 0;
76
+ let retv = node;
77
+ let containingLoopNode = node;
78
+ while (containingLoopNode && containingLoopNode.range[0] >= border) {
79
+ retv = containingLoopNode;
80
+ containingLoopNode = getContainingLoopNode(containingLoopNode);
81
+ }
82
+ return retv;
83
+ }
84
+ /**
85
+ * Checks whether a given reference which refers to an upper scope's variable is
86
+ * safe or not.
87
+ * @param loopNode A containing loop node.
88
+ * @param reference A reference to check.
89
+ * @returns `true` if the reference is safe or not.
90
+ */
91
+ function isSafe(loopNode, reference) {
92
+ const variable = reference.resolved;
93
+ const definition = variable?.defs[0];
94
+ const declaration = definition?.parent;
95
+ const kind = declaration?.type === utils_1.AST_NODE_TYPES.VariableDeclaration
96
+ ? declaration.kind
97
+ : '';
98
+ // type references are all safe
99
+ // this only really matters for global types that haven't been configured
100
+ if (reference.isTypeReference) {
101
+ return true;
102
+ }
103
+ // Variables which are declared by `const` is safe.
104
+ if (kind === 'const') {
105
+ return true;
106
+ }
107
+ /*
108
+ * Variables which are declared by `let` in the loop is safe.
109
+ * It's a different instance from the next loop step's.
110
+ */
111
+ if (kind === 'let' &&
112
+ declaration &&
113
+ declaration.range[0] > loopNode.range[0] &&
114
+ declaration.range[1] < loopNode.range[1]) {
115
+ return true;
116
+ }
117
+ /*
118
+ * WriteReferences which exist after this border are unsafe because those
119
+ * can modify the variable.
120
+ */
121
+ const border = getTopLoopNode(loopNode, kind === 'let' ? declaration : null).range[0];
122
+ /**
123
+ * Checks whether a given reference is safe or not.
124
+ * The reference is every reference of the upper scope's variable we are
125
+ * looking now.
126
+ *
127
+ * It's safe if the reference matches one of the following condition.
128
+ * - is readonly.
129
+ * - doesn't exist inside a local function and after the border.
130
+ *
131
+ * @param upperRef A reference to check.
132
+ * @returns `true` if the reference is safe.
133
+ */
134
+ function isSafeReference(upperRef) {
135
+ const id = upperRef.identifier;
136
+ return (!upperRef.isWrite() ||
137
+ (variable?.scope.variableScope === upperRef.from.variableScope &&
138
+ id.range[0] < border));
139
+ }
140
+ return variable?.references.every(isSafeReference) ?? false;
141
+ }
142
+ /**
143
+ * Reports functions which match the following condition:
144
+ * - has a loop node in ancestors.
145
+ * - has any references which refers to an unsafe variable.
146
+ *
147
+ * @param node The AST node to check.
148
+ */
149
+ function checkForLoops(node) {
150
+ const loopNode = getContainingLoopNode(node);
151
+ if (!loopNode) {
152
+ return;
153
+ }
154
+ const references = context.sourceCode.getScope(node).through;
155
+ if (!(node.async || node.generator) && isIIFE(node)) {
156
+ const isFunctionExpression = node.type === utils_1.AST_NODE_TYPES.FunctionExpression;
157
+ // Check if the function is referenced elsewhere in the code
158
+ const isFunctionReferenced = isFunctionExpression && node.id
159
+ ? references.some(r => r.identifier.name === node.id?.name)
160
+ : false;
161
+ if (!isFunctionReferenced) {
162
+ SKIPPED_IIFE_NODES.add(node);
163
+ return;
164
+ }
165
+ }
166
+ const unsafeRefs = references
167
+ .filter(r => r.resolved && !isSafe(loopNode, r))
168
+ .map(r => r.identifier.name);
169
+ if (unsafeRefs.length > 0) {
170
+ context.report({
171
+ node,
172
+ messageId: 'unsafeRefs',
173
+ data: { varNames: `'${unsafeRefs.join("', '")}'` },
174
+ });
175
+ }
176
+ }
177
+ return {
178
+ ArrowFunctionExpression: checkForLoops,
179
+ FunctionDeclaration: checkForLoops,
180
+ FunctionExpression: checkForLoops,
181
+ };
182
+ },
183
+ });
184
+ function isIIFE(node) {
185
+ return (node.parent.type === utils_1.AST_NODE_TYPES.CallExpression &&
186
+ node.parent.callee === node);
187
+ }
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-loss-of-precision.d.ts ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import type { InferMessageIdsTypeFromRule, InferOptionsTypeFromRule } from '../util';
2
+ import { getESLintCoreRule } from '../util/getESLintCoreRule';
3
+ declare const baseRule: ReturnType<typeof getESLintCoreRule>;
4
+ export type Options = InferOptionsTypeFromRule<NonNullable<typeof baseRule>>;
5
+ export type MessageIds = InferMessageIdsTypeFromRule<NonNullable<typeof baseRule>>;
6
+ declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<"noLossOfPrecision", [], import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
7
+ name: string;
8
+ };
9
+ export default _default;
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-loss-of-precision.js ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const util_1 = require("../util");
4
+ const getESLintCoreRule_1 = require("../util/getESLintCoreRule");
5
+ const baseRule = (0, getESLintCoreRule_1.getESLintCoreRule)('no-loss-of-precision');
6
+ exports.default = (0, util_1.createRule)({
7
+ name: 'no-loss-of-precision',
8
+ meta: {
9
+ type: 'problem',
10
+ // defaultOptions, -- base rule does not use defaultOptions
11
+ deprecated: {
12
+ deprecatedSince: '8.0.0',
13
+ replacedBy: [
14
+ {
15
+ rule: {
16
+ name: 'no-loss-of-precision',
17
+ url: 'https://eslint.org/docs/latest/rules/no-loss-of-precision',
18
+ },
19
+ },
20
+ ],
21
+ url: 'https://github.com/typescript-eslint/typescript-eslint/pull/8832',
22
+ },
23
+ docs: {
24
+ description: 'Disallow literal numbers that lose precision',
25
+ extendsBaseRule: true,
26
+ },
27
+ hasSuggestions: baseRule.meta.hasSuggestions,
28
+ messages: baseRule.meta.messages,
29
+ schema: [],
30
+ },
31
+ defaultOptions: [],
32
+ create(context) {
33
+ return baseRule.create(context);
34
+ },
35
+ });
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-magic-numbers.d.ts ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { TSESTree } from '@typescript-eslint/utils';
2
+ import type { InferMessageIdsTypeFromRule, InferOptionsTypeFromRule } from '../util';
3
+ declare const baseRule: import("@typescript-eslint/utils/ts-eslint").RuleModule<"noMagic", [{
4
+ detectObjects?: boolean;
5
+ enforceConst?: boolean;
6
+ ignore?: (number | string)[];
7
+ ignoreArrayIndexes?: boolean;
8
+ ignoreEnums?: boolean;
9
+ ignoreNumericLiteralTypes?: boolean;
10
+ ignoreReadonlyClassProperties?: boolean;
11
+ ignoreTypeIndexes?: boolean;
12
+ }], unknown, {
13
+ Literal(node: TSESTree.Literal): void;
14
+ }>;
15
+ export type Options = InferOptionsTypeFromRule<typeof baseRule>;
16
+ export type MessageIds = InferMessageIdsTypeFromRule<typeof baseRule>;
17
+ declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<"noMagic", [{
18
+ detectObjects?: boolean;
19
+ enforceConst?: boolean;
20
+ ignore?: (number | string)[];
21
+ ignoreArrayIndexes?: boolean;
22
+ ignoreEnums?: boolean;
23
+ ignoreNumericLiteralTypes?: boolean;
24
+ ignoreReadonlyClassProperties?: boolean;
25
+ ignoreTypeIndexes?: boolean;
26
+ }], import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
27
+ name: string;
28
+ };
29
+ export default _default;
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-magic-numbers.js ADDED
@@ -0,0 +1,249 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@typescript-eslint/utils");
4
+ const util_1 = require("../util");
5
+ const getESLintCoreRule_1 = require("../util/getESLintCoreRule");
6
+ const baseRule = (0, getESLintCoreRule_1.getESLintCoreRule)('no-magic-numbers');
7
+ // Extend base schema with additional property to ignore TS numeric literal types
8
+ const schema = (0, util_1.deepMerge)(
9
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- https://github.com/microsoft/TypeScript/issues/17002
10
+ Array.isArray(baseRule.meta.schema)
11
+ ? baseRule.meta.schema[0]
12
+ : baseRule.meta.schema, {
13
+ properties: {
14
+ ignoreEnums: {
15
+ type: 'boolean',
16
+ description: 'Whether enums used in TypeScript are considered okay.',
17
+ },
18
+ ignoreNumericLiteralTypes: {
19
+ type: 'boolean',
20
+ description: 'Whether numbers used in TypeScript numeric literal types are considered okay.',
21
+ },
22
+ ignoreReadonlyClassProperties: {
23
+ type: 'boolean',
24
+ description: 'Whether `readonly` class properties are considered okay.',
25
+ },
26
+ ignoreTypeIndexes: {
27
+ type: 'boolean',
28
+ description: 'Whether numbers used to index types are okay.',
29
+ },
30
+ },
31
+ });
32
+ const defaultOptions = [
33
+ {
34
+ detectObjects: false,
35
+ enforceConst: false,
36
+ ignore: [],
37
+ ignoreArrayIndexes: false,
38
+ ignoreEnums: false,
39
+ ignoreNumericLiteralTypes: false,
40
+ ignoreReadonlyClassProperties: false,
41
+ ignoreTypeIndexes: false,
42
+ },
43
+ ];
44
+ exports.default = (0, util_1.createRule)({
45
+ name: 'no-magic-numbers',
46
+ meta: {
47
+ type: 'suggestion',
48
+ defaultOptions,
49
+ docs: {
50
+ description: 'Disallow magic numbers',
51
+ extendsBaseRule: true,
52
+ frozen: true,
53
+ },
54
+ messages: baseRule.meta.messages,
55
+ schema: [schema],
56
+ },
57
+ defaultOptions,
58
+ create(context, [options]) {
59
+ const rules = baseRule.create(context);
60
+ const ignored = new Set((options.ignore ?? []).map(normalizeIgnoreValue));
61
+ return {
62
+ Literal(node) {
63
+ // If it’s not a numeric literal we’re not interested
64
+ if (typeof node.value !== 'number' && typeof node.value !== 'bigint') {
65
+ return;
66
+ }
67
+ // This will be `true` if we’re configured to ignore this case (eg. it’s
68
+ // an enum and `ignoreEnums` is `true`). It will be `false` if we’re not
69
+ // configured to ignore this case. It will remain `undefined` if this is
70
+ // not one of our exception cases, and we’ll fall back to the base rule.
71
+ let isAllowed;
72
+ // Check if the node is ignored
73
+ if (ignored.has(normalizeLiteralValue(node, node.value))) {
74
+ isAllowed = true;
75
+ }
76
+ // Check if the node is a TypeScript enum declaration
77
+ else if (isParentTSEnumDeclaration(node)) {
78
+ isAllowed = options.ignoreEnums === true;
79
+ }
80
+ // Check TypeScript specific nodes for Numeric Literal
81
+ else if (isTSNumericLiteralType(node)) {
82
+ isAllowed = options.ignoreNumericLiteralTypes === true;
83
+ }
84
+ // Check if the node is a type index
85
+ else if (isAncestorTSIndexedAccessType(node)) {
86
+ isAllowed = options.ignoreTypeIndexes === true;
87
+ }
88
+ // Check if the node is a readonly class property
89
+ else if (isParentTSReadonlyPropertyDefinition(node)) {
90
+ isAllowed = options.ignoreReadonlyClassProperties === true;
91
+ }
92
+ // If we’ve hit a case where the ignore option is true we can return now
93
+ if (isAllowed === true) {
94
+ return;
95
+ }
96
+ // If the ignore option is *not* set we can report it now
97
+ if (isAllowed === false) {
98
+ let fullNumberNode = node;
99
+ let raw = node.raw;
100
+ if (node.parent.type === utils_1.AST_NODE_TYPES.UnaryExpression &&
101
+ // the base rule only shows the operator for negative numbers
102
+ // https://github.com/eslint/eslint/blob/9dfc8501fb1956c90dc11e6377b4cb38a6bea65d/lib/rules/no-magic-numbers.js#L126
103
+ node.parent.operator === '-') {
104
+ fullNumberNode = node.parent;
105
+ raw = `${node.parent.operator}${node.raw}`;
106
+ }
107
+ context.report({
108
+ node: fullNumberNode,
109
+ messageId: 'noMagic',
110
+ data: { raw },
111
+ });
112
+ return;
113
+ }
114
+ // Let the base rule deal with the rest
115
+ rules.Literal(node);
116
+ },
117
+ };
118
+ },
119
+ });
120
+ /**
121
+ * Convert the value to bigint if it's a string. Otherwise, return the value as-is.
122
+ * @param value The value to normalize.
123
+ * @returns The normalized value.
124
+ */
125
+ function normalizeIgnoreValue(value) {
126
+ if (typeof value === 'string') {
127
+ return BigInt(value.slice(0, -1));
128
+ }
129
+ return value;
130
+ }
131
+ /**
132
+ * Converts the node to its numeric value, handling prefixed numbers (-1 / +1)
133
+ * @param node the node to normalize.
134
+ * @param value the node's value.
135
+ */
136
+ function normalizeLiteralValue(node, value) {
137
+ if (node.parent.type === utils_1.AST_NODE_TYPES.UnaryExpression &&
138
+ ['-', '+'].includes(node.parent.operator) &&
139
+ node.parent.operator === '-') {
140
+ return -value;
141
+ }
142
+ return value;
143
+ }
144
+ /**
145
+ * Gets the true parent of the literal, handling prefixed numbers (-1 / +1)
146
+ */
147
+ function getLiteralParent(node) {
148
+ if (node.parent.type === utils_1.AST_NODE_TYPES.UnaryExpression &&
149
+ ['-', '+'].includes(node.parent.operator)) {
150
+ return node.parent.parent;
151
+ }
152
+ return node.parent;
153
+ }
154
+ /**
155
+ * Checks if the node grandparent is a Typescript type alias declaration
156
+ * @param node the node to be validated.
157
+ * @returns true if the node grandparent is a Typescript type alias declaration
158
+ * @private
159
+ */
160
+ function isGrandparentTSTypeAliasDeclaration(node) {
161
+ return node.parent?.parent?.type === utils_1.AST_NODE_TYPES.TSTypeAliasDeclaration;
162
+ }
163
+ /**
164
+ * Checks if the node grandparent is a Typescript union type and its parent is a type alias declaration
165
+ * @param node the node to be validated.
166
+ * @returns true if the node grandparent is a Typescript union type and its parent is a type alias declaration
167
+ * @private
168
+ */
169
+ function isGrandparentTSUnionType(node) {
170
+ if (node.parent?.parent?.type === utils_1.AST_NODE_TYPES.TSUnionType) {
171
+ return isGrandparentTSTypeAliasDeclaration(node.parent);
172
+ }
173
+ return false;
174
+ }
175
+ /**
176
+ * Checks if the node parent is a Typescript enum member
177
+ * @param node the node to be validated.
178
+ * @returns true if the node parent is a Typescript enum member
179
+ * @private
180
+ */
181
+ function isParentTSEnumDeclaration(node) {
182
+ const parent = getLiteralParent(node);
183
+ return parent?.type === utils_1.AST_NODE_TYPES.TSEnumMember;
184
+ }
185
+ /**
186
+ * Checks if the node parent is a Typescript literal type
187
+ * @param node the node to be validated.
188
+ * @returns true if the node parent is a Typescript literal type
189
+ * @private
190
+ */
191
+ function isParentTSLiteralType(node) {
192
+ return node.parent?.type === utils_1.AST_NODE_TYPES.TSLiteralType;
193
+ }
194
+ /**
195
+ * Checks if the node is a valid TypeScript numeric literal type.
196
+ * @param node the node to be validated.
197
+ * @returns true if the node is a TypeScript numeric literal type.
198
+ * @private
199
+ */
200
+ function isTSNumericLiteralType(node) {
201
+ // For negative numbers, use the parent node
202
+ if (node.parent?.type === utils_1.AST_NODE_TYPES.UnaryExpression &&
203
+ node.parent.operator === '-') {
204
+ node = node.parent;
205
+ }
206
+ // If the parent node is not a TSLiteralType, early return
207
+ if (!isParentTSLiteralType(node)) {
208
+ return false;
209
+ }
210
+ // If the grandparent is a TSTypeAliasDeclaration, ignore
211
+ if (isGrandparentTSTypeAliasDeclaration(node)) {
212
+ return true;
213
+ }
214
+ // If the grandparent is a TSUnionType and it's parent is a TSTypeAliasDeclaration, ignore
215
+ if (isGrandparentTSUnionType(node)) {
216
+ return true;
217
+ }
218
+ return false;
219
+ }
220
+ /**
221
+ * Checks if the node parent is a readonly class property
222
+ * @param node the node to be validated.
223
+ * @returns true if the node parent is a readonly class property
224
+ * @private
225
+ */
226
+ function isParentTSReadonlyPropertyDefinition(node) {
227
+ const parent = getLiteralParent(node);
228
+ if (parent?.type === utils_1.AST_NODE_TYPES.PropertyDefinition && parent.readonly) {
229
+ return true;
230
+ }
231
+ return false;
232
+ }
233
+ /**
234
+ * Checks if the node is part of a type indexed access (eg. Foo[4])
235
+ * @param node the node to be validated.
236
+ * @returns true if the node is part of an indexed access
237
+ * @private
238
+ */
239
+ function isAncestorTSIndexedAccessType(node) {
240
+ // Handle unary expressions (eg. -4)
241
+ let ancestor = getLiteralParent(node);
242
+ // Go up another level while we’re part of a type union (eg. 1 | 2) or
243
+ // intersection (eg. 1 & 2)
244
+ while (ancestor?.parent?.type === utils_1.AST_NODE_TYPES.TSUnionType ||
245
+ ancestor?.parent?.type === utils_1.AST_NODE_TYPES.TSIntersectionType) {
246
+ ancestor = ancestor.parent;
247
+ }
248
+ return ancestor?.parent?.type === utils_1.AST_NODE_TYPES.TSIndexedAccessType;
249
+ }
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-meaningless-void-operator.d.ts ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { TSESLint } from '@typescript-eslint/utils';
2
+ export type Options = [
3
+ {
4
+ checkNever: boolean;
5
+ }
6
+ ];
7
+ declare const _default: TSESLint.RuleModule<"meaninglessVoidOperator" | "removeVoid", Options, import("../../rules").ESLintPluginDocs, TSESLint.RuleListener> & {
8
+ name: string;
9
+ };
10
+ export default _default;
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-meaningless-void-operator.js ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const utils_1 = require("@typescript-eslint/utils");
37
+ const tsutils = __importStar(require("ts-api-utils"));
38
+ const ts = __importStar(require("typescript"));
39
+ const util_1 = require("../util");
40
+ exports.default = (0, util_1.createRule)({
41
+ name: 'no-meaningless-void-operator',
42
+ meta: {
43
+ type: 'suggestion',
44
+ docs: {
45
+ description: 'Disallow the `void` operator except when used to discard a value',
46
+ recommended: 'strict',
47
+ requiresTypeChecking: true,
48
+ },
49
+ fixable: 'code',
50
+ hasSuggestions: true,
51
+ messages: {
52
+ meaninglessVoidOperator: "void operator shouldn't be used on {{type}}; it should convey that a return value is being ignored",
53
+ removeVoid: "Remove 'void'",
54
+ },
55
+ schema: [
56
+ {
57
+ type: 'object',
58
+ additionalProperties: false,
59
+ properties: {
60
+ checkNever: {
61
+ type: 'boolean',
62
+ description: 'Whether to suggest removing `void` when the argument has type `never`.',
63
+ },
64
+ },
65
+ },
66
+ ],
67
+ },
68
+ defaultOptions: [{ checkNever: false }],
69
+ create(context, [{ checkNever }]) {
70
+ const services = utils_1.ESLintUtils.getParserServices(context);
71
+ const checker = services.program.getTypeChecker();
72
+ return {
73
+ 'UnaryExpression[operator="void"]'(node) {
74
+ const fix = (fixer) => {
75
+ return fixer.removeRange([
76
+ context.sourceCode.getTokens(node)[0].range[0],
77
+ context.sourceCode.getTokens(node)[1].range[0],
78
+ ]);
79
+ };
80
+ const argType = services.getTypeAtLocation(node.argument);
81
+ const unionParts = tsutils.unionConstituents(argType);
82
+ if (unionParts.every(part => tsutils.isTypeFlagSet(part, ts.TypeFlags.Void | ts.TypeFlags.Undefined))) {
83
+ context.report({
84
+ node,
85
+ messageId: 'meaninglessVoidOperator',
86
+ data: { type: checker.typeToString(argType) },
87
+ fix,
88
+ });
89
+ }
90
+ else if (checkNever &&
91
+ unionParts.every(part => tsutils.isTypeFlagSet(part, ts.TypeFlags.Void | ts.TypeFlags.Undefined | ts.TypeFlags.Never))) {
92
+ context.report({
93
+ node,
94
+ messageId: 'meaninglessVoidOperator',
95
+ data: { type: checker.typeToString(argType) },
96
+ suggest: [{ messageId: 'removeVoid', fix }],
97
+ });
98
+ }
99
+ },
100
+ };
101
+ },
102
+ });
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-misused-new.d.ts ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<"errorMessageClass" | "errorMessageInterface", [], import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
2
+ name: string;
3
+ };
4
+ export default _default;
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-misused-new.js ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@typescript-eslint/utils");
4
+ const util_1 = require("../util");
5
+ exports.default = (0, util_1.createRule)({
6
+ name: 'no-misused-new',
7
+ meta: {
8
+ type: 'problem',
9
+ docs: {
10
+ description: 'Enforce valid definition of `new` and `constructor`',
11
+ recommended: 'recommended',
12
+ },
13
+ messages: {
14
+ errorMessageClass: 'Class cannot have method named `new`.',
15
+ errorMessageInterface: 'Interfaces cannot be constructed, only classes.',
16
+ },
17
+ schema: [],
18
+ },
19
+ defaultOptions: [],
20
+ create(context) {
21
+ /**
22
+ * @param node type to be inspected.
23
+ * @returns name of simple type or null
24
+ */
25
+ function getTypeReferenceName(node) {
26
+ if (node) {
27
+ switch (node.type) {
28
+ case utils_1.AST_NODE_TYPES.TSTypeAnnotation:
29
+ return getTypeReferenceName(node.typeAnnotation);
30
+ case utils_1.AST_NODE_TYPES.TSTypeReference:
31
+ return getTypeReferenceName(node.typeName);
32
+ case utils_1.AST_NODE_TYPES.Identifier:
33
+ return node.name;
34
+ default:
35
+ break;
36
+ }
37
+ }
38
+ return null;
39
+ }
40
+ /**
41
+ * @param parent parent node.
42
+ * @param returnType type to be compared
43
+ */
44
+ function isMatchingParentType(parent, returnType) {
45
+ if (parent &&
46
+ (parent.type === utils_1.AST_NODE_TYPES.ClassDeclaration ||
47
+ parent.type === utils_1.AST_NODE_TYPES.ClassExpression ||
48
+ parent.type === utils_1.AST_NODE_TYPES.TSInterfaceDeclaration) &&
49
+ parent.id) {
50
+ return getTypeReferenceName(returnType) === parent.id.name;
51
+ }
52
+ return false;
53
+ }
54
+ return {
55
+ "ClassBody > MethodDefinition[key.name='new']"(node) {
56
+ if (node.value.type === utils_1.AST_NODE_TYPES.TSEmptyBodyFunctionExpression &&
57
+ isMatchingParentType(node.parent.parent, node.value.returnType)) {
58
+ context.report({
59
+ node,
60
+ messageId: 'errorMessageClass',
61
+ });
62
+ }
63
+ },
64
+ 'TSInterfaceBody > TSConstructSignatureDeclaration'(node) {
65
+ if (isMatchingParentType(node.parent.parent, node.returnType)) {
66
+ // constructor
67
+ context.report({
68
+ node,
69
+ messageId: 'errorMessageInterface',
70
+ });
71
+ }
72
+ },
73
+ "TSMethodSignature[key.name='constructor']"(node) {
74
+ context.report({
75
+ node,
76
+ messageId: 'errorMessageInterface',
77
+ });
78
+ },
79
+ };
80
+ },
81
+ });
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-misused-promises.d.ts ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { TSESLint } from '@typescript-eslint/utils';
2
+ export type Options = [
3
+ {
4
+ checksConditionals?: boolean;
5
+ checksSpreads?: boolean;
6
+ checksVoidReturn?: boolean | ChecksVoidReturnOptions;
7
+ }
8
+ ];
9
+ export interface ChecksVoidReturnOptions {
10
+ arguments?: boolean;
11
+ attributes?: boolean;
12
+ inheritedMethods?: boolean;
13
+ properties?: boolean;
14
+ returns?: boolean;
15
+ variables?: boolean;
16
+ }
17
+ export type MessageId = 'conditional' | 'predicate' | 'spread' | 'voidReturnArgument' | 'voidReturnAttribute' | 'voidReturnInheritedMethod' | 'voidReturnProperty' | 'voidReturnReturnValue' | 'voidReturnVariable';
18
+ declare const _default: TSESLint.RuleModule<MessageId, Options, import("../../rules").ESLintPluginDocs, TSESLint.RuleListener> & {
19
+ name: string;
20
+ };
21
+ export default _default;
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-misused-promises.js ADDED
@@ -0,0 +1,765 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const utils_1 = require("@typescript-eslint/utils");
37
+ const tsutils = __importStar(require("ts-api-utils"));
38
+ const ts = __importStar(require("typescript"));
39
+ const util_1 = require("../util");
40
+ const promiseUtils_1 = require("../util/promiseUtils");
41
+ function parseChecksVoidReturn(checksVoidReturn) {
42
+ switch (checksVoidReturn) {
43
+ case false:
44
+ return false;
45
+ case true:
46
+ case undefined:
47
+ return {
48
+ arguments: true,
49
+ attributes: true,
50
+ inheritedMethods: true,
51
+ properties: true,
52
+ returns: true,
53
+ variables: true,
54
+ };
55
+ default:
56
+ return {
57
+ arguments: checksVoidReturn.arguments ?? true,
58
+ attributes: checksVoidReturn.attributes ?? true,
59
+ inheritedMethods: checksVoidReturn.inheritedMethods ?? true,
60
+ properties: checksVoidReturn.properties ?? true,
61
+ returns: checksVoidReturn.returns ?? true,
62
+ variables: checksVoidReturn.variables ?? true,
63
+ };
64
+ }
65
+ }
66
+ exports.default = (0, util_1.createRule)({
67
+ name: 'no-misused-promises',
68
+ meta: {
69
+ type: 'problem',
70
+ docs: {
71
+ description: 'Disallow Promises in places not designed to handle them',
72
+ recommended: 'recommended',
73
+ requiresTypeChecking: true,
74
+ },
75
+ messages: {
76
+ conditional: 'Expected non-Promise value in a boolean conditional.',
77
+ predicate: 'Expected a non-Promise value to be returned.',
78
+ spread: 'Expected a non-Promise value to be spread in an object.',
79
+ voidReturnArgument: 'Promise returned in function argument where a void return was expected.',
80
+ voidReturnAttribute: 'Promise-returning function provided to attribute where a void return was expected.',
81
+ voidReturnInheritedMethod: "Promise-returning method provided where a void return was expected by extended/implemented type '{{ heritageTypeName }}'.",
82
+ voidReturnProperty: 'Promise-returning function provided to property where a void return was expected.',
83
+ voidReturnReturnValue: 'Promise-returning function provided to return value where a void return was expected.',
84
+ voidReturnVariable: 'Promise-returning function provided to variable where a void return was expected.',
85
+ },
86
+ schema: [
87
+ {
88
+ type: 'object',
89
+ additionalProperties: false,
90
+ properties: {
91
+ checksConditionals: {
92
+ type: 'boolean',
93
+ description: 'Whether to warn when a Promise is provided to conditional statements.',
94
+ },
95
+ checksSpreads: {
96
+ type: 'boolean',
97
+ description: 'Whether to warn when `...` spreading a `Promise`.',
98
+ },
99
+ checksVoidReturn: {
100
+ description: 'Whether to warn when a Promise is returned from a function typed as returning `void`.',
101
+ oneOf: [
102
+ {
103
+ type: 'boolean',
104
+ description: 'Whether to disable checking all asynchronous functions.',
105
+ },
106
+ {
107
+ type: 'object',
108
+ additionalProperties: false,
109
+ description: 'Which forms of functions may have checking disabled.',
110
+ properties: {
111
+ arguments: {
112
+ type: 'boolean',
113
+ description: 'Disables checking an asynchronous function passed as argument where the parameter type expects a function that returns `void`.',
114
+ },
115
+ attributes: {
116
+ type: 'boolean',
117
+ description: 'Disables checking an asynchronous function passed as a JSX attribute expected to be a function that returns `void`.',
118
+ },
119
+ inheritedMethods: {
120
+ type: 'boolean',
121
+ description: 'Disables checking an asynchronous method in a type that extends or implements another type expecting that method to return `void`.',
122
+ },
123
+ properties: {
124
+ type: 'boolean',
125
+ description: 'Disables checking an asynchronous function passed as an object property expected to be a function that returns `void`.',
126
+ },
127
+ returns: {
128
+ type: 'boolean',
129
+ description: 'Disables checking an asynchronous function returned in a function whose return type is a function that returns `void`.',
130
+ },
131
+ variables: {
132
+ type: 'boolean',
133
+ description: 'Disables checking an asynchronous function used as a variable whose return type is a function that returns `void`.',
134
+ },
135
+ },
136
+ },
137
+ ],
138
+ },
139
+ },
140
+ },
141
+ ],
142
+ },
143
+ defaultOptions: [
144
+ {
145
+ checksConditionals: true,
146
+ checksSpreads: true,
147
+ checksVoidReturn: true,
148
+ },
149
+ ],
150
+ create(context, [{ checksConditionals, checksSpreads, checksVoidReturn }]) {
151
+ const services = (0, util_1.getParserServices)(context);
152
+ const checker = services.program.getTypeChecker();
153
+ const checkedNodes = new Set();
154
+ const conditionalChecks = {
155
+ 'CallExpression > MemberExpression': checkArrayPredicates,
156
+ ConditionalExpression: checkTestConditional,
157
+ DoWhileStatement: checkTestConditional,
158
+ ForStatement: checkTestConditional,
159
+ IfStatement: checkTestConditional,
160
+ LogicalExpression: checkConditional,
161
+ 'UnaryExpression[operator="!"]'(node) {
162
+ checkConditional(node.argument, true);
163
+ },
164
+ WhileStatement: checkTestConditional,
165
+ };
166
+ checksVoidReturn = parseChecksVoidReturn(checksVoidReturn);
167
+ const voidReturnChecks = checksVoidReturn
168
+ ? {
169
+ ...(checksVoidReturn.arguments && {
170
+ CallExpression: checkArguments,
171
+ NewExpression: checkArguments,
172
+ }),
173
+ ...(checksVoidReturn.attributes && {
174
+ JSXAttribute: checkJSXAttribute,
175
+ }),
176
+ ...(checksVoidReturn.inheritedMethods && {
177
+ ClassDeclaration: checkClassLikeOrInterfaceNode,
178
+ ClassExpression: checkClassLikeOrInterfaceNode,
179
+ TSInterfaceDeclaration: checkClassLikeOrInterfaceNode,
180
+ }),
181
+ ...(checksVoidReturn.properties && {
182
+ Property: checkProperty,
183
+ }),
184
+ ...(checksVoidReturn.returns && {
185
+ ReturnStatement: checkReturnStatement,
186
+ }),
187
+ ...(checksVoidReturn.variables && {
188
+ AssignmentExpression: checkAssignment,
189
+ VariableDeclarator: checkVariableDeclaration,
190
+ }),
191
+ }
192
+ : {};
193
+ const spreadChecks = {
194
+ SpreadElement: checkSpread,
195
+ };
196
+ /**
197
+ * A syntactic check to see if an annotated type is maybe a function type.
198
+ * This is a perf optimization to help avoid requesting types where possible
199
+ */
200
+ function isPossiblyFunctionType(node) {
201
+ switch (node.typeAnnotation.type) {
202
+ case utils_1.AST_NODE_TYPES.TSConditionalType:
203
+ case utils_1.AST_NODE_TYPES.TSConstructorType:
204
+ case utils_1.AST_NODE_TYPES.TSFunctionType:
205
+ case utils_1.AST_NODE_TYPES.TSImportType:
206
+ case utils_1.AST_NODE_TYPES.TSIndexedAccessType:
207
+ case utils_1.AST_NODE_TYPES.TSInferType:
208
+ case utils_1.AST_NODE_TYPES.TSIntersectionType:
209
+ case utils_1.AST_NODE_TYPES.TSQualifiedName:
210
+ case utils_1.AST_NODE_TYPES.TSThisType:
211
+ case utils_1.AST_NODE_TYPES.TSTypeOperator:
212
+ case utils_1.AST_NODE_TYPES.TSTypeQuery:
213
+ case utils_1.AST_NODE_TYPES.TSTypeReference:
214
+ case utils_1.AST_NODE_TYPES.TSUnionType:
215
+ return true;
216
+ case utils_1.AST_NODE_TYPES.TSTypeLiteral:
217
+ return node.typeAnnotation.members.some(member => member.type === utils_1.AST_NODE_TYPES.TSCallSignatureDeclaration ||
218
+ member.type === utils_1.AST_NODE_TYPES.TSConstructSignatureDeclaration);
219
+ case utils_1.AST_NODE_TYPES.TSAbstractKeyword:
220
+ case utils_1.AST_NODE_TYPES.TSAnyKeyword:
221
+ case utils_1.AST_NODE_TYPES.TSArrayType:
222
+ case utils_1.AST_NODE_TYPES.TSAsyncKeyword:
223
+ case utils_1.AST_NODE_TYPES.TSBigIntKeyword:
224
+ case utils_1.AST_NODE_TYPES.TSBooleanKeyword:
225
+ case utils_1.AST_NODE_TYPES.TSDeclareKeyword:
226
+ case utils_1.AST_NODE_TYPES.TSExportKeyword:
227
+ case utils_1.AST_NODE_TYPES.TSIntrinsicKeyword:
228
+ case utils_1.AST_NODE_TYPES.TSLiteralType:
229
+ case utils_1.AST_NODE_TYPES.TSMappedType:
230
+ case utils_1.AST_NODE_TYPES.TSNamedTupleMember:
231
+ case utils_1.AST_NODE_TYPES.TSNeverKeyword:
232
+ case utils_1.AST_NODE_TYPES.TSNullKeyword:
233
+ case utils_1.AST_NODE_TYPES.TSNumberKeyword:
234
+ case utils_1.AST_NODE_TYPES.TSObjectKeyword:
235
+ case utils_1.AST_NODE_TYPES.TSOptionalType:
236
+ case utils_1.AST_NODE_TYPES.TSPrivateKeyword:
237
+ case utils_1.AST_NODE_TYPES.TSProtectedKeyword:
238
+ case utils_1.AST_NODE_TYPES.TSPublicKeyword:
239
+ case utils_1.AST_NODE_TYPES.TSReadonlyKeyword:
240
+ case utils_1.AST_NODE_TYPES.TSRestType:
241
+ case utils_1.AST_NODE_TYPES.TSStaticKeyword:
242
+ case utils_1.AST_NODE_TYPES.TSStringKeyword:
243
+ case utils_1.AST_NODE_TYPES.TSSymbolKeyword:
244
+ case utils_1.AST_NODE_TYPES.TSTemplateLiteralType:
245
+ case utils_1.AST_NODE_TYPES.TSTupleType:
246
+ case utils_1.AST_NODE_TYPES.TSTypePredicate:
247
+ case utils_1.AST_NODE_TYPES.TSUndefinedKeyword:
248
+ case utils_1.AST_NODE_TYPES.TSUnknownKeyword:
249
+ case utils_1.AST_NODE_TYPES.TSVoidKeyword:
250
+ return false;
251
+ }
252
+ }
253
+ function checkTestConditional(node) {
254
+ if (node.test) {
255
+ checkConditional(node.test, true);
256
+ }
257
+ }
258
+ /**
259
+ * This function analyzes the type of a node and checks if it is a Promise in a boolean conditional.
260
+ * It uses recursion when checking nested logical operators.
261
+ * @param node The AST node to check.
262
+ * @param isTestExpr Whether the node is a descendant of a test expression.
263
+ */
264
+ function checkConditional(node, isTestExpr = false) {
265
+ // prevent checking the same node multiple times
266
+ if (checkedNodes.has(node)) {
267
+ return;
268
+ }
269
+ checkedNodes.add(node);
270
+ if (node.type === utils_1.AST_NODE_TYPES.LogicalExpression) {
271
+ // ignore the left operand for nullish coalescing expressions not in a context of a test expression
272
+ if (node.operator !== '??' || isTestExpr) {
273
+ checkConditional(node.left, isTestExpr);
274
+ }
275
+ // we ignore the right operand when not in a context of a test expression
276
+ if (isTestExpr) {
277
+ checkConditional(node.right, isTestExpr);
278
+ }
279
+ return;
280
+ }
281
+ const tsNode = services.esTreeNodeToTSNodeMap.get(node);
282
+ if (isAlwaysThenable(checker, tsNode)) {
283
+ context.report({
284
+ node,
285
+ messageId: 'conditional',
286
+ });
287
+ }
288
+ }
289
+ function checkArrayPredicates(node) {
290
+ const parent = node.parent;
291
+ if (parent.type === utils_1.AST_NODE_TYPES.CallExpression) {
292
+ const callback = parent.arguments.at(0);
293
+ if (callback &&
294
+ (0, util_1.isArrayMethodCallWithPredicate)(context, services, parent)) {
295
+ const type = services.esTreeNodeToTSNodeMap.get(callback);
296
+ if (returnsThenable(checker, type)) {
297
+ context.report({
298
+ node: callback,
299
+ messageId: 'predicate',
300
+ });
301
+ }
302
+ }
303
+ }
304
+ }
305
+ function checkArguments(node) {
306
+ if (node.type === utils_1.AST_NODE_TYPES.CallExpression &&
307
+ isPromiseFinallyMethod(node)) {
308
+ return;
309
+ }
310
+ const tsNode = services.esTreeNodeToTSNodeMap.get(node);
311
+ const voidArgs = voidFunctionArguments(checker, tsNode);
312
+ if (voidArgs.size === 0) {
313
+ return;
314
+ }
315
+ for (const [index, argument] of node.arguments.entries()) {
316
+ if (!voidArgs.has(index)) {
317
+ continue;
318
+ }
319
+ const tsNode = services.esTreeNodeToTSNodeMap.get(argument);
320
+ if (returnsThenable(checker, tsNode)) {
321
+ context.report({
322
+ node: argument,
323
+ messageId: 'voidReturnArgument',
324
+ });
325
+ }
326
+ }
327
+ }
328
+ function checkAssignment(node) {
329
+ const tsNode = services.esTreeNodeToTSNodeMap.get(node);
330
+ const varType = services.getTypeAtLocation(node.left);
331
+ if (!isVoidReturningFunctionType(checker, tsNode.left, varType)) {
332
+ return;
333
+ }
334
+ if (returnsThenable(checker, tsNode.right)) {
335
+ context.report({
336
+ node: node.right,
337
+ messageId: 'voidReturnVariable',
338
+ });
339
+ }
340
+ }
341
+ function checkVariableDeclaration(node) {
342
+ const tsNode = services.esTreeNodeToTSNodeMap.get(node);
343
+ if (tsNode.initializer == null ||
344
+ node.init == null ||
345
+ node.id.typeAnnotation == null) {
346
+ return;
347
+ }
348
+ // syntactically ignore some known-good cases to avoid touching type info
349
+ if (!isPossiblyFunctionType(node.id.typeAnnotation)) {
350
+ return;
351
+ }
352
+ const varType = services.getTypeAtLocation(node.id);
353
+ if (!isVoidReturningFunctionType(checker, tsNode.initializer, varType)) {
354
+ return;
355
+ }
356
+ if (returnsThenable(checker, tsNode.initializer)) {
357
+ context.report({
358
+ node: node.init,
359
+ messageId: 'voidReturnVariable',
360
+ });
361
+ }
362
+ }
363
+ function checkProperty(node) {
364
+ const tsNode = services.esTreeNodeToTSNodeMap.get(node);
365
+ if (ts.isPropertyAssignment(tsNode)) {
366
+ const contextualType = checker.getContextualType(tsNode.initializer);
367
+ if (contextualType != null &&
368
+ isVoidReturningFunctionType(checker, tsNode.initializer, contextualType) &&
369
+ returnsThenable(checker, tsNode.initializer)) {
370
+ if ((0, util_1.isFunction)(node.value)) {
371
+ const functionNode = node.value;
372
+ if (functionNode.returnType) {
373
+ context.report({
374
+ node: functionNode.returnType.typeAnnotation,
375
+ messageId: 'voidReturnProperty',
376
+ });
377
+ }
378
+ else {
379
+ context.report({
380
+ loc: (0, util_1.getFunctionHeadLoc)(functionNode, context.sourceCode),
381
+ messageId: 'voidReturnProperty',
382
+ });
383
+ }
384
+ }
385
+ else {
386
+ context.report({
387
+ node: node.value,
388
+ messageId: 'voidReturnProperty',
389
+ });
390
+ }
391
+ }
392
+ }
393
+ else if (ts.isShorthandPropertyAssignment(tsNode)) {
394
+ const contextualType = checker.getContextualType(tsNode.name);
395
+ if (contextualType != null &&
396
+ isVoidReturningFunctionType(checker, tsNode.name, contextualType) &&
397
+ returnsThenable(checker, tsNode.name)) {
398
+ context.report({
399
+ node: node.value,
400
+ messageId: 'voidReturnProperty',
401
+ });
402
+ }
403
+ }
404
+ else if (ts.isMethodDeclaration(tsNode)) {
405
+ if (ts.isComputedPropertyName(tsNode.name)) {
406
+ return;
407
+ }
408
+ const obj = tsNode.parent;
409
+ // Below condition isn't satisfied unless something goes wrong,
410
+ // but is needed for type checking.
411
+ // 'node' does not include class method declaration so 'obj' is
412
+ // always an object literal expression, but after converting 'node'
413
+ // to TypeScript AST, its type includes MethodDeclaration which
414
+ // does include the case of class method declaration.
415
+ if (!ts.isObjectLiteralExpression(obj)) {
416
+ return;
417
+ }
418
+ if (!returnsThenable(checker, tsNode)) {
419
+ return;
420
+ }
421
+ const objType = checker.getContextualType(obj);
422
+ if (objType == null) {
423
+ return;
424
+ }
425
+ const propertySymbol = tsutils
426
+ .unionConstituents(objType)
427
+ .map(t => checker.getPropertyOfType(t, tsNode.name.getText()))
428
+ .find(p => p);
429
+ if (propertySymbol == null) {
430
+ return;
431
+ }
432
+ const contextualType = checker.getTypeOfSymbolAtLocation(propertySymbol, tsNode.name);
433
+ if (isVoidReturningFunctionType(checker, tsNode.name, contextualType)) {
434
+ const functionNode = node.value;
435
+ if (functionNode.returnType) {
436
+ context.report({
437
+ node: functionNode.returnType.typeAnnotation,
438
+ messageId: 'voidReturnProperty',
439
+ });
440
+ }
441
+ else {
442
+ context.report({
443
+ loc: (0, util_1.getFunctionHeadLoc)(functionNode, context.sourceCode),
444
+ messageId: 'voidReturnProperty',
445
+ });
446
+ }
447
+ }
448
+ return;
449
+ }
450
+ }
451
+ function checkReturnStatement(node) {
452
+ const tsNode = services.esTreeNodeToTSNodeMap.get(node);
453
+ if (tsNode.expression == null || node.argument == null) {
454
+ return;
455
+ }
456
+ // syntactically ignore some known-good cases to avoid touching type info
457
+ const functionNode = (() => {
458
+ let current = node.parent;
459
+ while (current && !(0, util_1.isFunction)(current)) {
460
+ current = current.parent;
461
+ }
462
+ return (0, util_1.nullThrows)(current, util_1.NullThrowsReasons.MissingParent);
463
+ })();
464
+ if (functionNode.returnType &&
465
+ !isPossiblyFunctionType(functionNode.returnType)) {
466
+ return;
467
+ }
468
+ const contextualType = checker.getContextualType(tsNode.expression);
469
+ if (contextualType != null &&
470
+ isVoidReturningFunctionType(checker, tsNode.expression, contextualType) &&
471
+ returnsThenable(checker, tsNode.expression)) {
472
+ context.report({
473
+ node: node.argument,
474
+ messageId: 'voidReturnReturnValue',
475
+ });
476
+ }
477
+ }
478
+ function isPromiseFinallyMethod(node) {
479
+ const promiseFinallyCall = (0, promiseUtils_1.parseFinallyCall)(node, context);
480
+ return (promiseFinallyCall != null &&
481
+ (0, util_1.isPromiseLike)(services.program, (0, util_1.getConstrainedTypeAtLocation)(services, promiseFinallyCall.object)));
482
+ }
483
+ function checkClassLikeOrInterfaceNode(node) {
484
+ const tsNode = services.esTreeNodeToTSNodeMap.get(node);
485
+ const heritageTypes = getHeritageTypes(checker, tsNode);
486
+ if (!heritageTypes?.length) {
487
+ return;
488
+ }
489
+ for (const nodeMember of tsNode.members) {
490
+ const memberName = nodeMember.name?.getText();
491
+ if (memberName == null) {
492
+ // Call/construct/index signatures don't have names. TS allows call signatures to mismatch,
493
+ // and construct signatures can't be async.
494
+ // TODO - Once we're able to use `checker.isTypeAssignableTo` (v8), we can check an index
495
+ // signature here against its compatible index signatures in `heritageTypes`
496
+ continue;
497
+ }
498
+ if (!returnsThenable(checker, nodeMember)) {
499
+ continue;
500
+ }
501
+ const node = services.tsNodeToESTreeNodeMap.get(nodeMember);
502
+ if (isStaticMember(node)) {
503
+ continue;
504
+ }
505
+ for (const heritageType of heritageTypes) {
506
+ checkHeritageTypeForMemberReturningVoid(nodeMember, heritageType, memberName);
507
+ }
508
+ }
509
+ }
510
+ /**
511
+ * Checks `heritageType` for a member named `memberName` that returns void; reports the
512
+ * 'voidReturnInheritedMethod' message if found.
513
+ * @param nodeMember Node member that returns a Promise
514
+ * @param heritageType Heritage type to check against
515
+ * @param memberName Name of the member to check for
516
+ */
517
+ function checkHeritageTypeForMemberReturningVoid(nodeMember, heritageType, memberName) {
518
+ const heritageMember = getMemberIfExists(heritageType, memberName);
519
+ if (heritageMember == null) {
520
+ return;
521
+ }
522
+ const memberType = checker.getTypeOfSymbolAtLocation(heritageMember, nodeMember);
523
+ if (!isVoidReturningFunctionType(checker, nodeMember, memberType)) {
524
+ return;
525
+ }
526
+ context.report({
527
+ node: services.tsNodeToESTreeNodeMap.get(nodeMember),
528
+ messageId: 'voidReturnInheritedMethod',
529
+ data: { heritageTypeName: checker.typeToString(heritageType) },
530
+ });
531
+ }
532
+ function checkJSXAttribute(node) {
533
+ if (node.value?.type !== utils_1.AST_NODE_TYPES.JSXExpressionContainer) {
534
+ return;
535
+ }
536
+ const expressionContainer = services.esTreeNodeToTSNodeMap.get(node.value);
537
+ const expression = services.esTreeNodeToTSNodeMap.get(node.value.expression);
538
+ const contextualType = checker.getContextualType(expressionContainer);
539
+ if (contextualType != null &&
540
+ isVoidReturningFunctionType(checker, expressionContainer, contextualType) &&
541
+ returnsThenable(checker, expression)) {
542
+ context.report({
543
+ node: node.value,
544
+ messageId: 'voidReturnAttribute',
545
+ });
546
+ }
547
+ }
548
+ function checkSpread(node) {
549
+ const tsNode = services.esTreeNodeToTSNodeMap.get(node);
550
+ if (isSometimesThenable(checker, tsNode.expression)) {
551
+ context.report({
552
+ node: node.argument,
553
+ messageId: 'spread',
554
+ });
555
+ }
556
+ }
557
+ return {
558
+ ...(checksConditionals ? conditionalChecks : {}),
559
+ ...(checksVoidReturn ? voidReturnChecks : {}),
560
+ ...(checksSpreads ? spreadChecks : {}),
561
+ };
562
+ },
563
+ });
564
+ function isSometimesThenable(checker, node) {
565
+ const type = checker.getTypeAtLocation(node);
566
+ for (const subType of tsutils.unionConstituents(checker.getApparentType(type))) {
567
+ if (tsutils.isThenableType(checker, node, subType)) {
568
+ return true;
569
+ }
570
+ }
571
+ return false;
572
+ }
573
+ // Variation on the thenable check which requires all forms of the type (read:
574
+ // alternates in a union) to be thenable. Otherwise, you might be trying to
575
+ // check if something is defined or undefined and get caught because one of the
576
+ // branches is thenable.
577
+ function isAlwaysThenable(checker, node) {
578
+ const type = checker.getTypeAtLocation(node);
579
+ for (const subType of tsutils.unionConstituents(checker.getApparentType(type))) {
580
+ const thenProp = subType.getProperty('then');
581
+ // If one of the alternates has no then property, it is not thenable in all
582
+ // cases.
583
+ if (thenProp == null) {
584
+ return false;
585
+ }
586
+ // We walk through each variation of the then property. Since we know it
587
+ // exists at this point, we just need at least one of the alternates to
588
+ // be of the right form to consider it thenable.
589
+ const thenType = checker.getTypeOfSymbolAtLocation(thenProp, node);
590
+ let hasThenableSignature = false;
591
+ for (const subType of tsutils.unionConstituents(thenType)) {
592
+ for (const signature of subType.getCallSignatures()) {
593
+ if (signature.parameters.length !== 0 &&
594
+ isFunctionParam(checker, signature.parameters[0], node)) {
595
+ hasThenableSignature = true;
596
+ break;
597
+ }
598
+ }
599
+ // We only need to find one variant of the then property that has a
600
+ // function signature for it to be thenable.
601
+ if (hasThenableSignature) {
602
+ break;
603
+ }
604
+ }
605
+ // If no flavors of the then property are thenable, we don't consider the
606
+ // overall type to be thenable
607
+ if (!hasThenableSignature) {
608
+ return false;
609
+ }
610
+ }
611
+ // If all variants are considered thenable (i.e. haven't returned false), we
612
+ // consider the overall type thenable
613
+ return true;
614
+ }
615
+ function isFunctionParam(checker, param, node) {
616
+ const type = checker.getApparentType(checker.getTypeOfSymbolAtLocation(param, node));
617
+ for (const subType of tsutils.unionConstituents(type)) {
618
+ if (subType.getCallSignatures().length !== 0) {
619
+ return true;
620
+ }
621
+ }
622
+ return false;
623
+ }
624
+ function checkThenableOrVoidArgument(checker, node, type, index, thenableReturnIndices, voidReturnIndices) {
625
+ if (isThenableReturningFunctionType(checker, node.expression, type)) {
626
+ thenableReturnIndices.add(index);
627
+ }
628
+ else if (isVoidReturningFunctionType(checker, node.expression, type) &&
629
+ // If a certain argument accepts both thenable and void returns,
630
+ // a promise-returning function is valid
631
+ !thenableReturnIndices.has(index)) {
632
+ voidReturnIndices.add(index);
633
+ }
634
+ const contextualType = checker.getContextualTypeForArgumentAtIndex(node, index);
635
+ if (contextualType !== type) {
636
+ checkThenableOrVoidArgument(checker, node, contextualType, index, thenableReturnIndices, voidReturnIndices);
637
+ }
638
+ }
639
+ // Get the positions of arguments which are void functions (and not also
640
+ // thenable functions). These are the candidates for the void-return check at
641
+ // the current call site.
642
+ // If the function parameters end with a 'rest' parameter, then we consider
643
+ // the array type parameter (e.g. '...args:Array<SomeType>') when determining
644
+ // if trailing arguments are candidates.
645
+ function voidFunctionArguments(checker, node) {
646
+ // 'new' can be used without any arguments, as in 'let b = new Object;'
647
+ // In this case, there are no argument positions to check, so return early.
648
+ if (!node.arguments) {
649
+ return new Set();
650
+ }
651
+ const thenableReturnIndices = new Set();
652
+ const voidReturnIndices = new Set();
653
+ const type = checker.getTypeAtLocation(node.expression);
654
+ // We can't use checker.getResolvedSignature because it prefers an early '() => void' over a later '() => Promise<void>'
655
+ // See https://github.com/microsoft/TypeScript/issues/48077
656
+ for (const subType of tsutils.unionConstituents(type)) {
657
+ // Standard function calls and `new` have two different types of signatures
658
+ const signatures = ts.isCallExpression(node)
659
+ ? subType.getCallSignatures()
660
+ : subType.getConstructSignatures();
661
+ for (const signature of signatures) {
662
+ for (const [index, parameter] of signature.parameters.entries()) {
663
+ const decl = parameter.valueDeclaration;
664
+ let type = checker.getTypeOfSymbolAtLocation(parameter, node.expression);
665
+ // If this is a array 'rest' parameter, check all of the argument indices
666
+ // from the current argument to the end.
667
+ if (decl && (0, util_1.isRestParameterDeclaration)(decl)) {
668
+ if (checker.isArrayType(type)) {
669
+ // Unwrap 'Array<MaybeVoidFunction>' to 'MaybeVoidFunction',
670
+ // so that we'll handle it in the same way as a non-rest
671
+ // 'param: MaybeVoidFunction'
672
+ type = checker.getTypeArguments(type)[0];
673
+ for (let i = index; i < node.arguments.length; i++) {
674
+ checkThenableOrVoidArgument(checker, node, type, i, thenableReturnIndices, voidReturnIndices);
675
+ }
676
+ }
677
+ else if (checker.isTupleType(type)) {
678
+ // Check each type in the tuple - for example, [boolean, () => void] would
679
+ // add the index of the second tuple parameter to 'voidReturnIndices'
680
+ const typeArgs = checker.getTypeArguments(type);
681
+ for (let i = index; i < node.arguments.length && i - index < typeArgs.length; i++) {
682
+ checkThenableOrVoidArgument(checker, node, typeArgs[i - index], i, thenableReturnIndices, voidReturnIndices);
683
+ }
684
+ }
685
+ }
686
+ else {
687
+ checkThenableOrVoidArgument(checker, node, type, index, thenableReturnIndices, voidReturnIndices);
688
+ }
689
+ }
690
+ }
691
+ }
692
+ for (const index of thenableReturnIndices) {
693
+ voidReturnIndices.delete(index);
694
+ }
695
+ return voidReturnIndices;
696
+ }
697
+ /**
698
+ * @returns Whether any call signature of the type has a thenable return type.
699
+ */
700
+ function anySignatureIsThenableType(checker, node, type) {
701
+ for (const signature of type.getCallSignatures()) {
702
+ const returnType = signature.getReturnType();
703
+ if (tsutils.isThenableType(checker, node, returnType)) {
704
+ return true;
705
+ }
706
+ }
707
+ return false;
708
+ }
709
+ /**
710
+ * @returns Whether type is a thenable-returning function.
711
+ */
712
+ function isThenableReturningFunctionType(checker, node, type) {
713
+ for (const subType of tsutils.unionConstituents(type)) {
714
+ if (anySignatureIsThenableType(checker, node, subType)) {
715
+ return true;
716
+ }
717
+ }
718
+ return false;
719
+ }
720
+ /**
721
+ * @returns Whether type is a void-returning function.
722
+ */
723
+ function isVoidReturningFunctionType(checker, node, type) {
724
+ let hadVoidReturn = false;
725
+ for (const subType of tsutils.unionConstituents(type)) {
726
+ for (const signature of subType.getCallSignatures()) {
727
+ const returnType = signature.getReturnType();
728
+ // If a certain positional argument accepts both thenable and void returns,
729
+ // a promise-returning function is valid
730
+ if (tsutils.isThenableType(checker, node, returnType)) {
731
+ return false;
732
+ }
733
+ hadVoidReturn ||= tsutils.isTypeFlagSet(returnType, ts.TypeFlags.Void);
734
+ }
735
+ }
736
+ return hadVoidReturn;
737
+ }
738
+ /**
739
+ * @returns Whether expression is a function that returns a thenable.
740
+ */
741
+ function returnsThenable(checker, node) {
742
+ const type = checker.getApparentType(checker.getTypeAtLocation(node));
743
+ return tsutils
744
+ .unionConstituents(type)
745
+ .some(t => anySignatureIsThenableType(checker, node, t));
746
+ }
747
+ function getHeritageTypes(checker, tsNode) {
748
+ return tsNode.heritageClauses
749
+ ?.flatMap(clause => clause.types)
750
+ .map(typeExpression => checker.getTypeAtLocation(typeExpression));
751
+ }
752
+ /**
753
+ * @returns The member with the given name in `type`, if it exists.
754
+ */
755
+ function getMemberIfExists(type, memberName) {
756
+ const escapedMemberName = ts.escapeLeadingUnderscores(memberName);
757
+ const symbolMemberMatch = type.getSymbol()?.members?.get(escapedMemberName);
758
+ return (symbolMemberMatch ?? tsutils.getPropertyOfType(type, escapedMemberName));
759
+ }
760
+ function isStaticMember(node) {
761
+ return ((node.type === utils_1.AST_NODE_TYPES.MethodDefinition ||
762
+ node.type === utils_1.AST_NODE_TYPES.PropertyDefinition ||
763
+ node.type === utils_1.AST_NODE_TYPES.AccessorProperty) &&
764
+ node.static);
765
+ }
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-misused-spread.d.ts ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { TSESLint } from '@typescript-eslint/utils';
2
+ import type { TypeOrValueSpecifier } from '../util';
3
+ type Options = [
4
+ {
5
+ allow?: TypeOrValueSpecifier[];
6
+ }
7
+ ];
8
+ type MessageIds = 'addAwait' | 'noArraySpreadInObject' | 'noClassDeclarationSpreadInObject' | 'noClassInstanceSpreadInObject' | 'noFunctionSpreadInObject' | 'noIterableSpreadInObject' | 'noMapSpreadInObject' | 'noPromiseSpreadInObject' | 'noStringSpread' | 'replaceMapSpreadInObject';
9
+ declare const _default: TSESLint.RuleModule<MessageIds, Options, import("../../rules").ESLintPluginDocs, TSESLint.RuleListener> & {
10
+ name: string;
11
+ };
12
+ export default _default;
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-misused-spread.js ADDED
@@ -0,0 +1,260 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const utils_1 = require("@typescript-eslint/utils");
37
+ const tsutils = __importStar(require("ts-api-utils"));
38
+ const ts = __importStar(require("typescript"));
39
+ const util_1 = require("../util");
40
+ exports.default = (0, util_1.createRule)({
41
+ name: 'no-misused-spread',
42
+ meta: {
43
+ type: 'problem',
44
+ docs: {
45
+ description: 'Disallow using the spread operator when it might cause unexpected behavior',
46
+ recommended: 'strict',
47
+ requiresTypeChecking: true,
48
+ },
49
+ hasSuggestions: true,
50
+ messages: {
51
+ addAwait: 'Add await operator.',
52
+ noArraySpreadInObject: 'Using the spread operator on an array in an object will result in a list of indices.',
53
+ noClassDeclarationSpreadInObject: 'Using the spread operator on class declarations will spread only their static properties, and will lose their class prototype.',
54
+ noClassInstanceSpreadInObject: 'Using the spread operator on class instances will lose their class prototype.',
55
+ noFunctionSpreadInObject: 'Using the spread operator on a function without additional properties can cause unexpected behavior. Did you forget to call the function?',
56
+ noIterableSpreadInObject: 'Using the spread operator on an Iterable in an object can cause unexpected behavior.',
57
+ noMapSpreadInObject: 'Using the spread operator on a Map in an object will result in an empty object. Did you mean to use `Object.fromEntries(map)` instead?',
58
+ noPromiseSpreadInObject: 'Using the spread operator on Promise in an object can cause unexpected behavior. Did you forget to await the promise?',
59
+ noStringSpread: [
60
+ 'Using the spread operator on a string can mishandle special characters, as can `.split("")`.',
61
+ '- `...` produces Unicode code points, which will decompose complex emojis into individual emojis',
62
+ '- .split("") produces UTF-16 code units, which breaks rich characters in many languages',
63
+ 'Consider using `Intl.Segmenter` for locale-aware string decomposition.',
64
+ "Otherwise, if you don't need to preserve emojis or other non-Ascii characters, disable this lint rule on this line or configure the 'allow' rule option.",
65
+ ].join('\n'),
66
+ replaceMapSpreadInObject: 'Replace map spread in object with `Object.fromEntries()`',
67
+ },
68
+ schema: [
69
+ {
70
+ type: 'object',
71
+ additionalProperties: false,
72
+ properties: {
73
+ allow: {
74
+ ...util_1.readonlynessOptionsSchema.properties.allow,
75
+ description: 'An array of type specifiers that are known to be safe to spread.',
76
+ },
77
+ },
78
+ },
79
+ ],
80
+ },
81
+ defaultOptions: [
82
+ {
83
+ allow: [],
84
+ },
85
+ ],
86
+ create(context, [options]) {
87
+ const services = (0, util_1.getParserServices)(context);
88
+ const checker = services.program.getTypeChecker();
89
+ function checkArrayOrCallSpread(node) {
90
+ const type = (0, util_1.getConstrainedTypeAtLocation)(services, node.argument);
91
+ if (!(0, util_1.typeMatchesSomeSpecifier)(type, options.allow, services.program) &&
92
+ isString(type)) {
93
+ context.report({
94
+ node,
95
+ messageId: 'noStringSpread',
96
+ });
97
+ }
98
+ }
99
+ function getMapSpreadSuggestions(node, type) {
100
+ const types = tsutils.unionConstituents(type);
101
+ if (types.some(t => !isMap(services.program, t))) {
102
+ return null;
103
+ }
104
+ if (node.parent.type === utils_1.AST_NODE_TYPES.ObjectExpression &&
105
+ node.parent.properties.length === 1) {
106
+ return [
107
+ {
108
+ messageId: 'replaceMapSpreadInObject',
109
+ fix: (0, util_1.getWrappingFixer)({
110
+ node: node.parent,
111
+ innerNode: node.argument,
112
+ sourceCode: context.sourceCode,
113
+ wrap: code => `Object.fromEntries(${code})`,
114
+ }),
115
+ },
116
+ ];
117
+ }
118
+ return [
119
+ {
120
+ messageId: 'replaceMapSpreadInObject',
121
+ fix: (0, util_1.getWrappingFixer)({
122
+ node: node.argument,
123
+ sourceCode: context.sourceCode,
124
+ wrap: code => `Object.fromEntries(${code})`,
125
+ }),
126
+ },
127
+ ];
128
+ }
129
+ function getPromiseSpreadSuggestions(node) {
130
+ const isHighPrecedence = (0, util_1.isHigherPrecedenceThanAwait)(services.esTreeNodeToTSNodeMap.get(node));
131
+ return [
132
+ {
133
+ messageId: 'addAwait',
134
+ fix: fixer => isHighPrecedence
135
+ ? fixer.insertTextBefore(node, 'await ')
136
+ : [
137
+ fixer.insertTextBefore(node, 'await ('),
138
+ fixer.insertTextAfter(node, ')'),
139
+ ],
140
+ },
141
+ ];
142
+ }
143
+ function checkObjectSpread(node) {
144
+ const type = (0, util_1.getConstrainedTypeAtLocation)(services, node.argument);
145
+ if ((0, util_1.typeMatchesSomeSpecifier)(type, options.allow, services.program)) {
146
+ return;
147
+ }
148
+ if (isPromise(services.program, type)) {
149
+ context.report({
150
+ node,
151
+ messageId: 'noPromiseSpreadInObject',
152
+ suggest: getPromiseSpreadSuggestions(node.argument),
153
+ });
154
+ return;
155
+ }
156
+ if (isFunctionWithoutProps(type)) {
157
+ context.report({
158
+ node,
159
+ messageId: 'noFunctionSpreadInObject',
160
+ });
161
+ return;
162
+ }
163
+ if (isMap(services.program, type)) {
164
+ context.report({
165
+ node,
166
+ messageId: 'noMapSpreadInObject',
167
+ suggest: getMapSpreadSuggestions(node, type),
168
+ });
169
+ return;
170
+ }
171
+ if (isArray(checker, type)) {
172
+ context.report({
173
+ node,
174
+ messageId: 'noArraySpreadInObject',
175
+ });
176
+ return;
177
+ }
178
+ if (isIterable(type, checker) &&
179
+ // Don't report when the type is string, since TS will flag it already
180
+ !isString(type)) {
181
+ context.report({
182
+ node,
183
+ messageId: 'noIterableSpreadInObject',
184
+ });
185
+ return;
186
+ }
187
+ if (isClassInstance(checker, type)) {
188
+ context.report({
189
+ node,
190
+ messageId: 'noClassInstanceSpreadInObject',
191
+ });
192
+ return;
193
+ }
194
+ if (isClassDeclaration(type)) {
195
+ context.report({
196
+ node,
197
+ messageId: 'noClassDeclarationSpreadInObject',
198
+ });
199
+ }
200
+ }
201
+ return {
202
+ 'ArrayExpression > SpreadElement': checkArrayOrCallSpread,
203
+ 'CallExpression > SpreadElement': checkArrayOrCallSpread,
204
+ JSXSpreadAttribute: checkObjectSpread,
205
+ 'ObjectExpression > SpreadElement': checkObjectSpread,
206
+ };
207
+ },
208
+ });
209
+ function isIterable(type, checker) {
210
+ return tsutils
211
+ .typeConstituents(type)
212
+ .some(t => !!tsutils.getWellKnownSymbolPropertyOfType(t, 'iterator', checker));
213
+ }
214
+ function isArray(checker, type) {
215
+ return isTypeRecurser(type, t => checker.isArrayType(t) || checker.isTupleType(t));
216
+ }
217
+ function isString(type) {
218
+ return isTypeRecurser(type, t => (0, util_1.isTypeFlagSet)(t, ts.TypeFlags.StringLike));
219
+ }
220
+ function isFunctionWithoutProps(type) {
221
+ return isTypeRecurser(type, t => t.getCallSignatures().length > 0 && t.getProperties().length === 0);
222
+ }
223
+ function isPromise(program, type) {
224
+ return isTypeRecurser(type, t => (0, util_1.isPromiseLike)(program, t));
225
+ }
226
+ function isClassInstance(checker, type) {
227
+ return isTypeRecurser(type, t => {
228
+ // If the type itself has a construct signature, it's a class(-like)
229
+ if (t.getConstructSignatures().length) {
230
+ return false;
231
+ }
232
+ const symbol = t.getSymbol();
233
+ // If the type's symbol has a construct signature, the type is an instance
234
+ return !!symbol
235
+ ?.getDeclarations()
236
+ ?.some(declaration => checker
237
+ .getTypeOfSymbolAtLocation(symbol, declaration)
238
+ .getConstructSignatures().length);
239
+ });
240
+ }
241
+ function isClassDeclaration(type) {
242
+ return isTypeRecurser(type, t => {
243
+ if (tsutils.isObjectType(t) &&
244
+ tsutils.isObjectFlagSet(t, ts.ObjectFlags.InstantiationExpressionType)) {
245
+ return true;
246
+ }
247
+ const kind = t.getSymbol()?.valueDeclaration?.kind;
248
+ return (kind === ts.SyntaxKind.ClassDeclaration ||
249
+ kind === ts.SyntaxKind.ClassExpression);
250
+ });
251
+ }
252
+ function isMap(program, type) {
253
+ return isTypeRecurser(type, t => (0, util_1.isBuiltinSymbolLike)(program, t, ['Map', 'ReadonlyMap', 'WeakMap']));
254
+ }
255
+ function isTypeRecurser(type, predicate) {
256
+ if (type.isUnionOrIntersection()) {
257
+ return type.types.some(t => isTypeRecurser(t, predicate));
258
+ }
259
+ return predicate(type);
260
+ }
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-mixed-enums.d.ts ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<"mixed", [], import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
2
+ name: string;
3
+ };
4
+ export default _default;
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-mixed-enums.js ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const scope_manager_1 = require("@typescript-eslint/scope-manager");
37
+ const utils_1 = require("@typescript-eslint/utils");
38
+ const tsutils = __importStar(require("ts-api-utils"));
39
+ const ts = __importStar(require("typescript"));
40
+ const util_1 = require("../util");
41
+ var AllowedType;
42
+ (function (AllowedType) {
43
+ AllowedType[AllowedType["Number"] = 0] = "Number";
44
+ AllowedType[AllowedType["String"] = 1] = "String";
45
+ AllowedType[AllowedType["Unknown"] = 2] = "Unknown";
46
+ })(AllowedType || (AllowedType = {}));
47
+ exports.default = (0, util_1.createRule)({
48
+ name: 'no-mixed-enums',
49
+ meta: {
50
+ type: 'problem',
51
+ docs: {
52
+ description: 'Disallow enums from having both number and string members',
53
+ recommended: 'strict',
54
+ requiresTypeChecking: true,
55
+ },
56
+ messages: {
57
+ mixed: `Mixing number and string enums can be confusing.`,
58
+ },
59
+ schema: [],
60
+ },
61
+ defaultOptions: [],
62
+ create(context) {
63
+ const parserServices = (0, util_1.getParserServices)(context);
64
+ const typeChecker = parserServices.program.getTypeChecker();
65
+ function collectNodeDefinitions(node) {
66
+ const { name } = node.id;
67
+ const found = {
68
+ imports: [],
69
+ previousSibling: undefined,
70
+ };
71
+ let scope = context.sourceCode.getScope(node);
72
+ for (const definition of scope.upper?.set.get(name)?.defs ?? []) {
73
+ if (definition.node.type === utils_1.AST_NODE_TYPES.TSEnumDeclaration &&
74
+ definition.node.range[0] < node.range[0] &&
75
+ definition.node.body.members.length > 0) {
76
+ found.previousSibling = definition.node;
77
+ break;
78
+ }
79
+ }
80
+ while (scope) {
81
+ scope.set.get(name)?.defs.forEach(definition => {
82
+ if (definition.type === scope_manager_1.DefinitionType.ImportBinding) {
83
+ found.imports.push(definition.node);
84
+ }
85
+ });
86
+ scope = scope.upper;
87
+ }
88
+ return found;
89
+ }
90
+ function getAllowedTypeForNode(node) {
91
+ return tsutils.isTypeFlagSet(typeChecker.getTypeAtLocation(node), ts.TypeFlags.StringLike)
92
+ ? AllowedType.String
93
+ : AllowedType.Number;
94
+ }
95
+ function getTypeFromImported(imported) {
96
+ const type = typeChecker.getTypeAtLocation(parserServices.esTreeNodeToTSNodeMap.get(imported));
97
+ const valueDeclaration = type.getSymbol()?.valueDeclaration;
98
+ if (!valueDeclaration ||
99
+ !ts.isEnumDeclaration(valueDeclaration) ||
100
+ valueDeclaration.members.length === 0) {
101
+ return undefined;
102
+ }
103
+ return getAllowedTypeForNode(valueDeclaration.members[0]);
104
+ }
105
+ function getMemberType(member) {
106
+ if (!member.initializer) {
107
+ return AllowedType.Number;
108
+ }
109
+ switch (member.initializer.type) {
110
+ case utils_1.AST_NODE_TYPES.Literal:
111
+ switch (typeof member.initializer.value) {
112
+ case 'number':
113
+ return AllowedType.Number;
114
+ case 'string':
115
+ return AllowedType.String;
116
+ default:
117
+ return AllowedType.Unknown;
118
+ }
119
+ case utils_1.AST_NODE_TYPES.TemplateLiteral:
120
+ return AllowedType.String;
121
+ default:
122
+ return getAllowedTypeForNode(parserServices.esTreeNodeToTSNodeMap.get(member.initializer));
123
+ }
124
+ }
125
+ function getDesiredTypeForDefinition(node) {
126
+ const { imports, previousSibling } = collectNodeDefinitions(node);
127
+ // Case: Merged ambiently via module augmentation
128
+ // import { MyEnum } from 'other-module';
129
+ // declare module 'other-module' {
130
+ // enum MyEnum { A }
131
+ // }
132
+ for (const imported of imports) {
133
+ const typeFromImported = getTypeFromImported(imported);
134
+ if (typeFromImported != null) {
135
+ return typeFromImported;
136
+ }
137
+ }
138
+ // Case: Multiple enum declarations in the same file
139
+ // enum MyEnum { A }
140
+ // enum MyEnum { B }
141
+ if (previousSibling) {
142
+ return getMemberType(previousSibling.body.members[0]);
143
+ }
144
+ // Case: Namespace declaration merging
145
+ // namespace MyNamespace {
146
+ // export enum MyEnum { A }
147
+ // }
148
+ // namespace MyNamespace {
149
+ // export enum MyEnum { B }
150
+ // }
151
+ if (node.parent.type === utils_1.AST_NODE_TYPES.ExportNamedDeclaration &&
152
+ node.parent.parent.type === utils_1.AST_NODE_TYPES.TSModuleBlock) {
153
+ // https://github.com/typescript-eslint/typescript-eslint/issues/8352
154
+ // TODO: We don't need to dip into the TypeScript type checker here!
155
+ // Merged namespaces must all exist in the same file.
156
+ // We could instead compare this file's nodes to find the merges.
157
+ const tsNode = parserServices.esTreeNodeToTSNodeMap.get(node.id);
158
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
159
+ const declarations = typeChecker
160
+ .getSymbolAtLocation(tsNode)
161
+ .getDeclarations();
162
+ const [{ initializer }] = declarations[0]
163
+ .members;
164
+ return initializer &&
165
+ tsutils.isTypeFlagSet(typeChecker.getTypeAtLocation(initializer), ts.TypeFlags.StringLike)
166
+ ? AllowedType.String
167
+ : AllowedType.Number;
168
+ }
169
+ // Finally, we default to the type of the first enum member
170
+ return getMemberType(node.body.members[0]);
171
+ }
172
+ return {
173
+ TSEnumDeclaration(node) {
174
+ if (!node.body.members.length) {
175
+ return;
176
+ }
177
+ let desiredType = getDesiredTypeForDefinition(node);
178
+ if (desiredType === ts.TypeFlags.Unknown) {
179
+ return;
180
+ }
181
+ for (const member of node.body.members) {
182
+ const currentType = getMemberType(member);
183
+ if (currentType === AllowedType.Unknown) {
184
+ return;
185
+ }
186
+ if (currentType === AllowedType.Number) {
187
+ desiredType ??= currentType;
188
+ }
189
+ if (currentType !== desiredType) {
190
+ context.report({
191
+ node: member.initializer ?? member,
192
+ messageId: 'mixed',
193
+ });
194
+ return;
195
+ }
196
+ }
197
+ },
198
+ };
199
+ },
200
+ });
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-namespace.d.ts ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export type Options = [
2
+ {
3
+ allowDeclarations?: boolean;
4
+ allowDefinitionFiles?: boolean;
5
+ }
6
+ ];
7
+ export type MessageIds = 'moduleSyntaxIsPreferred';
8
+ declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<"moduleSyntaxIsPreferred", Options, import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
9
+ name: string;
10
+ };
11
+ export default _default;
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-namespace.js ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@typescript-eslint/utils");
4
+ const util_1 = require("../util");
5
+ exports.default = (0, util_1.createRule)({
6
+ name: 'no-namespace',
7
+ meta: {
8
+ type: 'suggestion',
9
+ docs: {
10
+ description: 'Disallow TypeScript namespaces',
11
+ recommended: 'recommended',
12
+ },
13
+ messages: {
14
+ moduleSyntaxIsPreferred: 'ES2015 module syntax is preferred over namespaces.',
15
+ },
16
+ schema: [
17
+ {
18
+ type: 'object',
19
+ additionalProperties: false,
20
+ properties: {
21
+ allowDeclarations: {
22
+ type: 'boolean',
23
+ description: 'Whether to allow `declare` with custom TypeScript namespaces.',
24
+ },
25
+ allowDefinitionFiles: {
26
+ type: 'boolean',
27
+ description: 'Whether to allow `declare` with custom TypeScript namespaces inside definition files.',
28
+ },
29
+ },
30
+ },
31
+ ],
32
+ },
33
+ defaultOptions: [
34
+ {
35
+ allowDeclarations: false,
36
+ allowDefinitionFiles: true,
37
+ },
38
+ ],
39
+ create(context, [{ allowDeclarations, allowDefinitionFiles }]) {
40
+ function isDeclaration(node) {
41
+ if (node.type === utils_1.AST_NODE_TYPES.TSModuleDeclaration && node.declare) {
42
+ return true;
43
+ }
44
+ return node.parent != null && isDeclaration(node.parent);
45
+ }
46
+ return {
47
+ "TSModuleDeclaration[global!=true][id.type!='Literal']"(node) {
48
+ if (node.parent.type === utils_1.AST_NODE_TYPES.TSModuleDeclaration ||
49
+ (allowDefinitionFiles && (0, util_1.isDefinitionFile)(context.filename)) ||
50
+ (allowDeclarations && isDeclaration(node))) {
51
+ return;
52
+ }
53
+ context.report({
54
+ node,
55
+ messageId: 'moduleSyntaxIsPreferred',
56
+ });
57
+ },
58
+ };
59
+ },
60
+ });
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-non-null-asserted-nullish-coalescing.d.ts ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ import type { TSESLint } from '@typescript-eslint/utils';
2
+ declare const _default: TSESLint.RuleModule<"noNonNullAssertedNullishCoalescing" | "suggestRemovingNonNull", [], import("../../rules").ESLintPluginDocs, TSESLint.RuleListener> & {
3
+ name: string;
4
+ };
5
+ export default _default;
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-non-null-asserted-nullish-coalescing.js ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const scope_manager_1 = require("@typescript-eslint/scope-manager");
4
+ const utils_1 = require("@typescript-eslint/utils");
5
+ const util_1 = require("../util");
6
+ function hasAssignmentBeforeNode(variable, node) {
7
+ return (variable.references.some(ref => ref.isWrite() && ref.identifier.range[1] < node.range[1]) ||
8
+ variable.defs.some(def => isDefinitionWithAssignment(def) && def.node.range[1] < node.range[1]));
9
+ }
10
+ function isDefinitionWithAssignment(definition) {
11
+ if (definition.type !== scope_manager_1.DefinitionType.Variable) {
12
+ return false;
13
+ }
14
+ const variableDeclarator = definition.node;
15
+ return variableDeclarator.definite || variableDeclarator.init != null;
16
+ }
17
+ exports.default = (0, util_1.createRule)({
18
+ name: 'no-non-null-asserted-nullish-coalescing',
19
+ meta: {
20
+ type: 'problem',
21
+ docs: {
22
+ description: 'Disallow non-null assertions in the left operand of a nullish coalescing operator',
23
+ recommended: 'strict',
24
+ },
25
+ hasSuggestions: true,
26
+ messages: {
27
+ noNonNullAssertedNullishCoalescing: 'The nullish coalescing operator is designed to handle undefined and null - using a non-null assertion is not needed.',
28
+ suggestRemovingNonNull: 'Remove the non-null assertion.',
29
+ },
30
+ schema: [],
31
+ },
32
+ defaultOptions: [],
33
+ create(context) {
34
+ return {
35
+ 'LogicalExpression[operator = "??"] > TSNonNullExpression.left'(node) {
36
+ if (node.expression.type === utils_1.TSESTree.AST_NODE_TYPES.Identifier) {
37
+ const scope = context.sourceCode.getScope(node);
38
+ const identifier = node.expression;
39
+ const variable = utils_1.ASTUtils.findVariable(scope, identifier.name);
40
+ if (variable && !hasAssignmentBeforeNode(variable, node)) {
41
+ return;
42
+ }
43
+ }
44
+ context.report({
45
+ node,
46
+ messageId: 'noNonNullAssertedNullishCoalescing',
47
+ /*
48
+ Use a suggestion instead of a fixer, because this can break type checks.
49
+ The resulting type of the nullish coalesce is only influenced by the right operand if the left operand can be `null` or `undefined`.
50
+ After removing the non-null assertion the type of the left operand might contain `null` or `undefined` and then the type of the right operand
51
+ might change the resulting type of the nullish coalesce.
52
+ See the following example:
53
+
54
+ function test(x?: string): string {
55
+ const bar = x! ?? false; // type analysis reports `bar` has type `string`
56
+ // x ?? false; // type analysis reports `bar` has type `string | false`
57
+ return bar;
58
+ }
59
+ */
60
+ suggest: [
61
+ {
62
+ messageId: 'suggestRemovingNonNull',
63
+ fix(fixer) {
64
+ const exclamationMark = (0, util_1.nullThrows)(context.sourceCode.getLastToken(node, utils_1.ASTUtils.isNonNullAssertionPunctuator), util_1.NullThrowsReasons.MissingToken('!', 'Non-null Assertion'));
65
+ return fixer.remove(exclamationMark);
66
+ },
67
+ },
68
+ ],
69
+ });
70
+ },
71
+ };
72
+ },
73
+ });
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-non-null-asserted-optional-chain.d.ts ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ import type { TSESLint } from '@typescript-eslint/utils';
2
+ declare const _default: TSESLint.RuleModule<"suggestRemovingNonNull" | "noNonNullOptionalChain", [], import("../../rules").ESLintPluginDocs, TSESLint.RuleListener> & {
3
+ name: string;
4
+ };
5
+ export default _default;
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-non-null-asserted-optional-chain.js ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const util_1 = require("../util");
4
+ exports.default = (0, util_1.createRule)({
5
+ name: 'no-non-null-asserted-optional-chain',
6
+ meta: {
7
+ type: 'problem',
8
+ docs: {
9
+ description: 'Disallow non-null assertions after an optional chain expression',
10
+ recommended: 'recommended',
11
+ },
12
+ hasSuggestions: true,
13
+ messages: {
14
+ noNonNullOptionalChain: 'Optional chain expressions can return undefined by design - using a non-null assertion is unsafe and wrong.',
15
+ suggestRemovingNonNull: 'You should remove the non-null assertion.',
16
+ },
17
+ schema: [],
18
+ },
19
+ defaultOptions: [],
20
+ create(context) {
21
+ return {
22
+ // non-nulling a wrapped chain will scrub all nulls introduced by the chain
23
+ // (x?.y)!
24
+ // (x?.())!
25
+ 'TSNonNullExpression > ChainExpression'(node) {
26
+ // selector guarantees this assertion
27
+ const parent = node.parent;
28
+ context.report({
29
+ node,
30
+ messageId: 'noNonNullOptionalChain',
31
+ // use a suggestion instead of a fixer, because this can obviously break type checks
32
+ suggest: [
33
+ {
34
+ messageId: 'suggestRemovingNonNull',
35
+ fix(fixer) {
36
+ return fixer.removeRange([
37
+ parent.range[1] - 1,
38
+ parent.range[1],
39
+ ]);
40
+ },
41
+ },
42
+ ],
43
+ });
44
+ },
45
+ // non-nulling at the end of a chain will scrub all nulls introduced by the chain
46
+ // x?.y!
47
+ // x?.()!
48
+ 'ChainExpression > TSNonNullExpression'(node) {
49
+ context.report({
50
+ node,
51
+ messageId: 'noNonNullOptionalChain',
52
+ // use a suggestion instead of a fixer, because this can obviously break type checks
53
+ suggest: [
54
+ {
55
+ messageId: 'suggestRemovingNonNull',
56
+ fix(fixer) {
57
+ return fixer.removeRange([node.range[1] - 1, node.range[1]]);
58
+ },
59
+ },
60
+ ],
61
+ });
62
+ },
63
+ };
64
+ },
65
+ });
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-non-null-assertion.d.ts ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ import type { TSESLint } from '@typescript-eslint/utils';
2
+ export type MessageIds = 'noNonNull' | 'suggestOptionalChain';
3
+ declare const _default: TSESLint.RuleModule<MessageIds, [], import("../../rules").ESLintPluginDocs, TSESLint.RuleListener> & {
4
+ name: string;
5
+ };
6
+ export default _default;
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-non-null-assertion.js ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@typescript-eslint/utils");
4
+ const util_1 = require("../util");
5
+ exports.default = (0, util_1.createRule)({
6
+ name: 'no-non-null-assertion',
7
+ meta: {
8
+ type: 'problem',
9
+ docs: {
10
+ description: 'Disallow non-null assertions using the `!` postfix operator',
11
+ recommended: 'strict',
12
+ },
13
+ hasSuggestions: true,
14
+ messages: {
15
+ noNonNull: 'Forbidden non-null assertion.',
16
+ suggestOptionalChain: 'Consider using the optional chain operator `?.` instead. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator.',
17
+ },
18
+ schema: [],
19
+ },
20
+ defaultOptions: [],
21
+ create(context) {
22
+ return {
23
+ TSNonNullExpression(node) {
24
+ const suggest = [];
25
+ // it always exists in non-null assertion
26
+ const nonNullOperator = (0, util_1.nullThrows)(context.sourceCode.getTokenAfter(node.expression, util_1.isNonNullAssertionPunctuator), util_1.NullThrowsReasons.MissingToken('!', 'expression'));
27
+ function replaceTokenWithOptional() {
28
+ return fixer => fixer.replaceText(nonNullOperator, '?.');
29
+ }
30
+ function removeToken() {
31
+ return fixer => fixer.remove(nonNullOperator);
32
+ }
33
+ if (node.parent.type === utils_1.AST_NODE_TYPES.MemberExpression &&
34
+ node.parent.object === node &&
35
+ !(0, util_1.isAssignee)(node.parent)) {
36
+ if (!node.parent.optional) {
37
+ if (node.parent.computed) {
38
+ // it is x![y]?.z
39
+ suggest.push({
40
+ messageId: 'suggestOptionalChain',
41
+ fix: replaceTokenWithOptional(),
42
+ });
43
+ }
44
+ else {
45
+ // it is x!.y?.z
46
+ suggest.push({
47
+ messageId: 'suggestOptionalChain',
48
+ fix(fixer) {
49
+ // x!.y?.z
50
+ // ^ punctuator
51
+ const punctuator = (0, util_1.nullThrows)(context.sourceCode.getTokenAfter(nonNullOperator), util_1.NullThrowsReasons.MissingToken('.', '!'));
52
+ return [
53
+ fixer.remove(nonNullOperator),
54
+ fixer.insertTextBefore(punctuator, '?'),
55
+ ];
56
+ },
57
+ });
58
+ }
59
+ }
60
+ else {
61
+ // it is x!?.[y].z or x!?.y.z
62
+ suggest.push({
63
+ messageId: 'suggestOptionalChain',
64
+ fix: removeToken(),
65
+ });
66
+ }
67
+ }
68
+ else if (node.parent.type === utils_1.AST_NODE_TYPES.CallExpression &&
69
+ node.parent.callee === node) {
70
+ if (!node.parent.optional) {
71
+ // it is x.y?.z!()
72
+ suggest.push({
73
+ messageId: 'suggestOptionalChain',
74
+ fix: replaceTokenWithOptional(),
75
+ });
76
+ }
77
+ else {
78
+ // it is x.y.z!?.()
79
+ suggest.push({
80
+ messageId: 'suggestOptionalChain',
81
+ fix: removeToken(),
82
+ });
83
+ }
84
+ }
85
+ context.report({
86
+ node,
87
+ messageId: 'noNonNull',
88
+ suggest,
89
+ });
90
+ },
91
+ };
92
+ },
93
+ });
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-redeclare.d.ts ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { TSESLint } from '@typescript-eslint/utils';
2
+ export type MessageIds = 'redeclared' | 'redeclaredAsBuiltin' | 'redeclaredBySyntax';
3
+ export type Options = [
4
+ {
5
+ builtinGlobals?: boolean;
6
+ ignoreDeclarationMerge?: boolean;
7
+ }
8
+ ];
9
+ declare const _default: TSESLint.RuleModule<MessageIds, Options, import("../../rules").ESLintPluginDocs, TSESLint.RuleListener> & {
10
+ name: string;
11
+ };
12
+ export default _default;
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-redeclare.js ADDED
@@ -0,0 +1,199 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const scope_manager_1 = require("@typescript-eslint/scope-manager");
4
+ const utils_1 = require("@typescript-eslint/utils");
5
+ const util_1 = require("../util");
6
+ exports.default = (0, util_1.createRule)({
7
+ name: 'no-redeclare',
8
+ meta: {
9
+ type: 'suggestion',
10
+ docs: {
11
+ description: 'Disallow variable redeclaration',
12
+ extendsBaseRule: true,
13
+ },
14
+ messages: {
15
+ redeclared: "'{{id}}' is already defined.",
16
+ redeclaredAsBuiltin: "'{{id}}' is already defined as a built-in global variable.",
17
+ redeclaredBySyntax: "'{{id}}' is already defined by a variable declaration.",
18
+ },
19
+ schema: [
20
+ {
21
+ type: 'object',
22
+ additionalProperties: false,
23
+ properties: {
24
+ builtinGlobals: {
25
+ type: 'boolean',
26
+ description: 'Whether to report shadowing of built-in global variables.',
27
+ },
28
+ ignoreDeclarationMerge: {
29
+ type: 'boolean',
30
+ description: 'Whether to ignore declaration merges between certain TypeScript declaration types.',
31
+ },
32
+ },
33
+ },
34
+ ],
35
+ },
36
+ defaultOptions: [
37
+ {
38
+ builtinGlobals: true,
39
+ ignoreDeclarationMerge: true,
40
+ },
41
+ ],
42
+ create(context, [options]) {
43
+ const CLASS_DECLARATION_MERGE_NODES = new Set([
44
+ utils_1.AST_NODE_TYPES.ClassDeclaration,
45
+ utils_1.AST_NODE_TYPES.TSInterfaceDeclaration,
46
+ utils_1.AST_NODE_TYPES.TSModuleDeclaration,
47
+ ]);
48
+ const FUNCTION_DECLARATION_MERGE_NODES = new Set([
49
+ utils_1.AST_NODE_TYPES.FunctionDeclaration,
50
+ utils_1.AST_NODE_TYPES.TSModuleDeclaration,
51
+ ]);
52
+ const ENUM_DECLARATION_MERGE_NODES = new Set([
53
+ utils_1.AST_NODE_TYPES.TSEnumDeclaration,
54
+ utils_1.AST_NODE_TYPES.TSModuleDeclaration,
55
+ ]);
56
+ function* iterateDeclarations(variable) {
57
+ if (options.builtinGlobals &&
58
+ 'eslintImplicitGlobalSetting' in variable &&
59
+ (variable.eslintImplicitGlobalSetting === 'readonly' ||
60
+ variable.eslintImplicitGlobalSetting === 'writable')) {
61
+ yield { type: 'builtin' };
62
+ }
63
+ if ('eslintExplicitGlobalComments' in variable &&
64
+ variable.eslintExplicitGlobalComments) {
65
+ for (const comment of variable.eslintExplicitGlobalComments) {
66
+ yield {
67
+ loc: (0, util_1.getNameLocationInGlobalDirectiveComment)(context.sourceCode, comment, variable.name),
68
+ node: comment,
69
+ type: 'comment',
70
+ };
71
+ }
72
+ }
73
+ const identifiers = variable.identifiers
74
+ .map(id => ({
75
+ identifier: id,
76
+ parent: id.parent,
77
+ }))
78
+ // ignore function declarations because TS will treat them as an overload
79
+ .filter(({ parent }) => parent.type !== utils_1.AST_NODE_TYPES.TSDeclareFunction);
80
+ if (options.ignoreDeclarationMerge && identifiers.length > 1) {
81
+ if (
82
+ // interfaces merging
83
+ identifiers.every(({ parent }) => parent.type === utils_1.AST_NODE_TYPES.TSInterfaceDeclaration)) {
84
+ return;
85
+ }
86
+ if (
87
+ // namespace/module merging
88
+ identifiers.every(({ parent }) => parent.type === utils_1.AST_NODE_TYPES.TSModuleDeclaration)) {
89
+ return;
90
+ }
91
+ if (
92
+ // class + interface/namespace merging
93
+ identifiers.every(({ parent }) => CLASS_DECLARATION_MERGE_NODES.has(parent.type))) {
94
+ const classDecls = identifiers.filter(({ parent }) => parent.type === utils_1.AST_NODE_TYPES.ClassDeclaration);
95
+ if (classDecls.length === 1) {
96
+ // safe declaration merging
97
+ return;
98
+ }
99
+ // there's more than one class declaration, which needs to be reported
100
+ for (const { identifier } of classDecls) {
101
+ yield { loc: identifier.loc, node: identifier, type: 'syntax' };
102
+ }
103
+ return;
104
+ }
105
+ if (
106
+ // class + interface/namespace merging
107
+ identifiers.every(({ parent }) => FUNCTION_DECLARATION_MERGE_NODES.has(parent.type))) {
108
+ const functionDecls = identifiers.filter(({ parent }) => parent.type === utils_1.AST_NODE_TYPES.FunctionDeclaration);
109
+ if (functionDecls.length === 1) {
110
+ // safe declaration merging
111
+ return;
112
+ }
113
+ // there's more than one function declaration, which needs to be reported
114
+ for (const { identifier } of functionDecls) {
115
+ yield { loc: identifier.loc, node: identifier, type: 'syntax' };
116
+ }
117
+ return;
118
+ }
119
+ if (
120
+ // enum + namespace merging
121
+ identifiers.every(({ parent }) => ENUM_DECLARATION_MERGE_NODES.has(parent.type))) {
122
+ const enumDecls = identifiers.filter(({ parent }) => parent.type === utils_1.AST_NODE_TYPES.TSEnumDeclaration);
123
+ if (enumDecls.length === 1) {
124
+ // safe declaration merging
125
+ return;
126
+ }
127
+ // there's more than one enum declaration, which needs to be reported
128
+ for (const { identifier } of enumDecls) {
129
+ yield { loc: identifier.loc, node: identifier, type: 'syntax' };
130
+ }
131
+ return;
132
+ }
133
+ }
134
+ for (const { identifier } of identifiers) {
135
+ yield { loc: identifier.loc, node: identifier, type: 'syntax' };
136
+ }
137
+ }
138
+ function findVariablesInScope(scope) {
139
+ for (const variable of scope.variables) {
140
+ const [declaration, ...extraDeclarations] = iterateDeclarations(variable);
141
+ if (extraDeclarations.length === 0) {
142
+ continue;
143
+ }
144
+ /*
145
+ * If the type of a declaration is different from the type of
146
+ * the first declaration, it shows the location of the first
147
+ * declaration.
148
+ */
149
+ const detailMessageId = declaration.type === 'builtin'
150
+ ? 'redeclaredAsBuiltin'
151
+ : 'redeclaredBySyntax';
152
+ const data = { id: variable.name };
153
+ // Report extra declarations.
154
+ for (const { loc, node, type } of extraDeclarations) {
155
+ const messageId = type === declaration.type ? 'redeclared' : detailMessageId;
156
+ if (node) {
157
+ context.report({ loc, node, messageId, data });
158
+ }
159
+ else if (loc) {
160
+ context.report({ loc, messageId, data });
161
+ }
162
+ }
163
+ }
164
+ }
165
+ /**
166
+ * Find variables in the current scope.
167
+ */
168
+ function checkForBlock(node) {
169
+ const scope = context.sourceCode.getScope(node);
170
+ /*
171
+ * In ES5, some node type such as `BlockStatement` doesn't have that scope.
172
+ * `scope.block` is a different node in such a case.
173
+ */
174
+ if (scope.block === node) {
175
+ findVariablesInScope(scope);
176
+ }
177
+ }
178
+ return {
179
+ ArrowFunctionExpression: checkForBlock,
180
+ BlockStatement: checkForBlock,
181
+ ForInStatement: checkForBlock,
182
+ ForOfStatement: checkForBlock,
183
+ ForStatement: checkForBlock,
184
+ FunctionDeclaration: checkForBlock,
185
+ FunctionExpression: checkForBlock,
186
+ Program(node) {
187
+ const scope = context.sourceCode.getScope(node);
188
+ findVariablesInScope(scope);
189
+ // Node.js or ES modules has a special scope.
190
+ if (scope.type === scope_manager_1.ScopeType.global &&
191
+ // The special scope's block is the Program node.
192
+ scope.block === scope.childScopes[0]?.block) {
193
+ findVariablesInScope(scope.childScopes[0]);
194
+ }
195
+ },
196
+ SwitchStatement: checkForBlock,
197
+ };
198
+ },
199
+ });
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-redundant-type-constituents.d.ts ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<"overrides" | "errorTypeOverrides" | "literalOverridden" | "overridden" | "primitiveOverridden", [], import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
2
+ name: string;
3
+ };
4
+ export default _default;
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-redundant-type-constituents.js ADDED
@@ -0,0 +1,431 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const utils_1 = require("@typescript-eslint/utils");
37
+ const tsutils = __importStar(require("ts-api-utils"));
38
+ const ts = __importStar(require("typescript"));
39
+ const util_1 = require("../util");
40
+ const literalToPrimitiveTypeFlags = {
41
+ [ts.TypeFlags.BigIntLiteral]: ts.TypeFlags.BigInt,
42
+ [ts.TypeFlags.BooleanLiteral]: ts.TypeFlags.Boolean,
43
+ [ts.TypeFlags.NumberLiteral]: ts.TypeFlags.Number,
44
+ [ts.TypeFlags.StringLiteral]: ts.TypeFlags.String,
45
+ [ts.TypeFlags.TemplateLiteral]: ts.TypeFlags.String,
46
+ };
47
+ const literalTypeFlags = [
48
+ ts.TypeFlags.BigIntLiteral,
49
+ ts.TypeFlags.BooleanLiteral,
50
+ ts.TypeFlags.NumberLiteral,
51
+ ts.TypeFlags.StringLiteral,
52
+ ts.TypeFlags.TemplateLiteral,
53
+ ];
54
+ const primitiveTypeFlags = [
55
+ ts.TypeFlags.BigInt,
56
+ ts.TypeFlags.Boolean,
57
+ ts.TypeFlags.Number,
58
+ ts.TypeFlags.String,
59
+ ];
60
+ const primitiveTypeFlagNames = {
61
+ [ts.TypeFlags.BigInt]: 'bigint',
62
+ [ts.TypeFlags.Boolean]: 'boolean',
63
+ [ts.TypeFlags.Number]: 'number',
64
+ [ts.TypeFlags.String]: 'string',
65
+ };
66
+ const primitiveTypeFlagTypes = {
67
+ bigint: ts.TypeFlags.BigIntLiteral,
68
+ boolean: ts.TypeFlags.BooleanLiteral,
69
+ number: ts.TypeFlags.NumberLiteral,
70
+ string: ts.TypeFlags.StringLiteral,
71
+ };
72
+ const keywordNodeTypesToTsTypes = new Map([
73
+ [utils_1.TSESTree.AST_NODE_TYPES.TSAnyKeyword, ts.TypeFlags.Any],
74
+ [utils_1.TSESTree.AST_NODE_TYPES.TSBigIntKeyword, ts.TypeFlags.BigInt],
75
+ [utils_1.TSESTree.AST_NODE_TYPES.TSBooleanKeyword, ts.TypeFlags.Boolean],
76
+ [utils_1.TSESTree.AST_NODE_TYPES.TSNeverKeyword, ts.TypeFlags.Never],
77
+ [utils_1.TSESTree.AST_NODE_TYPES.TSNumberKeyword, ts.TypeFlags.Number],
78
+ [utils_1.TSESTree.AST_NODE_TYPES.TSStringKeyword, ts.TypeFlags.String],
79
+ [utils_1.TSESTree.AST_NODE_TYPES.TSUnknownKeyword, ts.TypeFlags.Unknown],
80
+ ]);
81
+ function addToMapGroup(map, key, value) {
82
+ const existing = map.get(key);
83
+ if (existing) {
84
+ existing.push(value);
85
+ }
86
+ else {
87
+ map.set(key, [value]);
88
+ }
89
+ }
90
+ function describeLiteralType(type) {
91
+ if (type.isStringLiteral()) {
92
+ return JSON.stringify(type.value);
93
+ }
94
+ if ((0, util_1.isTypeBigIntLiteralType)(type)) {
95
+ return `${type.value.negative ? '-' : ''}${type.value.base10Value}n`;
96
+ }
97
+ if (type.isLiteral()) {
98
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
99
+ return type.value.toString();
100
+ }
101
+ if (tsutils.isIntrinsicErrorType(type) && type.aliasSymbol) {
102
+ return type.aliasSymbol.escapedName.toString();
103
+ }
104
+ if ((0, util_1.isTypeAnyType)(type)) {
105
+ return 'any';
106
+ }
107
+ if ((0, util_1.isTypeNeverType)(type)) {
108
+ return 'never';
109
+ }
110
+ if ((0, util_1.isTypeUnknownType)(type)) {
111
+ return 'unknown';
112
+ }
113
+ if ((0, util_1.isTypeTemplateLiteralType)(type)) {
114
+ return 'template literal type';
115
+ }
116
+ if ((0, util_1.isTypeBigIntLiteralType)(type)) {
117
+ return `${type.value.negative ? '-' : ''}${type.value.base10Value}n`;
118
+ }
119
+ if (tsutils.isTrueLiteralType(type)) {
120
+ return 'true';
121
+ }
122
+ if (tsutils.isFalseLiteralType(type)) {
123
+ return 'false';
124
+ }
125
+ return 'literal type';
126
+ }
127
+ function describeLiteralTypeNode(typeNode) {
128
+ switch (typeNode.type) {
129
+ case utils_1.AST_NODE_TYPES.TSAnyKeyword:
130
+ return 'any';
131
+ case utils_1.AST_NODE_TYPES.TSBooleanKeyword:
132
+ return 'boolean';
133
+ case utils_1.AST_NODE_TYPES.TSNeverKeyword:
134
+ return 'never';
135
+ case utils_1.AST_NODE_TYPES.TSNumberKeyword:
136
+ return 'number';
137
+ case utils_1.AST_NODE_TYPES.TSStringKeyword:
138
+ return 'string';
139
+ case utils_1.AST_NODE_TYPES.TSUnknownKeyword:
140
+ return 'unknown';
141
+ case utils_1.AST_NODE_TYPES.TSLiteralType:
142
+ switch (typeNode.literal.type) {
143
+ case utils_1.TSESTree.AST_NODE_TYPES.Literal:
144
+ switch (typeof typeNode.literal.value) {
145
+ case 'bigint':
146
+ return `${typeNode.literal.value < 0 ? '-' : ''}${typeNode.literal.value}n`;
147
+ case 'string':
148
+ return JSON.stringify(typeNode.literal.value);
149
+ default:
150
+ return `${typeNode.literal.value}`;
151
+ }
152
+ case utils_1.TSESTree.AST_NODE_TYPES.TemplateLiteral:
153
+ return 'template literal type';
154
+ }
155
+ }
156
+ return 'literal type';
157
+ }
158
+ function isNodeInsideReturnType(node) {
159
+ return (node.parent.type === utils_1.AST_NODE_TYPES.TSTypeAnnotation &&
160
+ (0, util_1.isFunctionOrFunctionType)(node.parent.parent));
161
+ }
162
+ /**
163
+ * @remarks TypeScript stores boolean types as the union false | true, always.
164
+ */
165
+ function unionTypePartsUnlessBoolean(type) {
166
+ return type.isUnion() &&
167
+ type.types.length === 2 &&
168
+ tsutils.isFalseLiteralType(type.types[0]) &&
169
+ tsutils.isTrueLiteralType(type.types[1])
170
+ ? [type]
171
+ : tsutils.unionConstituents(type);
172
+ }
173
+ exports.default = (0, util_1.createRule)({
174
+ name: 'no-redundant-type-constituents',
175
+ meta: {
176
+ type: 'suggestion',
177
+ docs: {
178
+ description: 'Disallow members of unions and intersections that do nothing or override type information',
179
+ recommended: 'recommended',
180
+ requiresTypeChecking: true,
181
+ },
182
+ messages: {
183
+ errorTypeOverrides: `'{{typeName}}' is an 'error' type that acts as 'any' and overrides all other types in this {{container}} type.`,
184
+ literalOverridden: `{{literal}} is overridden by {{primitive}} in this union type.`,
185
+ overridden: `'{{typeName}}' is overridden by other types in this {{container}} type.`,
186
+ overrides: `'{{typeName}}' overrides all other types in this {{container}} type.`,
187
+ primitiveOverridden: `{{primitive}} is overridden by the {{literal}} in this intersection type.`,
188
+ },
189
+ schema: [],
190
+ },
191
+ defaultOptions: [],
192
+ create(context) {
193
+ const services = (0, util_1.getParserServices)(context);
194
+ const typesCache = new Map();
195
+ function getTypeNodeTypePartFlags(typeNode) {
196
+ const keywordTypeFlags = keywordNodeTypesToTsTypes.get(typeNode.type);
197
+ if (keywordTypeFlags) {
198
+ return [
199
+ {
200
+ typeFlags: keywordTypeFlags,
201
+ typeName: describeLiteralTypeNode(typeNode),
202
+ },
203
+ ];
204
+ }
205
+ if (typeNode.type === utils_1.AST_NODE_TYPES.TSLiteralType &&
206
+ typeNode.literal.type === utils_1.AST_NODE_TYPES.Literal) {
207
+ return [
208
+ {
209
+ typeFlags: primitiveTypeFlagTypes[typeof typeNode.literal
210
+ .value],
211
+ typeName: describeLiteralTypeNode(typeNode),
212
+ },
213
+ ];
214
+ }
215
+ if (typeNode.type === utils_1.AST_NODE_TYPES.TSUnionType) {
216
+ return typeNode.types.flatMap(getTypeNodeTypePartFlags);
217
+ }
218
+ const nodeType = services.getTypeAtLocation(typeNode);
219
+ const typeParts = unionTypePartsUnlessBoolean(nodeType);
220
+ return typeParts.map(typePart => ({
221
+ typeFlags: typePart.flags,
222
+ typeName: describeLiteralType(typePart),
223
+ }));
224
+ }
225
+ function getTypeNodeTypePartFlagsCached(typeNode) {
226
+ const existing = typesCache.get(typeNode);
227
+ if (existing) {
228
+ return existing;
229
+ }
230
+ const created = getTypeNodeTypePartFlags(typeNode);
231
+ typesCache.set(typeNode, created);
232
+ return created;
233
+ }
234
+ return {
235
+ 'TSIntersectionType:exit'(node) {
236
+ const seenLiteralTypes = new Map();
237
+ const seenPrimitiveTypes = new Map();
238
+ const seenUnionTypes = new Map();
239
+ function checkIntersectionBottomAndTopTypes({ typeFlags, typeName }, typeNode) {
240
+ for (const [messageId, checkFlag] of [
241
+ ['overrides', ts.TypeFlags.Any],
242
+ ['overrides', ts.TypeFlags.Never],
243
+ ['overridden', ts.TypeFlags.Unknown],
244
+ ]) {
245
+ if (typeFlags === checkFlag) {
246
+ context.report({
247
+ node: typeNode,
248
+ messageId: typeFlags === ts.TypeFlags.Any && typeName !== 'any'
249
+ ? 'errorTypeOverrides'
250
+ : messageId,
251
+ data: {
252
+ container: 'intersection',
253
+ typeName,
254
+ },
255
+ });
256
+ return true;
257
+ }
258
+ }
259
+ return false;
260
+ }
261
+ for (const typeNode of node.types) {
262
+ const typePartFlags = getTypeNodeTypePartFlagsCached(typeNode);
263
+ for (const typePart of typePartFlags) {
264
+ if (checkIntersectionBottomAndTopTypes(typePart, typeNode)) {
265
+ continue;
266
+ }
267
+ for (const literalTypeFlag of literalTypeFlags) {
268
+ if (typePart.typeFlags === literalTypeFlag) {
269
+ addToMapGroup(seenLiteralTypes, literalToPrimitiveTypeFlags[literalTypeFlag], typePart.typeName);
270
+ break;
271
+ }
272
+ }
273
+ for (const primitiveTypeFlag of primitiveTypeFlags) {
274
+ if (typePart.typeFlags === primitiveTypeFlag) {
275
+ addToMapGroup(seenPrimitiveTypes, primitiveTypeFlag, typeNode);
276
+ }
277
+ }
278
+ }
279
+ // if any typeNode is TSTypeReference and typePartFlags have more than 1 element, than the referenced type is definitely a union.
280
+ if (typePartFlags.length >= 2) {
281
+ seenUnionTypes.set(typeNode, typePartFlags);
282
+ }
283
+ }
284
+ /**
285
+ * @example
286
+ * ```ts
287
+ * type F = "a"|2|"b";
288
+ * type I = F & string;
289
+ * ```
290
+ * This function checks if all the union members of `F` are assignable to the other member of `I`. If every member is assignable, then its reported else not.
291
+ */
292
+ const checkIfUnionsAreAssignable = () => {
293
+ for (const [typeRef, typeValues] of seenUnionTypes) {
294
+ let primitive = undefined;
295
+ for (const { typeFlags } of typeValues) {
296
+ if (seenPrimitiveTypes.has(literalToPrimitiveTypeFlags[typeFlags])) {
297
+ primitive =
298
+ literalToPrimitiveTypeFlags[typeFlags];
299
+ }
300
+ else {
301
+ primitive = undefined;
302
+ break;
303
+ }
304
+ }
305
+ if (Number.isInteger(primitive)) {
306
+ context.report({
307
+ node: typeRef,
308
+ messageId: 'primitiveOverridden',
309
+ data: {
310
+ literal: typeValues.map(name => name.typeName).join(' | '),
311
+ primitive: primitiveTypeFlagNames[primitive],
312
+ },
313
+ });
314
+ }
315
+ }
316
+ };
317
+ if (seenUnionTypes.size > 0) {
318
+ checkIfUnionsAreAssignable();
319
+ return;
320
+ }
321
+ // For each primitive type of all the seen primitive types,
322
+ // if there was a literal type seen that overrides it,
323
+ // report each of the primitive type's type nodes
324
+ for (const [primitiveTypeFlag, typeNodes] of seenPrimitiveTypes) {
325
+ const matchedLiteralTypes = seenLiteralTypes.get(primitiveTypeFlag);
326
+ if (matchedLiteralTypes) {
327
+ for (const typeNode of typeNodes) {
328
+ context.report({
329
+ node: typeNode,
330
+ messageId: 'primitiveOverridden',
331
+ data: {
332
+ literal: matchedLiteralTypes.join(' | '),
333
+ primitive: primitiveTypeFlagNames[primitiveTypeFlag],
334
+ },
335
+ });
336
+ }
337
+ }
338
+ }
339
+ },
340
+ 'TSUnionType:exit'(node) {
341
+ const seenLiteralTypes = new Map();
342
+ const seenPrimitiveTypes = new Set();
343
+ function checkUnionBottomAndTopTypes({ typeFlags, typeName }, typeNode) {
344
+ for (const checkFlag of [
345
+ ts.TypeFlags.Any,
346
+ ts.TypeFlags.Unknown,
347
+ ]) {
348
+ if (typeFlags === checkFlag) {
349
+ context.report({
350
+ node: typeNode,
351
+ messageId: typeFlags === ts.TypeFlags.Any && typeName !== 'any'
352
+ ? 'errorTypeOverrides'
353
+ : 'overrides',
354
+ data: {
355
+ container: 'union',
356
+ typeName,
357
+ },
358
+ });
359
+ return true;
360
+ }
361
+ }
362
+ if (typeFlags === ts.TypeFlags.Never &&
363
+ !isNodeInsideReturnType(node)) {
364
+ context.report({
365
+ node: typeNode,
366
+ messageId: 'overridden',
367
+ data: {
368
+ container: 'union',
369
+ typeName: 'never',
370
+ },
371
+ });
372
+ return true;
373
+ }
374
+ return false;
375
+ }
376
+ for (const typeNode of node.types) {
377
+ const typePartFlags = getTypeNodeTypePartFlagsCached(typeNode);
378
+ for (const typePart of typePartFlags) {
379
+ if (checkUnionBottomAndTopTypes(typePart, typeNode)) {
380
+ continue;
381
+ }
382
+ for (const literalTypeFlag of literalTypeFlags) {
383
+ if (typePart.typeFlags === literalTypeFlag) {
384
+ addToMapGroup(seenLiteralTypes, literalToPrimitiveTypeFlags[literalTypeFlag], {
385
+ literalValue: typePart.typeName,
386
+ typeNode,
387
+ });
388
+ break;
389
+ }
390
+ }
391
+ for (const primitiveTypeFlag of primitiveTypeFlags) {
392
+ if ((typePart.typeFlags & primitiveTypeFlag) !== 0) {
393
+ seenPrimitiveTypes.add(primitiveTypeFlag);
394
+ }
395
+ }
396
+ }
397
+ }
398
+ const overriddenTypeNodes = new Map();
399
+ // For each primitive type of all the seen literal types,
400
+ // if there was a primitive type seen that overrides it,
401
+ // upsert the literal text and primitive type under the backing type node
402
+ for (const [primitiveTypeFlag, typeNodesWithText] of seenLiteralTypes) {
403
+ if (seenPrimitiveTypes.has(primitiveTypeFlag)) {
404
+ for (const { literalValue, typeNode } of typeNodesWithText) {
405
+ addToMapGroup(overriddenTypeNodes, typeNode, {
406
+ literalValue,
407
+ primitiveTypeFlag,
408
+ });
409
+ }
410
+ }
411
+ }
412
+ // For each type node that had at least one overridden literal,
413
+ // group those literals by their primitive type,
414
+ // then report each primitive type with all its literals
415
+ for (const [typeNode, typeFlagsWithText] of overriddenTypeNodes) {
416
+ const grouped = (0, util_1.arrayGroupByToMap)(typeFlagsWithText, pair => pair.primitiveTypeFlag);
417
+ for (const [primitiveTypeFlag, pairs] of grouped) {
418
+ context.report({
419
+ node: typeNode,
420
+ messageId: 'literalOverridden',
421
+ data: {
422
+ literal: pairs.map(pair => pair.literalValue).join(' | '),
423
+ primitive: primitiveTypeFlagNames[primitiveTypeFlag],
424
+ },
425
+ });
426
+ }
427
+ }
428
+ },
429
+ };
430
+ },
431
+ });
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-require-imports.d.ts ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export type Options = [
2
+ {
3
+ allow?: string[];
4
+ allowAsImport?: boolean;
5
+ }
6
+ ];
7
+ export type MessageIds = 'noRequireImports';
8
+ declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<"noRequireImports", Options, import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
9
+ name: string;
10
+ };
11
+ export default _default;
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-require-imports.js ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const utils_1 = require("@typescript-eslint/utils");
37
+ const util = __importStar(require("../util"));
38
+ exports.default = util.createRule({
39
+ name: 'no-require-imports',
40
+ meta: {
41
+ type: 'problem',
42
+ docs: {
43
+ description: 'Disallow invocation of `require()`',
44
+ recommended: 'recommended',
45
+ },
46
+ messages: {
47
+ noRequireImports: 'A `require()` style import is forbidden.',
48
+ },
49
+ schema: [
50
+ {
51
+ type: 'object',
52
+ additionalProperties: false,
53
+ properties: {
54
+ allow: {
55
+ type: 'array',
56
+ description: 'Patterns of import paths to allow requiring from.',
57
+ items: { type: 'string' },
58
+ },
59
+ allowAsImport: {
60
+ type: 'boolean',
61
+ description: 'Allows `require` statements in import declarations.',
62
+ },
63
+ },
64
+ },
65
+ ],
66
+ },
67
+ defaultOptions: [{ allow: [], allowAsImport: false }],
68
+ create(context, options) {
69
+ const allowAsImport = options[0].allowAsImport;
70
+ const allowPatterns = options[0].allow?.map(pattern => new RegExp(pattern, 'u'));
71
+ function isImportPathAllowed(importPath) {
72
+ return allowPatterns?.some(pattern => importPath.match(pattern));
73
+ }
74
+ function isStringOrTemplateLiteral(node) {
75
+ return ((node.type === utils_1.AST_NODE_TYPES.Literal &&
76
+ typeof node.value === 'string') ||
77
+ node.type === utils_1.AST_NODE_TYPES.TemplateLiteral);
78
+ }
79
+ return {
80
+ 'CallExpression[callee.name="require"]'(node) {
81
+ if (node.arguments[0] && isStringOrTemplateLiteral(node.arguments[0])) {
82
+ const argValue = util.getStaticStringValue(node.arguments[0]);
83
+ if (typeof argValue === 'string' && isImportPathAllowed(argValue)) {
84
+ return;
85
+ }
86
+ }
87
+ const variable = utils_1.ASTUtils.findVariable(context.sourceCode.getScope(node), 'require');
88
+ // ignore non-global require usage as it's something user-land custom instead
89
+ // of the commonjs standard
90
+ if (!variable?.identifiers.length) {
91
+ context.report({
92
+ node,
93
+ messageId: 'noRequireImports',
94
+ });
95
+ }
96
+ },
97
+ TSExternalModuleReference(node) {
98
+ if (isStringOrTemplateLiteral(node.expression)) {
99
+ const argValue = util.getStaticStringValue(node.expression);
100
+ if (typeof argValue === 'string' && isImportPathAllowed(argValue)) {
101
+ return;
102
+ }
103
+ }
104
+ if (allowAsImport &&
105
+ node.parent.type === utils_1.AST_NODE_TYPES.TSImportEqualsDeclaration) {
106
+ return;
107
+ }
108
+ context.report({
109
+ node,
110
+ messageId: 'noRequireImports',
111
+ });
112
+ },
113
+ };
114
+ },
115
+ });
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-restricted-imports.d.ts ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import type { ArrayOfStringOrObject, RuleListener } from 'eslint/lib/rules/no-restricted-imports';
2
+ import type { InferMessageIdsTypeFromRule, InferOptionsTypeFromRule } from '../util';
3
+ declare const baseRule: import("@typescript-eslint/utils/ts-eslint").RuleModule<"everything" | "everythingWithCustomMessage" | "importName" | "importNameWithCustomMessage" | "path" | "pathWithCustomMessage" | "patterns" | "patternWithCustomMessage", [import("eslint/lib/rules/no-restricted-imports").ObjectOfPathsAndPatterns] | ArrayOfStringOrObject, unknown, RuleListener>;
4
+ export type Options = InferOptionsTypeFromRule<typeof baseRule>;
5
+ export type MessageIds = InferMessageIdsTypeFromRule<typeof baseRule>;
6
+ declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<"everything" | "everythingWithCustomMessage" | "importName" | "importNameWithCustomMessage" | "path" | "pathWithCustomMessage" | "patterns" | "patternWithCustomMessage", [import("eslint/lib/rules/no-restricted-imports").ObjectOfPathsAndPatterns] | ArrayOfStringOrObject, import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
7
+ name: string;
8
+ };
9
+ export default _default;
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-restricted-imports.js ADDED
@@ -0,0 +1,243 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("@typescript-eslint/utils");
7
+ const ignore_1 = __importDefault(require("ignore"));
8
+ const util_1 = require("../util");
9
+ const getESLintCoreRule_1 = require("../util/getESLintCoreRule");
10
+ const baseRule = (0, getESLintCoreRule_1.getESLintCoreRule)('no-restricted-imports');
11
+ // In some versions of eslint, the base rule has a completely incompatible schema
12
+ // This helper function is to safely try to get parts of the schema. If it's not
13
+ // possible, we'll fallback to less strict checks.
14
+ const tryAccess = (getter, fallback) => {
15
+ try {
16
+ return getter();
17
+ }
18
+ catch {
19
+ return fallback;
20
+ }
21
+ };
22
+ const baseSchema = baseRule.meta.schema;
23
+ const allowTypeImportsOptionSchema = {
24
+ allowTypeImports: {
25
+ type: 'boolean',
26
+ description: 'Whether to allow type-only imports for a path.',
27
+ },
28
+ };
29
+ const arrayOfStringsOrObjects = {
30
+ type: 'array',
31
+ items: {
32
+ anyOf: [
33
+ { type: 'string' },
34
+ {
35
+ type: 'object',
36
+ additionalProperties: false,
37
+ properties: {
38
+ ...tryAccess(() => baseSchema.anyOf[1].items[0].properties.paths.items.anyOf[1]
39
+ .properties, undefined),
40
+ ...allowTypeImportsOptionSchema,
41
+ },
42
+ required: tryAccess(() => baseSchema.anyOf[1].items[0].properties.paths.items.anyOf[1]
43
+ .required, undefined),
44
+ },
45
+ ],
46
+ },
47
+ uniqueItems: true,
48
+ };
49
+ const arrayOfStringsOrObjectPatterns = {
50
+ anyOf: [
51
+ {
52
+ type: 'array',
53
+ items: {
54
+ type: 'string',
55
+ },
56
+ uniqueItems: true,
57
+ },
58
+ {
59
+ type: 'array',
60
+ items: {
61
+ type: 'object',
62
+ additionalProperties: false,
63
+ properties: {
64
+ ...tryAccess(() => baseSchema.anyOf[1].items[0].properties.patterns.anyOf[1].items
65
+ .properties, undefined),
66
+ ...allowTypeImportsOptionSchema,
67
+ },
68
+ required: tryAccess(() => baseSchema.anyOf[1].items[0].properties.patterns.anyOf[1].items
69
+ .required, []),
70
+ },
71
+ uniqueItems: true,
72
+ },
73
+ ],
74
+ };
75
+ const schema = {
76
+ anyOf: [
77
+ arrayOfStringsOrObjects,
78
+ {
79
+ type: 'array',
80
+ additionalItems: false,
81
+ items: [
82
+ {
83
+ type: 'object',
84
+ additionalProperties: false,
85
+ properties: {
86
+ paths: arrayOfStringsOrObjects,
87
+ patterns: arrayOfStringsOrObjectPatterns,
88
+ },
89
+ },
90
+ ],
91
+ },
92
+ ],
93
+ };
94
+ function isObjectOfPaths(obj) {
95
+ return !!obj && Object.hasOwn(obj, 'paths');
96
+ }
97
+ function isObjectOfPatterns(obj) {
98
+ return !!obj && Object.hasOwn(obj, 'patterns');
99
+ }
100
+ function isOptionsArrayOfStringOrObject(options) {
101
+ if (isObjectOfPaths(options[0])) {
102
+ return false;
103
+ }
104
+ if (isObjectOfPatterns(options[0])) {
105
+ return false;
106
+ }
107
+ return true;
108
+ }
109
+ function getRestrictedPaths(options) {
110
+ if (isOptionsArrayOfStringOrObject(options)) {
111
+ return options;
112
+ }
113
+ if (isObjectOfPaths(options[0])) {
114
+ return options[0].paths;
115
+ }
116
+ return [];
117
+ }
118
+ function getRestrictedPatterns(options) {
119
+ if (isObjectOfPatterns(options[0])) {
120
+ return options[0].patterns;
121
+ }
122
+ return [];
123
+ }
124
+ function shouldCreateRule(baseRules, options) {
125
+ if (Object.keys(baseRules).length === 0 || options.length === 0) {
126
+ return false;
127
+ }
128
+ if (!isOptionsArrayOfStringOrObject(options)) {
129
+ return !!(options[0].paths?.length || options[0].patterns?.length);
130
+ }
131
+ return true;
132
+ }
133
+ exports.default = (0, util_1.createRule)({
134
+ name: 'no-restricted-imports',
135
+ meta: {
136
+ type: 'suggestion',
137
+ // defaultOptions, -- base rule does not use defaultOptions
138
+ docs: {
139
+ description: 'Disallow specified modules when loaded by `import`',
140
+ extendsBaseRule: true,
141
+ },
142
+ fixable: baseRule.meta.fixable,
143
+ messages: baseRule.meta.messages,
144
+ schema,
145
+ },
146
+ defaultOptions: [],
147
+ create(context) {
148
+ const rules = baseRule.create(context);
149
+ const { options } = context;
150
+ if (!shouldCreateRule(rules, options)) {
151
+ return {};
152
+ }
153
+ const restrictedPaths = getRestrictedPaths(options);
154
+ const allowedTypeImportPathNameSet = new Set();
155
+ for (const restrictedPath of restrictedPaths) {
156
+ if (typeof restrictedPath === 'object' &&
157
+ restrictedPath.allowTypeImports) {
158
+ allowedTypeImportPathNameSet.add(restrictedPath.name);
159
+ }
160
+ }
161
+ function isAllowedTypeImportPath(importSource) {
162
+ return allowedTypeImportPathNameSet.has(importSource);
163
+ }
164
+ const restrictedPatterns = getRestrictedPatterns(options);
165
+ const allowedImportTypeMatchers = [];
166
+ const allowedImportTypeRegexMatchers = [];
167
+ for (const restrictedPattern of restrictedPatterns) {
168
+ if (typeof restrictedPattern === 'object' &&
169
+ restrictedPattern.allowTypeImports) {
170
+ // Following how ignore is configured in the base rule
171
+ if (restrictedPattern.group) {
172
+ allowedImportTypeMatchers.push((0, ignore_1.default)({
173
+ allowRelativePaths: true,
174
+ ignoreCase: !restrictedPattern.caseSensitive,
175
+ }).add(restrictedPattern.group));
176
+ }
177
+ if (restrictedPattern.regex) {
178
+ allowedImportTypeRegexMatchers.push(new RegExp(restrictedPattern.regex, restrictedPattern.caseSensitive ? 'u' : 'iu'));
179
+ }
180
+ }
181
+ }
182
+ function isAllowedTypeImportPattern(importSource) {
183
+ return (
184
+ // As long as there's one matching pattern that allows type import
185
+ allowedImportTypeMatchers.some(matcher => matcher.ignores(importSource)) ||
186
+ allowedImportTypeRegexMatchers.some(regex => regex.test(importSource)));
187
+ }
188
+ function checkImportNode(node) {
189
+ if (node.importKind === 'type' ||
190
+ (node.specifiers.length > 0 &&
191
+ node.specifiers.every(specifier => specifier.type === utils_1.AST_NODE_TYPES.ImportSpecifier &&
192
+ specifier.importKind === 'type'))) {
193
+ const importSource = node.source.value.trim();
194
+ if (!isAllowedTypeImportPath(importSource) &&
195
+ !isAllowedTypeImportPattern(importSource)) {
196
+ return rules.ImportDeclaration(node);
197
+ }
198
+ }
199
+ else {
200
+ return rules.ImportDeclaration(node);
201
+ }
202
+ }
203
+ return {
204
+ ExportAllDeclaration: rules.ExportAllDeclaration,
205
+ 'ExportNamedDeclaration[source]'(node) {
206
+ if (node.exportKind === 'type' ||
207
+ (node.specifiers.length > 0 &&
208
+ node.specifiers.every(specifier => specifier.exportKind === 'type'))) {
209
+ const importSource = node.source.value.trim();
210
+ if (!isAllowedTypeImportPath(importSource) &&
211
+ !isAllowedTypeImportPattern(importSource)) {
212
+ return rules.ExportNamedDeclaration(node);
213
+ }
214
+ }
215
+ else {
216
+ return rules.ExportNamedDeclaration(node);
217
+ }
218
+ },
219
+ ImportDeclaration: checkImportNode,
220
+ TSImportEqualsDeclaration(node) {
221
+ if (node.moduleReference.type === utils_1.AST_NODE_TYPES.TSExternalModuleReference) {
222
+ const synthesizedImport = {
223
+ ...node,
224
+ type: utils_1.AST_NODE_TYPES.ImportDeclaration,
225
+ assertions: [],
226
+ attributes: [],
227
+ source: node.moduleReference.expression,
228
+ specifiers: [
229
+ {
230
+ ...node.id,
231
+ type: utils_1.AST_NODE_TYPES.ImportDefaultSpecifier,
232
+ local: node.id,
233
+ // @ts-expect-error -- parent types are incompatible but it's fine for the purposes of this extension
234
+ parent: node.id.parent,
235
+ },
236
+ ],
237
+ };
238
+ return checkImportNode(synthesizedImport);
239
+ }
240
+ },
241
+ };
242
+ },
243
+ });
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-restricted-types.d.ts ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { TSESLint } from '@typescript-eslint/utils';
2
+ type Types = Record<string, boolean | string | {
3
+ fixWith?: string;
4
+ message: string;
5
+ suggest?: readonly string[];
6
+ } | null>;
7
+ export type Options = [
8
+ {
9
+ types?: Types;
10
+ }
11
+ ];
12
+ export type MessageIds = 'bannedTypeMessage' | 'bannedTypeReplacement';
13
+ declare const _default: TSESLint.RuleModule<MessageIds, Options, import("../../rules").ESLintPluginDocs, TSESLint.RuleListener> & {
14
+ name: string;
15
+ };
16
+ export default _default;
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-restricted-types.js ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@typescript-eslint/utils");
4
+ const util_1 = require("../util");
5
+ function removeSpaces(str) {
6
+ return str.replaceAll(/\s/g, '');
7
+ }
8
+ function stringifyNode(node, sourceCode) {
9
+ return removeSpaces(sourceCode.getText(node));
10
+ }
11
+ function getCustomMessage(bannedType) {
12
+ if (!bannedType || bannedType === true) {
13
+ return '';
14
+ }
15
+ if (typeof bannedType === 'string') {
16
+ return ` ${bannedType}`;
17
+ }
18
+ if (bannedType.message) {
19
+ return ` ${bannedType.message}`;
20
+ }
21
+ return '';
22
+ }
23
+ const TYPE_KEYWORDS = {
24
+ bigint: utils_1.AST_NODE_TYPES.TSBigIntKeyword,
25
+ boolean: utils_1.AST_NODE_TYPES.TSBooleanKeyword,
26
+ never: utils_1.AST_NODE_TYPES.TSNeverKeyword,
27
+ null: utils_1.AST_NODE_TYPES.TSNullKeyword,
28
+ number: utils_1.AST_NODE_TYPES.TSNumberKeyword,
29
+ object: utils_1.AST_NODE_TYPES.TSObjectKeyword,
30
+ string: utils_1.AST_NODE_TYPES.TSStringKeyword,
31
+ symbol: utils_1.AST_NODE_TYPES.TSSymbolKeyword,
32
+ undefined: utils_1.AST_NODE_TYPES.TSUndefinedKeyword,
33
+ unknown: utils_1.AST_NODE_TYPES.TSUnknownKeyword,
34
+ void: utils_1.AST_NODE_TYPES.TSVoidKeyword,
35
+ };
36
+ exports.default = (0, util_1.createRule)({
37
+ name: 'no-restricted-types',
38
+ meta: {
39
+ type: 'suggestion',
40
+ docs: {
41
+ description: 'Disallow certain types',
42
+ },
43
+ fixable: 'code',
44
+ hasSuggestions: true,
45
+ messages: {
46
+ bannedTypeMessage: "Don't use `{{name}}` as a type.{{customMessage}}",
47
+ bannedTypeReplacement: 'Replace `{{name}}` with `{{replacement}}`.',
48
+ },
49
+ schema: [
50
+ {
51
+ type: 'object',
52
+ $defs: {
53
+ banConfig: {
54
+ oneOf: [
55
+ {
56
+ type: 'boolean',
57
+ description: 'Bans the type with the default message.',
58
+ enum: [true],
59
+ },
60
+ {
61
+ type: 'string',
62
+ description: 'Bans the type with a custom message.',
63
+ },
64
+ {
65
+ type: 'object',
66
+ additionalProperties: false,
67
+ description: 'Bans a type.',
68
+ properties: {
69
+ fixWith: {
70
+ type: 'string',
71
+ description: 'Type to autofix replace with. Note that autofixers can be applied automatically - so you need to be careful with this option.',
72
+ },
73
+ message: {
74
+ type: 'string',
75
+ description: 'Custom error message.',
76
+ },
77
+ suggest: {
78
+ type: 'array',
79
+ description: 'Types to suggest replacing with.',
80
+ items: { type: 'string' },
81
+ },
82
+ },
83
+ },
84
+ ],
85
+ },
86
+ },
87
+ additionalProperties: false,
88
+ properties: {
89
+ types: {
90
+ type: 'object',
91
+ additionalProperties: {
92
+ $ref: '#/items/0/$defs/banConfig',
93
+ },
94
+ description: 'An object whose keys are the types you want to ban, and the values are error messages.',
95
+ },
96
+ },
97
+ },
98
+ ],
99
+ },
100
+ defaultOptions: [{}],
101
+ create(context, [{ types = {} }]) {
102
+ const bannedTypes = new Map(Object.entries(types).map(([type, data]) => [removeSpaces(type), data]));
103
+ function checkBannedTypes(typeNode, name = stringifyNode(typeNode, context.sourceCode)) {
104
+ const bannedType = bannedTypes.get(name);
105
+ if (bannedType == null || bannedType === false) {
106
+ return;
107
+ }
108
+ const customMessage = getCustomMessage(bannedType);
109
+ const fixWith = bannedType && typeof bannedType === 'object' && bannedType.fixWith;
110
+ const suggest = bannedType && typeof bannedType === 'object'
111
+ ? bannedType.suggest
112
+ : undefined;
113
+ context.report({
114
+ node: typeNode,
115
+ messageId: 'bannedTypeMessage',
116
+ data: {
117
+ name,
118
+ customMessage,
119
+ },
120
+ fix: fixWith
121
+ ? (fixer) => fixer.replaceText(typeNode, fixWith)
122
+ : null,
123
+ suggest: suggest?.map(replacement => ({
124
+ messageId: 'bannedTypeReplacement',
125
+ data: {
126
+ name,
127
+ replacement,
128
+ },
129
+ fix: (fixer) => fixer.replaceText(typeNode, replacement),
130
+ })),
131
+ });
132
+ }
133
+ const keywordSelectors = (0, util_1.objectReduceKey)(TYPE_KEYWORDS, (acc, keyword) => {
134
+ if (bannedTypes.has(keyword)) {
135
+ acc[TYPE_KEYWORDS[keyword]] = (node) => checkBannedTypes(node, keyword);
136
+ }
137
+ return acc;
138
+ }, {});
139
+ return {
140
+ ...keywordSelectors,
141
+ TSClassImplements(node) {
142
+ checkBannedTypes(node.expression);
143
+ if (node.typeArguments) {
144
+ checkBannedTypes(node);
145
+ }
146
+ },
147
+ TSInterfaceHeritage(node) {
148
+ checkBannedTypes(node.expression);
149
+ if (node.typeArguments) {
150
+ checkBannedTypes(node);
151
+ }
152
+ },
153
+ TSTupleType(node) {
154
+ if (!node.elementTypes.length) {
155
+ checkBannedTypes(node);
156
+ }
157
+ },
158
+ TSTypeLiteral(node) {
159
+ if (!node.members.length) {
160
+ checkBannedTypes(node);
161
+ }
162
+ },
163
+ TSTypeReference(node) {
164
+ checkBannedTypes(node.typeName);
165
+ if (node.typeArguments) {
166
+ checkBannedTypes(node);
167
+ }
168
+ },
169
+ };
170
+ },
171
+ });
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-shadow.d.ts ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { TSESLint } from '@typescript-eslint/utils';
2
+ export type MessageIds = 'noShadow' | 'noShadowGlobal';
3
+ export type Options = [
4
+ {
5
+ allow?: string[];
6
+ builtinGlobals?: boolean;
7
+ hoist?: 'all' | 'functions' | 'functions-and-types' | 'never' | 'types';
8
+ ignoreFunctionTypeParameterNameValueShadow?: boolean;
9
+ ignoreOnInitialization?: boolean;
10
+ ignoreTypeValueShadow?: boolean;
11
+ }
12
+ ];
13
+ declare const _default: TSESLint.RuleModule<MessageIds, Options, import("../../rules").ESLintPluginDocs, TSESLint.RuleListener> & {
14
+ name: string;
15
+ };
16
+ export default _default;
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-shadow.js ADDED
@@ -0,0 +1,551 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const scope_manager_1 = require("@typescript-eslint/scope-manager");
4
+ const utils_1 = require("@typescript-eslint/utils");
5
+ const util_1 = require("../util");
6
+ const isTypeImport_1 = require("../util/isTypeImport");
7
+ const allowedFunctionVariableDefTypes = new Set([
8
+ utils_1.AST_NODE_TYPES.TSCallSignatureDeclaration,
9
+ utils_1.AST_NODE_TYPES.TSFunctionType,
10
+ utils_1.AST_NODE_TYPES.TSMethodSignature,
11
+ utils_1.AST_NODE_TYPES.TSEmptyBodyFunctionExpression,
12
+ utils_1.AST_NODE_TYPES.TSDeclareFunction,
13
+ utils_1.AST_NODE_TYPES.TSConstructSignatureDeclaration,
14
+ utils_1.AST_NODE_TYPES.TSConstructorType,
15
+ ]);
16
+ const functionsHoistedNodes = new Set([utils_1.AST_NODE_TYPES.FunctionDeclaration]);
17
+ const typesHoistedNodes = new Set([
18
+ utils_1.AST_NODE_TYPES.TSInterfaceDeclaration,
19
+ utils_1.AST_NODE_TYPES.TSTypeAliasDeclaration,
20
+ ]);
21
+ exports.default = (0, util_1.createRule)({
22
+ name: 'no-shadow',
23
+ meta: {
24
+ type: 'suggestion',
25
+ docs: {
26
+ description: 'Disallow variable declarations from shadowing variables declared in the outer scope',
27
+ extendsBaseRule: true,
28
+ },
29
+ messages: {
30
+ noShadow: "'{{name}}' is already declared in the upper scope on line {{shadowedLine}} column {{shadowedColumn}}.",
31
+ noShadowGlobal: "'{{name}}' is already a global variable.",
32
+ },
33
+ schema: [
34
+ {
35
+ type: 'object',
36
+ additionalProperties: false,
37
+ properties: {
38
+ allow: {
39
+ type: 'array',
40
+ description: 'Identifier names for which shadowing is allowed.',
41
+ items: {
42
+ type: 'string',
43
+ },
44
+ },
45
+ builtinGlobals: {
46
+ type: 'boolean',
47
+ description: 'Whether to report shadowing of built-in global variables.',
48
+ },
49
+ hoist: {
50
+ type: 'string',
51
+ description: 'Whether to report shadowing before outer functions or variables are defined.',
52
+ enum: ['all', 'functions', 'functions-and-types', 'never', 'types'],
53
+ },
54
+ ignoreFunctionTypeParameterNameValueShadow: {
55
+ type: 'boolean',
56
+ description: 'Whether to ignore function parameters named the same as a variable.',
57
+ },
58
+ ignoreOnInitialization: {
59
+ type: 'boolean',
60
+ description: 'Whether to ignore the variable initializers when the shadowed variable is presumably still unitialized.',
61
+ },
62
+ ignoreTypeValueShadow: {
63
+ type: 'boolean',
64
+ description: 'Whether to ignore types named the same as a variable.',
65
+ },
66
+ },
67
+ },
68
+ ],
69
+ },
70
+ defaultOptions: [
71
+ {
72
+ allow: [],
73
+ builtinGlobals: false,
74
+ hoist: 'functions-and-types',
75
+ ignoreFunctionTypeParameterNameValueShadow: true,
76
+ ignoreOnInitialization: false,
77
+ ignoreTypeValueShadow: true,
78
+ },
79
+ ],
80
+ create(context, [options]) {
81
+ /**
82
+ * Check if a scope is a TypeScript module augmenting the global namespace.
83
+ */
84
+ function isGlobalAugmentation(scope) {
85
+ return ((scope.type === scope_manager_1.ScopeType.tsModule && scope.block.kind === 'global') ||
86
+ (!!scope.upper && isGlobalAugmentation(scope.upper)));
87
+ }
88
+ /**
89
+ * Check if variable is a `this` parameter.
90
+ */
91
+ function isThisParam(variable) {
92
+ return (variable.defs[0].type === scope_manager_1.DefinitionType.Parameter &&
93
+ variable.name === 'this');
94
+ }
95
+ function isTypeValueShadow(variable, shadowed) {
96
+ if (options.ignoreTypeValueShadow !== true) {
97
+ return false;
98
+ }
99
+ if (!('isValueVariable' in variable)) {
100
+ // this shouldn't happen...
101
+ return false;
102
+ }
103
+ const firstDefinition = shadowed.defs.at(0);
104
+ const isShadowedValue = !('isValueVariable' in shadowed) ||
105
+ !firstDefinition ||
106
+ (!(0, isTypeImport_1.isTypeImport)(firstDefinition) && shadowed.isValueVariable);
107
+ return variable.isValueVariable !== isShadowedValue;
108
+ }
109
+ function isFunctionTypeParameterNameValueShadow(variable, shadowed) {
110
+ if (options.ignoreFunctionTypeParameterNameValueShadow !== true) {
111
+ return false;
112
+ }
113
+ if (!('isValueVariable' in variable)) {
114
+ // this shouldn't happen...
115
+ return false;
116
+ }
117
+ const isShadowedValue = 'isValueVariable' in shadowed ? shadowed.isValueVariable : true;
118
+ if (!isShadowedValue) {
119
+ return false;
120
+ }
121
+ return variable.defs.every(def => allowedFunctionVariableDefTypes.has(def.node.type));
122
+ }
123
+ function isGenericOfStaticMethod(variable) {
124
+ if (!('isTypeVariable' in variable)) {
125
+ // this shouldn't happen...
126
+ return false;
127
+ }
128
+ if (!variable.isTypeVariable) {
129
+ return false;
130
+ }
131
+ if (variable.identifiers.length === 0) {
132
+ return false;
133
+ }
134
+ const typeParameter = variable.identifiers[0].parent;
135
+ if (typeParameter.type !== utils_1.AST_NODE_TYPES.TSTypeParameter) {
136
+ return false;
137
+ }
138
+ const typeParameterDecl = typeParameter.parent;
139
+ if (typeParameterDecl.type !== utils_1.AST_NODE_TYPES.TSTypeParameterDeclaration) {
140
+ return false;
141
+ }
142
+ const functionExpr = typeParameterDecl.parent;
143
+ if (functionExpr.type !== utils_1.AST_NODE_TYPES.FunctionExpression &&
144
+ functionExpr.type !== utils_1.AST_NODE_TYPES.TSEmptyBodyFunctionExpression) {
145
+ return false;
146
+ }
147
+ const methodDefinition = functionExpr.parent;
148
+ if (methodDefinition.type !== utils_1.AST_NODE_TYPES.MethodDefinition) {
149
+ return false;
150
+ }
151
+ return methodDefinition.static;
152
+ }
153
+ function isGenericOfClass(variable) {
154
+ if (!('isTypeVariable' in variable)) {
155
+ // this shouldn't happen...
156
+ return false;
157
+ }
158
+ if (!variable.isTypeVariable) {
159
+ return false;
160
+ }
161
+ if (variable.identifiers.length === 0) {
162
+ return false;
163
+ }
164
+ const typeParameter = variable.identifiers[0].parent;
165
+ if (typeParameter.type !== utils_1.AST_NODE_TYPES.TSTypeParameter) {
166
+ return false;
167
+ }
168
+ const typeParameterDecl = typeParameter.parent;
169
+ if (typeParameterDecl.type !== utils_1.AST_NODE_TYPES.TSTypeParameterDeclaration) {
170
+ return false;
171
+ }
172
+ const classDecl = typeParameterDecl.parent;
173
+ return (classDecl.type === utils_1.AST_NODE_TYPES.ClassDeclaration ||
174
+ classDecl.type === utils_1.AST_NODE_TYPES.ClassExpression);
175
+ }
176
+ function isGenericOfAStaticMethodShadow(variable, shadowed) {
177
+ return isGenericOfStaticMethod(variable) && isGenericOfClass(shadowed);
178
+ }
179
+ function isImportDeclaration(definition) {
180
+ return definition.type === utils_1.AST_NODE_TYPES.ImportDeclaration;
181
+ }
182
+ function isExternalModuleDeclarationWithName(scope, name) {
183
+ return (scope.type === scope_manager_1.ScopeType.tsModule &&
184
+ scope.block.id.type === utils_1.AST_NODE_TYPES.Literal &&
185
+ scope.block.id.value === name);
186
+ }
187
+ function isExternalDeclarationMerging(scope, variable, shadowed) {
188
+ const [firstDefinition] = shadowed.defs;
189
+ const [secondDefinition] = variable.defs;
190
+ return ((0, isTypeImport_1.isTypeImport)(firstDefinition) &&
191
+ isImportDeclaration(firstDefinition.parent) &&
192
+ isExternalModuleDeclarationWithName(scope, firstDefinition.parent.source.value) &&
193
+ (secondDefinition.node.type === utils_1.AST_NODE_TYPES.TSInterfaceDeclaration ||
194
+ secondDefinition.node.type === utils_1.AST_NODE_TYPES.TSTypeAliasDeclaration));
195
+ }
196
+ /**
197
+ * Check if variable name is allowed.
198
+ * @param variable The variable to check.
199
+ * @returns Whether or not the variable name is allowed.
200
+ */
201
+ function isAllowed(variable) {
202
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
203
+ return options.allow.includes(variable.name);
204
+ }
205
+ /**
206
+ * Checks if a variable of the class name in the class scope of ClassDeclaration.
207
+ *
208
+ * ClassDeclaration creates two variables of its name into its outer scope and its class scope.
209
+ * So we should ignore the variable in the class scope.
210
+ * @param variable The variable to check.
211
+ * @returns Whether or not the variable of the class name in the class scope of ClassDeclaration.
212
+ */
213
+ function isDuplicatedClassNameVariable(variable) {
214
+ const block = variable.scope.block;
215
+ return (block.type === utils_1.AST_NODE_TYPES.ClassDeclaration &&
216
+ block.id === variable.identifiers[0]);
217
+ }
218
+ /**
219
+ * Checks if a variable of the class name in the class scope of TSEnumDeclaration.
220
+ *
221
+ * TSEnumDeclaration creates two variables of its name into its outer scope and its class scope.
222
+ * So we should ignore the variable in the class scope.
223
+ * @param variable The variable to check.
224
+ * @returns Whether or not the variable of the class name in the class scope of TSEnumDeclaration.
225
+ */
226
+ function isDuplicatedEnumNameVariable(variable) {
227
+ const block = variable.scope.block;
228
+ return (block.type === utils_1.AST_NODE_TYPES.TSEnumDeclaration &&
229
+ block.id === variable.identifiers[0]);
230
+ }
231
+ /**
232
+ * Checks whether or not a given location is inside of the range of a given node.
233
+ * @param node An node to check.
234
+ * @param location A location to check.
235
+ * @returns `true` if the location is inside of the range of the node.
236
+ */
237
+ function isInRange(node, location) {
238
+ return node && node.range[0] <= location && location <= node.range[1];
239
+ }
240
+ /**
241
+ * Searches from the current node through its ancestry to find a matching node.
242
+ * @param node a node to get.
243
+ * @param match a callback that checks whether or not the node verifies its condition or not.
244
+ * @returns the matching node.
245
+ */
246
+ function findSelfOrAncestor(node, match) {
247
+ let currentNode = node;
248
+ while (currentNode && !match(currentNode)) {
249
+ currentNode = currentNode.parent;
250
+ }
251
+ return currentNode;
252
+ }
253
+ /**
254
+ * Finds function's outer scope.
255
+ * @param scope Function's own scope.
256
+ * @returns Function's outer scope.
257
+ */
258
+ function getOuterScope(scope) {
259
+ const upper = scope.upper;
260
+ if (upper?.type === scope_manager_1.ScopeType.functionExpressionName) {
261
+ return upper.upper;
262
+ }
263
+ return upper;
264
+ }
265
+ /**
266
+ * Checks if a variable and a shadowedVariable have the same init pattern ancestor.
267
+ * @param variable a variable to check.
268
+ * @param shadowedVariable a shadowedVariable to check.
269
+ * @returns Whether or not the variable and the shadowedVariable have the same init pattern ancestor.
270
+ */
271
+ function isInitPatternNode(variable, shadowedVariable) {
272
+ const outerDef = shadowedVariable.defs.at(0);
273
+ if (!outerDef) {
274
+ return false;
275
+ }
276
+ const { variableScope } = variable.scope;
277
+ if (!((variableScope.block.type ===
278
+ utils_1.AST_NODE_TYPES.ArrowFunctionExpression ||
279
+ variableScope.block.type === utils_1.AST_NODE_TYPES.FunctionExpression) &&
280
+ getOuterScope(variableScope) === shadowedVariable.scope)) {
281
+ return false;
282
+ }
283
+ const fun = variableScope.block;
284
+ const { parent } = fun;
285
+ const callExpression = findSelfOrAncestor(parent, node => node.type === utils_1.AST_NODE_TYPES.CallExpression);
286
+ if (!callExpression) {
287
+ return false;
288
+ }
289
+ let node = outerDef.name;
290
+ const location = callExpression.range[1];
291
+ while (node) {
292
+ if (node.type === utils_1.AST_NODE_TYPES.VariableDeclarator) {
293
+ if (isInRange(node.init, location)) {
294
+ return true;
295
+ }
296
+ if ((node.parent.parent.type === utils_1.AST_NODE_TYPES.ForInStatement ||
297
+ node.parent.parent.type === utils_1.AST_NODE_TYPES.ForOfStatement) &&
298
+ isInRange(node.parent.parent.right, location)) {
299
+ return true;
300
+ }
301
+ break;
302
+ }
303
+ else if (node.type === utils_1.AST_NODE_TYPES.AssignmentPattern) {
304
+ if (isInRange(node.right, location)) {
305
+ return true;
306
+ }
307
+ }
308
+ else if ([
309
+ utils_1.AST_NODE_TYPES.ArrowFunctionExpression,
310
+ utils_1.AST_NODE_TYPES.CatchClause,
311
+ utils_1.AST_NODE_TYPES.ClassDeclaration,
312
+ utils_1.AST_NODE_TYPES.ClassExpression,
313
+ utils_1.AST_NODE_TYPES.ExportNamedDeclaration,
314
+ utils_1.AST_NODE_TYPES.FunctionDeclaration,
315
+ utils_1.AST_NODE_TYPES.FunctionExpression,
316
+ utils_1.AST_NODE_TYPES.ImportDeclaration,
317
+ ].includes(node.type)) {
318
+ break;
319
+ }
320
+ node = node.parent;
321
+ }
322
+ return false;
323
+ }
324
+ /**
325
+ * Finds the uppermost expression node that can evaluate to the given one,
326
+ * unwrapping through LogicalExpression and non-test ConditionalExpression branches.
327
+ * @param node The node to unwrap.
328
+ * @returns The topmost unwrapped node.
329
+ */
330
+ function unwrapExpression(node) {
331
+ const { parent } = node;
332
+ if (parent?.type === utils_1.AST_NODE_TYPES.LogicalExpression ||
333
+ (parent?.type === utils_1.AST_NODE_TYPES.ConditionalExpression &&
334
+ parent.test !== node)) {
335
+ return unwrapExpression(parent);
336
+ }
337
+ return node;
338
+ }
339
+ /**
340
+ * Checks if a variable is the name of a function or class expression that is
341
+ * directly assigned (or transparently through `||`/`?:`) as the initializer
342
+ * of scopeVar.
343
+ *
344
+ * Allows `var a = function a() {}` but reports `var a = wrap(function a() {})`.
345
+ * @param variable The variable to check.
346
+ * @param scopeVar The scope variable to look for.
347
+ * @returns Whether or not the variable is the direct initializer name of scopeVar.
348
+ */
349
+ function isOnInitializer(variable, scopeVar) {
350
+ const outerDef = scopeVar.defs.at(0);
351
+ const innerDef = variable.defs.at(0);
352
+ if (!outerDef || !innerDef) {
353
+ return false;
354
+ }
355
+ if (!((innerDef.type === scope_manager_1.DefinitionType.FunctionName &&
356
+ innerDef.node.type === utils_1.AST_NODE_TYPES.FunctionExpression) ||
357
+ (innerDef.type === scope_manager_1.DefinitionType.ClassName &&
358
+ innerDef.node.type === utils_1.AST_NODE_TYPES.ClassExpression))) {
359
+ return false;
360
+ }
361
+ const outerIdentifier = outerDef.name;
362
+ let initializerNode;
363
+ if (outerIdentifier.parent.type === utils_1.AST_NODE_TYPES.VariableDeclarator) {
364
+ initializerNode = outerIdentifier.parent.init;
365
+ }
366
+ else if (outerIdentifier.parent.type === utils_1.AST_NODE_TYPES.AssignmentPattern) {
367
+ initializerNode = outerIdentifier.parent.right;
368
+ }
369
+ if (!initializerNode) {
370
+ return false;
371
+ }
372
+ const nodeToCheck = innerDef.node;
373
+ if (!(initializerNode.range[0] <= nodeToCheck.range[0] &&
374
+ nodeToCheck.range[1] <= initializerNode.range[1])) {
375
+ return false;
376
+ }
377
+ return initializerNode === unwrapExpression(nodeToCheck);
378
+ }
379
+ /**
380
+ * Get a range of a variable's identifier node.
381
+ * @param variable The variable to get.
382
+ * @returns The range of the variable's identifier node.
383
+ */
384
+ function getNameRange(variable) {
385
+ const def = variable.defs.at(0);
386
+ return def?.name.range;
387
+ }
388
+ /**
389
+ * Checks if a variable is in TDZ of scopeVar.
390
+ * @param variable The variable to check.
391
+ * @param scopeVar The variable of TDZ.
392
+ * @returns Whether or not the variable is in TDZ of scopeVar.
393
+ */
394
+ function isInTdz(variable, scopeVar) {
395
+ const outerDef = scopeVar.defs.at(0);
396
+ const inner = getNameRange(variable);
397
+ const outer = getNameRange(scopeVar);
398
+ if (!inner || !outer || inner[1] >= outer[0]) {
399
+ return false;
400
+ }
401
+ if (!outerDef) {
402
+ return true;
403
+ }
404
+ if (options.hoist === 'functions') {
405
+ return !functionsHoistedNodes.has(outerDef.node.type);
406
+ }
407
+ if (options.hoist === 'types') {
408
+ return !typesHoistedNodes.has(outerDef.node.type);
409
+ }
410
+ if (options.hoist === 'functions-and-types') {
411
+ return (!functionsHoistedNodes.has(outerDef.node.type) &&
412
+ !typesHoistedNodes.has(outerDef.node.type));
413
+ }
414
+ return true;
415
+ }
416
+ /**
417
+ * Get declared line and column of a variable.
418
+ * @param variable The variable to get.
419
+ * @returns The declared line and column of the variable.
420
+ */
421
+ function getDeclaredLocation(variable) {
422
+ const identifier = variable.identifiers.at(0);
423
+ if (identifier) {
424
+ return {
425
+ column: identifier.loc.start.column + 1,
426
+ global: false,
427
+ line: identifier.loc.start.line,
428
+ };
429
+ }
430
+ return {
431
+ global: true,
432
+ };
433
+ }
434
+ /**
435
+ * Checks if the initialization of a variable has the declare modifier in a
436
+ * definition file.
437
+ */
438
+ function isDeclareInDTSFile(variable) {
439
+ const fileName = context.filename;
440
+ if (!(0, util_1.isDefinitionFile)(fileName)) {
441
+ return false;
442
+ }
443
+ return variable.defs.some(def => {
444
+ return ((def.type === scope_manager_1.DefinitionType.Variable && def.parent.declare) ||
445
+ (def.type === scope_manager_1.DefinitionType.ClassName && def.node.declare) ||
446
+ (def.type === scope_manager_1.DefinitionType.TSEnumName && def.node.declare) ||
447
+ (def.type === scope_manager_1.DefinitionType.TSModuleName && def.node.declare));
448
+ });
449
+ }
450
+ /**
451
+ * Checks the current context for shadowed variables.
452
+ * @param scope Fixme
453
+ */
454
+ function checkForShadows(scope) {
455
+ // ignore global augmentation
456
+ if (isGlobalAugmentation(scope)) {
457
+ return;
458
+ }
459
+ const variables = scope.variables;
460
+ for (const variable of variables) {
461
+ // ignore "arguments"
462
+ if (variable.identifiers.length === 0) {
463
+ continue;
464
+ }
465
+ // this params are pseudo-params that cannot be shadowed
466
+ if (isThisParam(variable)) {
467
+ continue;
468
+ }
469
+ // ignore variables of a class name in the class scope of ClassDeclaration
470
+ if (isDuplicatedClassNameVariable(variable)) {
471
+ continue;
472
+ }
473
+ // ignore variables of a class name in the class scope of ClassDeclaration
474
+ if (isDuplicatedEnumNameVariable(variable)) {
475
+ continue;
476
+ }
477
+ // ignore configured allowed names
478
+ if (isAllowed(variable)) {
479
+ continue;
480
+ }
481
+ // ignore variables with the declare keyword in .d.ts files
482
+ if (isDeclareInDTSFile(variable)) {
483
+ continue;
484
+ }
485
+ // Gets shadowed variable.
486
+ const shadowed = scope.upper
487
+ ? utils_1.ASTUtils.findVariable(scope.upper, variable.name)
488
+ : null;
489
+ if (!shadowed) {
490
+ continue;
491
+ }
492
+ // ignore type value variable shadowing if configured
493
+ if (isTypeValueShadow(variable, shadowed)) {
494
+ continue;
495
+ }
496
+ // ignore function type parameter name shadowing if configured
497
+ if (isFunctionTypeParameterNameValueShadow(variable, shadowed)) {
498
+ continue;
499
+ }
500
+ // ignore static class method generic shadowing class generic
501
+ // this is impossible for the scope analyser to understand
502
+ // so we have to handle this manually in this rule
503
+ if (isGenericOfAStaticMethodShadow(variable, shadowed)) {
504
+ continue;
505
+ }
506
+ if (isExternalDeclarationMerging(scope, variable, shadowed)) {
507
+ continue;
508
+ }
509
+ const isESLintGlobal = 'writeable' in shadowed;
510
+ if ((shadowed.identifiers.length > 0 ||
511
+ (options.builtinGlobals && isESLintGlobal)) &&
512
+ !isOnInitializer(variable, shadowed) &&
513
+ !(options.ignoreOnInitialization &&
514
+ isInitPatternNode(variable, shadowed)) &&
515
+ !(options.hoist !== 'all' && isInTdz(variable, shadowed))) {
516
+ const location = getDeclaredLocation(shadowed);
517
+ context.report({
518
+ node: variable.identifiers[0],
519
+ ...(location.global
520
+ ? {
521
+ messageId: 'noShadowGlobal',
522
+ data: {
523
+ name: variable.name,
524
+ },
525
+ }
526
+ : {
527
+ messageId: 'noShadow',
528
+ data: {
529
+ name: variable.name,
530
+ shadowedColumn: location.column,
531
+ shadowedLine: location.line,
532
+ },
533
+ }),
534
+ });
535
+ }
536
+ }
537
+ }
538
+ return {
539
+ 'Program:exit'(node) {
540
+ const globalScope = context.sourceCode.getScope(node);
541
+ const stack = [...globalScope.childScopes];
542
+ while (stack.length) {
543
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
544
+ const scope = stack.pop();
545
+ stack.push(...scope.childScopes);
546
+ checkForShadows(scope);
547
+ }
548
+ },
549
+ };
550
+ },
551
+ });
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-this-alias.d.ts ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export type Options = [
2
+ {
3
+ allowDestructuring?: boolean;
4
+ allowedNames?: string[];
5
+ }
6
+ ];
7
+ export type MessageIds = 'thisAssignment' | 'thisDestructure';
8
+ declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<MessageIds, Options, import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
9
+ name: string;
10
+ };
11
+ export default _default;
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-this-alias.js ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@typescript-eslint/utils");
4
+ const util_1 = require("../util");
5
+ exports.default = (0, util_1.createRule)({
6
+ name: 'no-this-alias',
7
+ meta: {
8
+ type: 'suggestion',
9
+ docs: {
10
+ description: 'Disallow aliasing `this`',
11
+ recommended: 'recommended',
12
+ },
13
+ messages: {
14
+ thisAssignment: "Unexpected aliasing of 'this' to local variable.",
15
+ thisDestructure: "Unexpected aliasing of members of 'this' to local variables.",
16
+ },
17
+ schema: [
18
+ {
19
+ type: 'object',
20
+ additionalProperties: false,
21
+ properties: {
22
+ allowDestructuring: {
23
+ type: 'boolean',
24
+ description: 'Whether to ignore destructurings, such as `const { props, state } = this`.',
25
+ },
26
+ allowedNames: {
27
+ type: 'array',
28
+ description: 'Names to ignore, such as ["self"] for `const self = this;`.',
29
+ items: {
30
+ type: 'string',
31
+ },
32
+ },
33
+ },
34
+ },
35
+ ],
36
+ },
37
+ defaultOptions: [
38
+ {
39
+ allowDestructuring: true,
40
+ allowedNames: [],
41
+ },
42
+ ],
43
+ create(context, [{ allowDestructuring, allowedNames }]) {
44
+ return {
45
+ "VariableDeclarator[init.type='ThisExpression'], AssignmentExpression[right.type='ThisExpression']"(node) {
46
+ const id = node.type === utils_1.AST_NODE_TYPES.VariableDeclarator ? node.id : node.left;
47
+ if (allowDestructuring && id.type !== utils_1.AST_NODE_TYPES.Identifier) {
48
+ return;
49
+ }
50
+ const hasAllowedName = id.type === utils_1.AST_NODE_TYPES.Identifier
51
+ ? // https://github.com/typescript-eslint/typescript-eslint/issues/5439
52
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
53
+ allowedNames.includes(id.name)
54
+ : false;
55
+ if (!hasAllowedName) {
56
+ context.report({
57
+ node: id,
58
+ messageId: id.type === utils_1.AST_NODE_TYPES.Identifier
59
+ ? 'thisAssignment'
60
+ : 'thisDestructure',
61
+ });
62
+ }
63
+ },
64
+ };
65
+ },
66
+ });
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-type-alias.d.ts ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ type Values = 'always' | 'in-intersections' | 'in-unions' | 'in-unions-and-intersections' | 'never';
2
+ export type Options = [
3
+ {
4
+ allowAliases?: Values;
5
+ allowCallbacks?: 'always' | 'never';
6
+ allowConditionalTypes?: 'always' | 'never';
7
+ allowConstructors?: 'always' | 'never';
8
+ allowGenerics?: 'always' | 'never';
9
+ allowLiterals?: Values;
10
+ allowMappedTypes?: Values;
11
+ allowTupleTypes?: Values;
12
+ }
13
+ ];
14
+ export type MessageIds = 'noCompositionAlias' | 'noTypeAlias';
15
+ declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<MessageIds, Options, import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
16
+ name: string;
17
+ };
18
+ export default _default;
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-type-alias.js ADDED
@@ -0,0 +1,268 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@typescript-eslint/utils");
4
+ const util_1 = require("../util");
5
+ exports.default = (0, util_1.createRule)({
6
+ name: 'no-type-alias',
7
+ meta: {
8
+ type: 'suggestion',
9
+ deprecated: {
10
+ deprecatedSince: '6.0.0',
11
+ replacedBy: [
12
+ {
13
+ rule: {
14
+ name: '@typescript-eslint/consistent-type-definitions',
15
+ url: 'https://typescript-eslint.io/rules/consistent-type-definitions',
16
+ },
17
+ },
18
+ ],
19
+ url: 'https://github.com/typescript-eslint/typescript-eslint/pull/6229',
20
+ },
21
+ docs: {
22
+ description: 'Disallow type aliases',
23
+ // too opinionated to be recommended
24
+ },
25
+ messages: {
26
+ noCompositionAlias: '{{typeName}} in {{compositionType}} types are not allowed.',
27
+ noTypeAlias: 'Type {{alias}} are not allowed.',
28
+ },
29
+ schema: [
30
+ {
31
+ type: 'object',
32
+ $defs: {
33
+ expandedOptions: {
34
+ type: 'string',
35
+ enum: [
36
+ 'always',
37
+ 'never',
38
+ 'in-unions',
39
+ 'in-intersections',
40
+ 'in-unions-and-intersections',
41
+ ],
42
+ },
43
+ simpleOptions: {
44
+ type: 'string',
45
+ enum: ['always', 'never'],
46
+ },
47
+ },
48
+ additionalProperties: false,
49
+ properties: {
50
+ allowAliases: {
51
+ $ref: '#/items/0/$defs/expandedOptions',
52
+ description: 'Whether to allow direct one-to-one type aliases.',
53
+ },
54
+ allowCallbacks: {
55
+ $ref: '#/items/0/$defs/simpleOptions',
56
+ description: 'Whether to allow type aliases for callbacks.',
57
+ },
58
+ allowConditionalTypes: {
59
+ $ref: '#/items/0/$defs/simpleOptions',
60
+ description: 'Whether to allow type aliases for conditional types.',
61
+ },
62
+ allowConstructors: {
63
+ $ref: '#/items/0/$defs/simpleOptions',
64
+ description: 'Whether to allow type aliases with constructors.',
65
+ },
66
+ allowGenerics: {
67
+ $ref: '#/items/0/$defs/simpleOptions',
68
+ description: 'Whether to allow type aliases with generic types.',
69
+ },
70
+ allowLiterals: {
71
+ $ref: '#/items/0/$defs/expandedOptions',
72
+ description: 'Whether to allow type aliases with object literal types.',
73
+ },
74
+ allowMappedTypes: {
75
+ $ref: '#/items/0/$defs/expandedOptions',
76
+ description: 'Whether to allow type aliases with mapped types.',
77
+ },
78
+ allowTupleTypes: {
79
+ $ref: '#/items/0/$defs/expandedOptions',
80
+ description: 'Whether to allow type aliases with tuple types.',
81
+ },
82
+ },
83
+ },
84
+ ],
85
+ },
86
+ defaultOptions: [
87
+ {
88
+ allowAliases: 'never',
89
+ allowCallbacks: 'never',
90
+ allowConditionalTypes: 'never',
91
+ allowConstructors: 'never',
92
+ allowGenerics: 'never',
93
+ allowLiterals: 'never',
94
+ allowMappedTypes: 'never',
95
+ allowTupleTypes: 'never',
96
+ },
97
+ ],
98
+ create(context, [{ allowAliases, allowCallbacks, allowConditionalTypes, allowConstructors, allowGenerics, allowLiterals, allowMappedTypes, allowTupleTypes, },]) {
99
+ const unions = ['always', 'in-unions', 'in-unions-and-intersections'];
100
+ const intersections = [
101
+ 'always',
102
+ 'in-intersections',
103
+ 'in-unions-and-intersections',
104
+ ];
105
+ const compositions = [
106
+ 'in-unions',
107
+ 'in-intersections',
108
+ 'in-unions-and-intersections',
109
+ ];
110
+ const aliasTypes = new Set([
111
+ utils_1.AST_NODE_TYPES.TSArrayType,
112
+ utils_1.AST_NODE_TYPES.TSImportType,
113
+ utils_1.AST_NODE_TYPES.TSIndexedAccessType,
114
+ utils_1.AST_NODE_TYPES.TSLiteralType,
115
+ utils_1.AST_NODE_TYPES.TSTemplateLiteralType,
116
+ utils_1.AST_NODE_TYPES.TSTypeQuery,
117
+ utils_1.AST_NODE_TYPES.TSTypeReference,
118
+ ]);
119
+ /**
120
+ * Determines if the composition type is supported by the allowed flags.
121
+ * @param isTopLevel a flag indicating this is the top level node.
122
+ * @param compositionType the composition type (either TSUnionType or TSIntersectionType)
123
+ * @param allowed the currently allowed flags.
124
+ */
125
+ function isSupportedComposition(isTopLevel, compositionType, allowed) {
126
+ return (!compositions.includes(allowed) ||
127
+ (!isTopLevel &&
128
+ ((compositionType === utils_1.AST_NODE_TYPES.TSUnionType &&
129
+ unions.includes(allowed)) ||
130
+ (compositionType === utils_1.AST_NODE_TYPES.TSIntersectionType &&
131
+ intersections.includes(allowed)))));
132
+ }
133
+ /**
134
+ * Gets the message to be displayed based on the node type and whether the node is a top level declaration.
135
+ * @param node the location
136
+ * @param compositionType the type of composition this alias is part of (undefined if not
137
+ * part of a composition)
138
+ * @param isRoot a flag indicating we are dealing with the top level declaration.
139
+ * @param type the kind of type alias being validated.
140
+ */
141
+ function reportError(node, compositionType, isRoot, type) {
142
+ if (isRoot) {
143
+ return context.report({
144
+ node,
145
+ messageId: 'noTypeAlias',
146
+ data: {
147
+ alias: type.toLowerCase(),
148
+ },
149
+ });
150
+ }
151
+ return context.report({
152
+ node,
153
+ messageId: 'noCompositionAlias',
154
+ data: {
155
+ compositionType: compositionType === utils_1.AST_NODE_TYPES.TSUnionType
156
+ ? 'union'
157
+ : 'intersection',
158
+ typeName: type,
159
+ },
160
+ });
161
+ }
162
+ const isValidTupleType = (type) => {
163
+ if (type.node.type === utils_1.AST_NODE_TYPES.TSTupleType) {
164
+ return true;
165
+ }
166
+ if (type.node.type === utils_1.AST_NODE_TYPES.TSTypeOperator &&
167
+ ['keyof', 'readonly'].includes(type.node.operator) &&
168
+ type.node.typeAnnotation?.type === utils_1.AST_NODE_TYPES.TSTupleType) {
169
+ return true;
170
+ }
171
+ return false;
172
+ };
173
+ const isValidGeneric = (type) => {
174
+ return (type.node.type === utils_1.AST_NODE_TYPES.TSTypeReference &&
175
+ type.node.typeArguments != null);
176
+ };
177
+ const checkAndReport = (optionValue, isTopLevel, type, label) => {
178
+ if (optionValue === 'never' ||
179
+ !isSupportedComposition(isTopLevel, type.compositionType, optionValue)) {
180
+ reportError(type.node, type.compositionType, isTopLevel, label);
181
+ }
182
+ };
183
+ /**
184
+ * Validates the node looking for aliases, callbacks and literals.
185
+ * @param type the type of composition this alias is part of (null if not
186
+ * part of a composition)
187
+ * @param isTopLevel a flag indicating this is the top level node.
188
+ */
189
+ function validateTypeAliases(type, isTopLevel = false) {
190
+ // https://github.com/typescript-eslint/typescript-eslint/issues/5439
191
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
192
+ if (type.node.type === utils_1.AST_NODE_TYPES.TSFunctionType) {
193
+ // callback
194
+ if (allowCallbacks === 'never') {
195
+ reportError(type.node, type.compositionType, isTopLevel, 'Callbacks');
196
+ }
197
+ }
198
+ else if (type.node.type === utils_1.AST_NODE_TYPES.TSConditionalType) {
199
+ // conditional type
200
+ if (allowConditionalTypes === 'never') {
201
+ reportError(type.node, type.compositionType, isTopLevel, 'Conditional types');
202
+ }
203
+ }
204
+ else if (type.node.type === utils_1.AST_NODE_TYPES.TSConstructorType) {
205
+ if (allowConstructors === 'never') {
206
+ reportError(type.node, type.compositionType, isTopLevel, 'Constructors');
207
+ }
208
+ }
209
+ else if (type.node.type === utils_1.AST_NODE_TYPES.TSTypeLiteral) {
210
+ // literal object type
211
+ checkAndReport(allowLiterals, isTopLevel, type, 'Literals');
212
+ }
213
+ else if (type.node.type === utils_1.AST_NODE_TYPES.TSMappedType) {
214
+ // mapped type
215
+ checkAndReport(allowMappedTypes, isTopLevel, type, 'Mapped types');
216
+ }
217
+ else if (isValidTupleType(type)) {
218
+ // tuple types
219
+ checkAndReport(allowTupleTypes, isTopLevel, type, 'Tuple Types');
220
+ }
221
+ else if (isValidGeneric(type)) {
222
+ if (allowGenerics === 'never') {
223
+ reportError(type.node, type.compositionType, isTopLevel, 'Generics');
224
+ }
225
+ }
226
+ else if (type.node.type.endsWith(utils_1.AST_TOKEN_TYPES.Keyword) ||
227
+ aliasTypes.has(type.node.type) ||
228
+ (type.node.type === utils_1.AST_NODE_TYPES.TSTypeOperator &&
229
+ (type.node.operator === 'keyof' ||
230
+ (type.node.operator === 'readonly' &&
231
+ type.node.typeAnnotation &&
232
+ aliasTypes.has(type.node.typeAnnotation.type))))) {
233
+ // alias / keyword
234
+ checkAndReport(allowAliases, isTopLevel, type, 'Aliases');
235
+ }
236
+ else {
237
+ // unhandled type - shouldn't happen
238
+ reportError(type.node, type.compositionType, isTopLevel, 'Unhandled');
239
+ }
240
+ /* eslint-enable @typescript-eslint/no-non-null-assertion */
241
+ }
242
+ /**
243
+ * Flatten the given type into an array of its dependencies
244
+ */
245
+ function getTypes(node, compositionType = null) {
246
+ if (node.type === utils_1.AST_NODE_TYPES.TSUnionType ||
247
+ node.type === utils_1.AST_NODE_TYPES.TSIntersectionType) {
248
+ return node.types.flatMap(type => getTypes(type, node.type));
249
+ }
250
+ return [{ node, compositionType }];
251
+ }
252
+ return {
253
+ TSTypeAliasDeclaration(node) {
254
+ const types = getTypes(node.typeAnnotation);
255
+ if (types.length === 1) {
256
+ // is a top level type annotation
257
+ validateTypeAliases(types[0], true);
258
+ }
259
+ else {
260
+ // is a composition type
261
+ types.forEach(type => {
262
+ validateTypeAliases(type);
263
+ });
264
+ }
265
+ },
266
+ };
267
+ },
268
+ });
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-unnecessary-boolean-literal-compare.d.ts ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export type MessageIds = 'comparingNullableToFalse' | 'comparingNullableToTrueDirect' | 'comparingNullableToTrueNegated' | 'direct' | 'negated' | 'noStrictNullCheck';
2
+ export type Options = [
3
+ {
4
+ allowComparingNullableBooleansToFalse?: boolean;
5
+ allowComparingNullableBooleansToTrue?: boolean;
6
+ allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing?: boolean;
7
+ }
8
+ ];
9
+ declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<MessageIds, Options, import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
10
+ name: string;
11
+ };
12
+ export default _default;
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-unnecessary-boolean-literal-compare.js ADDED
@@ -0,0 +1,263 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const utils_1 = require("@typescript-eslint/utils");
37
+ const tsutils = __importStar(require("ts-api-utils"));
38
+ const ts = __importStar(require("typescript"));
39
+ const util_1 = require("../util");
40
+ exports.default = (0, util_1.createRule)({
41
+ name: 'no-unnecessary-boolean-literal-compare',
42
+ meta: {
43
+ type: 'suggestion',
44
+ docs: {
45
+ description: 'Disallow unnecessary equality comparisons against boolean literals',
46
+ recommended: 'strict',
47
+ requiresTypeChecking: true,
48
+ },
49
+ fixable: 'code',
50
+ messages: {
51
+ comparingNullableToFalse: 'This expression unnecessarily compares a nullable boolean value to false instead of using the ?? operator to provide a default.',
52
+ comparingNullableToTrueDirect: 'This expression unnecessarily compares a nullable boolean value to true instead of using it directly.',
53
+ comparingNullableToTrueNegated: 'This expression unnecessarily compares a nullable boolean value to true instead of negating it.',
54
+ direct: 'This expression unnecessarily compares a boolean value to a boolean instead of using it directly.',
55
+ negated: 'This expression unnecessarily compares a boolean value to a boolean instead of negating it.',
56
+ noStrictNullCheck: 'This rule requires the `strictNullChecks` compiler option to be turned on to function correctly.',
57
+ },
58
+ schema: [
59
+ {
60
+ type: 'object',
61
+ additionalProperties: false,
62
+ properties: {
63
+ allowComparingNullableBooleansToFalse: {
64
+ type: 'boolean',
65
+ description: 'Whether to allow comparisons between nullable boolean variables and `false`.',
66
+ },
67
+ allowComparingNullableBooleansToTrue: {
68
+ type: 'boolean',
69
+ description: 'Whether to allow comparisons between nullable boolean variables and `true`.',
70
+ },
71
+ allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing: {
72
+ type: 'boolean',
73
+ description: 'Unless this is set to `true`, the rule will error on every file whose `tsconfig.json` does _not_ have the `strictNullChecks` compiler option (or `strict`) set to `true`.',
74
+ },
75
+ },
76
+ },
77
+ ],
78
+ },
79
+ defaultOptions: [
80
+ {
81
+ allowComparingNullableBooleansToFalse: true,
82
+ allowComparingNullableBooleansToTrue: true,
83
+ allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing: false,
84
+ },
85
+ ],
86
+ create(context, [options]) {
87
+ const services = (0, util_1.getParserServices)(context);
88
+ const checker = services.program.getTypeChecker();
89
+ const compilerOptions = services.program.getCompilerOptions();
90
+ const isStrictNullChecks = tsutils.isStrictCompilerOptionEnabled(compilerOptions, 'strictNullChecks');
91
+ if (!isStrictNullChecks &&
92
+ options.allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing !== true) {
93
+ context.report({
94
+ loc: {
95
+ start: { column: 0, line: 0 },
96
+ end: { column: 0, line: 0 },
97
+ },
98
+ messageId: 'noStrictNullCheck',
99
+ });
100
+ }
101
+ function getBooleanComparison(node) {
102
+ const comparison = deconstructComparison(node);
103
+ if (!comparison) {
104
+ return undefined;
105
+ }
106
+ const { constraintType, isTypeParameter } = (0, util_1.getConstraintInfo)(checker, services.getTypeAtLocation(comparison.expression));
107
+ if (isTypeParameter && constraintType == null) {
108
+ return undefined;
109
+ }
110
+ if (isBooleanType(constraintType)) {
111
+ return {
112
+ ...comparison,
113
+ expressionIsNullableBoolean: false,
114
+ };
115
+ }
116
+ if (isNullableBoolean(constraintType)) {
117
+ return {
118
+ ...comparison,
119
+ expressionIsNullableBoolean: true,
120
+ };
121
+ }
122
+ return undefined;
123
+ }
124
+ function isBooleanType(expressionType) {
125
+ return tsutils.isTypeFlagSet(expressionType, ts.TypeFlags.Boolean | ts.TypeFlags.BooleanLiteral);
126
+ }
127
+ /**
128
+ * checks if the expressionType is a union that
129
+ * 1) contains at least one nullish type (null or undefined)
130
+ * 2) contains at least once boolean type (true or false or boolean)
131
+ * 3) does not contain any types besides nullish and boolean types
132
+ */
133
+ function isNullableBoolean(expressionType) {
134
+ if (!expressionType.isUnion()) {
135
+ return false;
136
+ }
137
+ const { types } = expressionType;
138
+ const nonNullishTypes = types.filter(type => !tsutils.isTypeFlagSet(type, ts.TypeFlags.Undefined | ts.TypeFlags.Null));
139
+ const hasNonNullishType = nonNullishTypes.length > 0;
140
+ if (!hasNonNullishType) {
141
+ return false;
142
+ }
143
+ const hasNullableType = nonNullishTypes.length < types.length;
144
+ if (!hasNullableType) {
145
+ return false;
146
+ }
147
+ const allNonNullishTypesAreBoolean = nonNullishTypes.every(isBooleanType);
148
+ if (!allNonNullishTypesAreBoolean) {
149
+ return false;
150
+ }
151
+ return true;
152
+ }
153
+ function deconstructComparison(node) {
154
+ const comparisonType = getEqualsKind(node.operator);
155
+ if (!comparisonType) {
156
+ return undefined;
157
+ }
158
+ for (const [against, expression] of [
159
+ [node.right, node.left],
160
+ [node.left, node.right],
161
+ ]) {
162
+ if (against.type !== utils_1.AST_NODE_TYPES.Literal ||
163
+ typeof against.value !== 'boolean') {
164
+ continue;
165
+ }
166
+ const { value: literalBooleanInComparison } = against;
167
+ const negated = !comparisonType.isPositive;
168
+ return {
169
+ expression,
170
+ literalBooleanInComparison,
171
+ negated,
172
+ };
173
+ }
174
+ return undefined;
175
+ }
176
+ function nodeIsUnaryNegation(node) {
177
+ return (node.type === utils_1.AST_NODE_TYPES.UnaryExpression &&
178
+ node.prefix &&
179
+ node.operator === '!');
180
+ }
181
+ return {
182
+ BinaryExpression(node) {
183
+ const comparison = getBooleanComparison(node);
184
+ if (comparison == null) {
185
+ return;
186
+ }
187
+ if (comparison.expressionIsNullableBoolean) {
188
+ if (comparison.literalBooleanInComparison &&
189
+ options.allowComparingNullableBooleansToTrue) {
190
+ return;
191
+ }
192
+ if (!comparison.literalBooleanInComparison &&
193
+ options.allowComparingNullableBooleansToFalse) {
194
+ return;
195
+ }
196
+ }
197
+ context.report({
198
+ node,
199
+ messageId: comparison.expressionIsNullableBoolean
200
+ ? comparison.literalBooleanInComparison
201
+ ? comparison.negated
202
+ ? 'comparingNullableToTrueNegated'
203
+ : 'comparingNullableToTrueDirect'
204
+ : 'comparingNullableToFalse'
205
+ : comparison.negated
206
+ ? 'negated'
207
+ : 'direct',
208
+ *fix(fixer) {
209
+ // 1. isUnaryNegation - parent negation
210
+ // 2. literalBooleanInComparison - is compared to literal boolean
211
+ // 3. negated - is expression negated
212
+ const isUnaryNegation = nodeIsUnaryNegation(node.parent);
213
+ const shouldNegate = comparison.negated !== comparison.literalBooleanInComparison;
214
+ const mutatedNode = isUnaryNegation ? node.parent : node;
215
+ yield fixer.replaceText(mutatedNode, context.sourceCode.getText(comparison.expression));
216
+ // if `isUnaryNegation === literalBooleanInComparison === !negated` is true - negate the expression
217
+ if (shouldNegate === isUnaryNegation) {
218
+ yield fixer.insertTextBefore(mutatedNode, '!');
219
+ // if the expression `exp` is not a strong precedence node, wrap it in parentheses
220
+ if (!(0, util_1.isStrongPrecedenceNode)(comparison.expression)) {
221
+ yield fixer.insertTextBefore(mutatedNode, '(');
222
+ yield fixer.insertTextAfter(mutatedNode, ')');
223
+ }
224
+ }
225
+ // if the expression `exp` is nullable, and we're not comparing to `true`, insert `?? true`
226
+ if (comparison.expressionIsNullableBoolean &&
227
+ !comparison.literalBooleanInComparison) {
228
+ // provide the default `true`
229
+ yield fixer.insertTextBefore(mutatedNode, '(');
230
+ yield fixer.insertTextAfter(mutatedNode, ' ?? true)');
231
+ }
232
+ },
233
+ });
234
+ },
235
+ };
236
+ },
237
+ });
238
+ function getEqualsKind(operator) {
239
+ switch (operator) {
240
+ case '!=':
241
+ return {
242
+ isPositive: false,
243
+ isStrict: false,
244
+ };
245
+ case '!==':
246
+ return {
247
+ isPositive: false,
248
+ isStrict: true,
249
+ };
250
+ case '==':
251
+ return {
252
+ isPositive: true,
253
+ isStrict: false,
254
+ };
255
+ case '===':
256
+ return {
257
+ isPositive: true,
258
+ isStrict: true,
259
+ };
260
+ default:
261
+ return undefined;
262
+ }
263
+ }
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-unnecessary-condition.d.ts ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ type LegacyAllowConstantLoopConditions = boolean;
2
+ type AllowConstantLoopConditions = 'always' | 'never' | 'only-allowed-literals';
3
+ export type Options = [
4
+ {
5
+ allowConstantLoopConditions?: AllowConstantLoopConditions | LegacyAllowConstantLoopConditions;
6
+ allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing?: boolean;
7
+ checkTypePredicates?: boolean;
8
+ }
9
+ ];
10
+ export type MessageId = 'alwaysFalsy' | 'alwaysFalsyFunc' | 'alwaysNullish' | 'alwaysTruthy' | 'alwaysTruthyFunc' | 'comparisonBetweenLiteralTypes' | 'never' | 'neverNullish' | 'neverOptionalChain' | 'noOverlapBooleanExpression' | 'noStrictNullCheck' | 'suggestRemoveOptionalChain' | 'typeGuardAlreadyIsType';
11
+ declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<MessageId, Options, import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
12
+ name: string;
13
+ };
14
+ export default _default;
tools/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-unnecessary-condition.js ADDED
@@ -0,0 +1,689 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const utils_1 = require("@typescript-eslint/utils");
37
+ const tsutils = __importStar(require("ts-api-utils"));
38
+ const ts = __importStar(require("typescript"));
39
+ const util_1 = require("../util");
40
+ const assertionFunctionUtils_1 = require("../util/assertionFunctionUtils");
41
+ // #region
42
+ const nullishFlag = ts.TypeFlags.Undefined | ts.TypeFlags.Null;
43
+ function isNullishType(type) {
44
+ return tsutils.isTypeFlagSet(type, nullishFlag);
45
+ }
46
+ function isAlwaysNullish(type) {
47
+ return tsutils.unionConstituents(type).every(isNullishType);
48
+ }
49
+ /**
50
+ * Note that this differs from {@link isNullableType} in that it doesn't consider
51
+ * `any` or `unknown` to be nullable.
52
+ */
53
+ function isPossiblyNullish(type) {
54
+ return tsutils
55
+ .unionConstituents(type)
56
+ .some(t => isNullishType(t) || (0, util_1.isTypeFlagSet)(t, ts.TypeFlags.Void));
57
+ }
58
+ function toStaticValue(type) {
59
+ // type.isLiteral() only covers numbers/bigints and strings, hence the rest of the branches.
60
+ if (tsutils.isBooleanLiteralType(type)) {
61
+ return { value: tsutils.isTrueLiteralType(type) };
62
+ }
63
+ if (type.flags === ts.TypeFlags.Undefined) {
64
+ return { value: undefined };
65
+ }
66
+ if (type.flags === ts.TypeFlags.Null) {
67
+ return { value: null };
68
+ }
69
+ if (type.isLiteral()) {
70
+ return { value: (0, util_1.getValueOfLiteralType)(type) };
71
+ }
72
+ return undefined;
73
+ }
74
+ const BOOL_OPERATORS = new Set([
75
+ '<',
76
+ '>',
77
+ '<=',
78
+ '>=',
79
+ '==',
80
+ '===',
81
+ '!=',
82
+ '!==',
83
+ ]);
84
+ function isBoolOperator(operator) {
85
+ return BOOL_OPERATORS.has(operator);
86
+ }
87
+ function booleanComparison(left, operator, right) {
88
+ switch (operator) {
89
+ case '!=':
90
+ // eslint-disable-next-line eqeqeq -- intentionally comparing with loose equality
91
+ return left != right;
92
+ case '!==':
93
+ return left !== right;
94
+ case '<':
95
+ // @ts-expect-error: we don't care if the comparison seems unintentional.
96
+ return left < right;
97
+ case '<=':
98
+ // @ts-expect-error: we don't care if the comparison seems unintentional.
99
+ return left <= right;
100
+ case '==':
101
+ // eslint-disable-next-line eqeqeq -- intentionally comparing with loose equality
102
+ return left == right;
103
+ case '===':
104
+ return left === right;
105
+ case '>':
106
+ // @ts-expect-error: we don't care if the comparison seems unintentional.
107
+ return left > right;
108
+ case '>=':
109
+ // @ts-expect-error: we don't care if the comparison seems unintentional.
110
+ return left >= right;
111
+ }
112
+ }
113
+ const constantLoopConditionsAllowedLiterals = new Set([
114
+ true,
115
+ false,
116
+ 1,
117
+ 0,
118
+ ]);
119
+ exports.default = (0, util_1.createRule)({
120
+ name: 'no-unnecessary-condition',
121
+ meta: {
122
+ type: 'suggestion',
123
+ docs: {
124
+ description: 'Disallow conditionals where the type is always truthy or always falsy',
125
+ recommended: 'strict',
126
+ requiresTypeChecking: true,
127
+ },
128
+ hasSuggestions: true,
129
+ messages: {
130
+ alwaysFalsy: 'Unnecessary conditional, value is always falsy.',
131
+ alwaysFalsyFunc: 'This callback should return a conditional, but return is always falsy.',
132
+ alwaysNullish: 'Unnecessary conditional, left-hand side of `??` operator is always `null` or `undefined`.',
133
+ alwaysTruthy: 'Unnecessary conditional, value is always truthy.',
134
+ alwaysTruthyFunc: 'This callback should return a conditional, but return is always truthy.',
135
+ comparisonBetweenLiteralTypes: 'Unnecessary conditional, comparison is always {{trueOrFalse}}, since `{{left}} {{operator}} {{right}}` is {{trueOrFalse}}.',
136
+ never: 'Unnecessary conditional, value is `never`.',
137
+ neverNullish: 'Unnecessary conditional, expected left-hand side of `??` operator to be possibly null or undefined.',
138
+ neverOptionalChain: 'Unnecessary optional chain on a non-nullish value.',
139
+ noOverlapBooleanExpression: 'Unnecessary conditional, the types have no overlap.',
140
+ noStrictNullCheck: 'This rule requires the `strictNullChecks` compiler option to be turned on to function correctly.',
141
+ suggestRemoveOptionalChain: 'Remove unnecessary optional chain',
142
+ typeGuardAlreadyIsType: 'Unnecessary conditional, expression already has the type being checked by the {{typeGuardOrAssertionFunction}}.',
143
+ },
144
+ schema: [
145
+ {
146
+ type: 'object',
147
+ additionalProperties: false,
148
+ properties: {
149
+ allowConstantLoopConditions: {
150
+ description: 'Whether to ignore constant loop conditions, such as `while (true)`.',
151
+ oneOf: [
152
+ {
153
+ type: 'boolean',
154
+ description: 'Always ignore or not ignore the loop conditions',
155
+ },
156
+ {
157
+ type: 'string',
158
+ description: 'Which situations to ignore constant conditions in.',
159
+ enum: ['always', 'never', 'only-allowed-literals'],
160
+ },
161
+ ],
162
+ },
163
+ allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing: {
164
+ type: 'boolean',
165
+ description: 'Whether to not error when running with a tsconfig that has strictNullChecks turned.',
166
+ },
167
+ checkTypePredicates: {
168
+ type: 'boolean',
169
+ description: 'Whether to check the asserted argument of a type predicate function for unnecessary conditions',
170
+ },
171
+ },
172
+ },
173
+ ],
174
+ },
175
+ defaultOptions: [
176
+ {
177
+ allowConstantLoopConditions: 'never',
178
+ allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing: false,
179
+ checkTypePredicates: false,
180
+ },
181
+ ],
182
+ create(context, [{ allowConstantLoopConditions, allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing, checkTypePredicates, },]) {
183
+ const services = (0, util_1.getParserServices)(context);
184
+ const checker = services.program.getTypeChecker();
185
+ const compilerOptions = services.program.getCompilerOptions();
186
+ const isStrictNullChecks = tsutils.isStrictCompilerOptionEnabled(compilerOptions, 'strictNullChecks');
187
+ const isNoUncheckedIndexedAccess = tsutils.isCompilerOptionEnabled(compilerOptions, 'noUncheckedIndexedAccess');
188
+ const allowConstantLoopConditionsOption = normalizeAllowConstantLoopConditions(
189
+ // https://github.com/typescript-eslint/typescript-eslint/issues/5439
190
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
191
+ allowConstantLoopConditions);
192
+ if (!isStrictNullChecks &&
193
+ allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing !== true) {
194
+ context.report({
195
+ loc: {
196
+ start: { column: 0, line: 0 },
197
+ end: { column: 0, line: 0 },
198
+ },
199
+ messageId: 'noStrictNullCheck',
200
+ });
201
+ }
202
+ function nodeIsArrayType(node) {
203
+ const nodeType = (0, util_1.getConstrainedTypeAtLocation)(services, node);
204
+ return tsutils
205
+ .unionConstituents(nodeType)
206
+ .some(part => checker.isArrayType(part));
207
+ }
208
+ function nodeIsTupleType(node) {
209
+ const nodeType = (0, util_1.getConstrainedTypeAtLocation)(services, node);
210
+ return tsutils
211
+ .unionConstituents(nodeType)
212
+ .some(part => checker.isTupleType(part));
213
+ }
214
+ function isArrayIndexExpression(node) {
215
+ return (
216
+ // Is an index signature
217
+ node.type === utils_1.AST_NODE_TYPES.MemberExpression &&
218
+ node.computed &&
219
+ // ...into an array type
220
+ (nodeIsArrayType(node.object) ||
221
+ // ... or a tuple type
222
+ (nodeIsTupleType(node.object) &&
223
+ // Exception: literal index into a tuple - will have a sound type
224
+ node.property.type !== utils_1.AST_NODE_TYPES.Literal)));
225
+ }
226
+ // Conditional is always necessary if it involves:
227
+ // `any` or `unknown` or a naked type variable
228
+ function isConditionalAlwaysNecessary(type) {
229
+ return tsutils
230
+ .unionConstituents(type)
231
+ .some(part => (0, util_1.isTypeAnyType)(part) ||
232
+ (0, util_1.isTypeUnknownType)(part) ||
233
+ (0, util_1.isTypeFlagSet)(part, ts.TypeFlags.TypeVariable));
234
+ }
235
+ function isNullableMemberExpression(node) {
236
+ const objectType = services.getTypeAtLocation(node.object);
237
+ if (node.computed) {
238
+ const propertyType = services.getTypeAtLocation(node.property);
239
+ return isNullablePropertyType(objectType, propertyType);
240
+ }
241
+ const property = node.property;
242
+ // Get the actual property name, to account for private properties (this.#prop).
243
+ const propertyName = context.sourceCode.getText(property);
244
+ const propertyType = objectType
245
+ .getProperties()
246
+ .find(prop => prop.name === propertyName);
247
+ if (propertyType &&
248
+ tsutils.isSymbolFlagSet(propertyType, ts.SymbolFlags.Optional)) {
249
+ return true;
250
+ }
251
+ return false;
252
+ }
253
+ /**
254
+ * Checks if a conditional node is necessary:
255
+ * if the type of the node is always true or always false, it's not necessary.
256
+ */
257
+ function checkNode(expression, isUnaryNotArgument = false, node = expression) {
258
+ // Check if the node is Unary Negation expression and handle it
259
+ if (expression.type === utils_1.AST_NODE_TYPES.UnaryExpression &&
260
+ expression.operator === '!') {
261
+ return checkNode(expression.argument, !isUnaryNotArgument, node);
262
+ }
263
+ // Since typescript array index signature types don't represent the
264
+ // possibility of out-of-bounds access, if we're indexing into an array
265
+ // just skip the check, to avoid false positives
266
+ if (!isNoUncheckedIndexedAccess && isArrayIndexExpression(expression)) {
267
+ return;
268
+ }
269
+ // When checking logical expressions, only check the right side
270
+ // as the left side has been checked by checkLogicalExpressionForUnnecessaryConditionals
271
+ //
272
+ // Unless the node is nullish coalescing, as it's common to use patterns like `nullBool ?? true` to to strict
273
+ // boolean checks if we inspect the right here, it'll usually be a constant condition on purpose.
274
+ // In this case it's better to inspect the type of the expression as a whole.
275
+ if (expression.type === utils_1.AST_NODE_TYPES.LogicalExpression &&
276
+ expression.operator !== '??') {
277
+ return checkNode(expression.right);
278
+ }
279
+ const type = (0, util_1.getConstrainedTypeAtLocation)(services, expression);
280
+ if (isConditionalAlwaysNecessary(type)) {
281
+ return;
282
+ }
283
+ let messageId = null;
284
+ if ((0, util_1.isTypeFlagSet)(type, ts.TypeFlags.Never)) {
285
+ messageId = 'never';
286
+ }
287
+ else if (!(0, util_1.isPossiblyTruthy)(type)) {
288
+ messageId = !isUnaryNotArgument ? 'alwaysFalsy' : 'alwaysTruthy';
289
+ }
290
+ else if (!(0, util_1.isPossiblyFalsy)(type)) {
291
+ messageId = !isUnaryNotArgument ? 'alwaysTruthy' : 'alwaysFalsy';
292
+ }
293
+ if (messageId) {
294
+ context.report({ node, messageId });
295
+ }
296
+ }
297
+ function checkNodeForNullish(node) {
298
+ const type = (0, util_1.getConstrainedTypeAtLocation)(services, node);
299
+ // Conditional is always necessary if it involves `any`, `unknown` or a naked type parameter
300
+ if ((0, util_1.isTypeFlagSet)(type, ts.TypeFlags.Any |
301
+ ts.TypeFlags.Unknown |
302
+ ts.TypeFlags.TypeParameter |
303
+ ts.TypeFlags.TypeVariable)) {
304
+ return;
305
+ }
306
+ let messageId = null;
307
+ if ((0, util_1.isTypeFlagSet)(type, ts.TypeFlags.Never)) {
308
+ messageId = 'never';
309
+ }
310
+ else if (!isPossiblyNullish(type) &&
311
+ !(node.type === utils_1.AST_NODE_TYPES.MemberExpression &&
312
+ isNullableMemberExpression(node))) {
313
+ // Since typescript array index signature types don't represent the
314
+ // possibility of out-of-bounds access, if we're indexing into an array
315
+ // just skip the check, to avoid false positives
316
+ if (isNoUncheckedIndexedAccess ||
317
+ (!isArrayIndexExpression(node) &&
318
+ !(node.type === utils_1.AST_NODE_TYPES.ChainExpression &&
319
+ node.expression.type !== utils_1.AST_NODE_TYPES.TSNonNullExpression &&
320
+ optionChainContainsOptionArrayIndex(node.expression)))) {
321
+ messageId = 'neverNullish';
322
+ }
323
+ }
324
+ else if (isAlwaysNullish(type)) {
325
+ messageId = 'alwaysNullish';
326
+ }
327
+ if (messageId) {
328
+ context.report({ node, messageId });
329
+ }
330
+ }
331
+ /**
332
+ * Checks that a binary expression is necessarily conditional, reports otherwise.
333
+ * If both sides of the binary expression are literal values, it's not a necessary condition.
334
+ *
335
+ * NOTE: It's also unnecessary if the types that don't overlap at all
336
+ * but that case is handled by the Typescript compiler itself.
337
+ * Known exceptions:
338
+ * - https://github.com/microsoft/TypeScript/issues/32627
339
+ * - https://github.com/microsoft/TypeScript/issues/37160 (handled)
340
+ */
341
+ function checkIfBoolExpressionIsNecessaryConditional(node, left, right, operator) {
342
+ const leftType = (0, util_1.getConstrainedTypeAtLocation)(services, left);
343
+ const rightType = (0, util_1.getConstrainedTypeAtLocation)(services, right);
344
+ const leftStaticValue = toStaticValue(leftType);
345
+ const rightStaticValue = toStaticValue(rightType);
346
+ if (leftStaticValue != null && rightStaticValue != null) {
347
+ const conditionIsTrue = booleanComparison(leftStaticValue.value, operator, rightStaticValue.value);
348
+ context.report({
349
+ node,
350
+ messageId: 'comparisonBetweenLiteralTypes',
351
+ data: {
352
+ left: checker.typeToString(leftType),
353
+ operator,
354
+ right: checker.typeToString(rightType),
355
+ trueOrFalse: conditionIsTrue ? 'true' : 'false',
356
+ },
357
+ });
358
+ return;
359
+ }
360
+ // Workaround for https://github.com/microsoft/TypeScript/issues/37160
361
+ if (isStrictNullChecks) {
362
+ const UNDEFINED = ts.TypeFlags.Undefined;
363
+ const NULL = ts.TypeFlags.Null;
364
+ const VOID = ts.TypeFlags.Void;
365
+ const isComparable = (type, flag) => {
366
+ // Allow comparison to `any`, `unknown` or a naked type parameter.
367
+ flag |=
368
+ ts.TypeFlags.Any |
369
+ ts.TypeFlags.Unknown |
370
+ ts.TypeFlags.TypeParameter |
371
+ ts.TypeFlags.TypeVariable;
372
+ // Allow loose comparison to nullish values.
373
+ if (operator === '==' || operator === '!=') {
374
+ flag |= NULL | UNDEFINED | VOID;
375
+ }
376
+ return (0, util_1.isTypeFlagSet)(type, flag);
377
+ };
378
+ if ((leftType.flags === UNDEFINED &&
379
+ !isComparable(rightType, UNDEFINED | VOID)) ||
380
+ (rightType.flags === UNDEFINED &&
381
+ !isComparable(leftType, UNDEFINED | VOID)) ||
382
+ (leftType.flags === NULL && !isComparable(rightType, NULL)) ||
383
+ (rightType.flags === NULL && !isComparable(leftType, NULL))) {
384
+ context.report({ node, messageId: 'noOverlapBooleanExpression' });
385
+ return;
386
+ }
387
+ }
388
+ }
389
+ /**
390
+ * Checks that a logical expression contains a boolean, reports otherwise.
391
+ */
392
+ function checkLogicalExpressionForUnnecessaryConditionals(node) {
393
+ if (node.operator === '??') {
394
+ checkNodeForNullish(node.left);
395
+ return;
396
+ }
397
+ // Only checks the left side, since the right side might not be "conditional" at all.
398
+ // The right side will be checked if the LogicalExpression is used in a conditional context
399
+ checkNode(node.left);
400
+ }
401
+ /**
402
+ * Checks that a testable expression of a loop is necessarily conditional, reports otherwise.
403
+ */
404
+ function checkIfLoopIsNecessaryConditional(node) {
405
+ if (node.test == null) {
406
+ // e.g. `for(;;)`
407
+ return;
408
+ }
409
+ if (allowConstantLoopConditionsOption === 'only-allowed-literals' &&
410
+ node.test.type === utils_1.AST_NODE_TYPES.Literal &&
411
+ constantLoopConditionsAllowedLiterals.has(node.test.value)) {
412
+ return;
413
+ }
414
+ if (allowConstantLoopConditionsOption === 'always' &&
415
+ tsutils.isTrueLiteralType((0, util_1.getConstrainedTypeAtLocation)(services, node.test))) {
416
+ return;
417
+ }
418
+ checkNode(node.test);
419
+ }
420
+ function checkCallExpression(node) {
421
+ if (checkTypePredicates) {
422
+ const truthinessAssertedArgument = (0, assertionFunctionUtils_1.findTruthinessAssertedArgument)(services, node);
423
+ if (truthinessAssertedArgument != null) {
424
+ checkNode(truthinessAssertedArgument);
425
+ }
426
+ const typeGuardAssertedArgument = (0, assertionFunctionUtils_1.findTypeGuardAssertedArgument)(services, node);
427
+ if (typeGuardAssertedArgument != null) {
428
+ const typeOfArgument = (0, util_1.getConstrainedTypeAtLocation)(services, typeGuardAssertedArgument.argument);
429
+ if (
430
+ // Skip `any` — it is assignable to everything, producing
431
+ // false positives for meaningful runtime type guards.
432
+ !tsutils.isTypeFlagSet(typeOfArgument, ts.TypeFlags.Any | ts.TypeFlags.Unknown) &&
433
+ checker.isTypeAssignableTo(typeOfArgument, typeGuardAssertedArgument.type) &&
434
+ // Only flag if the types are mutually assignable (i.e. equivalent,
435
+ // like Narrower ↔ Wider with optional props) or the predicate type
436
+ // is a union that the argument is a strict subtype of. This avoids
437
+ // false positives with structural subtypes whose extra members are
438
+ // all optional in the *predicate* type (e.g. custom MappedType
439
+ // interfaces extending ts.Type).
440
+ (checker.isTypeAssignableTo(typeGuardAssertedArgument.type, typeOfArgument) ||
441
+ typeGuardAssertedArgument.type.isUnion())) {
442
+ context.report({
443
+ node: typeGuardAssertedArgument.argument,
444
+ messageId: 'typeGuardAlreadyIsType',
445
+ data: {
446
+ typeGuardOrAssertionFunction: typeGuardAssertedArgument.asserts
447
+ ? 'assertion function'
448
+ : 'type guard',
449
+ },
450
+ });
451
+ }
452
+ }
453
+ }
454
+ // If this is something like arr.filter(x => /*condition*/), check `condition`
455
+ if ((0, util_1.isArrayMethodCallWithPredicate)(context, services, node) &&
456
+ node.arguments.length) {
457
+ const callback = node.arguments[0];
458
+ // Inline defined functions
459
+ if (callback.type === utils_1.AST_NODE_TYPES.ArrowFunctionExpression ||
460
+ callback.type === utils_1.AST_NODE_TYPES.FunctionExpression) {
461
+ // Two special cases, where we can directly check the node that's returned:
462
+ // () => something
463
+ if (callback.body.type !== utils_1.AST_NODE_TYPES.BlockStatement) {
464
+ return checkNode(callback.body);
465
+ }
466
+ // () => { return something; }
467
+ const callbackBody = callback.body.body;
468
+ if (callbackBody.length === 1 &&
469
+ callbackBody[0].type === utils_1.AST_NODE_TYPES.ReturnStatement &&
470
+ callbackBody[0].argument) {
471
+ return checkNode(callbackBody[0].argument);
472
+ }
473
+ // Potential enhancement: could use code-path analysis to check
474
+ // any function with a single return statement
475
+ // (Value to complexity ratio is dubious however)
476
+ }
477
+ // Otherwise just do type analysis on the function as a whole.
478
+ const returnTypes = tsutils
479
+ .getCallSignaturesOfType((0, util_1.getConstrainedTypeAtLocation)(services, callback))
480
+ .map(sig => sig.getReturnType());
481
+ if (returnTypes.length === 0) {
482
+ // Not a callable function, e.g. `any`
483
+ return;
484
+ }
485
+ let hasFalsyReturnTypes = false;
486
+ let hasTruthyReturnTypes = false;
487
+ for (const type of returnTypes) {
488
+ const { constraintType } = (0, util_1.getConstraintInfo)(checker, type);
489
+ // Predicate is always necessary if it involves `any` or `unknown`
490
+ if (!constraintType ||
491
+ (0, util_1.isTypeAnyType)(constraintType) ||
492
+ (0, util_1.isTypeUnknownType)(constraintType)) {
493
+ return;
494
+ }
495
+ if ((0, util_1.isPossiblyFalsy)(constraintType)) {
496
+ hasFalsyReturnTypes = true;
497
+ }
498
+ if ((0, util_1.isPossiblyTruthy)(constraintType)) {
499
+ hasTruthyReturnTypes = true;
500
+ }
501
+ // bail early if both a possibly-truthy and a possibly-falsy have been detected
502
+ if (hasFalsyReturnTypes && hasTruthyReturnTypes) {
503
+ return;
504
+ }
505
+ }
506
+ if (!hasFalsyReturnTypes) {
507
+ return context.report({
508
+ node: callback,
509
+ messageId: 'alwaysTruthyFunc',
510
+ });
511
+ }
512
+ if (!hasTruthyReturnTypes) {
513
+ return context.report({
514
+ node: callback,
515
+ messageId: 'alwaysFalsyFunc',
516
+ });
517
+ }
518
+ }
519
+ }
520
+ // Recursively searches an optional chain for an array index expression
521
+ // Has to search the entire chain, because an array index will "infect" the rest of the types
522
+ // Example:
523
+ // ```
524
+ // [{x: {y: "z"} }][n] // type is {x: {y: "z"}}
525
+ // ?.x // type is {y: "z"}
526
+ // ?.y // This access is considered "unnecessary" according to the types
527
+ // ```
528
+ function optionChainContainsOptionArrayIndex(node) {
529
+ const lhsNode = node.type === utils_1.AST_NODE_TYPES.CallExpression ? node.callee : node.object;
530
+ if (node.optional && isArrayIndexExpression(lhsNode)) {
531
+ return true;
532
+ }
533
+ if (lhsNode.type === utils_1.AST_NODE_TYPES.MemberExpression ||
534
+ lhsNode.type === utils_1.AST_NODE_TYPES.CallExpression) {
535
+ return optionChainContainsOptionArrayIndex(lhsNode);
536
+ }
537
+ return false;
538
+ }
539
+ function isNullablePropertyType(objType, propertyType) {
540
+ if (propertyType.isUnion()) {
541
+ return propertyType.types.some(type => isNullablePropertyType(objType, type));
542
+ }
543
+ if (propertyType.isNumberLiteral() || propertyType.isStringLiteral()) {
544
+ const propType = (0, util_1.getTypeOfPropertyOfName)(checker, objType, propertyType.value.toString());
545
+ if (propType) {
546
+ return (0, util_1.isNullableType)(propType);
547
+ }
548
+ }
549
+ const typeName = (0, util_1.getTypeName)(checker, propertyType);
550
+ return checker
551
+ .getIndexInfosOfType(objType)
552
+ .some(info => (0, util_1.getTypeName)(checker, info.keyType) === typeName);
553
+ }
554
+ // Checks whether a member expression is nullable or not regardless of it's previous node.
555
+ // Example:
556
+ // ```
557
+ // // 'bar' is nullable if 'foo' is null.
558
+ // // but this function checks regardless of 'foo' type, so returns 'true'.
559
+ // declare const foo: { bar : { baz: string } } | null
560
+ // foo?.bar;
561
+ // ```
562
+ function isMemberExpressionNullableOriginFromObject(node) {
563
+ const prevType = (0, util_1.getConstrainedTypeAtLocation)(services, node.object);
564
+ const property = node.property;
565
+ if (prevType.isUnion() && (0, util_1.isIdentifier)(property)) {
566
+ const isOwnNullable = prevType.types.some(type => {
567
+ if (node.computed) {
568
+ const propertyType = (0, util_1.getConstrainedTypeAtLocation)(services, node.property);
569
+ return isNullablePropertyType(type, propertyType);
570
+ }
571
+ const propType = (0, util_1.getTypeOfPropertyOfName)(checker, type, property.name);
572
+ if (propType) {
573
+ return (0, util_1.isNullableType)(propType);
574
+ }
575
+ const indexInfo = checker.getIndexInfosOfType(type);
576
+ return indexInfo.some(info => {
577
+ const isStringTypeName = (0, util_1.getTypeName)(checker, info.keyType) === 'string';
578
+ return (isStringTypeName &&
579
+ (isNoUncheckedIndexedAccess || (0, util_1.isNullableType)(info.type)));
580
+ });
581
+ });
582
+ return !isOwnNullable && (0, util_1.isNullableType)(prevType);
583
+ }
584
+ return false;
585
+ }
586
+ function isCallExpressionNullableOriginFromCallee(node) {
587
+ const prevType = (0, util_1.getConstrainedTypeAtLocation)(services, node.callee);
588
+ if (prevType.isUnion()) {
589
+ const isOwnNullable = prevType.types.some(type => {
590
+ const signatures = type.getCallSignatures();
591
+ return signatures.some(sig => (0, util_1.isNullableType)(sig.getReturnType()));
592
+ });
593
+ return !isOwnNullable && (0, util_1.isNullableType)(prevType);
594
+ }
595
+ return false;
596
+ }
597
+ function isOptionableExpression(node) {
598
+ const type = (0, util_1.getConstrainedTypeAtLocation)(services, node);
599
+ const isOwnNullable = node.type === utils_1.AST_NODE_TYPES.MemberExpression
600
+ ? !isMemberExpressionNullableOriginFromObject(node)
601
+ : node.type === utils_1.AST_NODE_TYPES.CallExpression
602
+ ? !isCallExpressionNullableOriginFromCallee(node)
603
+ : true;
604
+ return (isConditionalAlwaysNecessary(type) ||
605
+ (isOwnNullable && (0, util_1.isNullableType)(type)));
606
+ }
607
+ function checkOptionalChain(node, beforeOperator, fix) {
608
+ // We only care if this step in the chain is optional. If just descend
609
+ // from an optional chain, then that's fine.
610
+ if (!node.optional) {
611
+ return;
612
+ }
613
+ // Since typescript array index signature types don't represent the
614
+ // possibility of out-of-bounds access, if we're indexing into an array
615
+ // just skip the check, to avoid false positives
616
+ if (!isNoUncheckedIndexedAccess &&
617
+ optionChainContainsOptionArrayIndex(node)) {
618
+ return;
619
+ }
620
+ const nodeToCheck = node.type === utils_1.AST_NODE_TYPES.CallExpression ? node.callee : node.object;
621
+ if (isOptionableExpression(nodeToCheck)) {
622
+ return;
623
+ }
624
+ const questionDotOperator = (0, util_1.nullThrows)(context.sourceCode.getTokenAfter(beforeOperator, token => token.type === utils_1.AST_TOKEN_TYPES.Punctuator && token.value === '?.'), util_1.NullThrowsReasons.MissingToken('operator', node.type));
625
+ context.report({
626
+ loc: questionDotOperator.loc,
627
+ node,
628
+ messageId: 'neverOptionalChain',
629
+ suggest: [
630
+ {
631
+ messageId: 'suggestRemoveOptionalChain',
632
+ fix(fixer) {
633
+ return fixer.replaceText(questionDotOperator, fix);
634
+ },
635
+ },
636
+ ],
637
+ });
638
+ }
639
+ function checkOptionalMemberExpression(node) {
640
+ checkOptionalChain(node, node.object, node.computed ? '' : '.');
641
+ }
642
+ function checkOptionalCallExpression(node) {
643
+ checkOptionalChain(node, node.callee, '');
644
+ }
645
+ function checkAssignmentExpression(node) {
646
+ // Similar to checkLogicalExpressionForUnnecessaryConditionals, since
647
+ // a ||= b is equivalent to a || (a = b)
648
+ if (['&&=', '||='].includes(node.operator)) {
649
+ checkNode(node.left);
650
+ }
651
+ else if (node.operator === '??=') {
652
+ checkNodeForNullish(node.left);
653
+ }
654
+ }
655
+ return {
656
+ AssignmentExpression: checkAssignmentExpression,
657
+ BinaryExpression(node) {
658
+ const { operator } = node;
659
+ if (isBoolOperator(operator)) {
660
+ checkIfBoolExpressionIsNecessaryConditional(node, node.left, node.right, operator);
661
+ }
662
+ },
663
+ CallExpression: checkCallExpression,
664
+ 'CallExpression[optional = true]': checkOptionalCallExpression,
665
+ ConditionalExpression: (node) => checkNode(node.test),
666
+ DoWhileStatement: checkIfLoopIsNecessaryConditional,
667
+ ForStatement: checkIfLoopIsNecessaryConditional,
668
+ IfStatement: (node) => checkNode(node.test),
669
+ LogicalExpression: checkLogicalExpressionForUnnecessaryConditionals,
670
+ 'MemberExpression[optional = true]': checkOptionalMemberExpression,
671
+ SwitchCase({ parent, test }) {
672
+ // only check `case ...:`, not `default:`
673
+ if (test) {
674
+ checkIfBoolExpressionIsNecessaryConditional(test, parent.discriminant, test, '===');
675
+ }
676
+ },
677
+ WhileStatement: checkIfLoopIsNecessaryConditional,
678
+ };
679
+ },
680
+ });
681
+ function normalizeAllowConstantLoopConditions(allowConstantLoopConditions) {
682
+ if (allowConstantLoopConditions === true) {
683
+ return 'always';
684
+ }
685
+ if (allowConstantLoopConditions === false) {
686
+ return 'never';
687
+ }
688
+ return allowConstantLoopConditions;
689
+ }