-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Do we want to recommend the no-param-reassign
eslint rule in the docs?
#521
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
Comments
no-param-reassign
rule in the docs?no-param-reassign
eslint rule in the docs?
Pretty sure that rule also forbids mutating |
Only if you override the default configuration of |
Long time user of redux here, new to RTK / Immer. Running into ESLint complaining that I'm reassigning state in createSlice. But this is fine though, right, because RTK is using
|
Assigning If you want to return a completely new state value / replace the existing state, you need to actually return it: |
Ohhh okay, thanks much. |
And that's exactly why I suggest recommending this eslint rule xD |
So what does it mean to "suggest" it in this case, exactly? Where would we document that info? How would we encourage people to do so? |
Hmm, that's the question. Maybe in the style guide, hand-in-hand with the |
That could work, yeah. |
I'm interested to know what the proposed solution/information to be in the style guide would be here. If you use the standard eslint setup and use an example from RTK such as:
You would get the reassignment errors on the |
@StuartMorris0 that is most definitely not the standard eslint setup, as the A correct configuration would be just |
You're right it is the airbnb extends causing the issue, I have reverted the rule to its default. Thanks |
Yes, this, 💯 :) |
Does anyone know of any other good defaults I could review please? |
@StuartMorris0 I would start with https://www.npmjs.com/package/eslint-config-react-app . |
If Airbnb rule set has outlived its usefulness, is there a newly recommended one? Thx! |
@BenjiTheC what about the defaults that ship with eslint? |
What I normally do is
so the
|
Now covered in our docs: https://redux-toolkit.js.org/usage/immer-reducers#linting-state-mutations |
l'm a bit late to the party but I create my slices with naming convention of
|
better solution, update the docs with this logic ? |
You should probably not turn off the rule completely, otherwise it won't warn you when reassigning // @filename .eslintrc.js
module.exports = {
...
overrides: [
{
files: ['scr/**/slice.ts'],
rules: { 'no-param-reassign': ['error', { props: false }] },
},
],
} |
I just had this idea when another user tried to assign to the
state
function argument.There is actually an eslint rule for that:
no-param-reassign
I'd suggest we either add that rule as a recommendation somehwere in the docs or go even one step farther and create a shareable config package .
That way we could add some more recommended rules in the future.
I'm thinking of later-on adding a self-written eslint-typescript rule that disallows assigning to anything of the type
Draft
or something similar.The text was updated successfully, but these errors were encountered: