Skip to content
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

Avoid unnecessary optional chaining in autofix for no-get rule when using useOptionalChaining option #1286

Merged
merged 1 commit into from Aug 24, 2021

Conversation

raycohen
Copy link
Contributor

@raycohen raycohen commented Aug 24, 2021

This maintains the behavior more closely when a nested chain contains a nullish value.

  // when foo or bar is nullish:
  this.get('foo.bar').baz // will error with "baz of undefined"
  this.foo?.bar?.baz      // (previous behavior) evaluates to `undefined`
  this.foo.bar.baz        // (updated behavior)  errors with either "bar of undefined" or "baz of undefined"

…ptional when autofixing

  this.get('foo.bar').baz // will error if either foo or bar is nullish "baz of undefined"
  this.foo?.bar?.baz      // (previous behavior) evaluates to `undefined`
  this.foo.bar.baz        // (updated behavior)  errors with either "bar of undefined" or "baz of undefined"

This maintains the behavior more closely when a nested chain contains a nullish value.
@raycohen raycohen force-pushed the no-get-infer-non-optional-nesting branch from 1689e1d to 4c2366c Compare August 24, 2021 01:39
@bmish bmish added the Bug label Aug 24, 2021
@raycohen raycohen marked this pull request as ready for review August 24, 2021 02:04
@bmish bmish changed the title Improve no-get - infer when nesting is not optional Avoid unnecessary optional chaining in autofix for no-get rule when using useOptionalChaining option Aug 24, 2021
Copy link
Member

@bmish bmish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@bmish bmish merged commit bd8a789 into ember-cli:master Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants