From f92d7a3f8c6bfc7807e0e2dcdb49e89d8be7884f Mon Sep 17 00:00:00 2001 From: Elliot Winkler Date: Wed, 15 Jan 2025 12:12:22 -0700 Subject: [PATCH 1/2] Relax switch-exhaustiveness-check lint rule (#5157) The default behavior for this rule enforces that a switch statement handle all possible values that the given variable could be, including type unions. This rule seems to be acting differently in different environments, especially CI, preventing developers from merging PRs. We could disable this rule entirely, but let's try relaxing it a bit to see if that improves the situation. --- eslint.config.mjs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index dec0b60327..2ed8169174 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -117,6 +117,14 @@ const config = createConfig([ }, }, rules: { + // These rules have been customized from their defaults. + '@typescript-eslint/switch-exhaustiveness-check': [ + 'error', + { + considerDefaultExhaustiveForUnions: true, + }, + ], + // This rule does not detect multiple imports of the same file where types // are being imported in one case and runtime values are being imported in // another @@ -151,7 +159,6 @@ const config = createConfig([ '@typescript-eslint/only-throw-error': 'warn', '@typescript-eslint/prefer-promise-reject-errors': 'warn', '@typescript-eslint/prefer-readonly': 'warn', - '@typescript-eslint/switch-exhaustiveness-check': 'warn', 'import-x/namespace': 'warn', 'import-x/no-named-as-default': 'warn', 'import-x/order': 'warn', From f41895209e150285ca83d4327ab180c9b506d746 Mon Sep 17 00:00:00 2001 From: Elliot Winkler Date: Wed, 15 Jan 2025 13:08:01 -0700 Subject: [PATCH 2/2] Update ESLint warning thresholds, and produce them consistently (#5151) The ESLint warning thresholds file records warnings that were produced the last time that `eslint` was run, categorizing them by rule. This file should be kept up to date at all times so we can know whether new code changes introduce a regression in the number of warnings or an improvement. Specifically, the lint step will now fail if more warnings are introduced to the codebase. However, in the past we have observed inconsistencies in the behavior of ESLint across different people's machines as well as in CI. With the addition of the quality gate this means that some people are unable to merge PRs because warnings are produced that are not seen in development, and the warnings may not be reproducible by other developers. With that said, we recently learned that if `dist` directories are present from a previous run of `yarn build`, it could affect the behavior of the TypeScript-specific lint rules and cause the observed inconsistencies. To mitigate this problem, this commit ensures that all `dist` directories are removed before running `eslint`. This indeed does change the number of warnings produced, and the thresholds file has been updated to reflect this. --- eslint-warning-thresholds.json | 6 ++---- package.json | 5 +++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/eslint-warning-thresholds.json b/eslint-warning-thresholds.json index fc7d2173b6..92cc78a3f7 100644 --- a/eslint-warning-thresholds.json +++ b/eslint-warning-thresholds.json @@ -2,16 +2,14 @@ "@typescript-eslint/consistent-type-exports": 19, "@typescript-eslint/no-base-to-string": 3, "@typescript-eslint/no-duplicate-enum-values": 2, - "@typescript-eslint/no-misused-promises": 3, - "@typescript-eslint/no-unsafe-enum-comparison": 59, + "@typescript-eslint/no-unsafe-enum-comparison": 34, "@typescript-eslint/no-unused-vars": 36, "@typescript-eslint/prefer-promise-reject-errors": 13, "@typescript-eslint/prefer-readonly": 145, - "@typescript-eslint/switch-exhaustiveness-check": 10, "import-x/namespace": 189, "import-x/no-named-as-default": 1, "import-x/no-named-as-default-member": 8, - "import-x/order": 209, + "import-x/order": 205, "jest/no-conditional-in-test": 129, "jest/prefer-lowercase-title": 2, "jest/prefer-strict-equal": 2, diff --git a/package.json b/package.json index a52e92956a..67464d8c8b 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ ], "scripts": { "build": "yarn ts-bridge --project tsconfig.build.json --verbose", - "build:clean": "rimraf dist '**/*.tsbuildinfo' && yarn build", + "build:clean": "yarn build:only-clean && yarn build", + "build:only-clean": "rimraf -g 'packages/*/dist'", "build:docs": "yarn workspaces foreach --all --no-private --parallel --interlaced --verbose run build:docs", "build:types": "tsc --build tsconfig.build.json --verbose", "changelog:update": "yarn workspaces foreach --all --no-private --parallel --interlaced --verbose run changelog:update", @@ -23,7 +24,7 @@ "lint": "yarn lint:eslint && yarn lint:misc --check && yarn constraints && yarn lint:dependencies && yarn lint:teams", "lint:dependencies": "depcheck && yarn dedupe --check", "lint:dependencies:fix": "depcheck && yarn dedupe", - "lint:eslint": "yarn ts-node ./scripts/run-eslint.ts --cache", + "lint:eslint": "yarn build:only-clean && yarn ts-node ./scripts/run-eslint.ts --cache", "lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write && yarn constraints --fix && yarn lint:dependencies:fix", "lint:misc": "prettier --no-error-on-unmatched-pattern '**/*.json' '**/*.md' '**/*.yml' '!.yarnrc.yml' '!merged-packages/**' --ignore-path .gitignore", "lint:teams": "ts-node scripts/lint-teams-json.ts",