UNPKG

9.16 kBTypeScriptView Raw
1import type { CacheDurationSeconds, DebugLevel, JSDocParsingMode, ProjectServiceOptions } from '@typescript-eslint/types';
2import type * as ts from 'typescript';
3import type { TSESTree, TSESTreeToTSNode, TSNode, TSToken } from './ts-estree';
4export { ProjectServiceOptions } from '@typescript-eslint/types';
5interface ParseOptions {
6 /**
7 * Prevents the parser from throwing an error if it receives an invalid AST from TypeScript.
8 * This case only usually occurs when attempting to lint invalid code.
9 */
10 allowInvalidAST?: boolean;
11 /**
12 * create a top-level comments array containing all comments
13 */
14 comment?: boolean;
15 /**
16 * An array of modules to turn explicit debugging on for.
17 * - 'typescript-eslint' is the same as setting the env var `DEBUG=typescript-eslint:*`
18 * - 'eslint' is the same as setting the env var `DEBUG=eslint:*`
19 * - 'typescript' is the same as setting `extendedDiagnostics: true` in your tsconfig compilerOptions
20 *
21 * For convenience, also supports a boolean:
22 * - true === ['typescript-eslint']
23 * - false === []
24 */
25 debugLevel?: DebugLevel;
26 /**
27 * Cause the parser to error if it encounters an unknown AST node type (useful for testing).
28 * This case only usually occurs when TypeScript releases new features.
29 */
30 errorOnUnknownASTType?: boolean;
31 /**
32 * Absolute (or relative to `cwd`) path to the file being parsed.
33 */
34 filePath?: string;
35 /**
36 * If you are using TypeScript version >=5.3 then this option can be used as a performance optimization.
37 *
38 * The valid values for this rule are:
39 * - `'all'` - parse all JSDoc comments, always.
40 * - `'none'` - parse no JSDoc comments, ever.
41 * - `'type-info'` - parse just JSDoc comments that are required to provide correct type-info. TS will always parse JSDoc in non-TS files, but never in TS files.
42 *
43 * If you do not rely on JSDoc tags from the TypeScript AST, then you can safely set this to `'none'` to improve performance.
44 */
45 jsDocParsingMode?: JSDocParsingMode;
46 /**
47 * Enable parsing of JSX.
48 * For more details, see https://www.typescriptlang.org/docs/handbook/jsx.html
49 *
50 * NOTE: this setting does not effect known file types (.js, .cjs, .mjs, .jsx, .ts, .mts, .cts, .tsx, .json) because the
51 * TypeScript compiler has its own internal handling for known file extensions.
52 *
53 * For the exact behavior, see https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/parser#parseroptionsecmafeaturesjsx
54 */
55 jsx?: boolean;
56 /**
57 * Controls whether the `loc` information to each node.
58 * The `loc` property is an object which contains the exact line/column the node starts/ends on.
59 * This is similar to the `range` property, except it is line/column relative.
60 */
61 loc?: boolean;
62 loggerFn?: false | ((message: string) => void);
63 /**
64 * Controls whether the `range` property is included on AST nodes.
65 * The `range` property is a [number, number] which indicates the start/end index of the node in the file contents.
66 * This is similar to the `loc` property, except this is the absolute index.
67 */
68 range?: boolean;
69 /**
70 * Set to true to create a top-level array containing all tokens from the file.
71 */
72 tokens?: boolean;
73 /**
74 * Whether deprecated AST properties should skip calling console.warn on accesses.
75 */
76 suppressDeprecatedPropertyWarnings?: boolean;
77}
78interface ParseAndGenerateServicesOptions extends ParseOptions {
79 /**
80 * Granular control of the expiry lifetime of our internal caches.
81 * You can specify the number of seconds as an integer number, or the string
82 * 'Infinity' if you never want the cache to expire.
83 *
84 * By default cache entries will be evicted after 30 seconds, or will persist
85 * indefinitely if `disallowAutomaticSingleRunInference = false` AND the parser
86 * infers that it is a single run.
87 */
88 cacheLifetime?: {
89 /**
90 * Glob resolution for `parserOptions.project` values.
91 */
92 glob?: CacheDurationSeconds;
93 };
94 /**
95 * ESLint (and therefore typescript-eslint) is used in both "single run"/one-time contexts,
96 * such as an ESLint CLI invocation, and long-running sessions (such as continuous feedback
97 * on a file in an IDE).
98 *
99 * When typescript-eslint handles TypeScript Program management behind the scenes, this distinction
100 * is important because there is significant overhead to managing the so called Watch Programs
101 * needed for the long-running use-case.
102 *
103 * By default, we will use common heuristics to infer whether ESLint is being
104 * used as part of a single run. This option disables those heuristics, and
105 * therefore the performance optimizations gained by them.
106 *
107 * In other words, typescript-eslint is faster by default, and this option
108 * disables an automatic performance optimization.
109 *
110 * This setting's default value can be specified by setting a `TSESTREE_SINGLE_RUN`
111 * environment variable to `"false"` or `"true"`.
112 * Otherwise, the default value is `false`.
113 */
114 disallowAutomaticSingleRunInference?: boolean;
115 /**
116 * Causes the parser to error if the TypeScript compiler returns any unexpected syntax/semantic errors.
117 */
118 errorOnTypeScriptSyntacticAndSemanticIssues?: boolean;
119 /**
120 * When `project` is provided, this controls the non-standard file extensions which will be parsed.
121 * It accepts an array of file extensions, each preceded by a `.`.
122 *
123 * NOTE: When used with {@link projectService}, full project reloads may occur.
124 */
125 extraFileExtensions?: string[];
126 /**
127 * Absolute (or relative to `tsconfigRootDir`) path to the file being parsed.
128 * When `project` is provided, this is required, as it is used to fetch the file from the TypeScript compiler's cache.
129 */
130 filePath?: string;
131 /**
132 * Allows the user to control whether or not two-way AST node maps are preserved
133 * during the AST conversion process.
134 *
135 * By default: the AST node maps are NOT preserved, unless `project` has been specified,
136 * in which case the maps are made available on the returned `parserServices`.
137 *
138 * NOTE: If `preserveNodeMaps` is explicitly set by the user, it will be respected,
139 * regardless of whether or not `project` is in use.
140 */
141 preserveNodeMaps?: boolean;
142 /**
143 * Absolute (or relative to `tsconfigRootDir`) paths to the tsconfig(s),
144 * or `true` to find the nearest tsconfig.json to the file.
145 * If this is provided, type information will be returned.
146 *
147 * If set to `false`, `null` or `undefined` type information will not be returned.
148 *
149 * Note that {@link projectService} is now preferred.
150 */
151 project?: string[] | string | boolean | null;
152 /**
153 * If you provide a glob (or globs) to the project option, you can use this option to ignore certain folders from
154 * being matched by the globs.
155 * This accepts an array of globs to ignore.
156 *
157 * By default, this is set to ["**\/node_modules/**"]
158 */
159 projectFolderIgnoreList?: string[];
160 /**
161 * Whether to create a shared TypeScript project service to power program creation.
162 */
163 projectService?: boolean | ProjectServiceOptions;
164 /**
165 * The absolute path to the root directory for all provided `project`s.
166 */
167 tsconfigRootDir?: string;
168 /**
169 * An array of one or more instances of TypeScript Program objects to be used for type information.
170 * This overrides any program or programs that would have been computed from the `project` option.
171 * All linted files must be part of the provided program(s).
172 */
173 programs?: ts.Program[] | null;
174}
175export type TSESTreeOptions = ParseAndGenerateServicesOptions;
176export interface ParserWeakMap<Key, ValueBase> {
177 get<Value extends ValueBase>(key: Key): Value;
178 has(key: unknown): boolean;
179}
180export interface ParserWeakMapESTreeToTSNode<Key extends TSESTree.Node = TSESTree.Node> {
181 get<KeyBase extends Key>(key: KeyBase): TSESTreeToTSNode<KeyBase>;
182 has(key: unknown): boolean;
183}
184export interface ParserServicesBase {
185 emitDecoratorMetadata: boolean | undefined;
186 experimentalDecorators: boolean | undefined;
187}
188export interface ParserServicesNodeMaps {
189 esTreeNodeToTSNodeMap: ParserWeakMapESTreeToTSNode;
190 tsNodeToESTreeNodeMap: ParserWeakMap<TSNode | TSToken, TSESTree.Node>;
191}
192export interface ParserServicesWithTypeInformation extends ParserServicesNodeMaps, ParserServicesBase {
193 program: ts.Program;
194 getSymbolAtLocation: (node: TSESTree.Node) => ts.Symbol | undefined;
195 getTypeAtLocation: (node: TSESTree.Node) => ts.Type;
196}
197export interface ParserServicesWithoutTypeInformation extends ParserServicesNodeMaps, ParserServicesBase {
198 program: null;
199}
200export type ParserServices = ParserServicesWithoutTypeInformation | ParserServicesWithTypeInformation;
201//# sourceMappingURL=parser-options.d.ts.map
\No newline at end of file