Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[no-non-null-asserted-optional-chain] Possible Infinite Loop #2521

Closed
Labels
accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin
@hjkcai

Description

@hjkcai
  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I haveread the FAQ and my problem is not listed.

Repro

{"rules": {"@typescript-eslint/no-non-null-asserted-optional-chain":"error"  }}
letfoo1:{bar:{baz:string}}|undefined;console.log(foo1?.bar!.baz);

Expected Result

ESLint reports error.

Actual Result

Infinite Loop.

Additional Info

I am using ESLint programmatically:

import{CLIEngine,Linter}from'eslint';constcli=newCLIEngine({});cli.executeOnFiles('/path/to/the/file.ts');

But the script never ended. However this problem was not present in VSCode ESLint Plugin. I have no idea about what's happening. I am not sure the above code can reproduce the problem (because it is extracted from a large codebase).

I used the debugger to pause when infinite loop occurred. It ended up here:

https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/src/rules/no-non-null-asserted-optional-chain.ts#L116

There is an obvious logical error: thebreak only breaks theswitch statement, meanwhilecurrent.optional is truthy, meaningcurrent is truthy. TheoreticallyTHE LOOP WILL NEVER STOP WHEN A OPTIONAL CHAIN IS FOUND.

while(current){switch(current.type){caseAST_NODE_TYPES.MemberExpression:if(current.optional){// found an optional chain! stop traversingbreak;}current=current.object;continue;caseAST_NODE_TYPES.CallExpression:if(current.optional){// found an optional chain! stop traversingbreak;}current=current.callee;continue;default:// something that's not a ChainElement, which means this is not an optional chain we want to checkreturn;}}

Versions

packageversion
@typescript-eslint/eslint-plugin4.1.0
@typescript-eslint/parser4.1.0
TypeScript3.7.3
ESLint6.8.0
node12.18.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp