我想包含来自eslint plugin节点的规则eslint plugin节点,但是它与我当前的.eslintrc冲突,因为我使用的是打字稿和eslint-导入解析器-类型记录。
这是我目前的配置:
{
"parser": "@typescript-eslint/parser", // Specifies the ESLint parser
"extends": [
"airbnb-base",
"plugin:@typescript-eslint/recommended", // Uses the recommended rules from the @typescript-eslint/eslint-plugin
"prettier", // Enables eslint-plugin-prettier and displays prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array
"prettier/@typescript-eslint" // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
],
"parserOptions": {
"project": "./tsconfig.json",
"ecmaVersion": 6, // Allows for the parsing of modern ECMAScript features
"sourceType": "module" // Allows for the use of imports
},
"rules": {
},
"settings": {
"import/resolver": {
"node": {
"extensions": [".js", ".ts"]
},
// use <root>/tsconfig.json
"typescript": {
"alwaysTryTypes": true // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`
}
}
},
"root": true
}但是,如果我将编译过程添加到plugin:node/recommended选项中,编译过程将失败:
1:1 error Import and export declarations are not supported yet node/no-unsupported-features/es-syntax
1:43 error "express" is not found node/no-missing-import
2:1 error Import and export declarations are not supported yet node/no-unsupported-features/es-syntax我的package.json包括node": ">=12.0.0。另外,这个规则应该被忽略,因为我使用的是类型记录。另一方面,我只是从express导出类型,因为模块不使用它。
根据这个问题,冲突应该由eslint-plugin-node来解决。
如何完成两个插件的合并?我必须一个一个地禁用规则吗?
更新:似乎是在eslint-plugin-node存储库的问题中被问到的。它适用于no-unsupported-features和no-missing-import,但是,它在express和no-extraneous-import的导入定义方面仍然失败。
更新了2:,似乎eslint-plugin-node正在做一个增强来完成它。在此发行
发布于 2020-04-04 06:58:04
首先,必须添加选项tryExtension以包含TS文件:
"settings": {
"node": {
"tryExtensions": [".js", ".json", ".node", ".ts", ".d.ts"]
},要解决no-unsupported-features/es-syntax,根据这个关于向TypeScript添加信息的问题,如果您使用的是传输程序,则必须在rules下忽略它
"node/no-unsupported-features/es-syntax": ["error", { "ignores": ["modules"] }],另一方面,只使用类型,而不是eslint-plugin-node还不支持代码。他们正在开发一个增强功能来解决这个问题。但是,要解决no-missing-import,必须将node_modules/@types添加到resolvePath中
"node": {
"resolvePaths": ["node_modules/@types"],
"tryExtensions": [".js", ".json", ".node", ".ts", ".d.ts"]
},即便如此,它也会生成一个no-extraneous-import,因为它不检测模块,因为它只是一个类型。同时,您可以在此规则下使用allowModules来解决此问题:
"node/no-extraneous-import": ["error", {
"allowModules": ["express"]
}]https://stackoverflow.com/questions/61024198
复制相似问题