package main func init() { register(Check{ Seq: 24, ID: "2e", Title: "Warn on any usage in Go and TypeScript", Run: func(ctx *ScanContext, rep *Reporter) { // By default only warn on `any` introduced in the unstaged working-tree // diff; --all-any scans every source file. var keep lineKeeper if !ctx.allAny { idx := newDiffIndex() keep = idx.isChanged } var anyWarnings []anyUsageWarning for _, target := range ctx.backendTargets { for _, w := range checkGoAnyUsage(target.root, keep) { w.file = prefixDisplayPath(target.displayOrRoot(), w.file) anyWarnings = append(anyWarnings, w) } } for _, target := range ctx.pluginTargets { for _, w := range checkGoAnyUsage(target.root, keep) { w.file = prefixDisplayPath(target.display, w.file) anyWarnings = append(anyWarnings, w) } } for _, target := range collectESLintDirectiveTargets(ctx.repoRoot, ctx.frontendTargets) { for _, w := range checkTypeScriptAnyUsage(target.dir, keep) { w.file = prefixDisplayPath(target.label, w.file) anyWarnings = append(anyWarnings, w) } } if len(anyWarnings) == 0 { if ctx.allAny { rep.OK("no any usage found") } else { rep.OK("no any usage in changed lines") } return } scope := "any usage" if !ctx.allAny { scope = "any usage in changed lines" } limit := min(len(anyWarnings), maxAnyWarningsPrinted) extra := "" if !ctx.allAny { extra = ", --all-any to scan all" } rep.Warn("%d %s (showing %d%s)", len(anyWarnings), scope, limit, extra) for _, w := range anyWarnings[:limit] { rep.Findingf("%s:%d [%s] %s", w.file, w.line, w.lang, w.snippet) } if len(anyWarnings) > limit { rep.Findingf("... %d more omitted", len(anyWarnings)-limit) } }, }) }