覆盖 eslint 推荐的平面配置规则

问题描述 投票:0回答:1

我按照新 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
)的一般方法是什么?

typescript eslint typescript-eslint
1个回答
0
投票

看起来您走在正确的轨道上,但面临 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'
    }
  }
);
© www.soinside.com 2019 - 2024. All rights reserved.