Skip to content

Commit

Permalink
Ignore TypeSpec
Browse files Browse the repository at this point in the history
TypeSpec is an inline type. There is no complexity for these.
  • Loading branch information
elliotchance committed Oct 8, 2018
1 parent 907b54e commit f829d3f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
12 changes: 11 additions & 1 deletion main.go
Expand Up @@ -139,7 +139,17 @@ func LineComplexity(line ast.Stmt) int {

total := 0
for _, spec := range specs {
total += exprsComplexity(spec.(*ast.ValueSpec).Values)
switch s := spec.(type) {
case *ast.TypeSpec:
// TypeSpec is an inline type. There is no complexity for these.

case *ast.ValueSpec:
total += exprsComplexity(s.Values)

default:
printLine(-1, line)
panic(n)
}
}

return total
Expand Down
3 changes: 3 additions & 0 deletions main_test.go
Expand Up @@ -177,4 +177,7 @@ func TestLineComplexity(t *testing.T) {

LC = tf.NamedFunction(t, "Chan", fn)
LC(`make(chan string)`).Returns(1)

LC = tf.NamedFunction(t, "TypeSpec", fn)
LC(`type Foobar struct{}`).Returns(0)
}

0 comments on commit f829d3f

Please sign in to comment.