如何使用新的平面-Config系统(也称为eslint.config.js文件)配置eslint.config.js,使其与@ TypeScript ESLint /ESLint-plugin&TypeScript解析器一起工作?
-
ESLint的新配置系统,“平面Config”允许多个规则集在一个单一的配置文件.这使得重写规则比使用ESLint在其原始配置系统中实现的级联文件系统概念容易得多。因为当我向NPM发布包时,我必须增加对ESM和CJS的支持,所以平面配置就像梦想成真,因为它将允许我以更简单的方式使用ESLint。
唯一的问题是,我不能让ESLint的新配置系统与任何插件一起工作,而在问题的另一面,我不能让插件使用平面配置。
当Linting TypeScript使用ESLint时,安装我下面列出的两个插件非常重要。这两个插件实现了允许类型记录能够正确链接typescript代码库的规则。我必须拥有它们。
2 2BH我到处都是我的配置文件,目前它看起来像下面的例子,但是这个例子只是显示了我最近绝望的尝试,我尝试了各种各样的东西。
import eslintPlugin from '@typescript-eslint/eslint-plugin'
export default [
{
files: ["src/**/*.ts", "src/main.cts", "src/main.mts"],
ignores: ["**/*.d.*", "**/*.map.*", "**/*.js", "**/*.mjs", "**/*.cjs"],
plugins: { eslintPlugin },
languageOptions: {
ecmaVersion: "latest",
sourceType: "module",
parser: "eslintPlugin/parser",
},
rules: {
semi: "error",
quotes: ["error", "single"],
indent: [
"error",
2,
{
SwitchCase: 1,
VariableDeclarator: "first",
ImportDeclaration: "first",
ArrayExpression: "first",
ObjectExpression: "first",
CallExpression: { arguments: "first" },
FunctionDeclaration: { body: 1, parameters: 4 },
FunctionExpression: { body: 1, parameters: 4 },
},
],
},
},
];
我还使用了TypeScript插件TypeScript ESLint语言服务插件。我不喜欢TypeScript & ESLint报告相同的错误,所以我不对ESLint使用任何扩展,但是我确实集成了一个构建系统,该系统将我的项目链接为工作对象,ESLint发现的错误是通过TSC编译器报告的。
但问题是一样的,我无法让“类型记录/ ESLint语言服务”插件与新的ESLint配置系统(又名平面配置)一起工作。
如果有人知道如何使用eslint.config.js平面配置文件配置eslint,以便它能够与类型记录/eslint插件(eslint的插件)和/或"TS语言服务“插件(类型记录的插件)一起工作,我想请您告诉我这种配置是什么样子的。
发布于 2022-11-01 16:41:29
我使用的是带有类型记录的平面配置。下面是我认为配置的重要部分:
import ts from '@typescript-eslint/eslint-plugin';
import tsParser from '@typescript-eslint/parser';
import functional from 'eslint-plugin-functional';
import imprt from 'eslint-plugin-import'; // 'import' is ambiguous & prettier has trouble
...
languageOptions: {
parser: tsParser,
parserOptions: {
ecmaFeatures: { modules: true },
ecmaVersion: 'latest',
project: './tsconfig.json',
},
},
plugins: {
functional,
import: imprt,
'@typescript-eslint': ts,
ts,
},
...
rules: {
...ts.configs['eslint-recommended'].rules,
...ts.configs['recommended'].rules,
'ts/return-await': 2,注意,ts插件已经存在了两次。共享信任使用比我想要使用的更长的命名空间。
https://stackoverflow.com/questions/74237042
复制相似问题