[Bug]: checked-requires-onchange-or-readonly options are inverted
Is there an existing issue for this?
- [X] I have searched the existing issues and my issue is unique
- [X] My issue appears in the command-line and not only in the text editor
Description Overview
-
"ignoreMissingProperties": trueworks likefalse, and vice-versa -
"ignoreExclusiveCheckedAttribute": trueworks likefalse, and vice-versa
{
"react/checked-requires-onchange-or-readonly": [
"error",
{
"ignoreMissingProperties": true,
"ignoreExclusiveCheckedAttribute": true
}
],
}
function My() {
return (
<>
<input type="checkbox" checked />
<input type="checkbox" checked defaultChecked />
<input type="radio" checked defaultChecked />
</>
);
}
The rule gives warnings for the above code.
eslint .
Expected Behavior
- The rule SHOULD NOT give warnings when options are set to
true - The rule SHOULD give warnings when options are set to
false -
falseshould be the new default value for the options (to warn by default, as it is now)
eslint-plugin-react version
v7.34.0
eslint version
v8.57.0
node version
v20.11.1
lol that seems like such an obvious bug that i'm not sure i even believe it, but indeed the tests seem to indicate this. cc @jaesoekjjang
hmm, actually - the tests specifically cover it, correctly:
{
code: '<input type="checkbox" checked />',
options: [{ ignoreMissingProperties: true }],
},
{
code: '<input type="checkbox" checked={true} />',
options: [{ ignoreMissingProperties: true }],
},
{
code: '<input type="checkbox" onChange={noop} checked defaultChecked />',
options: [{ ignoreExclusiveCheckedAttribute: true }],
},
{
code: '<input type="checkbox" onChange={noop} checked={true} defaultChecked />',
options: [{ ignoreExclusiveCheckedAttribute: true }],
},
also, the defaults are that both are true.
Given that the tests seem to contradict your OP, can you provide a repro repo?
@ljharb Where do you see those tests?
I see this:
https://github.com/jsx-eslint/eslint-plugin-react/blob/da1013c6760a997dca3050a4d1d8452f783584f1/tests/lib/rules/checked-requires-onchange-or-readonly.js#L41-L56
OMG... I named the options in reverse. What a mistake... my bad🥲 How about renaming those options to 'noMissingProperties', 'noExclusiveCheckedAttrbute'?
Renaming them seems more awkward than fixing the logic.
Renaming them seems more awkward than fixing the logic.
Yeah.. negative naming will make more confusion. Opened new PR https://github.com/jsx-eslint/eslint-plugin-react/pull/3715