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

prefer-dom-node-dataset - Add support to optional chaining #2158

Conversation

gcunsolo
Copy link

@gcunsolo gcunsolo commented Jun 22, 2023

999d3df failing tests on #2156
8170555 fix
...
3da90d7 snapshots update

@gcunsolo gcunsolo marked this pull request as ready for review June 22, 2023 11:56
> Output

`␊
1 | element.dataset.optionalChaining = "foo";␊
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can't fix to this, it will break code.

Copy link
Author

Choose a reason for hiding this comment

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

Hello Fisk, thanks!
How exactly can I help?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We should either remove the fix for optional members or add a safe fix.

Copy link
Author

Choose a reason for hiding this comment

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

I'm sorry @fisker, it took me a while to understand what was wrong, I think I got it now:

We should expect the autofix feature to keep the optional chaining, is that it?

Like

Suggested change
1 | element.dataset.optionalChaining = "foo";␊
1 | element?.dataset.optionalChaining = "foo";␊

Did I get it right?

Thanks again for your review, cheers

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think so, optional chaining can't be LHS.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let me think a little bit. If there is safe fix.

Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. element?.setAttribute('data-foo', 'bar')

Since foo?.dataset.foo = 'bar' is invalid, and we don't want auto fix to wrap it in a if, so we should just remove the autofix.

  1. element?.getAttribute('data-foo')

Should be safe to fix to element?.dataset.foo

  1. element?.removeAttribute('data-foo')

Should be safe to fix to delete element?.dataset.foo

  1. element?.hasAttribute('data-foo')

Since Object.hasOwn(element?.dataset, 'foo') can cause runtime error, so I guess we should remove the autofix too.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm adding hasOptionalChainElement utility in #2169, you can use it after we merge.

@sindresorhus
Copy link
Owner

@gcunsolo Bump :)

@sindresorhus
Copy link
Owner

Bump

@sindresorhus
Copy link
Owner

Closing for lack of activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants