From 702246be380525874387c91d159752642c327cec Mon Sep 17 00:00:00 2001 From: Yury Bondarenko Date: Mon, 8 May 2023 15:53:05 +0200 Subject: [PATCH] ESLint: enforce prefer-const where possible https://eslint.org/docs/latest/rules/prefer-const In our tests we use this pattern a lot: ``` let something; beforeEach(() => { something = ...; }); ``` This is not valid ~ prefer-const, but can be "let through" with some configuration. However, this would make the rule too loose for the non-test codebase. Therefore, we enable it overall but turn it off for tests only -- the `*.spec.ts` overrides apply to test files only and take precedence over `*.ts` --- .eslintrc.json | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/.eslintrc.json b/.eslintrc.json index af1b97849b..7361034a43 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -104,7 +104,7 @@ "allowTernary": true } ], - "prefer-const": "off", // todo: re-enable & fix errors (more strict than it used to be in TSLint) + "prefer-const": "error", "prefer-spread": "off", "no-underscore-dangle": "off", @@ -213,6 +213,21 @@ ] } }, + { + "files": [ + "*.spec.ts" + ], + "parserOptions": { + "project": [ + "./tsconfig.json", + "./cypress/tsconfig.json" + ], + "createDefaultProgram": true + }, + "rules": { + "prefer-const": "off" + } + }, { "files": [ "*.html"