Skip to content

Commit 2162adb

Browse files
authored
Describe issues found as complex nested instead of deeply nested (#9)
Complexity is not about just nesting depth, there are other considerations. Closes #8
1 parent a072451 commit 2162adb

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Go Doc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](http://godoc.org/github.com/nakabonne/nestif)
44

5-
Reports deeply nested if statements in Go code, by calculating its complexities based on the rules defined by the [Cognitive Complexity white paper by G. Ann Campbell](https://www.sonarsource.com/docs/CognitiveComplexity.pdf).
5+
Reports complex nested if statements in Go code, by calculating its complexities based on the rules defined by the [Cognitive Complexity white paper by G. Ann Campbell](https://www.sonarsource.com/docs/CognitiveComplexity.pdf).
66

77
It helps you find if statements that make your code hard to read, and clarifies which parts to refactor.
88

cmd/nestif/main_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,23 @@ func TestRun(t *testing.T) {
3131
args: []string{"../../testdata/a.go"},
3232
minComplexity: 1,
3333
top: 10,
34-
want: "../../testdata/a.go:9:2: `if b1` is deeply nested (complexity: 1)\n",
34+
want: "../../testdata/a.go:9:2: `if b1` has complex nested blocks (complexity: 1)\n",
3535
code: 0,
3636
},
3737
{
3838
name: "show only top 2",
3939
args: []string{"../../testdata/d.go"},
4040
minComplexity: 1,
4141
top: 2,
42-
want: "../../testdata/d.go:16:2: `if b1` is deeply nested (complexity: 3)\n../../testdata/d.go:6:2: `if b1` is deeply nested (complexity: 1)\n",
42+
want: "../../testdata/d.go:16:2: `if b1` has complex nested blocks (complexity: 3)\n../../testdata/d.go:6:2: `if b1` has complex nested blocks (complexity: 1)\n",
4343
code: 0,
4444
},
4545
{
4646
name: "show only those with complexity of 2 or more",
4747
args: []string{"../../testdata/d.go"},
4848
minComplexity: 2,
4949
top: 10,
50-
want: "../../testdata/d.go:16:2: `if b1` is deeply nested (complexity: 3)\n",
50+
want: "../../testdata/d.go:16:2: `if b1` has complex nested blocks (complexity: 3)\n",
5151
code: 0,
5252
},
5353
{
@@ -63,15 +63,15 @@ func TestRun(t *testing.T) {
6363
args: []string{"../../testdata/a"},
6464
minComplexity: 1,
6565
top: 10,
66-
want: "../../testdata/a/a.go:8:2: `if b1` is deeply nested (complexity: 1)\n",
66+
want: "../../testdata/a/a.go:8:2: `if b1` has complex nested blocks (complexity: 1)\n",
6767
code: 0,
6868
},
6969
{
7070
name: "Check files recursively",
7171
args: []string{"../../testdata/a/..."},
7272
minComplexity: 1,
7373
top: 10,
74-
want: "../../testdata/a/a.go:8:2: `if b1` is deeply nested (complexity: 1)\n../../testdata/a/b/a.go:8:2: `if b1` is deeply nested (complexity: 1)\n",
74+
want: "../../testdata/a/a.go:8:2: `if b1` has complex nested blocks (complexity: 1)\n../../testdata/a/b/a.go:8:2: `if b1` has complex nested blocks (complexity: 1)\n",
7575
code: 0,
7676
},
7777
{
@@ -99,7 +99,7 @@ func TestRun(t *testing.T) {
9999
top: 10,
100100
want: func() string {
101101
path, _ := filepath.Abs("../../testdata/a/a.go")
102-
return path + ":8:2: `if b1` is deeply nested (complexity: 1)\n"
102+
return path + ":8:2: `if b1` has complex nested blocks (complexity: 1)\n"
103103
}(),
104104
code: 0,
105105
},
@@ -109,7 +109,7 @@ func TestRun(t *testing.T) {
109109
args: []string{"../../testdata/a.go"},
110110
minComplexity: 1,
111111
top: 10,
112-
want: "[{\"Pos\":{\"Filename\":\"../../testdata/a.go\",\"Offset\":78,\"Line\":9,\"Column\":2},\"Complexity\":1,\"Message\":\"`if b1` is deeply nested (complexity: 1)\"}]\n",
112+
want: "[{\"Pos\":{\"Filename\":\"../../testdata/a.go\",\"Offset\":78,\"Line\":9,\"Column\":2},\"Complexity\":1,\"Message\":\"`if b1` has complex nested blocks (complexity: 1)\"}]\n",
113113
code: 0,
114114
},
115115
{

nestif.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Use of this source code is governed by a BSD-style
55
// license that can be found in the LICENSE file.
66

7-
// Package nestif provides an API to detect deeply nested if statements.
7+
// Package nestif provides an API to detect complex nested if statements.
88
package nestif
99

1010
import (
@@ -133,7 +133,7 @@ func (c *Checker) makeMessage(complexity int, cond ast.Expr, fset *token.FileSet
133133
if err := p.Fprint(b, fset, cond); err != nil {
134134
c.debug("failed to convert condition into string: %v", err)
135135
}
136-
return fmt.Sprintf("`if %s` is deeply nested (complexity: %d)", b.String(), complexity)
136+
return fmt.Sprintf("`if %s` has complex nested blocks (complexity: %d)", b.String(), complexity)
137137
}
138138

139139
// DebugMode makes it possible to emit debug logs.

nestif_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestCheck(t *testing.T) {
3636
Column: 2,
3737
},
3838
Complexity: 1,
39-
Message: "`if b1` is deeply nested (complexity: 1)",
39+
Message: "`if b1` has complex nested blocks (complexity: 1)",
4040
},
4141
},
4242
},
@@ -53,7 +53,7 @@ func TestCheck(t *testing.T) {
5353
Column: 2,
5454
},
5555
Complexity: 9,
56-
Message: "`if b1` is deeply nested (complexity: 9)",
56+
Message: "`if b1` has complex nested blocks (complexity: 9)",
5757
},
5858
},
5959
},
@@ -70,7 +70,7 @@ func TestCheck(t *testing.T) {
7070
Column: 2,
7171
},
7272
Complexity: 4,
73-
Message: "`if b1` is deeply nested (complexity: 4)",
73+
Message: "`if b1` has complex nested blocks (complexity: 4)",
7474
},
7575
{
7676
Pos: token.Position{
@@ -80,7 +80,7 @@ func TestCheck(t *testing.T) {
8080
Column: 2,
8181
},
8282
Complexity: 4,
83-
Message: "`if b1` is deeply nested (complexity: 4)",
83+
Message: "`if b1` has complex nested blocks (complexity: 4)",
8484
},
8585
},
8686
},

0 commit comments

Comments
 (0)