no_undef

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoUndefRule = rule.Rule{
	Name:             "no-undef",
	RequiresTypeInfo: true,
	Run: func(ctx rule.RuleContext, options any) rule.RuleListeners {
		opts := parseOptions(options)

		if ctx.TypeChecker == nil {
			return rule.RuleListeners{}
		}

		declaredGlobals := parseGlobalComments(ctx.SourceFile.Text())

		return rule.RuleListeners{
			ast.KindIdentifier: func(node *ast.Node) {

				if shouldSkip(node, opts.checkTypeof) {
					return
				}

				if node.Parent.Kind == ast.KindShorthandPropertyAssignment {
					valueSym := ctx.TypeChecker.GetShorthandAssignmentValueSymbol(node.Parent)
					if valueSym != nil {
						return
					}
				} else {
					sym := ctx.TypeChecker.GetSymbolAtLocation(node)
					if sym != nil {
						return
					}
				}

				name := node.Text()

				if declaredGlobals[name] {
					return
				}

				ctx.ReportNode(node, rule.RuleMessage{
					Id:          "undef",
					Description: fmt.Sprintf("'%s' is not defined.", name),
				})
			},
		}
	},
}

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