UNPKG

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