Skip to content

Bug: [no-non-null-assertion] Fix puts ? on wrong line when member access is on next line #8179

Closed
@JoshuaKGoldberg

Description

@JoshuaKGoldberg

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.

Playground Link

https://typescript-eslint.io/play/#ts=5.3.3&fileType=.ts&code=CYUwxgNghgTiAEYD2A7AzgF3gNyhAriAFzyYwCWKA5gNwBQduBIAdALZQZgAWAFAPRQARmH4BKAIR148FgDNoGXmJpA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1s6e4XloBDZMkTR8lDk3RQx0DtEjgwAXxAqgA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eFYDAruuGAL4g9A&tokens=false

Repro Code

declare const value: string;

value.match(/abc/)!
  .flat();

ESLint Config

module.exports = {
  "rules": {
    "@typescript-eslint/no-non-null-assertion": "error"
  }
}

tsconfig

{
  "compilerOptions": {
    "strict": true
  }
}

Expected Result

Auto-fixing should result in something like:

declare const value: string;

value.match(/abc/)
  ?.flat();

Actual Result

declare const value: string;

value.match(/abc/)?
  .flat();

Additional Info

Interestingly, it does work well when the member access is computed:

declare const value: string;

value.match(/abc/)!
  ['flat']();

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