mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[eslint] strip tailing property in assignments (#16784)
* [eslint] strip tailing property in assignments * inline `stripTailingPropInAssignment`
This commit is contained in:
@@ -584,6 +584,16 @@ const tests = {
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
code: normalizeIndent`
|
||||
function MyComponent(props) {
|
||||
let foo = {}
|
||||
useEffect(() => {
|
||||
foo.bar.baz = 43;
|
||||
}, [foo.bar]);
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
// Valid because we assign ref.current
|
||||
// ourselves. Therefore it's likely not
|
||||
@@ -6395,6 +6405,39 @@ const tests = {
|
||||
// Keep this until major IDEs and VS Code FB ESLint plugin support Suggestions API.
|
||||
options: [{enableDangerousAutofixThisMayCauseInfiniteLoops: true}],
|
||||
},
|
||||
{
|
||||
code: normalizeIndent`
|
||||
function MyComponent(props) {
|
||||
let foo = {}
|
||||
useEffect(() => {
|
||||
foo.bar.baz = 43;
|
||||
props.foo.bar.baz = 1;
|
||||
}, []);
|
||||
}
|
||||
`,
|
||||
errors: [
|
||||
{
|
||||
message:
|
||||
"React Hook useEffect has missing dependencies: 'foo.bar' and 'props.foo.bar'. " +
|
||||
'Either include them or remove the dependency array.',
|
||||
suggestions: [
|
||||
{
|
||||
desc:
|
||||
'Update the dependencies array to be: [foo.bar, props.foo.bar]',
|
||||
output: normalizeIndent`
|
||||
function MyComponent(props) {
|
||||
let foo = {}
|
||||
useEffect(() => {
|
||||
foo.bar.baz = 43;
|
||||
props.foo.bar.baz = 1;
|
||||
}, [foo.bar, props.foo.bar]);
|
||||
}
|
||||
`,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
|
||||
@@ -1437,6 +1437,12 @@ function getDependency(node) {
|
||||
)
|
||||
) {
|
||||
return getDependency(node.parent);
|
||||
} else if (
|
||||
node.type === 'MemberExpression' &&
|
||||
node.parent &&
|
||||
node.parent.type === 'AssignmentExpression'
|
||||
) {
|
||||
return node.object;
|
||||
} else {
|
||||
return node;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user