no_for_in_array

package
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoForInArrayRule = rule.CreateRule(rule.Rule{
	Name: "no-for-in-array",
	Run: func(ctx rule.RuleContext, options any) rule.RuleListeners {
		hasArrayishLength := func(t *checker.Type) bool {
			lengthProperty := checker.Checker_getPropertyOfType(ctx.TypeChecker, t, "length")
			if lengthProperty == nil {
				return false
			}

			return utils.IsTypeFlagSet(checker.Checker_getTypeOfSymbol(ctx.TypeChecker, lengthProperty), checker.TypeFlagsNumberLike)
		}
		isArrayLike := func(t *checker.Type) bool {
			return utils.TypeRecurser(t, func(t *checker.Type) bool {
				return utils.GetNumberIndexType(ctx.TypeChecker, t) != nil && hasArrayishLength(t)
			})
		}

		return rule.RuleListeners{
			ast.KindForInStatement: func(node *ast.Node) {
				t := utils.GetConstrainedTypeAtLocation(ctx.TypeChecker, node.AsForInOrOfStatement().Expression)

				if isArrayLike(t) {
					ctx.ReportRange(
						utils.GetForStatementHeadLoc(ctx.SourceFile, node),
						buildForInViolationMessage(),
					)
				}
			},
		}
	},
})

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL