New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: ESLint parser and plugin have wrong types for programatic use in ESLint flat config #7494
Comments
We don't officially support flat configs yet - they aren't truly production ready and there are various issues for us to add support for them that the ESLint team has yet to resolve and document. Once the system is more stable and the ESLint team has solved the backwards-compatibility problem, we'll look to supporting things. Rest assured that we are talking and working with the ESLint team as best we can to progress things. It is expected that the types are incorrect. This is also why we explicitly provide our own types for This isn't an "us vs them" or a "we don't want to worry about DefinitelyTyped" attitude - this is just a reality of working within the limitations of TS - our hands are just tied. Once we add support for flat config types (#7273) then you can use our types instead and things should work then. Though note that the types aren't us supporting flat configs as I mentioned above. |
Is the TypeScript ESLint AST a superset of the ESTree one? Then maybe the Or maybe the types for ESLint configs and plugins should not try to make assumptions about the AST produced by parsers at all. The ESLint config types need to account for being able to have different parsers and ASTs accordingly for different files within a single config. Does the flat config types in #7273 account for that, or does it assume every file, plugin, and rule is using the AST from the TypeScript parser? I still disagree that it's ok to pretend that It's hard to accept the premise that no types in If For example, look at the interface LintResult {
filePath: string;
messages: Linter.LintMessage[];
suppressedMessages: Linter.SuppressedLintMessage[];
errorCount: number;
fatalErrorCount: number;
warningCount: number;
fixableErrorCount: number;
fixableWarningCount: number;
output?: string | undefined;
source?: string | undefined;
usedDeprecatedRules: DeprecatedRuleUse[];
} I can't see TypeScript AST specific things in there (even if there was, the AST types could be passed in by adding some generic args). Compare the exact same interface in TypeScript ESLint: typescript-eslint/packages/utils/src/ts-eslint/ESLint.ts Lines 212 to 265 in 951a3bb
It's got nice JSDoc descriptions of every property for good intellisense. None of that quality has been contributed to the wider ESLint ecosystem. |
Here is an example where Microsoft is not contributing type fixes for ESLint to the wider ecosystem in I had to fix DefinitelyTyped/DefinitelyTyped#62941 The ESLint types maintained internally in the TypeScript ESLint project had that value for the last 2 years, and didn't contribute the better types for the wider ecosystem:
|
Note that this project is not affiliated with (or even sponsored by) Microsoft. The reason that we cannot just augment
This is also why you can't easily define
Right now we haven't really thought too deeply about the usecase of a truly strictly typed config. Most users aren't looking for strictly typed configs given ESLint config files are required to be It's entirely possible we could reuse some parts of DefinitelyTyped isn't designed in a way that allows you to break up a package - each So why didn't we contribute our types upstream to Any community member has been free to contribute our types to the DT repo - but nobody has been so motivated to volunteer their time either. Everything is maintained by volunteers and as such people put there time where they see the most value, and nobody has seen enough value. If you see such value - you're welcome and encouraged to contribute our improvements! Be the change you want to see! |
It's worth noting that you're coming into this from the fresh perspective of a user who has run into troubles with types for a brand new, not-ready-for-production feature. However this is the first time in the ecosystem that people have actively needed to import and pass a parser, a plugin OR a shared config somewhere. Previously (for the entire lifetime of ESLint) it was taboo to explicitly import/require a parser or plugin directly and instead all the importing was done by ESLint itself via the paths or identifiers you pass. As such our approach suited the ecosystem well! From the perspective of a consumer of the ESLint types:
This is the first time ever that parsers, plugins and configs have had to even consider the types that they export. It's a big turning point in the ecosystem. As I mentioned - we haven't moved to land support for flat configs yet on purpose because they are not production ready, nor are they officially released. There is still a lot the ESLint team need to do to get them to a good state for project like ours to add support. This is a space that's actively being explored and worked on as our limited volunteer time dictates. |
Again - Microsoft is in no way affiliated with this project. This is a purely community maintained project. We have docs on how to build rules using our tooling. These docs explicitly warn against using the We have published our own types and tooling for writing rules in typescript for typescript as far back as 4 years ago (#425). I'm sorry that you're having a bad time with the At this point your tone and language are very hostile and as a volunteer maintainer I'm no longer going to engage in this, so I'm going to end this discussion here. |
Before You File a Bug Report Please Confirm You Have Done The Following...
Relevant Package
Playground Link
No response
Repro Code
ESLint has a new “flat” config system:
Unfortunately, when attempting to import and use the TypeScript ESLint plugin and parser within the ESLint config of type
import("eslint").Linter.FlatConfig
they result in TypeScript errors.In
eslint.config.js
:ESLint Config
No response
tsconfig
No response
Expected Result
The TypeScript ESLint plugin and parser should be usable within ESLint “flat” config of type
import("eslint").Linter.FlatConfig
without causing TypeScript errors.Actual Result
The
languageOptions.parser
has this TypeScript error:The
plugins["@typescript-eslint"]
has this TypeScript error:Additional Info
The TypeScript ESLint project should be using the same ESLint types from
@types/eslint
like the rest of the ecosystem is using, instead of internally maintaining separate types. Where there are problems with the@types/eslint
types they should be fixed in contributions so the entire ecosystem benefits.This attitude is upsetting:
typescript-eslint/packages/utils/typings/eslint.d.ts
Lines 1 to 6 in 951a3bb
I have run into frustrations before because Microsoft have not been participating in contributing to the main ESLint types the community is using, and as a consequence they are of poor quality.
Versions
@typescript-eslint/eslint-plugin
6.4.0
@typescript-eslint/parser
6.4.0
TypeScript
5.1.6
ESLint
8.47.0
node
20.5.0
The text was updated successfully, but these errors were encountered: