internal

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FuncCanBeConstructor

func FuncCanBeConstructor(n *ast.FuncDecl) bool

func FuncIsMethod

func FuncIsMethod(n *ast.FuncDecl) (*ast.Ident, bool)

func GetIdent

func GetIdent(expr ast.Expr) (*ast.Ident, bool)

func GetStartingPos

func GetStartingPos(function *ast.FuncDecl) token.Pos

GetStartingPos returns the token starting position of the function taking into account if there are comments.

func NewAdjacentConstructorsNotSortedAlphabetically

func NewAdjacentConstructorsNotSortedAlphabetically(
	structSpec *ast.TypeSpec,
	constructorNotSorted *ast.FuncDecl,
	otherConstructorNotSorted *ast.FuncDecl,
) analysis.Diagnostic

func NewAdjacentStructMethodsNotSortedAlphabetically

func NewAdjacentStructMethodsNotSortedAlphabetically(
	structSpec *ast.TypeSpec,
	method *ast.FuncDecl,
	otherMethod *ast.FuncDecl,
) analysis.Diagnostic

func NewConstructorNotAfterStructType

func NewConstructorNotAfterStructType(structSpec *ast.TypeSpec, constructor *ast.FuncDecl) analysis.Diagnostic

func NewConstructorNotBeforeStructMethod

func NewConstructorNotBeforeStructMethod(
	structSpec *ast.TypeSpec,
	constructor *ast.FuncDecl,
	method *ast.FuncDecl,
) analysis.Diagnostic

func NewUnexportedMethodBeforeExportedForStruct

func NewUnexportedMethodBeforeExportedForStruct(
	structSpec *ast.TypeSpec,
	privateMethod *ast.FuncDecl,
	publicMethod *ast.FuncDecl,
) analysis.Diagnostic

func NodeToBytes

func NodeToBytes(fset *token.FileSet, node ast.Node) ([]byte, error)

NodeToBytes convert the ast.Node in bytes.

func SplitExportedUnexported

func SplitExportedUnexported(funcDecls []*ast.FuncDecl) (exported, unexported []*ast.FuncDecl)

SplitExportedUnexported split functions/methods based on whether they are exported or not.

Types

type ExportedMethods

type ExportedMethods []*ast.FuncDecl

type Feature

type Feature uint8
const (
	ConstructorCheck Feature = 1 << iota
	StructMethodCheck
	AlphabeticalCheck
)

func (*Feature) Enable

func (f *Feature) Enable(other Feature)

func (*Feature) IsEnabled

func (f *Feature) IsEnabled(other Feature) bool

type FileProcessor

type FileProcessor struct {
	// contains filtered or unexported fields
}

FileProcessor Holder to store all the functions that are potential to be constructors and all the structs.

func NewFileProcessor

func NewFileProcessor(fset *token.FileSet, checkers Feature) *FileProcessor

NewFileProcessor creates a new file processor.

func (*FileProcessor) Analyze

func (fp *FileProcessor) Analyze() []analysis.Diagnostic

Analyze check whether the order of the methods in the constructor is correct.

func (*FileProcessor) NewFileNode

func (fp *FileProcessor) NewFileNode(_ *ast.File)

func (*FileProcessor) NewFuncDecl

func (fp *FileProcessor) NewFuncDecl(n *ast.FuncDecl)

func (*FileProcessor) NewTypeSpec

func (fp *FileProcessor) NewTypeSpec(n *ast.TypeSpec)

type StructConstructor

type StructConstructor struct {
	// contains filtered or unexported fields
}

func NewStructConstructor

func NewStructConstructor(funcDec *ast.FuncDecl) (StructConstructor, bool)

func (StructConstructor) GetConstructor

func (sc StructConstructor) GetConstructor() *ast.FuncDecl

func (StructConstructor) GetStructReturn

func (sc StructConstructor) GetStructReturn() *ast.Ident

GetStructReturn Return the struct linked to this "constructor".

type StructHolder

type StructHolder struct {
	// The fileset
	Fset *token.FileSet
	// The features to be analyzed
	Features Feature

	// The struct declaration
	Struct *ast.TypeSpec

	// A Struct constructor is considered if starts with `New...` and the 1st output parameter is a struct
	Constructors []*ast.FuncDecl

	// Struct methods
	StructMethods []*ast.FuncDecl
}

StructHolder contains all the information around a Go struct.

func (*StructHolder) AddConstructor

func (sh *StructHolder) AddConstructor(fn *ast.FuncDecl)

func (*StructHolder) AddMethod

func (sh *StructHolder) AddMethod(fn *ast.FuncDecl)

func (*StructHolder) Analyze

func (sh *StructHolder) Analyze() []analysis.Diagnostic

Analyze applies the linter to the struct holder.

type UnexportedMethods

type UnexportedMethods []*ast.FuncDecl

Jump to

Keyboard shortcuts

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