-
-
Notifications
You must be signed in to change notification settings - Fork 638
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
[New]: Add no-duplicate-ids lint rule #955
base: main
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## main #955 +/- ##
=======================================
Coverage 99.02% 99.03%
=======================================
Files 105 106 +1
Lines 1642 1658 +16
Branches 578 581 +3
=======================================
+ Hits 1626 1642 +16
Misses 16 16
|
Enforces that no `id` attributes are reused. This rule does a basic check to ensure that `id` attribute values are not the same. In the case of a JSX expression, it checks that no `id` attributes reuse the same expression.
12ba068
to
837e891
Compare
This would only be valuable for single files where an ID is duplicated, which seems like a very minority case - the common case here will be an ID that's mentioned once per file, but across multiple files.
|
@ljharb thanks for reviewing! We've seen that, when branching code due to AB tests, this can happen quite a lot due to copy paste and not noticing an |
Nothing can be added to the recommended config without it being a breaking change, so that's not an option regardless. This is something best discussed in an issue before writing any code, for future reference, but now that it's a PR let's discuss here. Can you share some examples? I've seen lots of a/b tests in a react codebase and never run into this problem. |
@ljharb Sorry will open an issue next time! Basically something like this (this is example code with errors): <div>
<label htmlFor="input1">Username:</label>
<input type="text" id="input1" name="username" />
{emailIsEnabled ? (
<div>
<label htmlFor="input1">Email:</label>
<input type="email" id="input1" name="email" />
</div>
) : null}
{passwordIsEnabled ? (
<div>
<label htmlFor="input1">Password:</label>
<input type="password" id="input1" name="password" />
</div>
) : null}
</div> Also when dealing with |
Enforces that no
id
attributes are reused. This rule does a basic check to ensure thatid
attribute values are not the same. In the case of a JSX expression, it checks that noid
attributes reuse the same expression.Open questions: