package filters

import "github.com/zmap/zlint/v3/integration/lints/filters"

Index

Functions

func Declarations

func Declarations(decls []ast.Decl, predicate func(decl ast.Decl) bool) (filtered []ast.Decl)

Declarations takes in a list of a declarations and a predicate that takes in one declaration and returns a boolean. Only the declarations for which `predicate` returns true will be included in the returned list of declarations.

For example, the following returns a list of only function declarations.

filters.Declarations(tree.Decls, func(decl ast.Decl) bool {
	_, ok := decl.(*ast.FuncDecl)
	return ok
})

The order of declarations is maintained.

func FunctionsOnly

func FunctionsOnly(decls []ast.Decl) []ast.Decl

FunctionsOnly returns a list of only the most outer function declarations present within the provided list. This filter does NOT recurse into those function declarations to find lambdas. For example, the following file...

func hi() bool {
	return func() bool {
		return true
	}()
}

func hello() bool {
	return false
}

...will return the hi and hello functions but not the inner lambda within hi.

func IsAGoFile

func IsAGoFile(file *lint.File) bool

func IsALint

func IsALint(file *lint.File) bool

func IsATest

func IsATest(file *lint.File) bool

Source Files

files.go nodes.go

Version
v3.6.6 (latest)
Published
Apr 19, 2025
Platform
linux/amd64
Imports
3 packages
Last checked
2 weeks ago

Tools for package owners.