Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var NoDeprecatedRule = rule.Rule{ Name: "react/no-deprecated", Run: func(ctx rule.RuleContext, options any) rule.RuleListeners { pragma := detectJsxPragma(ctx.SourceFile.Text()) if pragma == "" { pragma = reactutil.GetReactPragma(ctx.Settings) } createClass := reactutil.GetReactCreateClass(ctx.Settings) deprecated := buildDeprecated(pragma) report := func(node *ast.Node, methodName string, d deprecationInfo) { ctx.ReportNode(node, rule.RuleMessage{ Id: "deprecated", Description: formatMessage(methodName, d), }) } check := func(node *ast.Node, methodName string) { d, ok := deprecated[methodName] if !ok { return } if !versionActive(ctx.Settings, d.version) { return } report(node, methodName, d) } checkComponentMembers := func(members []*ast.Node) { for _, m := range members { if m == nil { continue } key := m.Name() if key == nil || key.Kind != ast.KindIdentifier { continue } name := key.AsIdentifier().Text check(key, name) } } return rule.RuleListeners{ ast.KindPropertyAccessExpression: func(node *ast.Node) { path := buildDottedPath(node) if path == "" { return } check(node, path) }, ast.KindImportDeclaration: func(node *ast.Node) { decl := node.AsImportDeclaration() if decl == nil || decl.ModuleSpecifier == nil || decl.ModuleSpecifier.Kind != ast.KindStringLiteral { return } canonical := canonicalForModuleSource(decl.ModuleSpecifier.AsStringLiteral().Text) if canonical == "" { return } if decl.ImportClause == nil { return } clause := decl.ImportClause.AsImportClause() if clause == nil || clause.NamedBindings == nil || clause.NamedBindings.Kind != ast.KindNamedImports { return } named := clause.NamedBindings.AsNamedImports() if named == nil || named.Elements == nil { return } for _, elem := range named.Elements.Nodes { spec := elem.AsImportSpecifier() if spec == nil { continue } importedNode := spec.PropertyName if importedNode == nil { importedNode = spec.Name() } if importedNode == nil || importedNode.Kind != ast.KindIdentifier { continue } check(elem, canonical+"."+importedNode.AsIdentifier().Text) } }, ast.KindVariableDeclaration: func(node *ast.Node) { vd := node.AsVariableDeclaration() if vd == nil || vd.Initializer == nil { return } bindingName := vd.Name() if bindingName == nil || bindingName.Kind != ast.KindObjectBindingPattern { return } init := ast.SkipParentheses(vd.Initializer) canonical := "" if init.Kind == ast.KindCallExpression { call := init.AsCallExpression() if call.Arguments != nil && len(call.Arguments.Nodes) > 0 { arg0 := ast.SkipParentheses(call.Arguments.Nodes[0]) if arg0.Kind == ast.KindStringLiteral { canonical = canonicalForModuleSource(arg0.AsStringLiteral().Text) } } } if canonical == "" && init.Kind == ast.KindIdentifier { canonical = canonicalForModuleIdentifier(init.AsIdentifier().Text) } if canonical == "" { return } obp := bindingName.AsBindingPattern() if obp == nil || obp.Elements == nil { return } for _, elem := range obp.Elements.Nodes { if elem == nil { continue } be := elem.AsBindingElement() if be == nil { continue } if be.DotDotDotToken != nil { continue } keyNode := be.PropertyName if keyNode == nil { keyNode = be.Name() } if keyNode == nil || keyNode.Kind != ast.KindIdentifier { continue } check(keyNode, canonical+"."+keyNode.AsIdentifier().Text) } }, ast.KindClassDeclaration: func(node *ast.Node) { if !reactutil.ExtendsReactComponent(node, pragma) { return } checkComponentMembers(node.Members()) }, ast.KindClassExpression: func(node *ast.Node) { if !reactutil.ExtendsReactComponent(node, pragma) { return } checkComponentMembers(node.Members()) }, ast.KindObjectLiteralExpression: func(node *ast.Node) { if !reactutil.IsCreateReactClassObjectArg(node, pragma, createClass) { return } ol := node.AsObjectLiteralExpression() if ol == nil || ol.Properties == nil { return } checkComponentMembers(ol.Properties.Nodes) }, } }, }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.