I want ESLint to behave in the same way as the rules check in my tsconfig.json file.
Here is the code snippet:
export class SomePage {
private page: Page;
commentButton = this.page.getByTestId('open-comments');
constructor(private page: Page) {}
};
This is how my tsconfig.json looks like:
{
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"module": "CommonJS",
"sourceMap": true,
"baseUrl": "."
}
}
The line where commentButton
is declared is highlighted because of an error:
Property 'page' is used before its initialization.ts(2729)
Visual Studio Code has detected this issue, but ESLint seems to have missed it. Here is my eslint.config.mjs configuration:
import pluginJs from '@eslint/js';
import globals from 'globals';
import tseslint from 'typescript-eslint';
export default [
{ files: ['**/*.ts'] },
{
languageOptions: {
globals: globals.node,
},
},
pluginJs.configs.recommended,
...tseslint.configs.recommended,
];
Given that this rule is part of ES2022, why is ESLint not respecting it?
Would importing the tsconfig into ESLint config make sense?
Environment:
$ npx tsc -v
Version 5.6.3
package.json
{
"name": "tests",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"lint": "npx eslint . -c ./tslint.config.mjs --max-warnings=0"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@eslint/js": "^9.12.0",
"@types/node": "^22.7.5",
"eslint": "^9.12.0",
"globals": "^15.11.0",
"typescript-eslint": "^8.8.1"
}
}