Improve the way to find tsconfig.json
shiyangzhaoa opened this issue · comments
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
:
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.
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.
Duplicate of import-js/eslint-import-resolver-typescript#274