eslint-plugin-react icon indicating copy to clipboard operation
eslint-plugin-react copied to clipboard

[Bug]: checked-requires-onchange-or-readonly options are inverted

Open EvgenyOrekhov opened this issue 1 year ago • 7 comments

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": true works like false, and vice-versa
  • "ignoreExclusiveCheckedAttribute": true works like false, 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
  • false should 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

EvgenyOrekhov avatar Mar 14 '24 22:03 EvgenyOrekhov

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

ljharb avatar Mar 15 '24 04:03 ljharb

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.

ljharb avatar Mar 15 '24 04:03 ljharb

Given that the tests seem to contradict your OP, can you provide a repro repo?

ljharb avatar Mar 15 '24 04:03 ljharb

@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

EvgenyOrekhov avatar Mar 15 '24 11:03 EvgenyOrekhov

OMG... I named the options in reverse. What a mistake... my bad🥲 How about renaming those options to 'noMissingProperties', 'noExclusiveCheckedAttrbute'?

jaesoekjjang avatar Mar 15 '24 14:03 jaesoekjjang

Renaming them seems more awkward than fixing the logic.

ljharb avatar Mar 15 '24 14:03 ljharb

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

jaesoekjjang avatar Mar 15 '24 15:03 jaesoekjjang