Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var OnlyThrowErrorRule = rule.CreateRule(rule.Rule{ Name: "only-throw-error", Run: func(ctx rule.RuleContext, options any) rule.RuleListeners { opts, ok := options.(OnlyThrowErrorOptions) if !ok { opts = OnlyThrowErrorOptions{} } if opts.Allow == nil { opts.Allow = []utils.TypeOrValueSpecifier{} } if opts.AllowInline == nil { opts.AllowInline = []string{} } if opts.AllowThrowingAny == nil { opts.AllowThrowingAny = utils.Ref(true) } if opts.AllowThrowingUnknown == nil { opts.AllowThrowingUnknown = utils.Ref(true) } return rule.RuleListeners{ ast.KindThrowStatement: func(node *ast.Node) { expr := node.Expression() t := ctx.TypeChecker.GetTypeAtLocation(expr) if utils.TypeMatchesSomeSpecifier(t, opts.Allow, opts.AllowInline, ctx.Program) { return } if utils.IsTypeFlagSet(t, checker.TypeFlagsUndefined) { ctx.ReportNode(node, buildUndefMessage()) return } if *opts.AllowThrowingAny && utils.IsTypeAnyType(t) { return } if *opts.AllowThrowingUnknown && utils.IsTypeUnknownType(t) { return } if utils.IsErrorLike(ctx.Program, ctx.TypeChecker, t) { return } ctx.ReportNode(expr, buildObjectMessage()) }, } }, })
Functions ¶
This section is empty.
Types ¶
type OnlyThrowErrorOptions ¶
type OnlyThrowErrorOptions struct {
Allow []utils.TypeOrValueSpecifier
AllowInline []string
AllowThrowingAny *bool
AllowThrowingUnknown *bool
}
Click to show internal directories.
Click to hide internal directories.