typescript-eslint: Bug: [no-unused-expressions, no-empty-functions, possibly others...] extension rules crash with eslint v9.15.0

Before You File a Bug Report Please Confirm You Have Done The Following…

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Issue Description

eslint crashes when using the latest version of node 22 and the latest version of typescript-eslint.

Oops! Something went wrong! :(

ESLint: 9.15.0

TypeError: Error while loading rule '@typescript-eslint/no-unused-expressions': Cannot read properties of undefined (reading 'allowShortCircuit')
Occurred while linting /home/ext4cats/Projects/tseslint-8.14.0-bug/index.js
    at Object.create (/home/ext4cats/Projects/tseslint-8.14.0-bug/node_modules/.pnpm/eslint@9.15.0/node_modules/eslint/lib/rules/no-unused-expressions.js:75:13)
    at create (/home/ext4cats/Projects/tseslint-8.14.0-bug/node_modules/.pnpm/@typescript-eslint+eslint-plugin@8.14.0_@typescript-eslint+parser@8.14.0_eslint@9.15.0_typesc_u2crwq53uno6k5fweinf7nowby/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-unused-expressions.js:28:32)
    at Object.create (/home/ext4cats/Projects/tseslint-8.14.0-bug/node_modules/.pnpm/@typescript-eslint+utils@8.14.0_eslint@9.15.0_typescript@5.6.3/node_modules/@typescript-eslint/utils/dist/eslint-utils/RuleCreator.js:31:20)
    at createRuleListeners (/home/ext4cats/Projects/tseslint-8.14.0-bug/node_modules/.pnpm/eslint@9.15.0/node_modules/eslint/lib/linter/linter.js:944:21)
    at /home/ext4cats/Projects/tseslint-8.14.0-bug/node_modules/.pnpm/eslint@9.15.0/node_modules/eslint/lib/linter/linter.js:1082:84
    at Array.forEach (<anonymous>)
    at runRules (/home/ext4cats/Projects/tseslint-8.14.0-bug/node_modules/.pnpm/eslint@9.15.0/node_modules/eslint/lib/linter/linter.js:1013:34)
    at #flatVerifyWithoutProcessors (/home/ext4cats/Projects/tseslint-8.14.0-bug/node_modules/.pnpm/eslint@9.15.0/node_modules/eslint/lib/linter/linter.js:1911:31)
    at Linter._verifyWithFlatConfigArrayAndWithoutProcessors (/home/ext4cats/Projects/tseslint-8.14.0-bug/node_modules/.pnpm/eslint@9.15.0/node_modules/eslint/lib/linter/linter.js:1993:49)
    at Linter._verifyWithFlatConfigArray (/home/ext4cats/Projects/tseslint-8.14.0-bug/node_modules/.pnpm/eslint@9.15.0/node_modules/eslint/lib/linter/linter.js:2082:21)

Reproduction Repository Link

https://github.com/ext4cats/tseslint-8.14.0-bug

Repro Steps

  1. clone the repo
  2. follow steps in readme

Versions

package version
typescript-eslint 8.14.0
TypeScript 5.6.3
ESLint 9.15.0
node 22.11.0

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 73
  • Comments: 29 (9 by maintainers)

Commits related to this issue

Most upvoted comments

I downgraded my project to eslint v9.14.0 and the crash is gone. Seems to be a regression in eslint itself.

The fix has merged and will soon be released to our canary tag. The fix will release to latest with our next release in a few days. https://typescript-eslint.io/users/releases

Considered it, but it seems like a wider change, so I’m hesitant given my limited knowledge of this codebase…

Totally fair! Rest assured that the root cause of this type of bug is very well understood by each of the maintenance team members, and will be addressed as soon as our bandwidth permits, unless a community champion is able to get to it first 🙂

This is the eslint patch I used to get it working with typescript-eslint and unicorn

diff --git a/lib/rules/no-unused-expressions.js b/lib/rules/no-unused-expressions.js
index fd1437c1606a56cbce147d040d601d0acef3d24a..1ac2d6e45fbb04f93d9cccdc5265bb38c3701aca 100644
--- a/lib/rules/no-unused-expressions.js
+++ b/lib/rules/no-unused-expressions.js
@@ -76,7 +76,7 @@ module.exports = {
             allowTernary,
             allowTaggedTemplates,
             enforceForJSX
-        }] = context.options;
+        } = {}] = context.options;
 
         /**
          * Has AST suggesting a directive.
diff --git a/lib/rules/no-warning-comments.js b/lib/rules/no-warning-comments.js
index 628f5a2ac513303cc3fe2cc9adcbf1ae54128747..a42e8318e028c6a3717afceef3c949bf8eab5827 100644
--- a/lib/rules/no-warning-comments.js
+++ b/lib/rules/no-warning-comments.js
@@ -64,7 +64,7 @@ module.exports = {
 
     create(context) {
         const sourceCode = context.sourceCode;
-        const [{ decoration, location, terms: warningTerms }] = context.options;
+        const [{ decoration, location, terms: warningTerms } = this.meta.defaultOptions[0]] = context.options;
         const escapedDecoration = escapeRegExp(decoration ? decoration.join("") : "");
         const selfConfigRegEx = /\bno-warning-comments\b/u;

for some reason, @typescript-eslint/no-unused-expressions’s create function appears to be receiving these options as a second parameter: not sure if this inconsistency was always there…

@AviVahl our utilities have always supported a top-level defaultOptions property for as long as they have existed! Our API design was to pass the merged options as a second parameter to the create function rather than changing the options on the context object because it allowed greater flexibility – it gives you the option to see BOTH the user’s actual config and the merged config – which can sometimes be useful if you want to act differently when a user skipped an option but also avoid having undefineds around the place.

Unfortunately ESLint core chose a different location for the defaultOptions property just added in v9.15.0:

  • It was added to meta.defaultOptions rather than as a top-level property, and
  • They chose to overwrite the context.options rather than pass it as a separate argument.

In the next major we’ll likely converge on their solution to deduplicate things.

The issue is known. The fix is in progress. Locking to avoid further noise.

Please subscribe to this issue to keep updated.

… I note that https://github.com/eslint/eslint/pull/17656 seems to much broader than just affecting no-unused-expressions, so I honestly wouldn’t be surprised if other rules are broken with eslint v9.15.0 too for the same reason. Worth looking into.

I originally hit this bug with typescript-eslint/no-empty-function. It was only after completely turning off that rule, I found the rule in this issue. Which then searching online found this GitHub issue. So yes, there are other rules that are affected.