Skip to content
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

no-did-mount-set-state with cDU or cDM as ClassProperties #1613

Merged
merged 1 commit into from
May 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/util/makeNoMethodSetStateRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function makeNoMethodSetStateRule(methodName, shouldCheckUnsafeCb) {
depth++;
}
if (
(ancestor.type !== 'Property' && ancestor.type !== 'MethodDefinition') ||
(ancestor.type !== 'Property' && ancestor.type !== 'MethodDefinition' && ancestor.type !== 'ClassProperty') ||
!nameMatches(ancestor.key.name) ||
(mode !== 'disallow-in-func' && depth > 1)
) {
Expand Down
14 changes: 14 additions & 0 deletions tests/lib/rules/no-did-mount-set-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ ruleTester.run('no-did-mount-set-state', rule, {
errors: [{
message: 'Do not use setState in componentDidMount'
}]
}, {
code: `
class Hello extends React.Component {
componentDidMount = () => {
this.setState({
data: data
});
}
}
`,
parser: 'babel-eslint',
errors: [{
message: 'Do not use setState in componentDidMount'
}]
}, {
code: `
var Hello = createReactClass({
Expand Down
14 changes: 14 additions & 0 deletions tests/lib/rules/no-did-update-set-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ ruleTester.run('no-did-update-set-state', rule, {
errors: [{
message: 'Do not use setState in componentDidUpdate'
}]
}, {
code: `
class Hello extends React.Component {
componentDidUpdate = () => {
this.setState({
data: data
});
}
}
`,
parser: 'babel-eslint',
errors: [{
message: 'Do not use setState in componentDidUpdate'
}]
}, {
code: `
var Hello = createReactClass({
Expand Down