【发布时间】:2020-07-16 08:23:38
【问题描述】:
我想包含来自eslint-plugin-node 的规则no-unpublished-import,但是它与我当前的.eslintrc 冲突,因为我使用的是typescript-eslint 和eslint-import-resolver-typescript。
这是我目前的配置:
{
"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 导出类型,因为模块不使用它。
根据这个issue,冲突应该由eslint-plugin-node解决。
如何实现两个插件的合并?我是否必须一一禁用规则?
更新:
似乎在eslint-plugin-node 存储库的issue 中询问了它。它适用于no-unsupported-features 和no-missing-import,但是,对于express 和no-extraneous-import 的导入定义,它仍然失败。
更新 2:
似乎eslint-plugin-node 正在努力改进以实现它。 Issue here
【问题讨论】:
标签: node.js typescript eslint