Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var NoUselessCatchRule = rule.Rule{ Name: "no-useless-catch", Run: func(ctx rule.RuleContext, options any) rule.RuleListeners { return rule.RuleListeners{ ast.KindCatchClause: func(node *ast.Node) { catchClause := node.AsCatchClause() if catchClause == nil { return } if catchClause.VariableDeclaration == nil { return } varDecl := catchClause.VariableDeclaration.AsVariableDeclaration() if varDecl == nil || varDecl.Name() == nil { return } paramName := varDecl.Name() if paramName.Kind != ast.KindIdentifier { return } catchParamText := paramName.AsIdentifier().Text if catchClause.Block == nil { return } block := catchClause.Block.AsBlock() if block == nil || block.Statements == nil || len(block.Statements.Nodes) == 0 { return } stmt := block.Statements.Nodes[0] if stmt == nil || stmt.Kind != ast.KindThrowStatement { return } throwStmt := stmt.AsThrowStatement() if throwStmt == nil || throwStmt.Expression == nil { return } thrown := ast.SkipParentheses(throwStmt.Expression) if thrown == nil || thrown.Kind != ast.KindIdentifier { return } if thrown.AsIdentifier().Text != catchParamText { return } tryStmt := node.Parent if tryStmt == nil || tryStmt.Kind != ast.KindTryStatement { return } tryData := tryStmt.AsTryStatement() if tryData == nil { return } if tryData.FinallyBlock != nil { ctx.ReportNode(node, rule.RuleMessage{ Id: "unnecessaryCatchClause", Description: "Unnecessary catch clause.", }) } else { ctx.ReportNode(tryStmt, rule.RuleMessage{ Id: "unnecessaryCatch", Description: "Unnecessary try/catch wrapper.", }) } }, } }, }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.