no_shadow

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoShadowRule = rule.Rule{
	Name: "no-shadow",
	Run: func(ctx rule.RuleContext, rawOptions any) rule.RuleListeners {
		opts := parseOptions(rawOptions)
		if ctx.SourceFile == nil {
			return rule.RuleListeners{}
		}

		b := &builder{sourceFile: ctx.SourceFile}
		global := b.buildProgram(ctx.SourceFile)

		filename := ""
		if ctx.SourceFile.AsNode() != nil {
			filename = ctx.SourceFile.FileName()
		}
		isDeclFile := strings.HasSuffix(filename, ".d.ts") ||
			strings.HasSuffix(filename, ".d.cts") ||
			strings.HasSuffix(filename, ".d.mts")

		builtinGlobals := map[string]bool{}
		if opts.builtinGlobals {
			for name := range ecmaScriptGlobals {
				builtinGlobals[name] = true
			}
			if ctx.TypeChecker != nil && ctx.Program != nil {
				for _, sym := range ctx.TypeChecker.GetSymbolsInScope(ctx.SourceFile.AsNode(), ast.SymbolFlagsValue) {
					if sym == nil || sym.Name == "" {
						continue
					}
					if utils.IsSymbolFromDefaultLibrary(ctx.Program, sym) {
						builtinGlobals[sym.Name] = true
					}
				}
			}
		}
		b.builtinGlobals = builtinGlobals

		for _, s := range b.allScopes {
			if s.globalAugmentation {
				continue
			}
			for _, v := range s.vars {
				if opts.allow[v.name] {
					continue
				}
				if v.name == "this" {
					continue
				}
				if isDuplicatedClassNameInClassScope(v) {
					continue
				}
				if isDeclFile && v.declareModifier {
					continue
				}
				b.checkVariable(ctx, s, v, opts, global)
			}
		}

		return rule.RuleListeners{}
	},
}

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