Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var NoWillUpdateSetStateRule = rule.Rule{ Name: "react/no-will-update-set-state", Run: func(ctx rule.RuleContext, options any) rule.RuleListeners { disallowInFunc := parseDisallowInFunc(options) checkUnsafe := shouldCheckUnsafe(ctx.Settings) return rule.RuleListeners{ ast.KindCallExpression: func(node *ast.Node) { call := node.AsCallExpression() callee := ast.SkipParentheses(call.Expression) if callee.Kind != ast.KindPropertyAccessExpression { return } prop := callee.AsPropertyAccessExpression() if ast.SkipParentheses(prop.Expression).Kind != ast.KindThisKeyword { return } if esTreeNameOf(prop.Name()) != "setState" { return } depth := 0 for p := node.Parent; p != nil; p = p.Parent { if ast.IsFunctionLikeDeclaration(p) { depth++ } if !isStopper(p) { continue } sn := stopperName(p) if sn != methodName && (!checkUnsafe || sn != unsafeMethodName) { continue } if !disallowInFunc && depth > 1 { continue } ctx.ReportNode(callee, rule.RuleMessage{ Id: "noSetState", Description: "Do not use setState in " + sn, }) return } }, } }, }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.