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

Rule proposal: the inverse of prefer-dom-node-dataset #2451

Open
bschlenk opened this issue Sep 16, 2024 · 1 comment
Open

Rule proposal: the inverse of prefer-dom-node-dataset #2451

bschlenk opened this issue Sep 16, 2024 · 1 comment

Comments

@bschlenk
Copy link
Contributor

bschlenk commented Sep 16, 2024

Description

I work in a large codebase that happens to use lots of magic data attributes to change behavior of things in subtle ways. It can hurt greppability when seeing one of these data attributes used in css, but on the js side the data attribute is accessed via the dataset property. If you search the codebase for the data-* attribute you see in css, you won't find its usage on the js side and you have to know to strip the data and camelCase the name to find it.

It'd be nice if there was an inverse of prefer-dom-node-dataset, or if it took an option to invert the check.

Maybe this is easy enough to set up with no-restricted-syntax?

Fail

el.dataset.someLongDataAttribute

Pass

el.hasAttribute('data-some-long-data-attribute')

Proposed rule name

prefer-dom-node-has-attribute

Additional Info

For now I can use no-restricted-syntax with MemberExpression[property.name="dataset"], but an autofixer would be nice here.

@github-actions github-actions bot changed the title Rule proposal: the inverse of prefer-dom-node-dataset Rule proposal: the inverse of prefer-dom-node-dataset Sep 16, 2024
@fregante
Copy link
Collaborator

fregante commented Sep 19, 2024

I had the same experience with this rule: I disable it because it breaks greppability between JS and HTML

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

No branches or pull requests

2 participants