import-js / eslint-plugin-import

ESLint plugin with rules that help validate proper imports.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improve the way to find tsconfig.json

shiyangzhaoa opened this issue · comments

commented

I have a monorepo project, and its structure looks like this:

monorepo
├── packages
│  ├── packageA
│  └── packageB
└── index.mjs

I want to run the eslint command in the root directory, like:

const eslint = new ESLint({
    cwd: '/workspace/monorepo/packages/packageA',
    extensions: ['.ts', '.tsx', '.mts', '.cts'],
});

const result = await eslint.lintFiles('/workspace/monorepo/packages/packageA/index.ts');

console.log('result---', result);

The eslint-plugin-import plugin seems to be unable to find the tsconfig.json file of packageA:
image

I think eslint’s cwd configuration should be used first, it looks like this:

const tsconfigInfo = tsConfigLoader({
    cwd: context.parserOptions && context.parserOptions.tsconfigRootDir || eslint.options.cwd || process.cwd(),
    getEnv: (key) => process.env[key],
});

PS

At first I thought the context was the context configured by eslint, but later I found out that it was the plugin itself.
image

So I tried writing it like this and found that nothing worked 😅:

new ESLint({
    cwd: '/workspace/monorepo/packages/packageA',
    extensions: ['.ts', '.tsx', '.mts', '.cts'],
    overrideConfig: {
        parserOptions: {
            tsconfigRootDir: '/workspace/monorepo/packages/packageA'
         },
    },
})

Please stop doing this.