What's up with the two parserOptions
?
#6830
Replies: 4 comments 3 replies
-
Some context: @Jutanium and I paired on Twitch to set up a new Astro+Solid+TypeScript project with linting. The typescript-eslint setup steps were mostly smooth until Typed Linting (#6826, #6828). This was another issue we had that I asked Dan to start as a discussion here: the two config values weren't intuitive in our pair, and I think it'd be good to discuss if we can make it simpler and/or more obvious what things do. For example, if the user specifies |
Beta Was this translation helpful? Give feedback.
-
Why are there two? Well until a month or so ago you had no option but to tell us the explicit paths to your tsconfig(s). Unfortunately ESLint doesn't tell the parser the path to the config file for various reasons [1] so the only paths we explicitly know about are (1) the CWD and (2) the path to the file currently being linted. (2) is obviously useless as a marker to resolve a relative path against so we have to leverage (1) the CWD. The problem you run into is that the CWD is dynamic! It's not uncommon to Why do we allow relative paths at all? A few reasons reasons:
With the new Worth noting that you may not realise it but there's actually THREE parser options for type-aware linting - the third being I don't think there's many (if any) people that change this from its default of "ignore [1] reasons ESLint doesn't tell the parser about the config file path:
The cascading and overriding means that ultimately ESLint does not keep track of where the final value for each property came from - it just knows the final value. So knowing one of the possible config paths is technically meaningless in the world of ESLint! |
Beta Was this translation helpful? Give feedback.
-
Some fun facts on the history of the names - you can trace the names
|
Beta Was this translation helpful? Give feedback.
-
In regards to the best path forwards...
Personally I don't think we should make such a change - I think people should always provide We do have If I had to specify a "north star" - I would probably want to introduce a state like this to group the config: type Path = RelativePath | AbsolutePath | GlobPath;
interface ExplicitProjectConfig {
/** Paths to the tsconfigs to explicitly load for type information */
tsconfigPaths: Path[];
/** Paths to ignore when resolving globs from `tsconfigPaths` */
globIgnoreList?: Path[];
/** Absolute path to the project root to use when resolving relative paths */
relativeRootDir?: AbsolutePath;
}
interface AutomaticProjectConfig {
/** Explicitly opt-in to the automatic resolution and also a disjoin union field??? */
automatic: true;
/** Absolute path to the project root to stop traversing at when looking for tsconfigs */
traversalRootDir: AbsolutePath;
}
interface ParserOptions {
/**
* `null` allows people to explicitly opt folders out of type-aware linting
* for specific paths. It allows users to write configs as "type-aware-first" and
* have non-type-aware linting being the edge case applied via `overrides` by
* the config `plugin:@typescript-eslint/disable-type-checked`
*/
project: ExplicitProjectConfig | AutomaticProjectConfig | null;
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm new to ESLint. There appear to be two
parserOptions
, one of which is often redundant.If I set
tsconfigRootDir
to a directory, ESLint knows where to find my project. Why should I setproject
?As a side note,
project
is an ambiguous name - what kind of project? What kind of value? (The possibletrue
value makes this even more confusing.)Beta Was this translation helpful? Give feedback.
All reactions