Documentation
¶
Overview ¶
Package filter applies file and symbol filters to skip noisy error sites.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultSymbolGlobs = []string{
"fmt.Print*",
"fmt.Fprint*",
"fmt.Sprint*",
"fmt.Scan*",
"log.Print*",
"log.Output",
"strings.Builder.Write*",
"bytes.Buffer.Write*",
"bytes.Buffer.Read*",
"io.WriteString",
}
DefaultSymbolGlobs defines a list of function signatures that are commonly ignored in Go programs and thus excluded by default to reduce noise.
This list includes printing functions and memory buffer writes which, while returning errors, are rarely handled in application logic unless strict reliability determines 100% check coverage.
Functions ¶
func GetTestingParamName ¶
GetTestingParamName returns the name of the testing parameter (e.g., "t", "b", "f") if the function is a valid test handler.
This is useful for refactoring tools that need to inject "t.Fatal(err)" calls instead of returns.
decl: The function declaration.
Returns the identifier name of the first parameter if it is a testing type, or empty string.
func IsTestHandler ¶
IsTestHandler checks if the provided function declaration matches a standard Go testing entry point signature.
It detects:
- Unit Tests: func TestXxx(t *testing.T)
- Benchmarks: func BenchmarkXxx(b *testing.B)
- Fuzz Tests: func FuzzXxx(f *testing.F)
- Test Main: func TestMain(m *testing.M)
- Examples: func ExampleXxx()
These functions are critical because their signatures cannot be modified (e.g., adding an error return) without breaking the 'go test' runner.
decl: The function declaration to inspect.
Returns true if the function is a testing entry point.
func IsTestHelper ¶
IsTestHelper determines if the function declaration behaves as a test helper. A function is considered a test helper if it calls the `Helper()` method on a parameter of type `*testing.T`, `*testing.B`, or `*testing.F`.
This detection allows refactoring tools to choose `t.Fatal(err)` injection over signature modification, preserving the helper's signature (which often cannot return errors without breaking test suite patterns).
decl: The function declaration to inspect.
Returns true if `Helper()` is called, and the name of the testing parameter (e.g. "t").
Types ¶
type Filter ¶
type Filter struct {
// contains filtered or unexported fields
}
Filter determines whether specific files or symbols should be excluded from analysis. It uses glob patterns for file paths and symbol names, and inspects file headers for generated code markers.
func New ¶
New creates a new Filter with the provided glob patterns.
fileGlobs: A list of patterns to match against file paths (e.g., "*_test.go", "vendor/*"). symbolGlobs: A list of patterns to match against fully qualified symbol names (e.g., "fmt.*", "github.com/pkg/errors.Wrap").
func (*Filter) MatchesFile ¶
MatchesFile checks if the file corresponding to the provided token.Pos is excluded. It excludes files if: 1. The filename matches a configured exclude glob. 2. The file content contains a standard "Code generated ... DO NOT EDIT." header in the first 20 lines.
fset: The file set containing the position. pos: The position within the file to check.