I'm getting ESlint error in this file
Bar.ts:
class Bar {
constructor(public foo: string) {}
hello(): string {
return this.foo;
}
}
export default Bar;
my eslint config:
{
"env": {
"browser": true,
"commonjs": true,
"es2020": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"airbnb/base",
"eslint-config-prettier"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 11
},
"plugins": ["@typescript-eslint/eslint-plugin", "eslint-plugin-prettier"],
"rules": {
"prettier/prettier": "error",
"no-unused-vars": "warn",
"@typescript-eslint/no-var-requires": "warn",
"func-names": "off",
"no-underscore-dangle": "off",
"class-methods-use-this": "off"
},
"overrides": [
{
"files": ["*.ts"],
"excludedFiles": ["*.js"],
"rules": {
"@typescript/no-var-requires": "off"
}
}
]
}
Eslint error on Bar.ts:
Useless constructor. eslint(no-useless-constructor)
If you are curious why my eslint config looks the way it is, it's because I'm trying to setup a project with both JS and TS files, and make ESLint work for each type of the file respectively.
What do I need to change in my ESLint config to make it not complaining about totally relevant code?
Thanks to @jonrsharpe I have figured out that that the issue was inside the extends
block. The airbnb/base
in particular which is meant for js files.
I had to replace it with airbnb-typescript/base
and then the other issue popped up which was even more critical:
To use airbnb-typescript/base I had to:
project
option in my parserOptions
which points to the tsconfig
Somebody who is familiar with the TS and ESlint probably has noticed from the very beginning that my eslint config was missing that option.
I'm pretty sure I'm missing a lot of things here and this is not the last question about this topic, but for now the error is gone and I can move forward.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With