Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var RequireArraySortCompareRule = rule.CreateRule(rule.Rule{ Name: "require-array-sort-compare", Run: func(ctx rule.RuleContext, options any) rule.RuleListeners { opts, ok := options.(RequireArraySortCompareOptions) if !ok { opts = RequireArraySortCompareOptions{} } if opts.IgnoreStringArrays == nil { opts.IgnoreStringArrays = utils.Ref(true) } return rule.RuleListeners{ ast.KindCallExpression: func(node *ast.Node) { expr := node.AsCallExpression() if len(expr.Arguments.Nodes) != 0 { return } callee := expr.Expression if !ast.IsAccessExpression(callee) { return } if propertyName, found := checker.Checker_getAccessedPropertyName(ctx.TypeChecker, callee); !found || (propertyName != "sort" && propertyName != "toSorted") { return } calleeObjType := utils.GetConstrainedTypeAtLocation(ctx.TypeChecker, callee.Expression()) if *opts.IgnoreStringArrays && checker.Checker_isArrayOrTupleType(ctx.TypeChecker, calleeObjType) { if utils.Every(checker.Checker_getTypeArguments(ctx.TypeChecker, calleeObjType), func(t *checker.Type) bool { return utils.IsTypeFlagSet(t, checker.TypeFlagsString) }) { return } } if utils.Every(utils.UnionTypeParts(calleeObjType), func(t *checker.Type) bool { return checker.Checker_isArrayOrTupleType(ctx.TypeChecker, t) }) { ctx.ReportNode(node, buildRequireCompareMessage()) } }, } }, })
Functions ¶
This section is empty.
Types ¶
type RequireArraySortCompareOptions ¶
type RequireArraySortCompareOptions struct {
IgnoreStringArrays *bool
}
Click to show internal directories.
Click to hide internal directories.