[eslint] strip tailing property in assignments (#16784)

* [eslint] strip tailing property in assignments

* inline `stripTailingPropInAssignment`
This commit is contained in:
Zen
2020-04-04 21:26:39 +08:00
committed by GitHub
parent f625fce857
commit 2ff27ec112
2 changed files with 49 additions and 0 deletions
@@ -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;
}