ota-meshi / typescript-eslint-parser-for-extra-files

An experimental ESLint custom parser for Vue, Svelte, and Astro for use with TypeScript. It provides type information in combination with each framework's ESLint custom parser.
MIT License
43 stars 1 forks source link

typescript-parser is not changed in flat config #95

Open appano1 opened 7 months ago

appano1 commented 7 months ago

Before You File a Bug Report Please Confirm You Have Done The Following...

What version of ESLint are you using?

8.57.0

What version of typescript-eslint-parser-for-extra-files are you using?

What did you do?

Configuration ``` import tsParser from "typescript-eslint-parser-for-extra-files"; import vueParser from "vue-eslint-parser"; [ ...tseslint.configs.recommended, { languageOptions: { parser: tsParser, }, }, { files: ["**/*.vue"], languageOptions: { parser: vueParser, parserOptions: { parser: tsParser, }, }, }, ] ```

What did you expect to happen?

When I set the config with flat config with typescript-eslint, I expected that typescript eslint will uses typescript-eslint-parser-for-extra-files.

What actually happened?

But actually, it seems that tyepscript-eslint uses it's own parser. I don't know why the following configs don't override parser.

https://github.com/typescript-eslint/typescript-eslint/blob/6e29721d699f8c62e23f39b9f07cf928108adfac/packages/typescript-eslint/src/index.ts#L31-L45

Link to GitHub Repo with Minimal Reproducible Example

https://github.com/appano1/parser-in-flat-config

Additional comments

I think some limitations need to be added in README.md or creating a configuration builder need to be added

appano1 commented 6 months ago

Oh sorry my link was wrong. I've edited the link now.

pboling commented 6 months ago

I am having the same or similar issue with flat config. Does this project work with flat config? All the docs use legacy cofnig.

n0099 commented 4 months ago

When using flat config, packages @typescript-eslint/{parser,eslint-plugin} should be replaced by the merged typescript-eslint since they only provide flat .configs in that package: https://github.com/typescript-eslint/typescript-eslint/pull/7935

But typescript-eslint-parser-for-extra-files is still using @typescript-eslint/{parser,eslint-plugin} when the user only have typescript-eslint leading to cannot resolve these packages.

So currently we may only use @eslint/eslintrc: https://eslint.org/blog/2024/05/eslint-compatibility-utilities/

import { FlatCompat } from '@eslint/eslintrc';

const compat = new FlatCompat();

export default [
    ...compat.extends( // https://github.com/ota-meshi/typescript-eslint-parser-for-extra-files/issues/95
        'plugin:@typescript-eslint/strict-type-checked',
        'plugin:@typescript-eslint/stylistic-type-checked',
    ),
    {
        files: ['**/*.ts'],
        languageOptions: { parser: typescriptESLintParserForExtraFiles },
    },
    {
        files: ['**/*.vue'],
        languageOptions: {
            parser: vueESLintParser,
            parserOptions: {
                parser: typescriptESLintParserForExtraFiles,
                project: ['./tsconfig.json', './tsconfig.node.json'],
                tsconfigRootDir: import.meta.dirname,
            },
        },
    },
];
liuzw2579 commented 2 months ago

Seems change tsEslintParser import package, can fix it... I use it in eslint v9 success.

- import * as tsEslintParser from "@typescript-eslint/parser";
+ import { parser as tsEslintParser } from 'typescript-eslint'

image