Showing 65 of 81 total issues
Avoid deeply nested control flow statements. Open
Open
if ok {
// add init
var inject []node
inject = append(inject, typ...)
for i := start; i < pos; i++ {
Method parser.parseStmt
has 6 return statements (exceeds 4 allowed). Open
Open
func (p *parser) parseStmt() (stmts []goast.Stmt) {
onlyForRecover := p.ident
pos := p.ns[p.ident].pos
Method parser.isComplex
has 5 return statements (exceeds 4 allowed). Open
Open
func (p *parser) isComplex(e goast.Expr) (isComplex, ok bool) {
if par, ok := e.(*goast.ParenExpr); ok {
if st, ok := par.X.(*goast.StarExpr); ok {
if id, ok := st.X.(*goast.Ident); ok {
if v, ok := p.initVars.get(id.Name); ok {
Method goType.getMinLimit
has 5 return statements (exceeds 4 allowed). Open
Open
func (g goType) getMinLimit(col int) (size int, ok bool) {
if !g.isArray() {
return
}
if col > len(g.arrayNode) {
Method strChanger.Visit
has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring. Open
Open
func (s strChanger) Visit(node goast.Node) (w goast.Visitor) {
if call, ok := node.(*goast.CallExpr); ok {
if sel, ok := call.Fun.(*goast.SelectorExpr); ok {
if id, ok := sel.X.(*goast.Ident); ok {
if id.Name == "fmt" || id.Name == "math" {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"