我按照新 ts 项目的通用说明创建了一个新的平面配置
eslint.config.mjs
import eslint from '@eslint/js'
import tseslint from 'typescript-eslint'
export default tseslint.config(
{
ignores: ["**/*.config.*"],
},
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
{
languageOptions: {
parserOptions: {
project: true,
tsconfigRootDir: import.meta.dirname,
},
},
}
);
现在我想禁用此规则
@typescript-eslint/no-unsafe-assignment
但我无法做到。
我尝试过的:
// ... previous code
export default tseslint.config(
{
ignores: ["**/*.config.*"],
},
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
{
languageOptions: {
parserOptions: {
project: true,
tsconfigRootDir: import.meta.dirname,
},
},
rules: {
'@typescript-eslint/no-unsafe-argument': 'off', // NOT WORKING
'@typescript-eslint/naming-convention': 'warn' // WORKING
}
}
);
不知道为什么,但
naming-convention
自定义功能正常,但 no-unsafe-argument
不起作用(收到的错误是 Unsafe assignment of an 'any' value.eslint@typescript-eslint/no-unsafe-assignment)
。
我还尝试将新对象添加到配置中
...tseslint.configs.recommendedTypeChecked,
{
languageOptions: {
parserOptions: {
project: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
// New config
{
files: ['*.ts'],
rules: {
'@typescript-eslint/no-unsafe-argument': 'off',
},
}
仍然没有运气。
覆盖默认规则(如
eslint.configs.recommended
或 tseslint.configs.recommended
)的一般方法是什么?
看起来您走在正确的轨道上,但面临 ESLint 规则配置的一些问题
根据您分享的内容以及旨在纠正问题的内容,您的配置可能如下所示:
import eslint from '@eslint/js'
import tseslint from 'typescript-eslint'
export default tseslint.config(
{
ignores: ["**/*.config.*"],
},
eslint.configs.recommended,
tseslint.configs.recommendedTypeChecked,
{
languageOptions: {
parserOptions: {
project: true,
tsconfigRootDir: import.meta.dirname,
},
},
rules: {
'@typescript-eslint/no-unsafe-assignment': 'off', // Corrected rule name and placement
'@typescript-eslint/naming-convention': 'warn'
}
}
);