predeclared

command module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: BSD-3-Clause Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

The predeclared static analysis finds declarations in Go source code that shadow any of Go's predeclared identifiers.

The analysis and the available flags are documented in the package comment in the 'passes/predeclared/predeclared.go' file. The documentation can be read using 'go doc' or on pkg.go.dev.

go doc github.com/nishanths/predeclared/passes/predeclared

https://pkg.go.dev/github.com/nishanths/predeclared/passes/predeclared

The list of predeclared identifiers can be found in the language specification. The predeclared identifiers, as of go1.26, are listed below for reference.

https://golang.org/ref/spec#Predeclared_identifiers

Types:
    any bool byte comparable
    complex64 complex128 error float32 float64
    int int8 int16 int32 int64 rune string
    uint uint8 uint16 uint32 uint64 uintptr

Constants:
    true false iota

Zero value:
    nil

Functions:
    append cap clear close complex copy delete imag len
    make max min new panic print println real recover

Usage

The predeclared command can be installed using 'go install'.

go install github.com/nishanths/predeclared@latest

The predeclared command can be used with the -vettool flag of 'go vet'. See 'go help vet' for more information.

go install github.com/nishanths/predeclared@latest
go vet -vettool=$(which predeclared)

The Go package in the 'passes/predeclared' directory provides an analysis.Analyzer value that can be used by analysis driver programs. See https://golang.org/x/tools/go/analysis for more details.

Examples

For the source file:

package a

import "strconv"

func clear[S ~[]E, E any](s S) { ... }

func baz(s string) {
	const max = 8192
	int, err := strconv.Atoi(s)
	...
}

func copy(dst, src string) { ... }

the predeclared analysis reports these diagnostics:

a.go:5:6: clear: shadows predeclared identifier
a.go:8:8: max: shadows predeclared identifier
a.go:9:2: int: shadows predeclared identifier
a.go:14:6: copy: shadows predeclared identifier

Documentation

Overview

Command predeclared applies the predeclared static analysis to the specified Go packages.

Directories

Path Synopsis
passes
predeclared
Package predeclared provides a static analysis that finds declarations in Go source code that shadow any of Go's predeclared identifiers.
Package predeclared provides a static analysis that finds declarations in Go source code that shadow any of Go's predeclared identifiers.

Jump to

Keyboard shortcuts

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