I've been delving into Webpack Encore and ESLint issues for quite some time now, but unfortunately, I haven't been able to find a solution to my problem.
Specifically, I've been trying to change or disable certain TypeScript-ESLint rules, but no matter what I do, I keep getting linter warnings. Here is how my configuration looks:
.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"
]
}
Below are the relevant parts of my encore configuration:
Encore
// ...
.enableTypeScriptLoader()
.enableForkedTypeScriptTypesChecking()
.enableVueLoader()
.enableEslintLoader((options) => {}, { lintVue: true })
// ...
;
Despite disabling the rule, I still receive the following warning:
/some/path/my-file.ts
97:82 warning Forbidden non-null assertion @typescript-eslint/no-non-null-assertion
It seems like this PR should resolve my issue, but unfortunately, it hasn't.
Do any of you have any suggestions? I would greatly appreciate any tips :)
Edit:
Thanks to the assistance of lotype and one of my colleagues, I finally managed to find a solution. A few things needed tweaking.
Firstly, ensure that the correct parser is being used:
.enableEslintLoader((options) => {
options.parser = require('./.eslintrc.json').parser;
// https://webpack.js.org/loaders/eslint-loader/#cache
options.cache = false; // optional, but recommended
}, { lintVue: true })
Next, make sure to add TypeScript rules to the override section, while keeping "normal" rules in the rule section like so:
{
"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"
}
}
]
}
Once again, a big thank you for assisting me with this!