-
Notifications
You must be signed in to change notification settings - Fork 657
Conversation
catch up with base
This seemed like a pretty safe rule to start on. This is very much a work in progress, just thought I'd push the beginnings up in case anybody wanted to steer me away from a bad route I'm starting to take. Depending on how deep we have to check, I imagine I'll likely need some kind of recursive validator. I noticed the spreadsheet in this issue doesn't say anything about this being fixable, but it seems to me that setState or spreading could be used to fix. |
0d7069a
to
9f488ae
Compare
9f488ae
to
ef3b807
Compare
packages/@romejs/js-compiler/lint/rules/react/noDirectMutationState.ts
Outdated
Show resolved
Hide resolved
bodyBodyNode.expression.left.type === 'MemberExpression' && | ||
bodyBodyNode.expression.left.object.type === 'MemberExpression' && | ||
bodyBodyNode.expression.left.object.object.type === 'ThisExpression' && | ||
bodyBodyNode.expression.left.object.property.value.type === 'Identifier' && | ||
bodyBodyNode.expression.left.object.property.value.name === 'state' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With #396 this can now just be:
bodyBodyNode.expression.left.type === 'MemberExpression' && | |
bodyBodyNode.expression.left.object.type === 'MemberExpression' && | |
bodyBodyNode.expression.left.object.object.type === 'ThisExpression' && | |
bodyBodyNode.expression.left.object.property.value.type === 'Identifier' && | |
bodyBodyNode.expression.left.object.property.value.name === 'state' | |
doesNodeMatchPattern(bodyBodyNode.expression.left, 'this.state') |
Or if this check is valuable you could also do:
doesNodeMatchPattern(bodyBodyNode.expression.left, 'this.state.**')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like doesNodeMatchPattern was having difficulty with ThisExpressions
, so I ended up having to tweak getNodeReferenceParts
slightly. I imagine you may want to look over the tweak. Also I have yet to implement this pattern for what I ended up doing up in the constructor.
packages/@romejs/js-compiler/lint/rules/react/noDirectMutationState.ts
Outdated
Show resolved
Hide resolved
Currently I'm thinking about the exemplified violation below:
My thought is that |
I didn't forget about this. My employer has been very demanding lately. Hoping that will end in a weekish. |
@@ -0,0 +1,79 @@ | |||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think new files should not have this comment anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah since moving to the new org new files don't need the header.
I intend to pick this back up over the weekend |
Hey @macovedj, I also decided this was a good first rule to start on and so I implemented it but didn't check if someone else was working on it too. Here is the commit in case you want to take a look. I noticed you didn't have test file in this pr so if you don't have one locally, you should grab the one in my commit and test with that. |
@stefanuros why don't you just go ahead and merge then? I prioritized some other stuff over rome for awhile, so never really finished implementing. Since you did , you should go ahead and merge and I can close this one, and I'll pick up another one when I can. |
@stefanuros I can see you're actively working on your lint issue. If you get stuck and want a second pair of eyes, I'm happy to lend them. I haven't looked at your PR in depth. |
no-direct-mutation-state eslint rule