typescript - ESLint、TypeScript、Vue 和 WebPack Encore:无法禁用 ESLint 规则
问题描述
我花了几个小时研究 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
// ...
.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
对我来说,这个 PR似乎应该解决我的问题,但事实并非如此。
你们有什么想法吗?我将非常感谢任何提示:)
编辑:
在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"
}
}
]
}
谢谢你们帮我解决这个问题,伙计们!
解决方案
您会尝试将其放入 .eslintrc.json 的覆盖部分吗?
"overrides": [
{
"files": ["*.ts"],
"rules": {
"@typescript-eslint/no-non-null-assertion": "off"
}
}
]
编辑:根据规范需要“文件”
推荐阅读
- html - 如何防止内联复选框的复选框文本标签重叠?
- javascript - 如何删除带参数的事件回调
- python - 无法在 VSCode 中安装 Tensorflow 1.13.2
- javascript - 将 Remote Dev 添加到 Facebook Flux Store 应用程序,帮助列出 Action Creator
- ansible - 替换 Ansible 中的行
- node.js - 将 PM2 日志写入动态日志路径
- python - 熊猫检查同一组中两列的总和是否等于
- java - 一个 ImageView 的图像到 int Android Studio
- c - 编译文件似乎不起作用
- html - 如何同时使用显示内联和边距/文本对齐