no_var

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: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoVarRule = rule.Rule{
	Name: "no-var",
	Run: func(ctx rule.RuleContext, options any) rule.RuleListeners {
		return rule.RuleListeners{
			ast.KindVariableDeclarationList: func(node *ast.Node) {

				if node.Flags&ast.NodeFlagsBlockScoped != 0 {
					return
				}

				if isInDeclareGlobal(node) {
					return
				}

				reportNode := node
				if node.Parent != nil && node.Parent.Kind == ast.KindVariableStatement &&
					!ast.HasSyntacticModifier(node.Parent, ast.ModifierFlagsExport) {
					reportNode = node.Parent
				}

				msg := rule.RuleMessage{
					Id:          "unexpectedVar",
					Description: "Unexpected var, use let or const instead.",
				}

				if ctx.TypeChecker != nil && canFix(node, &ctx) {
					varRange := utils.GetVarKeywordRange(node, ctx.SourceFile)
					ctx.ReportNodeWithFixes(reportNode, msg,
						rule.RuleFixReplaceRange(varRange, "let"))
				} else {
					ctx.ReportNode(reportNode, msg)
				}
			},
		}
	},
}

https://eslint.org/docs/latest/rules/no-var

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