Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
4 tasks done
JoshuaKGoldberg opened this issue Jan 3, 2024 · 0 comments · Fixed by #8185
Closed
4 tasks done
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@JoshuaKGoldberg
Copy link
Member

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']();
@JoshuaKGoldberg JoshuaKGoldberg added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin accepting prs Go ahead, send a pull request that resolves this issue labels Jan 3, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
1 participant