I have spent some hours digging into Webpack Encore and ESLint issues, but I cannot seem to find a solution to this problem.
I specify that I want to change or turn off some TypeScript-ESLint rules, but nothing happens. I get linter warnings anyway. My configuration looks as follows:
.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"
]
}
And here are the relevant parts of my encore configuration:
Encore
// ...
.enableTypeScriptLoader()
.enableForkedTypeScriptTypesChecking()
.enableVueLoader()
.enableEslintLoader((options) => {}, { lintVue: true })
// ...
;
And this is the warning I receive, although I disabled the rule:
/some/path/my-file.ts
97:82 warning Forbidden non-null assertion @typescript-eslint/no-non-null-assertion
To me, it seems like this PR should fix my issue, but it does not.
Do you guys have any idea? I would be very grateful for any tip :)
Edit:
With the help of lotype and a coworker of mine, I finally found the solution. A couple of things must be changed.
First, make sure the correct parser is 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 })
Then, make sure to add TypeScript rules to the override section, and "normal" rules to the rule section like this:
{
"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"
}
}
]
}
Thanks for helping me with this, guys!