@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,183 @@
|
|
|
1
|
+
import type { AST_NODE_TYPES, AST_TOKEN_TYPES } from '../ts-estree';
|
|
2
|
+
import type { ClassicConfig } from './Config';
|
|
3
|
+
import type { Linter } from './Linter';
|
|
4
|
+
import type { ParserOptions } from './ParserOptions';
|
|
5
|
+
import type { ReportDescriptorMessageData, RuleCreateFunction, RuleModule, SharedConfigurationSettings } from './Rule';
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated Use `@typescript-eslint/rule-tester` instead.
|
|
8
|
+
*/
|
|
9
|
+
export interface ValidTestCase<Options extends readonly unknown[]> {
|
|
10
|
+
/**
|
|
11
|
+
* Code for the test case.
|
|
12
|
+
*/
|
|
13
|
+
readonly code: string;
|
|
14
|
+
/**
|
|
15
|
+
* Environments for the test case.
|
|
16
|
+
*/
|
|
17
|
+
readonly env?: Readonly<Linter.EnvironmentConfig>;
|
|
18
|
+
/**
|
|
19
|
+
* The fake filename for the test case. Useful for rules that make assertion about filenames.
|
|
20
|
+
*/
|
|
21
|
+
readonly filename?: string;
|
|
22
|
+
/**
|
|
23
|
+
* The additional global variables.
|
|
24
|
+
*/
|
|
25
|
+
readonly globals?: Readonly<Linter.GlobalsConfig>;
|
|
26
|
+
/**
|
|
27
|
+
* Name for the test case.
|
|
28
|
+
*/
|
|
29
|
+
readonly name?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Run this case exclusively for debugging in supported test frameworks.
|
|
32
|
+
*/
|
|
33
|
+
readonly only?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Options for the test case.
|
|
36
|
+
*/
|
|
37
|
+
readonly options?: Readonly<Options>;
|
|
38
|
+
/**
|
|
39
|
+
* The absolute path for the parser.
|
|
40
|
+
*/
|
|
41
|
+
readonly parser?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Options for the parser.
|
|
44
|
+
*/
|
|
45
|
+
readonly parserOptions?: Readonly<ParserOptions>;
|
|
46
|
+
/**
|
|
47
|
+
* Settings for the test case.
|
|
48
|
+
*/
|
|
49
|
+
readonly settings?: Readonly<SharedConfigurationSettings>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* @deprecated Use `@typescript-eslint/rule-tester` instead.
|
|
53
|
+
*/
|
|
54
|
+
export interface SuggestionOutput<MessageIds extends string> {
|
|
55
|
+
/**
|
|
56
|
+
* The data used to fill the message template.
|
|
57
|
+
*/
|
|
58
|
+
readonly data?: ReportDescriptorMessageData;
|
|
59
|
+
/**
|
|
60
|
+
* Reported message ID.
|
|
61
|
+
*/
|
|
62
|
+
readonly messageId: MessageIds;
|
|
63
|
+
/**
|
|
64
|
+
* NOTE: Suggestions will be applied as a stand-alone change, without triggering multi-pass fixes.
|
|
65
|
+
* Each individual error has its own suggestion, so you have to show the correct, _isolated_ output for each suggestion.
|
|
66
|
+
*/
|
|
67
|
+
readonly output: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* @deprecated Use `@typescript-eslint/rule-tester` instead.
|
|
71
|
+
*/
|
|
72
|
+
export interface InvalidTestCase<MessageIds extends string, Options extends readonly unknown[]> extends ValidTestCase<Options> {
|
|
73
|
+
/**
|
|
74
|
+
* Expected errors.
|
|
75
|
+
*/
|
|
76
|
+
readonly errors: readonly TestCaseError<MessageIds>[];
|
|
77
|
+
/**
|
|
78
|
+
* The expected code after autofixes are applied. If set to `null`, the test runner will assert that no autofix is suggested.
|
|
79
|
+
*/
|
|
80
|
+
readonly output?: string | string[] | null;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* @deprecated Use `@typescript-eslint/rule-tester` instead.
|
|
84
|
+
*/
|
|
85
|
+
export interface TestCaseError<MessageIds extends string> {
|
|
86
|
+
/**
|
|
87
|
+
* The 1-based column number of the reported start location.
|
|
88
|
+
*/
|
|
89
|
+
readonly column?: number;
|
|
90
|
+
/**
|
|
91
|
+
* The data used to fill the message template.
|
|
92
|
+
*/
|
|
93
|
+
readonly data?: ReportDescriptorMessageData;
|
|
94
|
+
/**
|
|
95
|
+
* The 1-based column number of the reported end location.
|
|
96
|
+
*/
|
|
97
|
+
readonly endColumn?: number;
|
|
98
|
+
/**
|
|
99
|
+
* The 1-based line number of the reported end location.
|
|
100
|
+
*/
|
|
101
|
+
readonly endLine?: number;
|
|
102
|
+
/**
|
|
103
|
+
* The 1-based line number of the reported start location.
|
|
104
|
+
*/
|
|
105
|
+
readonly line?: number;
|
|
106
|
+
/**
|
|
107
|
+
* Reported message ID.
|
|
108
|
+
*/
|
|
109
|
+
readonly messageId: MessageIds;
|
|
110
|
+
/**
|
|
111
|
+
* Reported suggestions.
|
|
112
|
+
*/
|
|
113
|
+
readonly suggestions?: readonly SuggestionOutput<MessageIds>[] | null;
|
|
114
|
+
/**
|
|
115
|
+
* The type of the reported AST node.
|
|
116
|
+
*/
|
|
117
|
+
readonly type?: AST_NODE_TYPES | AST_TOKEN_TYPES;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* @param text a string describing the rule
|
|
121
|
+
* @deprecated Use `@typescript-eslint/rule-tester` instead.
|
|
122
|
+
*/
|
|
123
|
+
export type RuleTesterTestFrameworkFunction = (text: string, callback: () => void) => void;
|
|
124
|
+
/**
|
|
125
|
+
* @deprecated Use `@typescript-eslint/rule-tester` instead.
|
|
126
|
+
*/
|
|
127
|
+
export interface RunTests<MessageIds extends string, Options extends readonly unknown[]> {
|
|
128
|
+
readonly invalid: readonly InvalidTestCase<MessageIds, Options>[];
|
|
129
|
+
readonly valid: readonly (string | ValidTestCase<Options>)[];
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* @deprecated Use `@typescript-eslint/rule-tester` instead.
|
|
133
|
+
*/
|
|
134
|
+
export interface RuleTesterConfig extends ClassicConfig.Config {
|
|
135
|
+
readonly parser: string;
|
|
136
|
+
readonly parserOptions?: Readonly<ParserOptions>;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* @deprecated Use `@typescript-eslint/rule-tester` instead.
|
|
140
|
+
*/
|
|
141
|
+
declare class RuleTesterBase {
|
|
142
|
+
/**
|
|
143
|
+
* Creates a new instance of RuleTester.
|
|
144
|
+
* @param testerConfig extra configuration for the tester
|
|
145
|
+
*/
|
|
146
|
+
constructor(testerConfig?: RuleTesterConfig);
|
|
147
|
+
/**
|
|
148
|
+
* Adds a new rule test to execute.
|
|
149
|
+
* @param ruleName The name of the rule to run.
|
|
150
|
+
* @param rule The rule to test.
|
|
151
|
+
* @param tests The collection of tests to run.
|
|
152
|
+
*/
|
|
153
|
+
run<MessageIds extends string, Options extends readonly unknown[]>(ruleName: string, rule: RuleModule<MessageIds, Options>, tests: RunTests<MessageIds, Options>): void;
|
|
154
|
+
/**
|
|
155
|
+
* If you supply a value to this property, the rule tester will call this instead of using the version defined on
|
|
156
|
+
* the global namespace.
|
|
157
|
+
*/
|
|
158
|
+
static get describe(): RuleTesterTestFrameworkFunction;
|
|
159
|
+
static set describe(value: RuleTesterTestFrameworkFunction | undefined);
|
|
160
|
+
/**
|
|
161
|
+
* If you supply a value to this property, the rule tester will call this instead of using the version defined on
|
|
162
|
+
* the global namespace.
|
|
163
|
+
*/
|
|
164
|
+
static get it(): RuleTesterTestFrameworkFunction;
|
|
165
|
+
static set it(value: RuleTesterTestFrameworkFunction | undefined);
|
|
166
|
+
/**
|
|
167
|
+
* If you supply a value to this property, the rule tester will call this instead of using the version defined on
|
|
168
|
+
* the global namespace.
|
|
169
|
+
*/
|
|
170
|
+
static get itOnly(): RuleTesterTestFrameworkFunction;
|
|
171
|
+
static set itOnly(value: RuleTesterTestFrameworkFunction | undefined);
|
|
172
|
+
/**
|
|
173
|
+
* Define a rule for one particular run of tests.
|
|
174
|
+
*/
|
|
175
|
+
defineRule<MessageIds extends string, Options extends readonly unknown[]>(name: string, rule: RuleCreateFunction<MessageIds, Options> | RuleModule<MessageIds, Options>): void;
|
|
176
|
+
}
|
|
177
|
+
declare const RuleTester_base: typeof RuleTesterBase;
|
|
178
|
+
/**
|
|
179
|
+
* @deprecated Use `@typescript-eslint/rule-tester` instead.
|
|
180
|
+
*/
|
|
181
|
+
export declare class RuleTester extends RuleTester_base {
|
|
182
|
+
}
|
|
183
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RuleTester = void 0;
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-deprecated */
|
|
5
|
+
const eslint_1 = require("eslint");
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated Use `@typescript-eslint/rule-tester` instead.
|
|
8
|
+
*/
|
|
9
|
+
class RuleTester extends eslint_1.RuleTester {
|
|
10
|
+
}
|
|
11
|
+
exports.RuleTester = RuleTester;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as scopeManager from '@typescript-eslint/scope-manager';
|
|
2
|
+
export declare namespace Scope {
|
|
3
|
+
type ScopeManager = scopeManager.ScopeManager;
|
|
4
|
+
type Reference = scopeManager.Reference;
|
|
5
|
+
type Variable = scopeManager.ScopeVariable;
|
|
6
|
+
type Scope = scopeManager.Scope;
|
|
7
|
+
const ScopeType: typeof scopeManager.ScopeType;
|
|
8
|
+
type DefinitionType = scopeManager.Definition;
|
|
9
|
+
type Definition = scopeManager.Definition;
|
|
10
|
+
const DefinitionType: typeof scopeManager.DefinitionType;
|
|
11
|
+
namespace Definitions {
|
|
12
|
+
type CatchClauseDefinition = scopeManager.CatchClauseDefinition;
|
|
13
|
+
type ClassNameDefinition = scopeManager.ClassNameDefinition;
|
|
14
|
+
type FunctionNameDefinition = scopeManager.FunctionNameDefinition;
|
|
15
|
+
type ImplicitGlobalVariableDefinition = scopeManager.ImplicitGlobalVariableDefinition;
|
|
16
|
+
type ImportBindingDefinition = scopeManager.ImportBindingDefinition;
|
|
17
|
+
type ParameterDefinition = scopeManager.ParameterDefinition;
|
|
18
|
+
type TSEnumMemberDefinition = scopeManager.TSEnumMemberDefinition;
|
|
19
|
+
type TSEnumNameDefinition = scopeManager.TSEnumNameDefinition;
|
|
20
|
+
type TSModuleNameDefinition = scopeManager.TSModuleNameDefinition;
|
|
21
|
+
type TypeDefinition = scopeManager.TypeDefinition;
|
|
22
|
+
type VariableDefinition = scopeManager.VariableDefinition;
|
|
23
|
+
}
|
|
24
|
+
namespace Scopes {
|
|
25
|
+
type BlockScope = scopeManager.BlockScope;
|
|
26
|
+
type CatchScope = scopeManager.CatchScope;
|
|
27
|
+
type ClassScope = scopeManager.ClassScope;
|
|
28
|
+
type ConditionalTypeScope = scopeManager.ConditionalTypeScope;
|
|
29
|
+
type ForScope = scopeManager.ForScope;
|
|
30
|
+
type FunctionExpressionNameScope = scopeManager.FunctionExpressionNameScope;
|
|
31
|
+
type FunctionScope = scopeManager.FunctionScope;
|
|
32
|
+
type FunctionTypeScope = scopeManager.FunctionTypeScope;
|
|
33
|
+
type GlobalScope = scopeManager.GlobalScope;
|
|
34
|
+
type MappedTypeScope = scopeManager.MappedTypeScope;
|
|
35
|
+
type ModuleScope = scopeManager.ModuleScope;
|
|
36
|
+
type SwitchScope = scopeManager.SwitchScope;
|
|
37
|
+
type TSEnumScope = scopeManager.TSEnumScope;
|
|
38
|
+
type TSModuleScope = scopeManager.TSModuleScope;
|
|
39
|
+
type TypeScope = scopeManager.TypeScope;
|
|
40
|
+
type WithScope = scopeManager.WithScope;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-namespace */
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.Scope = void 0;
|
|
38
|
+
const scopeManager = __importStar(require("@typescript-eslint/scope-manager"));
|
|
39
|
+
var Scope;
|
|
40
|
+
(function (Scope) {
|
|
41
|
+
Scope.ScopeType = scopeManager.ScopeType;
|
|
42
|
+
Scope.DefinitionType = scopeManager.DefinitionType;
|
|
43
|
+
})(Scope || (exports.Scope = Scope = {}));
|
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import type { ParserServices, TSESTree } from '../ts-estree';
|
|
2
|
+
import type { Parser } from './Parser';
|
|
3
|
+
import type { Scope } from './Scope';
|
|
4
|
+
declare class TokenStore {
|
|
5
|
+
/**
|
|
6
|
+
* Checks whether any comments exist or not between the given 2 nodes.
|
|
7
|
+
* @param left The node to check.
|
|
8
|
+
* @param right The node to check.
|
|
9
|
+
* @returns `true` if one or more comments exist.
|
|
10
|
+
*/
|
|
11
|
+
commentsExistBetween(left: TSESTree.Node | TSESTree.Token, right: TSESTree.Node | TSESTree.Token): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Gets all comment tokens directly after the given node or token.
|
|
14
|
+
* @param nodeOrToken The AST node or token to check for adjacent comment tokens.
|
|
15
|
+
* @returns An array of comments in occurrence order.
|
|
16
|
+
*/
|
|
17
|
+
getCommentsAfter(nodeOrToken: TSESTree.Node | TSESTree.Token): TSESTree.Comment[];
|
|
18
|
+
/**
|
|
19
|
+
* Gets all comment tokens directly before the given node or token.
|
|
20
|
+
* @param nodeOrToken The AST node or token to check for adjacent comment tokens.
|
|
21
|
+
* @returns An array of comments in occurrence order.
|
|
22
|
+
*/
|
|
23
|
+
getCommentsBefore(nodeOrToken: TSESTree.Node | TSESTree.Token): TSESTree.Comment[];
|
|
24
|
+
/**
|
|
25
|
+
* Gets all comment tokens inside the given node.
|
|
26
|
+
* @param node The AST node to get the comments for.
|
|
27
|
+
* @returns An array of comments in occurrence order.
|
|
28
|
+
*/
|
|
29
|
+
getCommentsInside(node: TSESTree.Node): TSESTree.Comment[];
|
|
30
|
+
/**
|
|
31
|
+
* Gets the first token of the given node.
|
|
32
|
+
* @param node The AST node.
|
|
33
|
+
* @param options The option object. If this is a number then it's `options.skip`. If this is a function then it's `options.filter`.
|
|
34
|
+
* @returns An object representing the token.
|
|
35
|
+
*/
|
|
36
|
+
getFirstToken<T extends SourceCode.CursorWithSkipOptions>(node: TSESTree.Node, options?: T): SourceCode.ReturnTypeFromOptions<T> | null;
|
|
37
|
+
/**
|
|
38
|
+
* Gets the first token between two non-overlapping nodes.
|
|
39
|
+
* @param left Node before the desired token range.
|
|
40
|
+
* @param right Node after the desired token range.
|
|
41
|
+
* @param options The option object. If this is a number then it's `options.skip`. If this is a function then it's `options.filter`.
|
|
42
|
+
* @returns An object representing the token.
|
|
43
|
+
*/
|
|
44
|
+
getFirstTokenBetween<T extends SourceCode.CursorWithSkipOptions>(left: TSESTree.Node | TSESTree.Token, right: TSESTree.Node | TSESTree.Token, options?: T): SourceCode.ReturnTypeFromOptions<T> | null;
|
|
45
|
+
/**
|
|
46
|
+
* Gets the first `count` tokens of the given node.
|
|
47
|
+
* @param node The AST node.
|
|
48
|
+
* @param options The option object. If this is a number then it's `options.count`. If this is a function then it's `options.filter`.
|
|
49
|
+
*/
|
|
50
|
+
getFirstTokens<T extends SourceCode.CursorWithCountOptions>(node: TSESTree.Node, options?: T): SourceCode.ReturnTypeFromOptions<T>[];
|
|
51
|
+
/**
|
|
52
|
+
* Gets the first `count` tokens between two non-overlapping nodes.
|
|
53
|
+
* @param left Node before the desired token range.
|
|
54
|
+
* @param right Node after the desired token range.
|
|
55
|
+
* @param options The option object. If this is a number then it's `options.count`. If this is a function then it's `options.filter`.
|
|
56
|
+
* @returns Tokens between left and right.
|
|
57
|
+
*/
|
|
58
|
+
getFirstTokensBetween<T extends SourceCode.CursorWithCountOptions>(left: TSESTree.Node | TSESTree.Token, right: TSESTree.Node | TSESTree.Token, options?: T): SourceCode.ReturnTypeFromOptions<T>[];
|
|
59
|
+
/**
|
|
60
|
+
* Gets the last token of the given node.
|
|
61
|
+
* @param node The AST node.
|
|
62
|
+
* @param options The option object. If this is a number then it's `options.skip`. If this is a function then it's `options.filter`.
|
|
63
|
+
* @returns An object representing the token.
|
|
64
|
+
*/
|
|
65
|
+
getLastToken<T extends SourceCode.CursorWithSkipOptions>(node: TSESTree.Node, options?: T): SourceCode.ReturnTypeFromOptions<T> | null;
|
|
66
|
+
/**
|
|
67
|
+
* Gets the last token between two non-overlapping nodes.
|
|
68
|
+
* @param left Node before the desired token range.
|
|
69
|
+
* @param right Node after the desired token range.
|
|
70
|
+
* @param options The option object. If this is a number then it's `options.skip`. If this is a function then it's `options.filter`.
|
|
71
|
+
* @returns An object representing the token.
|
|
72
|
+
*/
|
|
73
|
+
getLastTokenBetween<T extends SourceCode.CursorWithSkipOptions>(left: TSESTree.Node | TSESTree.Token, right: TSESTree.Node | TSESTree.Token, options?: T): SourceCode.ReturnTypeFromOptions<T> | null;
|
|
74
|
+
/**
|
|
75
|
+
* Gets the last `count` tokens of the given node.
|
|
76
|
+
* @param node The AST node.
|
|
77
|
+
* @param options The option object. If this is a number then it's `options.count`. If this is a function then it's `options.filter`.
|
|
78
|
+
*/
|
|
79
|
+
getLastTokens<T extends SourceCode.CursorWithCountOptions>(node: TSESTree.Node, options?: T): SourceCode.ReturnTypeFromOptions<T>[];
|
|
80
|
+
/**
|
|
81
|
+
* Gets the last `count` tokens between two non-overlapping nodes.
|
|
82
|
+
* @param left Node before the desired token range.
|
|
83
|
+
* @param right Node after the desired token range.
|
|
84
|
+
* @param options The option object. If this is a number then it's `options.count`. If this is a function then it's `options.filter`.
|
|
85
|
+
* @returns Tokens between left and right.
|
|
86
|
+
*/
|
|
87
|
+
getLastTokensBetween<T extends SourceCode.CursorWithCountOptions>(left: TSESTree.Node | TSESTree.Token, right: TSESTree.Node | TSESTree.Token, options?: T): SourceCode.ReturnTypeFromOptions<T>[];
|
|
88
|
+
/**
|
|
89
|
+
* Gets the token that follows a given node or token.
|
|
90
|
+
* @param node The AST node or token.
|
|
91
|
+
* @param options The option object. If this is a number then it's `options.skip`. If this is a function then it's `options.filter`.
|
|
92
|
+
* @returns An object representing the token.
|
|
93
|
+
*/
|
|
94
|
+
getTokenAfter<T extends SourceCode.CursorWithSkipOptions>(node: TSESTree.Node | TSESTree.Token, options?: T): SourceCode.ReturnTypeFromOptions<T> | null;
|
|
95
|
+
/**
|
|
96
|
+
* Gets the token that precedes a given node or token.
|
|
97
|
+
* @param node The AST node or token.
|
|
98
|
+
* @param options The option object
|
|
99
|
+
* @returns An object representing the token.
|
|
100
|
+
*/
|
|
101
|
+
getTokenBefore<T extends SourceCode.CursorWithSkipOptions>(node: TSESTree.Node | TSESTree.Token, options?: T): SourceCode.ReturnTypeFromOptions<T> | null;
|
|
102
|
+
/**
|
|
103
|
+
* Gets the token starting at the specified index.
|
|
104
|
+
* @param offset Index of the start of the token's range.
|
|
105
|
+
* @param options The option object. If this is a number then it's `options.skip`. If this is a function then it's `options.filter`.
|
|
106
|
+
* @returns The token starting at index, or null if no such token.
|
|
107
|
+
*/
|
|
108
|
+
getTokenByRangeStart<T extends {
|
|
109
|
+
includeComments?: boolean;
|
|
110
|
+
}>(offset: number, options?: T): SourceCode.ReturnTypeFromOptions<T> | null;
|
|
111
|
+
/**
|
|
112
|
+
* Gets all tokens that are related to the given node.
|
|
113
|
+
* @param node The AST node.
|
|
114
|
+
* @param beforeCount The number of tokens before the node to retrieve.
|
|
115
|
+
* @param afterCount The number of tokens after the node to retrieve.
|
|
116
|
+
* @returns Array of objects representing tokens.
|
|
117
|
+
*/
|
|
118
|
+
getTokens(node: TSESTree.Node, beforeCount?: number, afterCount?: number): TSESTree.Token[];
|
|
119
|
+
/**
|
|
120
|
+
* Gets all tokens that are related to the given node.
|
|
121
|
+
* @param node The AST node.
|
|
122
|
+
* @param options The option object. If this is a function then it's `options.filter`.
|
|
123
|
+
* @returns Array of objects representing tokens.
|
|
124
|
+
*/
|
|
125
|
+
getTokens<T extends SourceCode.CursorWithCountOptions>(node: TSESTree.Node, options: T): SourceCode.ReturnTypeFromOptions<T>[];
|
|
126
|
+
/**
|
|
127
|
+
* Gets the `count` tokens that follows a given node or token.
|
|
128
|
+
* @param node The AST node.
|
|
129
|
+
* @param options The option object. If this is a number then it's `options.count`. If this is a function then it's `options.filter`.
|
|
130
|
+
*/
|
|
131
|
+
getTokensAfter<T extends SourceCode.CursorWithCountOptions>(node: TSESTree.Node | TSESTree.Token, options?: number | T): SourceCode.ReturnTypeFromOptions<T>[];
|
|
132
|
+
/**
|
|
133
|
+
* Gets the `count` tokens that precedes a given node or token.
|
|
134
|
+
* @param node The AST node.
|
|
135
|
+
* @param options The option object. If this is a number then it's `options.count`. If this is a function then it's `options.filter`.
|
|
136
|
+
*/
|
|
137
|
+
getTokensBefore<T extends SourceCode.CursorWithCountOptions>(node: TSESTree.Node | TSESTree.Token, options?: number | T): SourceCode.ReturnTypeFromOptions<T>[];
|
|
138
|
+
/**
|
|
139
|
+
* Gets all of the tokens between two non-overlapping nodes.
|
|
140
|
+
* @param left Node before the desired token range.
|
|
141
|
+
* @param right Node after the desired token range.
|
|
142
|
+
* @param options The option object. If this is a number then it's `options.count`. If this is a function then it's `options.filter`.
|
|
143
|
+
* @returns Tokens between left and right.
|
|
144
|
+
*/
|
|
145
|
+
getTokensBetween<T extends SourceCode.CursorWithCountOptions>(left: TSESTree.Node | TSESTree.Token, right: TSESTree.Node | TSESTree.Token, options?: number | T): SourceCode.ReturnTypeFromOptions<T>[];
|
|
146
|
+
}
|
|
147
|
+
declare class SourceCodeBase extends TokenStore {
|
|
148
|
+
/**
|
|
149
|
+
* Represents parsed source code.
|
|
150
|
+
* @param ast The Program node of the AST representing the code. This AST should be created from the text that BOM was stripped.
|
|
151
|
+
*/
|
|
152
|
+
constructor(text: string, ast: SourceCode.Program);
|
|
153
|
+
/**
|
|
154
|
+
* Represents parsed source code.
|
|
155
|
+
* @param config The config object.
|
|
156
|
+
*/
|
|
157
|
+
constructor(config: SourceCode.SourceCodeConfig);
|
|
158
|
+
/**
|
|
159
|
+
* The parsed AST for the source code.
|
|
160
|
+
*/
|
|
161
|
+
ast: SourceCode.Program;
|
|
162
|
+
applyInlineConfig(): void;
|
|
163
|
+
applyLanguageOptions(): void;
|
|
164
|
+
finalize(): void;
|
|
165
|
+
/**
|
|
166
|
+
* Retrieves an array containing all comments in the source code.
|
|
167
|
+
* @returns An array of comment nodes.
|
|
168
|
+
*/
|
|
169
|
+
getAllComments(): TSESTree.Comment[];
|
|
170
|
+
/**
|
|
171
|
+
* Converts a (line, column) pair into a range index.
|
|
172
|
+
* @param location A line/column location
|
|
173
|
+
* @returns The range index of the location in the file.
|
|
174
|
+
*/
|
|
175
|
+
getIndexFromLoc(location: TSESTree.Position): number;
|
|
176
|
+
/**
|
|
177
|
+
* Gets the entire source text split into an array of lines.
|
|
178
|
+
* @returns The source text as an array of lines.
|
|
179
|
+
*/
|
|
180
|
+
getLines(): string[];
|
|
181
|
+
/**
|
|
182
|
+
* Converts a source text index into a (line, column) pair.
|
|
183
|
+
* @param index The index of a character in a file
|
|
184
|
+
* @returns A {line, column} location object with a 0-indexed column
|
|
185
|
+
*/
|
|
186
|
+
getLocFromIndex(index: number): TSESTree.Position;
|
|
187
|
+
/**
|
|
188
|
+
* Gets the deepest node containing a range index.
|
|
189
|
+
* @param index Range index of the desired node.
|
|
190
|
+
* @returns The node if found or `null` if not found.
|
|
191
|
+
*/
|
|
192
|
+
getNodeByRangeIndex(index: number): TSESTree.Node | null;
|
|
193
|
+
/**
|
|
194
|
+
* Gets the source code for the given node.
|
|
195
|
+
* @param node The AST node to get the text for.
|
|
196
|
+
* @param beforeCount The number of characters before the node to retrieve.
|
|
197
|
+
* @param afterCount The number of characters after the node to retrieve.
|
|
198
|
+
* @returns The text representing the AST node.
|
|
199
|
+
*/
|
|
200
|
+
getText(node?: TSESTree.Node | TSESTree.Token, beforeCount?: number, afterCount?: number): string;
|
|
201
|
+
/**
|
|
202
|
+
* The flag to indicate that the source code has Unicode BOM.
|
|
203
|
+
*/
|
|
204
|
+
hasBOM: boolean;
|
|
205
|
+
/**
|
|
206
|
+
* Determines if two nodes or tokens have at least one whitespace character
|
|
207
|
+
* between them. Order does not matter. Returns false if the given nodes or
|
|
208
|
+
* tokens overlap.
|
|
209
|
+
* @param first The first node or token to check between.
|
|
210
|
+
* @param second The second node or token to check between.
|
|
211
|
+
* @returns True if there is a whitespace character between any of the tokens found between the two given nodes or tokens.
|
|
212
|
+
*/
|
|
213
|
+
isSpaceBetween(first: TSESTree.Node | TSESTree.Token, second: TSESTree.Node | TSESTree.Token): boolean;
|
|
214
|
+
/**
|
|
215
|
+
* Determines if two nodes or tokens have at least one whitespace character
|
|
216
|
+
* between them. Order does not matter. Returns false if the given nodes or
|
|
217
|
+
* tokens overlap.
|
|
218
|
+
* For backward compatibility, this method returns true if there are
|
|
219
|
+
* `JSXText` tokens that contain whitespace between the two.
|
|
220
|
+
* @param first The first node or token to check between.
|
|
221
|
+
* @param second The second node or token to check between.
|
|
222
|
+
* @returns {boolean} True if there is a whitespace character between
|
|
223
|
+
* any of the tokens found between the two given nodes or tokens.
|
|
224
|
+
* @deprecated in favor of isSpaceBetween
|
|
225
|
+
*/
|
|
226
|
+
isSpaceBetweenTokens(first: TSESTree.Token, second: TSESTree.Token): boolean;
|
|
227
|
+
/**
|
|
228
|
+
* Returns the scope of the given node.
|
|
229
|
+
* This information can be used track references to variables.
|
|
230
|
+
*/
|
|
231
|
+
getScope(node: TSESTree.Node): Scope.Scope;
|
|
232
|
+
/**
|
|
233
|
+
* Returns an array of the ancestors of the given node, starting at
|
|
234
|
+
* the root of the AST and continuing through the direct parent of the current node.
|
|
235
|
+
* This array does not include the currently-traversed node itself.
|
|
236
|
+
*/
|
|
237
|
+
getAncestors(node: TSESTree.Node): TSESTree.Node[];
|
|
238
|
+
/**
|
|
239
|
+
* Returns a list of variables declared by the given node.
|
|
240
|
+
* This information can be used to track references to variables.
|
|
241
|
+
*/
|
|
242
|
+
getDeclaredVariables(node: TSESTree.Node): readonly Scope.Variable[];
|
|
243
|
+
/**
|
|
244
|
+
* Marks a variable with the given name in the current scope as used.
|
|
245
|
+
* This affects the no-unused-vars rule.
|
|
246
|
+
*/
|
|
247
|
+
markVariableAsUsed(name: string, node: TSESTree.Node): boolean;
|
|
248
|
+
/**
|
|
249
|
+
* The source code split into lines according to ECMA-262 specification.
|
|
250
|
+
* This is done to avoid each rule needing to do so separately.
|
|
251
|
+
*/
|
|
252
|
+
lines: string[];
|
|
253
|
+
/**
|
|
254
|
+
* The indexes in `text` that each line starts
|
|
255
|
+
*/
|
|
256
|
+
lineStartIndices: number[];
|
|
257
|
+
/**
|
|
258
|
+
* The parser services of this source code.
|
|
259
|
+
*/
|
|
260
|
+
parserServices?: Partial<ParserServices>;
|
|
261
|
+
/**
|
|
262
|
+
* The scope of this source code.
|
|
263
|
+
*/
|
|
264
|
+
scopeManager: Scope.ScopeManager | null;
|
|
265
|
+
/**
|
|
266
|
+
* The original text source code. BOM was stripped from this text.
|
|
267
|
+
*/
|
|
268
|
+
text: string;
|
|
269
|
+
/**
|
|
270
|
+
* All of the tokens and comments in the AST.
|
|
271
|
+
*
|
|
272
|
+
* TODO: rename to 'tokens'
|
|
273
|
+
*/
|
|
274
|
+
tokensAndComments: TSESTree.Token[];
|
|
275
|
+
/**
|
|
276
|
+
* The visitor keys to traverse AST.
|
|
277
|
+
*/
|
|
278
|
+
visitorKeys: SourceCode.VisitorKeys;
|
|
279
|
+
/**
|
|
280
|
+
* Split the source code into multiple lines based on the line delimiters.
|
|
281
|
+
* @param text Source code as a string.
|
|
282
|
+
* @returns Array of source code lines.
|
|
283
|
+
*/
|
|
284
|
+
static splitLines(text: string): string[];
|
|
285
|
+
}
|
|
286
|
+
declare namespace SourceCode {
|
|
287
|
+
interface Program extends TSESTree.Program {
|
|
288
|
+
comments: TSESTree.Comment[];
|
|
289
|
+
tokens: TSESTree.Token[];
|
|
290
|
+
}
|
|
291
|
+
interface SourceCodeConfig {
|
|
292
|
+
/**
|
|
293
|
+
* The Program node of the AST representing the code. This AST should be created from the text that BOM was stripped.
|
|
294
|
+
*/
|
|
295
|
+
ast: Program;
|
|
296
|
+
/**
|
|
297
|
+
* The parser services.
|
|
298
|
+
*/
|
|
299
|
+
parserServices: ParserServices | null;
|
|
300
|
+
/**
|
|
301
|
+
* The scope of this source code.
|
|
302
|
+
*/
|
|
303
|
+
scopeManager: Scope.ScopeManager | null;
|
|
304
|
+
/**
|
|
305
|
+
* The source code text.
|
|
306
|
+
*/
|
|
307
|
+
text: string;
|
|
308
|
+
/**
|
|
309
|
+
* The visitor keys to traverse AST.
|
|
310
|
+
*/
|
|
311
|
+
visitorKeys: VisitorKeys | null;
|
|
312
|
+
}
|
|
313
|
+
type VisitorKeys = Parser.VisitorKeys;
|
|
314
|
+
type FilterPredicate = (token: TSESTree.Token) => boolean;
|
|
315
|
+
type GetFilterPredicate<Filter, Default> = Filter extends ((token: TSESTree.Token) => token is infer U extends TSESTree.Token) ? U : Default;
|
|
316
|
+
type GetFilterPredicateFromOptions<Options, Default> = Options extends {
|
|
317
|
+
filter?: FilterPredicate;
|
|
318
|
+
} ? GetFilterPredicate<Options['filter'], Default> : GetFilterPredicate<Options, Default>;
|
|
319
|
+
type ReturnTypeFromOptions<T> = T extends {
|
|
320
|
+
includeComments: true;
|
|
321
|
+
} ? GetFilterPredicateFromOptions<T, TSESTree.Token> : GetFilterPredicateFromOptions<T, Exclude<TSESTree.Token, TSESTree.Comment>>;
|
|
322
|
+
type CursorWithSkipOptions = number | FilterPredicate | {
|
|
323
|
+
/**
|
|
324
|
+
* The predicate function to choose tokens.
|
|
325
|
+
*/
|
|
326
|
+
filter?: FilterPredicate;
|
|
327
|
+
/**
|
|
328
|
+
* The flag to iterate comments as well.
|
|
329
|
+
*/
|
|
330
|
+
includeComments?: boolean;
|
|
331
|
+
/**
|
|
332
|
+
* The count of tokens the cursor skips.
|
|
333
|
+
*/
|
|
334
|
+
skip?: number;
|
|
335
|
+
};
|
|
336
|
+
type CursorWithCountOptions = number | FilterPredicate | {
|
|
337
|
+
/**
|
|
338
|
+
* The maximum count of tokens the cursor iterates.
|
|
339
|
+
*/
|
|
340
|
+
count?: number;
|
|
341
|
+
/**
|
|
342
|
+
* The predicate function to choose tokens.
|
|
343
|
+
*/
|
|
344
|
+
filter?: FilterPredicate;
|
|
345
|
+
/**
|
|
346
|
+
* The flag to iterate comments as well.
|
|
347
|
+
*/
|
|
348
|
+
includeComments?: boolean;
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
declare const SourceCode_base: typeof SourceCodeBase;
|
|
352
|
+
declare class SourceCode extends SourceCode_base {
|
|
353
|
+
}
|
|
354
|
+
export { SourceCode };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-namespace, no-restricted-syntax */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.SourceCode = void 0;
|
|
5
|
+
const eslint_1 = require("eslint");
|
|
6
|
+
class SourceCode extends eslint_1.SourceCode {
|
|
7
|
+
}
|
|
8
|
+
exports.SourceCode = SourceCode;
|