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

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

Open
2 tasks done
EvgenyOrekhov opened this issue Mar 14, 2024 · 7 comments
Open
2 tasks done
Labels

Comments

@EvgenyOrekhov
Copy link

Is there an existing issue for this?

  • I have searched the existing issues and my issue is unique
  • 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 added a commit to EvgenyOrekhov/eslint-config-hardcore that referenced this issue Mar 14, 2024
1. It's buggy: jsx-eslint/eslint-plugin-react#3711
2. Its cases are already covered by react-form-fields plugin
@ljharb
Copy link
Member

ljharb commented Mar 15, 2024

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
Copy link
Member

ljharb commented Mar 15, 2024

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
Copy link
Member

ljharb commented Mar 15, 2024

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

@EvgenyOrekhov
Copy link
Author

@ljharb Where do you see those tests?

I see this:

{
code: '<input type="checkbox" checked />',
options: [{ ignoreMissingProperties: false }],
},
{
code: '<input type="checkbox" checked={true} />',
options: [{ ignoreMissingProperties: false }],
},
{
code: '<input type="checkbox" onChange={noop} checked defaultChecked />',
options: [{ ignoreExclusiveCheckedAttribute: false }],
},
{
code: '<input type="checkbox" onChange={noop} checked={true} defaultChecked />',
options: [{ ignoreExclusiveCheckedAttribute: false }],
},

@jaesoekjjang
Copy link
Contributor

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

@ljharb
Copy link
Member

ljharb commented Mar 15, 2024

Renaming them seems more awkward than fixing the logic.

@jaesoekjjang
Copy link
Contributor

Renaming them seems more awkward than fixing the logic.

Yeah.. negative naming will make more confusion.
Opened new PR #3715

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

No branches or pull requests

3 participants