Skip to content

Error while configuring react/jsx-props-no-spreading #2387

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

Closed
Solavon opened this issue Aug 20, 2019 · 21 comments
Closed

Error while configuring react/jsx-props-no-spreading #2387

Solavon opened this issue Aug 20, 2019 · 21 comments
Labels

Comments

@Solavon
Copy link

Solavon commented Aug 20, 2019

While setting up my eslint rules, I ran into some issues when configuring jsx-props-no-spreading

Expected:
Allow props spreading when the following rule is set

'react/jsx-props-no-spreading': ['error', {
      html: "ignore",
      custom: "ignore",
      exceptions: [],
    }],

Actual:
Getting the following error

Error: .eslintrc.js:
Configuration for rule "react/jsx-props-no-spreading" is invalid:
Value {"html":"ignore","custom":"ignore","exceptions":[]} should NOT be valid.

Package versions:

"eslint": "^6.2.0",
"eslint-plugin-react": "^7.14.3",
@ljharb
Copy link
Member

ljharb commented Aug 20, 2019

This is intentional; there's no point in using the rule if you're ignoring everything and have no exceptions: https://github.com/yannickcr/eslint-plugin-react/blob/master/lib/rules/jsx-props-no-spreading.js#L48-L63

If you add an exception, or change one of the ignores to "enforce", it should work.

@ljharb ljharb closed this as completed Aug 20, 2019
@Solavon
Copy link
Author

Solavon commented Aug 21, 2019

I understand that it would be pointless, but unfortunately it's part of the airbnb rules that comes with its extension, in any case, after keeping it for a while I can already see its benefit, thank you!

@ljharb
Copy link
Member

ljharb commented Aug 21, 2019

The airbnb config doesn’t ignore both kinds of components.

@Solavon
Copy link
Author

Solavon commented Aug 21, 2019

No, as in, this rule came as part of the airbnb config, and I was trying to turn it off.

@ljharb
Copy link
Member

ljharb commented Aug 21, 2019

Set it to "off" then :-)

@Solavon
Copy link
Author

Solavon commented Aug 21, 2019

Thanks for teaching me that :P
But I'm going to keep it on for the time being!

after keeping it for a while I can already see its benefit, thank you!

hkulur added a commit to hkulur/eslint-config that referenced this issue Sep 17, 2019
Cannot pass a configuration object that ignores everything and has no exception
jsx-eslint/eslint-plugin-react#2387
@MichaelPretorius
Copy link

How do u switch it to off?

@MichaelPretorius
Copy link

No worries got it, thanks

@sadafk831
Copy link

Just for the record:
If you wish to use the rule and wish to ignore instead of setting it off. This is how you should use:
In the rule definition, all the fields are made compulsory and specially exceptions is suppose to have an array of string not empty, so the declaration of rules goes like follow

'react/jsx-props-no-spreading': ['error', {
      html: "ignore",
      custom: "ignore",
      exceptions: [""],
    }],

For setting it off you can use either any of the following

'react/jsx-props-no-spreading': ['off']
'react/jsx-props-no-spreading': 0

@AdamAnSubtractM
Copy link

This may seem obvious to most people but wasn't to me, this can be set up in an eslintrc.json or eslintrc.js file or in your package.json file by adding a rules object like so:

"rules": { "react/jsx-props-no-spreading": 0 }

@flaviouk
Copy link

"rules": {
      "react/jsx-props-no-spreading": [
        "error",
        {
          "explicitSpread": "enforce",
          "html": "ignore",
          "custom": "ignore",
          "exceptions": []
        }
      ]
    }
Configuration for rule "react/jsx-props-no-spreading" is invalid:
	Value {"explicitSpread":"enforce","html":"ignore","custom":"ignore","exceptions":[]} should NOT be valid.

This doesn't work for some reason.. What am I missing? @ljharb

@ljharb
Copy link
Member

ljharb commented Oct 14, 2020

@nix6839

This comment was marked as outdated.

@ljharb

This comment was marked as resolved.

@divmgl
Copy link

divmgl commented Aug 9, 2024

Back in 2024 and this is not working:

    "react/jsx-props-no-spreading": [
      "error",
      {
        html: "ignore",
        custom: "ignore",
        explicitSpread: "enforce",
      },
    ],

I want to specifically only ban explicitSpread. Is there any way to do this? Unfortunately, I'm getting

Error: .eslintrc.cjs:
        Configuration for rule "react/jsx-props-no-spreading" is invalid:
        Value {"html":"ignore","custom":"ignore","explicitSpread":"enforce"} should NOT be valid.

@ljharb
Copy link
Member

ljharb commented Aug 9, 2024

@divmgl what version of the plugin are you using?

@divmgl
Copy link

divmgl commented Aug 9, 2024

7.31.11

@divmgl
Copy link

divmgl commented Aug 9, 2024

Just updated to latest and it's still occurring unfortunately.

@ljharb
Copy link
Member

ljharb commented Aug 9, 2024

@divmgl that's pretty ancient :-), but the docs for that version imply it should still be working even without the upgrade (it's still wise to upgrade). Can you file a new issue with a test case that reproduces the problem?

@divmgl
Copy link

divmgl commented Aug 9, 2024

Sure!

@divmgl
Copy link

divmgl commented Aug 9, 2024

@ljharb #3799

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

8 participants