@depup/typescript-eslint__utils 8.57.1-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +25 -0
- package/changes.json +5 -0
- package/dist/ast-utils/eslint-utils/PatternMatcher.d.ts +47 -0
- package/dist/ast-utils/eslint-utils/PatternMatcher.js +44 -0
- package/dist/ast-utils/eslint-utils/ReferenceTracker.d.ts +75 -0
- package/dist/ast-utils/eslint-utils/ReferenceTracker.js +48 -0
- package/dist/ast-utils/eslint-utils/astUtilities.d.ts +83 -0
- package/dist/ast-utils/eslint-utils/astUtilities.js +101 -0
- package/dist/ast-utils/eslint-utils/index.d.ts +5 -0
- package/dist/ast-utils/eslint-utils/index.js +21 -0
- package/dist/ast-utils/eslint-utils/predicates.d.ts +31 -0
- package/dist/ast-utils/eslint-utils/predicates.js +59 -0
- package/dist/ast-utils/eslint-utils/scopeAnalysis.d.ts +16 -0
- package/dist/ast-utils/eslint-utils/scopeAnalysis.js +51 -0
- package/dist/ast-utils/helpers.d.ts +18 -0
- package/dist/ast-utils/helpers.js +21 -0
- package/dist/ast-utils/index.d.ts +4 -0
- package/dist/ast-utils/index.js +20 -0
- package/dist/ast-utils/misc.d.ts +6 -0
- package/dist/ast-utils/misc.js +11 -0
- package/dist/ast-utils/predicates.d.ts +68 -0
- package/dist/ast-utils/predicates.js +108 -0
- package/dist/eslint-utils/InferTypesFromRule.d.ts +9 -0
- package/dist/eslint-utils/InferTypesFromRule.js +2 -0
- package/dist/eslint-utils/RuleCreator.d.ts +32 -0
- package/dist/eslint-utils/RuleCreator.js +54 -0
- package/dist/eslint-utils/applyDefault.d.ts +8 -0
- package/dist/eslint-utils/applyDefault.js +33 -0
- package/dist/eslint-utils/deepMerge.d.ts +14 -0
- package/dist/eslint-utils/deepMerge.js +46 -0
- package/dist/eslint-utils/getParserServices.d.ts +22 -0
- package/dist/eslint-utils/getParserServices.js +41 -0
- package/dist/eslint-utils/index.d.ts +6 -0
- package/dist/eslint-utils/index.js +22 -0
- package/dist/eslint-utils/nullThrows.d.ts +12 -0
- package/dist/eslint-utils/nullThrows.js +21 -0
- package/dist/eslint-utils/parserSeemsToBeTSESLint.d.ts +1 -0
- package/dist/eslint-utils/parserSeemsToBeTSESLint.js +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +45 -0
- package/dist/json-schema.d.ts +387 -0
- package/dist/json-schema.js +8 -0
- package/dist/ts-eslint/AST.d.ts +8 -0
- package/dist/ts-eslint/AST.js +3 -0
- package/dist/ts-eslint/Config.d.ts +291 -0
- package/dist/ts-eslint/Config.js +3 -0
- package/dist/ts-eslint/ESLint.d.ts +7 -0
- package/dist/ts-eslint/ESLint.js +13 -0
- package/dist/ts-eslint/Linter.d.ts +255 -0
- package/dist/ts-eslint/Linter.js +13 -0
- package/dist/ts-eslint/Parser.d.ts +94 -0
- package/dist/ts-eslint/Parser.js +3 -0
- package/dist/ts-eslint/ParserOptions.d.ts +1 -0
- package/dist/ts-eslint/ParserOptions.js +2 -0
- package/dist/ts-eslint/Processor.d.ts +63 -0
- package/dist/ts-eslint/Processor.js +3 -0
- package/dist/ts-eslint/Rule.d.ts +614 -0
- package/dist/ts-eslint/Rule.js +2 -0
- package/dist/ts-eslint/RuleTester.d.ts +183 -0
- package/dist/ts-eslint/RuleTester.js +11 -0
- package/dist/ts-eslint/Scope.d.ts +42 -0
- package/dist/ts-eslint/Scope.js +43 -0
- package/dist/ts-eslint/SourceCode.d.ts +354 -0
- package/dist/ts-eslint/SourceCode.js +8 -0
- package/dist/ts-eslint/eslint/ESLintShared.d.ts +381 -0
- package/dist/ts-eslint/eslint/ESLintShared.js +2 -0
- package/dist/ts-eslint/eslint/FlatESLint.d.ts +87 -0
- package/dist/ts-eslint/eslint/FlatESLint.js +19 -0
- package/dist/ts-eslint/eslint/LegacyESLint.d.ts +72 -0
- package/dist/ts-eslint/eslint/LegacyESLint.js +36 -0
- package/dist/ts-eslint/index.d.ts +11 -0
- package/dist/ts-eslint/index.js +27 -0
- package/dist/ts-estree.d.ts +3 -0
- package/dist/ts-estree.js +9 -0
- package/dist/ts-utils/NoInfer.d.ts +9 -0
- package/dist/ts-utils/NoInfer.js +2 -0
- package/dist/ts-utils/index.d.ts +2 -0
- package/dist/ts-utils/index.js +18 -0
- package/dist/ts-utils/isArray.d.ts +1 -0
- package/dist/ts-utils/isArray.js +7 -0
- package/package.json +120 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AST_NODE_TYPES, AST_TOKEN_TYPES, TSESTree } from '../ts-estree';
|
|
2
|
+
export declare const isNodeOfType: <NodeType extends AST_NODE_TYPES>(nodeType: NodeType) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
|
|
3
|
+
type: NodeType;
|
|
4
|
+
}>;
|
|
5
|
+
export declare const isNodeOfTypes: <NodeTypes extends readonly AST_NODE_TYPES[]>(nodeTypes: NodeTypes) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
|
|
6
|
+
type: NodeTypes[number];
|
|
7
|
+
}>;
|
|
8
|
+
export declare const isNodeOfTypeWithConditions: <NodeType extends AST_NODE_TYPES, ExtractedNode extends Extract<TSESTree.Node, {
|
|
9
|
+
type: NodeType;
|
|
10
|
+
}>, Conditions extends Partial<ExtractedNode>>(nodeType: NodeType, conditions: Conditions) => ((node: TSESTree.Node | null | undefined) => node is Conditions & ExtractedNode);
|
|
11
|
+
export declare const isTokenOfTypeWithConditions: <TokenType extends AST_TOKEN_TYPES, ExtractedToken extends Extract<TSESTree.Token, {
|
|
12
|
+
type: TokenType;
|
|
13
|
+
}>, Conditions extends Partial<{
|
|
14
|
+
type: TokenType;
|
|
15
|
+
} & TSESTree.Token>>(tokenType: TokenType, conditions: Conditions) => ((token: TSESTree.Token | null | undefined) => token is Conditions & ExtractedToken);
|
|
16
|
+
export declare const isNotTokenOfTypeWithConditions: <TokenType extends AST_TOKEN_TYPES, ExtractedToken extends Extract<TSESTree.Token, {
|
|
17
|
+
type: TokenType;
|
|
18
|
+
}>, Conditions extends Partial<ExtractedToken>>(tokenType: TokenType, conditions: Conditions) => ((token: TSESTree.Token | null | undefined) => token is Exclude<TSESTree.Token, Conditions & ExtractedToken>);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isNotTokenOfTypeWithConditions = exports.isTokenOfTypeWithConditions = exports.isNodeOfTypeWithConditions = exports.isNodeOfTypes = exports.isNodeOfType = void 0;
|
|
4
|
+
const isNodeOfType = (nodeType) => (node) => node?.type === nodeType;
|
|
5
|
+
exports.isNodeOfType = isNodeOfType;
|
|
6
|
+
const isNodeOfTypes = (nodeTypes) => (node) => !!node && nodeTypes.includes(node.type);
|
|
7
|
+
exports.isNodeOfTypes = isNodeOfTypes;
|
|
8
|
+
const isNodeOfTypeWithConditions = (nodeType, conditions) => {
|
|
9
|
+
const entries = Object.entries(conditions);
|
|
10
|
+
return (node) => node?.type === nodeType &&
|
|
11
|
+
entries.every(([key, value]) => node[key] === value);
|
|
12
|
+
};
|
|
13
|
+
exports.isNodeOfTypeWithConditions = isNodeOfTypeWithConditions;
|
|
14
|
+
const isTokenOfTypeWithConditions = (tokenType, conditions) => {
|
|
15
|
+
const entries = Object.entries(conditions);
|
|
16
|
+
return (token) => token?.type === tokenType &&
|
|
17
|
+
entries.every(([key, value]) => token[key] === value);
|
|
18
|
+
};
|
|
19
|
+
exports.isTokenOfTypeWithConditions = isTokenOfTypeWithConditions;
|
|
20
|
+
const isNotTokenOfTypeWithConditions = (tokenType, conditions) => (token) => !(0, exports.isTokenOfTypeWithConditions)(tokenType, conditions)(token);
|
|
21
|
+
exports.isNotTokenOfTypeWithConditions = isNotTokenOfTypeWithConditions;
|
|
@@ -0,0 +1,20 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./eslint-utils"), exports);
|
|
18
|
+
__exportStar(require("./helpers"), exports);
|
|
19
|
+
__exportStar(require("./misc"), exports);
|
|
20
|
+
__exportStar(require("./predicates"), exports);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { TSESTree } from '../ts-estree';
|
|
2
|
+
export declare const LINEBREAK_MATCHER: RegExp;
|
|
3
|
+
/**
|
|
4
|
+
* Determines whether two adjacent tokens are on the same line
|
|
5
|
+
*/
|
|
6
|
+
export declare function isTokenOnSameLine(left: TSESTree.Node | TSESTree.Token, right: TSESTree.Node | TSESTree.Token): boolean;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LINEBREAK_MATCHER = void 0;
|
|
4
|
+
exports.isTokenOnSameLine = isTokenOnSameLine;
|
|
5
|
+
exports.LINEBREAK_MATCHER = /\r\n|[\r\n\u2028\u2029]/;
|
|
6
|
+
/**
|
|
7
|
+
* Determines whether two adjacent tokens are on the same line
|
|
8
|
+
*/
|
|
9
|
+
function isTokenOnSameLine(left, right) {
|
|
10
|
+
return left.loc.end.line === right.loc.start.line;
|
|
11
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { TSESTree } from '../ts-estree';
|
|
2
|
+
export declare const isOptionalChainPunctuator: (token: TSESTree.Token | null | undefined) => token is {
|
|
3
|
+
value: "?.";
|
|
4
|
+
} & TSESTree.PunctuatorToken;
|
|
5
|
+
export declare const isNotOptionalChainPunctuator: (token: TSESTree.Token | null | undefined) => token is TSESTree.BooleanToken | TSESTree.BlockComment | TSESTree.LineComment | TSESTree.IdentifierToken | TSESTree.JSXIdentifierToken | TSESTree.JSXTextToken | TSESTree.KeywordToken | TSESTree.NullToken | TSESTree.NumericToken | TSESTree.PrivateIdentifierToken | TSESTree.PunctuatorToken | TSESTree.RegularExpressionToken | TSESTree.StringToken | TSESTree.TemplateToken;
|
|
6
|
+
export declare const isNonNullAssertionPunctuator: (token: TSESTree.Token | null | undefined) => token is {
|
|
7
|
+
value: "!";
|
|
8
|
+
} & TSESTree.PunctuatorToken;
|
|
9
|
+
export declare const isNotNonNullAssertionPunctuator: (token: TSESTree.Token | null | undefined) => token is TSESTree.BooleanToken | TSESTree.BlockComment | TSESTree.LineComment | TSESTree.IdentifierToken | TSESTree.JSXIdentifierToken | TSESTree.JSXTextToken | TSESTree.KeywordToken | TSESTree.NullToken | TSESTree.NumericToken | TSESTree.PrivateIdentifierToken | TSESTree.PunctuatorToken | TSESTree.RegularExpressionToken | TSESTree.StringToken | TSESTree.TemplateToken;
|
|
10
|
+
/**
|
|
11
|
+
* Returns true if and only if the node represents: foo?.() or foo.bar?.()
|
|
12
|
+
*/
|
|
13
|
+
export declare const isOptionalCallExpression: (node: TSESTree.Node | null | undefined) => node is {
|
|
14
|
+
optional: boolean;
|
|
15
|
+
} & TSESTree.CallExpression;
|
|
16
|
+
/**
|
|
17
|
+
* Returns true if and only if the node represents logical OR
|
|
18
|
+
*/
|
|
19
|
+
export declare const isLogicalOrOperator: (node: TSESTree.Node | null | undefined) => node is Partial<TSESTree.LogicalExpression> & TSESTree.LogicalExpression;
|
|
20
|
+
/**
|
|
21
|
+
* Checks if a node is a type assertion:
|
|
22
|
+
* ```
|
|
23
|
+
* x as foo
|
|
24
|
+
* <foo>x
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare const isTypeAssertion: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSTypeAssertion;
|
|
28
|
+
export declare const isVariableDeclarator: (node: TSESTree.Node | null | undefined) => node is TSESTree.VariableDeclaratorDefiniteAssignment | TSESTree.VariableDeclaratorMaybeInit | TSESTree.VariableDeclaratorNoInit | TSESTree.UsingInForOfDeclarator | TSESTree.UsingInNormalContextDeclarator;
|
|
29
|
+
export declare const isFunction: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression;
|
|
30
|
+
export declare const isFunctionType: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSCallSignatureDeclaration | TSESTree.TSConstructorType | TSESTree.TSConstructSignatureDeclaration | TSESTree.TSDeclareFunctionNoDeclare | TSESTree.TSDeclareFunctionWithDeclare | TSESTree.TSEmptyBodyFunctionExpression | TSESTree.TSFunctionType | TSESTree.TSMethodSignatureComputedName | TSESTree.TSMethodSignatureNonComputedName;
|
|
31
|
+
export declare const isFunctionOrFunctionType: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression | TSESTree.TSCallSignatureDeclaration | TSESTree.TSConstructorType | TSESTree.TSConstructSignatureDeclaration | TSESTree.TSDeclareFunctionNoDeclare | TSESTree.TSDeclareFunctionWithDeclare | TSESTree.TSEmptyBodyFunctionExpression | TSESTree.TSFunctionType | TSESTree.TSMethodSignatureComputedName | TSESTree.TSMethodSignatureNonComputedName;
|
|
32
|
+
export declare const isTSFunctionType: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSFunctionType;
|
|
33
|
+
export declare const isTSConstructorType: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSConstructorType;
|
|
34
|
+
export declare const isClassOrTypeElement: (node: TSESTree.Node | null | undefined) => node is TSESTree.FunctionExpression | TSESTree.MethodDefinitionComputedName | TSESTree.MethodDefinitionNonComputedName | TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName | TSESTree.TSAbstractMethodDefinitionComputedName | TSESTree.TSAbstractMethodDefinitionNonComputedName | TSESTree.TSAbstractPropertyDefinitionComputedName | TSESTree.TSAbstractPropertyDefinitionNonComputedName | TSESTree.TSCallSignatureDeclaration | TSESTree.TSConstructSignatureDeclaration | TSESTree.TSEmptyBodyFunctionExpression | TSESTree.TSIndexSignature | TSESTree.TSMethodSignatureComputedName | TSESTree.TSMethodSignatureNonComputedName | TSESTree.TSPropertySignatureComputedName | TSESTree.TSPropertySignatureNonComputedName;
|
|
35
|
+
/**
|
|
36
|
+
* Checks if a node is a constructor method.
|
|
37
|
+
*/
|
|
38
|
+
export declare const isConstructor: (node: TSESTree.Node | null | undefined) => node is Partial<TSESTree.MethodDefinitionComputedName | TSESTree.MethodDefinitionNonComputedName> & (TSESTree.MethodDefinitionComputedName | TSESTree.MethodDefinitionNonComputedName);
|
|
39
|
+
/**
|
|
40
|
+
* Checks if a node is a setter method.
|
|
41
|
+
*/
|
|
42
|
+
export declare function isSetter(node: TSESTree.Node | undefined): node is {
|
|
43
|
+
kind: 'set';
|
|
44
|
+
} & (TSESTree.MethodDefinition | TSESTree.Property);
|
|
45
|
+
export declare const isIdentifier: (node: TSESTree.Node | null | undefined) => node is TSESTree.Identifier;
|
|
46
|
+
/**
|
|
47
|
+
* Checks if a node represents an `await …` expression.
|
|
48
|
+
*/
|
|
49
|
+
export declare const isAwaitExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.AwaitExpression;
|
|
50
|
+
/**
|
|
51
|
+
* Checks if a possible token is the `await` keyword.
|
|
52
|
+
*/
|
|
53
|
+
export declare const isAwaitKeyword: (token: TSESTree.Token | null | undefined) => token is {
|
|
54
|
+
value: "await";
|
|
55
|
+
} & TSESTree.IdentifierToken;
|
|
56
|
+
/**
|
|
57
|
+
* Checks if a possible token is the `type` keyword.
|
|
58
|
+
*/
|
|
59
|
+
export declare const isTypeKeyword: (token: TSESTree.Token | null | undefined) => token is {
|
|
60
|
+
value: "type";
|
|
61
|
+
} & TSESTree.IdentifierToken;
|
|
62
|
+
/**
|
|
63
|
+
* Checks if a possible token is the `import` keyword.
|
|
64
|
+
*/
|
|
65
|
+
export declare const isImportKeyword: (token: TSESTree.Token | null | undefined) => token is {
|
|
66
|
+
value: "import";
|
|
67
|
+
} & TSESTree.KeywordToken;
|
|
68
|
+
export declare const isLoop: (node: TSESTree.Node | null | undefined) => node is TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.WhileStatement;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isLoop = exports.isImportKeyword = exports.isTypeKeyword = exports.isAwaitKeyword = exports.isAwaitExpression = exports.isIdentifier = exports.isConstructor = exports.isClassOrTypeElement = exports.isTSConstructorType = exports.isTSFunctionType = exports.isFunctionOrFunctionType = exports.isFunctionType = exports.isFunction = exports.isVariableDeclarator = exports.isTypeAssertion = exports.isLogicalOrOperator = exports.isOptionalCallExpression = exports.isNotNonNullAssertionPunctuator = exports.isNonNullAssertionPunctuator = exports.isNotOptionalChainPunctuator = exports.isOptionalChainPunctuator = void 0;
|
|
4
|
+
exports.isSetter = isSetter;
|
|
5
|
+
const ts_estree_1 = require("../ts-estree");
|
|
6
|
+
const helpers_1 = require("./helpers");
|
|
7
|
+
exports.isOptionalChainPunctuator = (0, helpers_1.isTokenOfTypeWithConditions)(ts_estree_1.AST_TOKEN_TYPES.Punctuator, { value: '?.' });
|
|
8
|
+
exports.isNotOptionalChainPunctuator = (0, helpers_1.isNotTokenOfTypeWithConditions)(ts_estree_1.AST_TOKEN_TYPES.Punctuator, { value: '?.' });
|
|
9
|
+
exports.isNonNullAssertionPunctuator = (0, helpers_1.isTokenOfTypeWithConditions)(ts_estree_1.AST_TOKEN_TYPES.Punctuator, { value: '!' });
|
|
10
|
+
exports.isNotNonNullAssertionPunctuator = (0, helpers_1.isNotTokenOfTypeWithConditions)(ts_estree_1.AST_TOKEN_TYPES.Punctuator, { value: '!' });
|
|
11
|
+
/**
|
|
12
|
+
* Returns true if and only if the node represents: foo?.() or foo.bar?.()
|
|
13
|
+
*/
|
|
14
|
+
exports.isOptionalCallExpression = (0, helpers_1.isNodeOfTypeWithConditions)(ts_estree_1.AST_NODE_TYPES.CallExpression,
|
|
15
|
+
// this flag means the call expression itself is option
|
|
16
|
+
// i.e. it is foo.bar?.() and not foo?.bar()
|
|
17
|
+
{ optional: true });
|
|
18
|
+
/**
|
|
19
|
+
* Returns true if and only if the node represents logical OR
|
|
20
|
+
*/
|
|
21
|
+
exports.isLogicalOrOperator = (0, helpers_1.isNodeOfTypeWithConditions)(ts_estree_1.AST_NODE_TYPES.LogicalExpression, { operator: '||' });
|
|
22
|
+
/**
|
|
23
|
+
* Checks if a node is a type assertion:
|
|
24
|
+
* ```
|
|
25
|
+
* x as foo
|
|
26
|
+
* <foo>x
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
exports.isTypeAssertion = (0, helpers_1.isNodeOfTypes)([
|
|
30
|
+
ts_estree_1.AST_NODE_TYPES.TSAsExpression,
|
|
31
|
+
ts_estree_1.AST_NODE_TYPES.TSTypeAssertion,
|
|
32
|
+
]);
|
|
33
|
+
exports.isVariableDeclarator = (0, helpers_1.isNodeOfType)(ts_estree_1.AST_NODE_TYPES.VariableDeclarator);
|
|
34
|
+
const functionTypes = [
|
|
35
|
+
ts_estree_1.AST_NODE_TYPES.ArrowFunctionExpression,
|
|
36
|
+
ts_estree_1.AST_NODE_TYPES.FunctionDeclaration,
|
|
37
|
+
ts_estree_1.AST_NODE_TYPES.FunctionExpression,
|
|
38
|
+
];
|
|
39
|
+
exports.isFunction = (0, helpers_1.isNodeOfTypes)(functionTypes);
|
|
40
|
+
const functionTypeTypes = [
|
|
41
|
+
ts_estree_1.AST_NODE_TYPES.TSCallSignatureDeclaration,
|
|
42
|
+
ts_estree_1.AST_NODE_TYPES.TSConstructorType,
|
|
43
|
+
ts_estree_1.AST_NODE_TYPES.TSConstructSignatureDeclaration,
|
|
44
|
+
ts_estree_1.AST_NODE_TYPES.TSDeclareFunction,
|
|
45
|
+
ts_estree_1.AST_NODE_TYPES.TSEmptyBodyFunctionExpression,
|
|
46
|
+
ts_estree_1.AST_NODE_TYPES.TSFunctionType,
|
|
47
|
+
ts_estree_1.AST_NODE_TYPES.TSMethodSignature,
|
|
48
|
+
];
|
|
49
|
+
exports.isFunctionType = (0, helpers_1.isNodeOfTypes)(functionTypeTypes);
|
|
50
|
+
exports.isFunctionOrFunctionType = (0, helpers_1.isNodeOfTypes)([
|
|
51
|
+
...functionTypes,
|
|
52
|
+
...functionTypeTypes,
|
|
53
|
+
]);
|
|
54
|
+
exports.isTSFunctionType = (0, helpers_1.isNodeOfType)(ts_estree_1.AST_NODE_TYPES.TSFunctionType);
|
|
55
|
+
exports.isTSConstructorType = (0, helpers_1.isNodeOfType)(ts_estree_1.AST_NODE_TYPES.TSConstructorType);
|
|
56
|
+
exports.isClassOrTypeElement = (0, helpers_1.isNodeOfTypes)([
|
|
57
|
+
// ClassElement
|
|
58
|
+
ts_estree_1.AST_NODE_TYPES.PropertyDefinition,
|
|
59
|
+
ts_estree_1.AST_NODE_TYPES.FunctionExpression,
|
|
60
|
+
ts_estree_1.AST_NODE_TYPES.MethodDefinition,
|
|
61
|
+
ts_estree_1.AST_NODE_TYPES.TSAbstractPropertyDefinition,
|
|
62
|
+
ts_estree_1.AST_NODE_TYPES.TSAbstractMethodDefinition,
|
|
63
|
+
ts_estree_1.AST_NODE_TYPES.TSEmptyBodyFunctionExpression,
|
|
64
|
+
ts_estree_1.AST_NODE_TYPES.TSIndexSignature,
|
|
65
|
+
// TypeElement
|
|
66
|
+
ts_estree_1.AST_NODE_TYPES.TSCallSignatureDeclaration,
|
|
67
|
+
ts_estree_1.AST_NODE_TYPES.TSConstructSignatureDeclaration,
|
|
68
|
+
// AST_NODE_TYPES.TSIndexSignature,
|
|
69
|
+
ts_estree_1.AST_NODE_TYPES.TSMethodSignature,
|
|
70
|
+
ts_estree_1.AST_NODE_TYPES.TSPropertySignature,
|
|
71
|
+
]);
|
|
72
|
+
/**
|
|
73
|
+
* Checks if a node is a constructor method.
|
|
74
|
+
*/
|
|
75
|
+
exports.isConstructor = (0, helpers_1.isNodeOfTypeWithConditions)(ts_estree_1.AST_NODE_TYPES.MethodDefinition, { kind: 'constructor' });
|
|
76
|
+
/**
|
|
77
|
+
* Checks if a node is a setter method.
|
|
78
|
+
*/
|
|
79
|
+
function isSetter(node) {
|
|
80
|
+
return (!!node &&
|
|
81
|
+
(node.type === ts_estree_1.AST_NODE_TYPES.MethodDefinition ||
|
|
82
|
+
node.type === ts_estree_1.AST_NODE_TYPES.Property) &&
|
|
83
|
+
node.kind === 'set');
|
|
84
|
+
}
|
|
85
|
+
exports.isIdentifier = (0, helpers_1.isNodeOfType)(ts_estree_1.AST_NODE_TYPES.Identifier);
|
|
86
|
+
/**
|
|
87
|
+
* Checks if a node represents an `await …` expression.
|
|
88
|
+
*/
|
|
89
|
+
exports.isAwaitExpression = (0, helpers_1.isNodeOfType)(ts_estree_1.AST_NODE_TYPES.AwaitExpression);
|
|
90
|
+
/**
|
|
91
|
+
* Checks if a possible token is the `await` keyword.
|
|
92
|
+
*/
|
|
93
|
+
exports.isAwaitKeyword = (0, helpers_1.isTokenOfTypeWithConditions)(ts_estree_1.AST_TOKEN_TYPES.Identifier, { value: 'await' });
|
|
94
|
+
/**
|
|
95
|
+
* Checks if a possible token is the `type` keyword.
|
|
96
|
+
*/
|
|
97
|
+
exports.isTypeKeyword = (0, helpers_1.isTokenOfTypeWithConditions)(ts_estree_1.AST_TOKEN_TYPES.Identifier, { value: 'type' });
|
|
98
|
+
/**
|
|
99
|
+
* Checks if a possible token is the `import` keyword.
|
|
100
|
+
*/
|
|
101
|
+
exports.isImportKeyword = (0, helpers_1.isTokenOfTypeWithConditions)(ts_estree_1.AST_TOKEN_TYPES.Keyword, { value: 'import' });
|
|
102
|
+
exports.isLoop = (0, helpers_1.isNodeOfTypes)([
|
|
103
|
+
ts_estree_1.AST_NODE_TYPES.DoWhileStatement,
|
|
104
|
+
ts_estree_1.AST_NODE_TYPES.ForStatement,
|
|
105
|
+
ts_estree_1.AST_NODE_TYPES.ForInStatement,
|
|
106
|
+
ts_estree_1.AST_NODE_TYPES.ForOfStatement,
|
|
107
|
+
ts_estree_1.AST_NODE_TYPES.WhileStatement,
|
|
108
|
+
]);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RuleCreateFunction, RuleModule } from '../ts-eslint';
|
|
2
|
+
/**
|
|
3
|
+
* Uses type inference to fetch the Options type from the given RuleModule
|
|
4
|
+
*/
|
|
5
|
+
export type InferOptionsTypeFromRule<T> = T extends RuleModule<infer _MessageIds, infer Options> ? Options : T extends RuleCreateFunction<infer _MessageIds, infer Options> ? Options : unknown;
|
|
6
|
+
/**
|
|
7
|
+
* Uses type inference to fetch the MessageIds type from the given RuleModule
|
|
8
|
+
*/
|
|
9
|
+
export type InferMessageIdsTypeFromRule<T> = T extends RuleModule<infer MessageIds, infer _TOptions> ? MessageIds : T extends RuleCreateFunction<infer MessageIds, infer _TOptions> ? MessageIds : unknown;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { RuleContext, RuleListener, RuleMetaData, RuleMetaDataDocs, RuleModule } from '../ts-eslint/Rule';
|
|
2
|
+
export type NamedCreateRuleMetaDocs = Omit<RuleMetaDataDocs, 'url'>;
|
|
3
|
+
export type NamedCreateRuleMeta<MessageIds extends string, PluginDocs = unknown, Options extends readonly unknown[] = []> = {
|
|
4
|
+
docs: PluginDocs & RuleMetaDataDocs;
|
|
5
|
+
} & Omit<RuleMetaData<MessageIds, PluginDocs, Options>, 'docs'>;
|
|
6
|
+
export interface RuleCreateAndOptions<Options extends readonly unknown[], MessageIds extends string> {
|
|
7
|
+
create: (context: Readonly<RuleContext<MessageIds, Options>>, optionsWithDefault: Readonly<Options>) => RuleListener;
|
|
8
|
+
/** @deprecated Use meta.defaultOptions instead */
|
|
9
|
+
defaultOptions?: Readonly<Options>;
|
|
10
|
+
}
|
|
11
|
+
export interface RuleWithMeta<Options extends readonly unknown[], MessageIds extends string, Docs = unknown> extends RuleCreateAndOptions<Options, MessageIds> {
|
|
12
|
+
meta: RuleMetaData<MessageIds, Docs, Options>;
|
|
13
|
+
name?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface RuleWithMetaAndName<Options extends readonly unknown[], MessageIds extends string, Docs = unknown> extends RuleCreateAndOptions<Options, MessageIds> {
|
|
16
|
+
meta: NamedCreateRuleMeta<MessageIds, Docs, Options>;
|
|
17
|
+
name: string;
|
|
18
|
+
}
|
|
19
|
+
type RuleModuleWithName<MessageIds extends string, Options extends readonly unknown[] = [], Docs = unknown, ExtendedRuleListener extends RuleListener = RuleListener> = RuleModule<MessageIds, Options, Docs, ExtendedRuleListener> & {
|
|
20
|
+
name: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Creates reusable function to create rules with default options and docs URLs.
|
|
24
|
+
*
|
|
25
|
+
* @param urlCreator Creates a documentation URL for a given rule name.
|
|
26
|
+
* @returns Function to create a rule with the docs URL format.
|
|
27
|
+
*/
|
|
28
|
+
export declare function RuleCreator<PluginDocs = unknown>(urlCreator: (ruleName: string) => string): <Options extends readonly unknown[], MessageIds extends string>({ meta, name, ...rule }: Readonly<RuleWithMetaAndName<Options, MessageIds, PluginDocs>>) => RuleModuleWithName<MessageIds, Options, PluginDocs>;
|
|
29
|
+
export declare namespace RuleCreator {
|
|
30
|
+
var withoutDocs: <Options extends readonly unknown[], MessageIds extends string>(args: Readonly<RuleWithMeta<Options, MessageIds>>) => RuleModule<MessageIds, Options>;
|
|
31
|
+
}
|
|
32
|
+
export { type RuleListener, type RuleModule } from '../ts-eslint/Rule';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RuleCreator = RuleCreator;
|
|
4
|
+
const applyDefault_1 = require("./applyDefault");
|
|
5
|
+
/**
|
|
6
|
+
* Creates reusable function to create rules with default options and docs URLs.
|
|
7
|
+
*
|
|
8
|
+
* @param urlCreator Creates a documentation URL for a given rule name.
|
|
9
|
+
* @returns Function to create a rule with the docs URL format.
|
|
10
|
+
*/
|
|
11
|
+
function RuleCreator(urlCreator) {
|
|
12
|
+
// This function will get much easier to call when this is merged https://github.com/Microsoft/TypeScript/pull/26349
|
|
13
|
+
// TODO - when the above PR lands; add type checking for the context.report `data` property
|
|
14
|
+
return function createNamedRule({ meta, name, ...rule }) {
|
|
15
|
+
const ruleWithDocs = createRule({
|
|
16
|
+
meta: {
|
|
17
|
+
...meta,
|
|
18
|
+
docs: {
|
|
19
|
+
...meta.docs,
|
|
20
|
+
url: urlCreator(name),
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
name,
|
|
24
|
+
...rule,
|
|
25
|
+
});
|
|
26
|
+
return ruleWithDocs;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function createRule({ create,
|
|
30
|
+
// Keep accepting deprecated defaultOptions for backward compatibility.
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
32
|
+
defaultOptions, meta, name, }) {
|
|
33
|
+
const resolvedDefaultOptions = (meta.defaultOptions ??
|
|
34
|
+
defaultOptions ??
|
|
35
|
+
[]);
|
|
36
|
+
return {
|
|
37
|
+
create(context) {
|
|
38
|
+
const optionsWithDefault = (0, applyDefault_1.applyDefault)(resolvedDefaultOptions, context.options);
|
|
39
|
+
return create(context, optionsWithDefault);
|
|
40
|
+
},
|
|
41
|
+
defaultOptions,
|
|
42
|
+
meta,
|
|
43
|
+
name,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Creates a well-typed TSESLint custom ESLint rule without a docs URL.
|
|
48
|
+
*
|
|
49
|
+
* @returns Well-typed TSESLint custom ESLint rule.
|
|
50
|
+
* @remarks It is generally better to provide a docs URL function to RuleCreator.
|
|
51
|
+
*/
|
|
52
|
+
RuleCreator.withoutDocs = function withoutDocs(args) {
|
|
53
|
+
return createRule(args);
|
|
54
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure function - doesn't mutate either parameter!
|
|
3
|
+
* Uses the default options and overrides with the options provided by the user
|
|
4
|
+
* @param defaultOptions the defaults
|
|
5
|
+
* @param userOptions the user opts
|
|
6
|
+
* @returns the options with defaults
|
|
7
|
+
*/
|
|
8
|
+
export declare function applyDefault<User extends readonly unknown[], Default extends User>(defaultOptions: Readonly<Default>, userOptions: Readonly<User> | null): Default;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyDefault = applyDefault;
|
|
4
|
+
const deepMerge_1 = require("./deepMerge");
|
|
5
|
+
/**
|
|
6
|
+
* Pure function - doesn't mutate either parameter!
|
|
7
|
+
* Uses the default options and overrides with the options provided by the user
|
|
8
|
+
* @param defaultOptions the defaults
|
|
9
|
+
* @param userOptions the user opts
|
|
10
|
+
* @returns the options with defaults
|
|
11
|
+
*/
|
|
12
|
+
function applyDefault(defaultOptions, userOptions) {
|
|
13
|
+
// clone defaults
|
|
14
|
+
const options = structuredClone(defaultOptions);
|
|
15
|
+
if (userOptions == null) {
|
|
16
|
+
return options;
|
|
17
|
+
}
|
|
18
|
+
// For avoiding the type error
|
|
19
|
+
// `This expression is not callable. Type 'unknown' has no call signatures.ts(2349)`
|
|
20
|
+
options.forEach((opt, i) => {
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/internal/eqeq-nullish
|
|
22
|
+
if (userOptions[i] !== undefined) {
|
|
23
|
+
const userOpt = userOptions[i];
|
|
24
|
+
if ((0, deepMerge_1.isObjectNotArray)(userOpt) && (0, deepMerge_1.isObjectNotArray)(opt)) {
|
|
25
|
+
options[i] = (0, deepMerge_1.deepMerge)(opt, userOpt);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
options[i] = userOpt;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
return options;
|
|
33
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type ObjectLike<T = unknown> = Record<string, T>;
|
|
2
|
+
/**
|
|
3
|
+
* Check if the variable contains an object strictly rejecting arrays
|
|
4
|
+
* @returns `true` if obj is an object
|
|
5
|
+
*/
|
|
6
|
+
export declare function isObjectNotArray(obj: unknown): obj is ObjectLike;
|
|
7
|
+
/**
|
|
8
|
+
* Pure function - doesn't mutate either parameter!
|
|
9
|
+
* Merges two objects together deeply, overwriting the properties in first with the properties in second
|
|
10
|
+
* @param first The first object
|
|
11
|
+
* @param second The second object
|
|
12
|
+
* @returns a new object
|
|
13
|
+
*/
|
|
14
|
+
export declare function deepMerge(first?: ObjectLike, second?: ObjectLike): Record<string, unknown>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isObjectNotArray = isObjectNotArray;
|
|
4
|
+
exports.deepMerge = deepMerge;
|
|
5
|
+
/**
|
|
6
|
+
* Check if the variable contains an object strictly rejecting arrays
|
|
7
|
+
* @returns `true` if obj is an object
|
|
8
|
+
*/
|
|
9
|
+
function isObjectNotArray(obj) {
|
|
10
|
+
return typeof obj === 'object' && obj != null && !Array.isArray(obj);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Pure function - doesn't mutate either parameter!
|
|
14
|
+
* Merges two objects together deeply, overwriting the properties in first with the properties in second
|
|
15
|
+
* @param first The first object
|
|
16
|
+
* @param second The second object
|
|
17
|
+
* @returns a new object
|
|
18
|
+
*/
|
|
19
|
+
function deepMerge(first = {}, second = {}) {
|
|
20
|
+
// get the unique set of keys across both objects
|
|
21
|
+
const keys = new Set([...Object.keys(first), ...Object.keys(second)]);
|
|
22
|
+
return Object.fromEntries([...keys].map(key => {
|
|
23
|
+
const firstHasKey = key in first;
|
|
24
|
+
const secondHasKey = key in second;
|
|
25
|
+
const firstValue = first[key];
|
|
26
|
+
const secondValue = second[key];
|
|
27
|
+
let value;
|
|
28
|
+
if (firstHasKey && secondHasKey) {
|
|
29
|
+
if (isObjectNotArray(firstValue) && isObjectNotArray(secondValue)) {
|
|
30
|
+
// object type
|
|
31
|
+
value = deepMerge(firstValue, secondValue);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
// value type
|
|
35
|
+
value = secondValue;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else if (firstHasKey) {
|
|
39
|
+
value = firstValue;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
value = secondValue;
|
|
43
|
+
}
|
|
44
|
+
return [key, value];
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type * as TSESLint from '../ts-eslint';
|
|
2
|
+
import type { ParserServices, ParserServicesWithTypeInformation } from '../ts-estree';
|
|
3
|
+
/**
|
|
4
|
+
* Try to retrieve type-aware parser service from context.
|
|
5
|
+
* This **_will_** throw if it is not available.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getParserServices<MessageIds extends string, Options extends readonly unknown[]>(context: Readonly<TSESLint.RuleContext<MessageIds, Options>>): ParserServicesWithTypeInformation;
|
|
8
|
+
/**
|
|
9
|
+
* Try to retrieve type-aware parser service from context.
|
|
10
|
+
* This **_will_** throw if it is not available.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getParserServices<MessageIds extends string, Options extends readonly unknown[]>(context: Readonly<TSESLint.RuleContext<MessageIds, Options>>, allowWithoutFullTypeInformation: false): ParserServicesWithTypeInformation;
|
|
13
|
+
/**
|
|
14
|
+
* Try to retrieve type-aware parser service from context.
|
|
15
|
+
* This **_will not_** throw if it is not available.
|
|
16
|
+
*/
|
|
17
|
+
export declare function getParserServices<MessageIds extends string, Options extends readonly unknown[]>(context: Readonly<TSESLint.RuleContext<MessageIds, Options>>, allowWithoutFullTypeInformation: true): ParserServices;
|
|
18
|
+
/**
|
|
19
|
+
* Try to retrieve type-aware parser service from context.
|
|
20
|
+
* This may or may not throw if it is not available, depending on if `allowWithoutFullTypeInformation` is `true`
|
|
21
|
+
*/
|
|
22
|
+
export declare function getParserServices<MessageIds extends string, Options extends readonly unknown[]>(context: Readonly<TSESLint.RuleContext<MessageIds, Options>>, allowWithoutFullTypeInformation: boolean): ParserServices;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getParserServices = getParserServices;
|
|
4
|
+
const parserSeemsToBeTSESLint_1 = require("./parserSeemsToBeTSESLint");
|
|
5
|
+
const ERROR_MESSAGE_REQUIRES_PARSER_SERVICES = "You have used a rule which requires type information, but don't have parserOptions set to generate type information for this file. See https://tseslint.com/typed-linting for enabling linting with type information.";
|
|
6
|
+
const ERROR_MESSAGE_UNKNOWN_PARSER = 'Note: detected a parser other than @typescript-eslint/parser. Make sure the parser is configured to forward "parserOptions.project" to @typescript-eslint/parser.';
|
|
7
|
+
function getParserServices(context, allowWithoutFullTypeInformation = false) {
|
|
8
|
+
const parser =
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated -- For compatibility with ESLint 8
|
|
10
|
+
context.parserPath || context.languageOptions.parser?.meta?.name;
|
|
11
|
+
// This check is unnecessary if the user is using the latest version of our parser.
|
|
12
|
+
//
|
|
13
|
+
// However the world isn't perfect:
|
|
14
|
+
// - Users often use old parser versions.
|
|
15
|
+
// Old versions of the parser would not return any parserServices unless parserOptions.project was set.
|
|
16
|
+
// - Users sometimes use parsers that aren't @typescript-eslint/parser
|
|
17
|
+
// Other parsers won't return the parser services we expect (if they return any at all).
|
|
18
|
+
//
|
|
19
|
+
// This check allows us to handle bad user setups whilst providing a nice user-facing
|
|
20
|
+
// error message explaining the problem.
|
|
21
|
+
if (context.sourceCode.parserServices?.esTreeNodeToTSNodeMap == null ||
|
|
22
|
+
context.sourceCode.parserServices.tsNodeToESTreeNodeMap == null) {
|
|
23
|
+
throwError(parser);
|
|
24
|
+
}
|
|
25
|
+
// if a rule requires full type information, then hard fail if it doesn't exist
|
|
26
|
+
// this forces the user to supply parserOptions.project
|
|
27
|
+
if (context.sourceCode.parserServices.program == null &&
|
|
28
|
+
!allowWithoutFullTypeInformation) {
|
|
29
|
+
throwError(parser);
|
|
30
|
+
}
|
|
31
|
+
return context.sourceCode.parserServices;
|
|
32
|
+
}
|
|
33
|
+
/* eslint-enable @typescript-eslint/unified-signatures */
|
|
34
|
+
function throwError(parser) {
|
|
35
|
+
const messages = [
|
|
36
|
+
ERROR_MESSAGE_REQUIRES_PARSER_SERVICES,
|
|
37
|
+
`Parser: ${parser || '(unknown)'}`,
|
|
38
|
+
!(0, parserSeemsToBeTSESLint_1.parserSeemsToBeTSESLint)(parser) && ERROR_MESSAGE_UNKNOWN_PARSER,
|
|
39
|
+
].filter(Boolean);
|
|
40
|
+
throw new Error(messages.join('\n'));
|
|
41
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./applyDefault"), exports);
|
|
18
|
+
__exportStar(require("./deepMerge"), exports);
|
|
19
|
+
__exportStar(require("./getParserServices"), exports);
|
|
20
|
+
__exportStar(require("./InferTypesFromRule"), exports);
|
|
21
|
+
__exportStar(require("./nullThrows"), exports);
|
|
22
|
+
__exportStar(require("./RuleCreator"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A set of common reasons for calling nullThrows
|
|
3
|
+
*/
|
|
4
|
+
export declare const NullThrowsReasons: {
|
|
5
|
+
readonly MissingParent: "Expected node to have a parent.";
|
|
6
|
+
readonly MissingToken: (token: string, thing: string) => string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Assert that a value must not be null or undefined.
|
|
10
|
+
* This is a nice explicit alternative to the non-null assertion operator.
|
|
11
|
+
*/
|
|
12
|
+
export declare function nullThrows<T>(value: T, message: string): NonNullable<T>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NullThrowsReasons = void 0;
|
|
4
|
+
exports.nullThrows = nullThrows;
|
|
5
|
+
/**
|
|
6
|
+
* A set of common reasons for calling nullThrows
|
|
7
|
+
*/
|
|
8
|
+
exports.NullThrowsReasons = {
|
|
9
|
+
MissingParent: 'Expected node to have a parent.',
|
|
10
|
+
MissingToken: (token, thing) => `Expected to find a ${token} for the ${thing}.`,
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Assert that a value must not be null or undefined.
|
|
14
|
+
* This is a nice explicit alternative to the non-null assertion operator.
|
|
15
|
+
*/
|
|
16
|
+
function nullThrows(value, message) {
|
|
17
|
+
if (value == null) {
|
|
18
|
+
throw new Error(`Non-null Assertion Failed: ${message}`);
|
|
19
|
+
}
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function parserSeemsToBeTSESLint(parser: string | undefined): boolean;
|
package/dist/index.d.ts
ADDED