funcpkg

package
v0.0.0-...-d31700d Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var Func = Rule{

	Name: namepkg.Rule{
		MaxLen: 30, Style: "camelCase",
	},
	Size: sizeRule{
		MaxParams: 5, MaxResults: 3, MaxStatements: 30,
	},
	// contains filtered or unexported fields
}
View Source
var FuncInTest = Rule{

	Name: namepkg.Rule{
		MaxLen: 50, Style: "camelCase",
	},
	Size: sizeRule{
		MaxParams: 5, MaxResults: 3, MaxStatements: 30,
	},
	// contains filtered or unexported fields
}

Functions

func Check

func Check(isTest bool, node ast.Node, fileSet *token.FileSet)
Example
problems.Clear()
w := walker.New("func.go")
w.Walk(func(isLocal bool, node ast.Node) {
	Check(false, node, w.FileSet)
})

w = walker.New("func_test.go")
w.Walk(func(isLocal bool, node ast.Node) {
	Check(true, node, w.FileSet)
})

problems.Render()
Output:

Types

type Rule

type Rule struct {
	Name namepkg.Rule
	Size sizeRule
	// contains filtered or unexported fields
}

func (*Rule) Check

func (r *Rule) Check(node ast.Node, fileSet *token.FileSet)
Example
var src = `package example
func (receiver *Type) F1(a, b int, c bool)  () {
}

var f = func(a, b int, c bool) {
}


type I1 interface {
  M1()
  M2()(a int, b bool)
  I2
}

type I2 interface{}
`
problems.Clear()
rule := Rule{
	key: "func",
	Name: namepkg.Rule{
		MaxLen: 30, Style: "camelCase",
	},
	Size: sizeRule{
		MaxParams: 2, MaxResults: 1, MaxStatements: 30,
	},
}

w := walker.Parse("example.go", src)
w.Walk(func(isLocal bool, node ast.Node) {
	rule.Check(node, w.FileSet)
})
problems.Render()
Output:

+-----------------+-----------------------------------------------+----------------------+
|    position     |                    problem                    |         rule         |
+-----------------+-----------------------------------------------+----------------------+
| example.go:2:25 | func F1 params size: 3, limit: 2              | func.size.maxParams  |
| example.go:5:13 | literal func params size: 3, limit: 2         | func.size.maxParams  |
| example.go:11:7 | interface method M2 results size: 2, limit: 1 | func.size.maxResults |
+-----------------+-----------------------------------------------+----------------------+

Jump to

Keyboard shortcuts

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