【发布时间】:2020-11-10 22:49:03
【问题描述】:
我花了几个小时研究 Webpack Encore 和 ESLint 问题,但我似乎找不到解决这个问题的方法。
我指定要更改或关闭一些 TypeScript-ESLint 规则,但没有任何反应。无论如何,我都会收到 linter 警告。我的配置如下:
.eslintrc.json
{
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"@typescript-eslint/no-non-null-assertion": "off"
}
}
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "ES2015",
"moduleResolution": "node",
"sourceMap": true,
"removeComments": true,
"preserveConstEnums": true,
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"strict": true,
"noImplicitAny": true,
"esModuleInterop": true,
"baseUrl": ".",
},
"include": [
"assets/scripts/**/*"
],
"exclude": [
"node_modules"
]
}
以下是我的 encore 配置的相关部分:
Encore
// ...
.enableTypeScriptLoader()
.enableForkedTypeScriptTypesChecking()
.enableVueLoader()
.enableEslintLoader((options) => {}, { lintVue: true })
// ...
;
这是我收到的警告,虽然我禁用了规则:
/some/path/my-file.ts
97:82 warning Forbidden non-null assertion @typescript-eslint/no-non-null-assertion
对我来说,this PR 似乎应该解决我的问题,但事实并非如此。
你们有什么想法吗?我将非常感谢任何提示:)
编辑:
通过the help of lotype 和我的一位同事,我终于找到了解决方案。有几件事必须改变。
首先,确保使用了正确的解析器:
.enableEslintLoader((options) => {
options.parser = require('./.eslintrc.json').parser;
// https://webpack.js.org/loaders/eslint-loader/#cache
options.cache = false; // optional, but recommended
}, { lintVue: true })
然后,确保将 TypeScript 规则添加到覆盖部分,并将“普通”规则添加到规则部分,如下所示:
{
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"no-console": "warn"
},
"overrides": [
{
"files": [
"*.ts"
],
"rules": {
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-explicit-any": "off"
}
}
]
}
谢谢你们帮我解决这个问题,伙计们!
【问题讨论】:
标签: typescript vue.js webpack eslint webpack-encore