You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was looking at the cognitive code complexity of the anytype-heart (which is written in my favourite language), but there are some complex parts in there. (I use a max complexity of 11 in my own projects, but I've used 50 here)
Here's the result:
./temp/anytype-heart/cmd/grpcserver/grpc.go:50:1 - main has complexity: 54
complexity = 1
+ 1 (found 'if' at line: 55, complexity = 2)
+ 2 (found 'if' at line: 57, complexity = 4)
+ 1 (found 'if' at line: 62, complexity = 5)
+ 2 (found 'if' at line: 63, complexity = 7)
+ 1 (found 'else' at line: 65, complexity = 8)
+ 1 (found 'if' at line: 70, complexity = 9)
+ 2 (found 'if' at line: 71, complexity = 11)
+ 1 (found 'else' at line: 73, complexity = 12)
+ 1 (found 'if' at line: 78, complexity = 13)
+ 1 (found 'logical operator' at line: 78, complexity = 14)
+ 2 (found 'go' at line: 79, complexity = 16)
+ 1 (found 'if' at line: 92, complexity = 17)
+ 1 (found 'if' at line: 98, complexity = 18)
+ 1 (found 'if' at line: 107, complexity = 19)
+ 1 (found 'if' at line: 119, complexity = 20)
+ 1 (found 'if with lines >= 10' at line: 119, complexity = 21)
+ 1 (found 'if' at line: 144, complexity = 22)
+ 1 (found 'if with lines >= 10' at line: 144, complexity = 23)
+ 2 (found 'has innerfunction' at line: 145, complexity = 25)
+ 2 (found 'if' at line: 153, complexity = 27)
+ 2 (found 'if' at line: 156, complexity = 29)
+ 1 (found 'if' at line: 162, complexity = 30)
+ 1 (found 'if with lines >= 10' at line: 162, complexity = 31)
+ 1 (found 'if with lines >= 25' at line: 162, complexity = 32)
+ 2 (found 'if' at line: 166, complexity = 34)
+ 2 (found 'if' at line: 169, complexity = 36)
+ 2 (found 'if' at line: 174, complexity = 38)
+ 2 (found 'defer' at line: 177, complexity = 40)
+ 2 (found 'if' at line: 186, complexity = 42)
+ 2 (found 'if' at line: 189, complexity = 44)
+ 1 (found 'if' at line: 205, complexity = 45)
+ 1 (found 'go' at line: 232, complexity = 46)
+ 1 (found 'go' at line: 237, complexity = 47)
+ 1 (found 'for' at line: 246, complexity = 48)
+ 1 (found 'for with lines >= 10' at line: 246, complexity = 49)
+ 2 (found 'if' at line: 248, complexity = 51)
+ 3 (found 'if' at line: 249, complexity = 54)
./temp/anytype-heart/core/block/editor/smartblock/smartblock.go:642:1 - Apply has complexity: 54
complexity = 1
+ 1 (found 'if' at line: 644, complexity = 2)
+ 1 (found 'range' at line: 656, complexity = 3)
+ 1 (found 'range with lines >= 10' at line: 656, complexity = 4)
+ 2 (found 'switch' at line: 657, complexity = 6)
+ 1 (found 'if' at line: 679, complexity = 7)
+ 2 (found 'if' at line: 680, complexity = 9)
+ 1 (found 'if' at line: 684, complexity = 10)
+ 1 (found 'logical operator' at line: 684, complexity = 11)
+ 2 (found 'if' at line: 685, complexity = 13)
+ 1 (found 'if' at line: 691, complexity = 14)
+ 1 (found 'logical operator' at line: 691, complexity = 15)
+ 2 (found 'if' at line: 695, complexity = 17)
+ 1 (found 'if' at line: 707, complexity = 18)
+ 1 (found 'if' at line: 714, complexity = 19)
+ 1 (found 'if' at line: 719, complexity = 20)
+ 1 (found 'if' at line: 732, complexity = 21)
+ 1 (found 'logical operator' at line: 732, complexity = 22)
+ 2 (found 'if' at line: 733, complexity = 24)
+ 1 (found 'else' at line: 736, complexity = 25)
+ 1 (found 'has innerfunction' at line: 742, complexity = 26)
+ 1 (found 'assign with lines >= 10' at line: 742, complexity = 27)
+ 1 (found 'assign with lines >= 25' at line: 742, complexity = 28)
+ 1 (found 'if' at line: 770, complexity = 29)
+ 1 (found 'if with lines >= 10' at line: 770, complexity = 30)
+ 1 (found 'else if' at line: 784, complexity = 31)
+ 1 (found 'logical operator' at line: 784, complexity = 32)
+ 2 (found 'if' at line: 771, complexity = 34)
+ 1 (found 'logical operator' at line: 771, complexity = 35)
+ 2 (found 'if' at line: 775, complexity = 37)
+ 2 (found 'if' at line: 778, complexity = 39)
+ 1 (found 'logical operator' at line: 778, complexity = 40)
+ 3 (found 'if' at line: 779, complexity = 43)
+ 1 (found 'if' at line: 792, complexity = 44)
+ 1 (found 'logical operator' at line: 792, complexity = 45)
+ 1 (found 'else' at line: 796, complexity = 46)
+ 1 (found 'if' at line: 801, complexity = 47)
+ 2 (found 'if' at line: 803, complexity = 49)
+ 1 (found 'else' at line: 805, complexity = 50)
+ 1 (found 'if' at line: 813, complexity = 51)
+ 1 (found 'if' at line: 817, complexity = 52)
+ 2 (found 'if' at line: 818, complexity = 54)
./temp/anytype-heart/core/block/editor/state/state.go:416:1 - apply has complexity: 100
complexity = 1
+ 1 (found 'if' at line: 417, complexity = 2)
+ 1 (found 'logical operator' at line: 417, complexity = 3)
+ 2 (found 'if' at line: 419, complexity = 5)
+ 1 (found 'if' at line: 424, complexity = 6)
+ 1 (found 'if' at line: 428, complexity = 7)
+ 2 (found 'if' at line: 429, complexity = 9)
+ 1 (found 'if' at line: 440, complexity = 10)
+ 2 (found 'if' at line: 444, complexity = 12)
+ 1 (found 'if' at line: 449, complexity = 13)
+ 1 (found 'logical operator' at line: 449, complexity = 14)
+ 1 (found 'if' at line: 454, complexity = 15)
+ 1 (found 'if with lines >= 10' at line: 454, complexity = 16)
+ 1 (found 'has innerfunction' at line: 476, complexity = 17)
+ 1 (found 'assign with lines >= 10' at line: 476, complexity = 18)
+ 1 (found 'range' at line: 491, complexity = 19)
+ 1 (found 'range with lines >= 10' at line: 491, complexity = 20)
+ 1 (found 'range with lines >= 25' at line: 491, complexity = 21)
+ 2 (found 'if' at line: 493, complexity = 23)
+ 1 (found 'if with lines >= 10' at line: 493, complexity = 24)
+ 1 (found 'if with lines >= 25' at line: 493, complexity = 25)
+ 1 (found 'else' at line: 500, complexity = 26)
+ 1 (found 'else with lines >= 10' at line: 500, complexity = 27)
+ 3 (found 'if' at line: 495, complexity = 30)
+ 1 (found 'if' at line: 533, complexity = 31)
+ 1 (found 'else' at line: 535, complexity = 32)
+ 1 (found 'range' at line: 538, complexity = 33)
+ 2 (found 'if' at line: 539, complexity = 35)
+ 1 (found 'if' at line: 543, complexity = 36)
+ 1 (found 'if' at line: 551, complexity = 37)
+ 1 (found 'if with lines >= 10' at line: 551, complexity = 38)
+ 1 (found 'if with lines >= 25' at line: 551, complexity = 39)
+ 1 (found 'logical operator' at line: 551, complexity = 40)
+ 2 (found 'if' at line: 554, complexity = 42)
+ 2 (found 'if' at line: 561, complexity = 44)
+ 1 (found 'if with lines >= 10' at line: 561, complexity = 45)
+ 2 (found 'if' at line: 573, complexity = 47)
+ 1 (found 'if with lines >= 10' at line: 573, complexity = 48)
+ 1 (found 'if' at line: 591, complexity = 49)
+ 2 (found 'range' at line: 592, complexity = 51)
+ 1 (found 'if' at line: 597, complexity = 52)
+ 2 (found 'range' at line: 598, complexity = 54)
+ 3 (found 'if' at line: 600, complexity = 57)
+ 1 (found 'if' at line: 605, complexity = 58)
+ 1 (found 'if' at line: 609, complexity = 59)
+ 1 (found 'logical operator' at line: 609, complexity = 60)
+ 1 (found 'if' at line: 612, complexity = 61)
+ 1 (found 'logical operator' at line: 612, complexity = 62)
+ 2 (found 'if' at line: 614, complexity = 64)
+ 1 (found 'else if' at line: 618, complexity = 65)
+ 1 (found 'if' at line: 623, complexity = 66)
+ 1 (found 'logical operator' at line: 623, complexity = 67)
+ 2 (found 'if' at line: 625, complexity = 69)
+ 1 (found 'if' at line: 631, complexity = 70)
+ 1 (found 'logical operator' at line: 631, complexity = 71)
+ 1 (found 'if' at line: 635, complexity = 72)
+ 1 (found 'logical operator' at line: 635, complexity = 73)
+ 1 (found 'if' at line: 639, complexity = 74)
+ 1 (found 'if with lines >= 10' at line: 639, complexity = 75)
+ 1 (found 'logical operator' at line: 639, complexity = 76)
+ 2 (found 'if' at line: 643, complexity = 78)
+ 1 (found 'if with lines >= 10' at line: 643, complexity = 79)
+ 3 (found 'if' at line: 644, complexity = 82)
+ 1 (found 'logical operator' at line: 644, complexity = 83)
+ 1 (found 'else' at line: 646, complexity = 84)
+ 3 (found 'if' at line: 649, complexity = 87)
+ 1 (found 'logical operator' at line: 649, complexity = 88)
+ 1 (found 'else' at line: 651, complexity = 89)
+ 1 (found 'if' at line: 657, complexity = 90)
+ 1 (found 'logical operator' at line: 657, complexity = 91)
+ 2 (found 'if' at line: 659, complexity = 93)
+ 1 (found 'else if' at line: 662, complexity = 94)
+ 1 (found 'if' at line: 667, complexity = 95)
+ 1 (found 'logical operator' at line: 667, complexity = 96)
+ 1 (found 'if' at line: 671, complexity = 97)
+ 1 (found 'logical operator' at line: 671, complexity = 98)
+ 1 (found 'if' at line: 675, complexity = 99)
+ 1 (found 'logical operator' at line: 675, complexity = 100)
./temp/anytype-heart/core/block/import/markdown/import.go:451:1 - addLinkToObjectBlocks has complexity: 52
complexity = 1
+ 1 (found 'range' at line: 453, complexity = 2)
+ 1 (found 'range with lines >= 10' at line: 453, complexity = 3)
+ 1 (found 'range with lines >= 25' at line: 453, complexity = 4)
+ 2 (found 'if' at line: 454, complexity = 6)
+ 2 (found 'if' at line: 459, complexity = 8)
+ 2 (found 'range' at line: 466, complexity = 10)
+ 1 (found 'range with lines >= 10' at line: 466, complexity = 11)
+ 1 (found 'range with lines >= 25' at line: 466, complexity = 12)
+ 3 (found 'if' at line: 467, complexity = 15)
+ 1 (found 'if with lines >= 10' at line: 467, complexity = 16)
+ 4 (found 'if' at line: 469, complexity = 20)
+ 5 (found 'if' at line: 471, complexity = 25)
+ 4 (found 'if' at line: 476, complexity = 29)
+ 4 (found 'if' at line: 482, complexity = 33)
+ 3 (found 'if' at line: 490, complexity = 36)
+ 1 (found 'logical operator' at line: 490, complexity = 37)
+ 4 (found 'range' at line: 491, complexity = 41)
+ 5 (found 'if' at line: 492, complexity = 46)
+ 1 (found 'logical operator' at line: 492, complexity = 47)
+ 5 (found 'if' at line: 496, complexity = 52)
./temp/anytype-heart/core/block/import/notion/api/property/propertyobject.go:155:1 - GetPropertyObject has complexity: 59
complexity = 1
+ 1 (found 'for' at line: 165, complexity = 2)
+ 1 (found 'for with lines >= 10' at line: 165, complexity = 3)
+ 1 (found 'for with lines >= 25' at line: 165, complexity = 4)
+ 1 (found 'for with lines >= 50' at line: 165, complexity = 5)
+ 2 (found 'if' at line: 167, complexity = 7)
+ 2 (found 'if' at line: 172, complexity = 9)
+ 2 (found 'if' at line: 177, complexity = 11)
+ 2 (found 'defer' at line: 180, complexity = 13)
+ 2 (found 'if' at line: 183, complexity = 15)
+ 2 (found 'if' at line: 187, complexity = 17)
+ 3 (found 'if' at line: 189, complexity = 20)
+ 2 (found 'if' at line: 196, complexity = 22)
+ 2 (found 'range' at line: 200, complexity = 24)
+ 1 (found 'range with lines >= 10' at line: 200, complexity = 25)
+ 1 (found 'range with lines >= 25' at line: 200, complexity = 26)
+ 3 (found 'if' at line: 202, complexity = 29)
+ 3 (found 'if' at line: 206, complexity = 32)
+ 4 (found 'if' at line: 209, complexity = 36)
+ 3 (found 'if' at line: 215, complexity = 39)
+ 4 (found 'if' at line: 218, complexity = 43)
+ 3 (found 'if' at line: 224, complexity = 46)
+ 4 (found 'if' at line: 227, complexity = 50)
+ 3 (found 'if' at line: 233, complexity = 53)
+ 4 (found 'if' at line: 236, complexity = 57)
+ 2 (found 'if' at line: 244, complexity = 59)
./temp/anytype-heart/core/block/import/notion/api/search/search.go:40:1 - Search has complexity: 51
complexity = 1
+ 1 (found 'for' at line: 53, complexity = 2)
+ 1 (found 'for with lines >= 10' at line: 53, complexity = 3)
+ 1 (found 'for with lines >= 25' at line: 53, complexity = 4)
+ 1 (found 'for with lines >= 50' at line: 53, complexity = 5)
+ 2 (found 'if' at line: 57, complexity = 7)
+ 2 (found 'if' at line: 63, complexity = 9)
+ 2 (found 'if' at line: 68, complexity = 11)
+ 2 (found 'defer' at line: 71, complexity = 13)
+ 2 (found 'if' at line: 75, complexity = 15)
+ 2 (found 'if' at line: 79, complexity = 17)
+ 3 (found 'if' at line: 81, complexity = 20)
+ 2 (found 'if' at line: 89, complexity = 22)
+ 2 (found 'range' at line: 92, complexity = 24)
+ 1 (found 'range with lines >= 10' at line: 92, complexity = 25)
+ 3 (found 'if' at line: 93, complexity = 28)
+ 1 (found 'if with lines >= 10' at line: 93, complexity = 29)
+ 4 (found 'if' at line: 95, complexity = 33)
+ 4 (found 'if' at line: 100, complexity = 37)
+ 3 (found 'if' at line: 105, complexity = 40)
+ 1 (found 'if with lines >= 10' at line: 105, complexity = 41)
+ 4 (found 'if' at line: 107, complexity = 45)
+ 4 (found 'if' at line: 112, complexity = 49)
+ 2 (found 'if' at line: 119, complexity = 51)
./temp/anytype-heart/core/block/object/objectlink/dependent_objects.go:33:1 - DependentObjectIDs has complexity: 55
complexity = 1
+ 1 (found 'if' at line: 34, complexity = 2)
+ 2 (found 'if' at line: 41, complexity = 4)
+ 1 (found 'if' at line: 46, complexity = 5)
+ 1 (found 'if with lines >= 10' at line: 46, complexity = 6)
+ 2 (found 'range' at line: 47, complexity = 8)
+ 1 (found 'range with lines >= 10' at line: 47, complexity = 9)
+ 3 (found 'if' at line: 48, complexity = 12)
+ 3 (found 'if' at line: 53, complexity = 15)
+ 1 (found 'if' at line: 62, complexity = 16)
+ 1 (found 'range' at line: 66, complexity = 17)
+ 1 (found 'range with lines >= 10' at line: 66, complexity = 18)
+ 1 (found 'range with lines >= 25' at line: 66, complexity = 19)
+ 1 (found 'range with lines >= 50' at line: 66, complexity = 20)
+ 2 (found 'if' at line: 68, complexity = 22)
+ 3 (found 'if' at line: 70, complexity = 25)
+ 2 (found 'if' at line: 77, complexity = 27)
+ 2 (found 'if' at line: 82, complexity = 29)
+ 1 (found 'logical operator' at line: 82, complexity = 30)
+ 3 (found 'if' at line: 86, complexity = 33)
+ 2 (found 'if' at line: 94, complexity = 35)
+ 1 (found 'logical operator' at line: 94, complexity = 36)
+ 3 (found 'if' at line: 96, complexity = 39)
+ 2 (found 'if' at line: 103, complexity = 41)
+ 1 (found 'logical operator' at line: 103, complexity = 42)
+ 2 (found 'if' at line: 110, complexity = 44)
+ 3 (found 'if' at line: 113, complexity = 47)
+ 2 (found 'if' at line: 120, complexity = 49)
+ 1 (found 'logical operator' at line: 120, complexity = 50)
+ 2 (found 'range' at line: 128, complexity = 52)
+ 3 (found 'if' at line: 129, complexity = 55)
./temp/anytype-heart/core/subscription/group.go:51:1 - onChange has complexity: 53
complexity = 1
+ 1 (found 'range' at line: 53, complexity = 2)
+ 1 (found 'range with lines >= 10' at line: 53, complexity = 3)
+ 2 (found 'if' at line: 55, complexity = 5)
+ 1 (found 'if with lines >= 10' at line: 55, complexity = 6)
+ 1 (found 'else if' at line: 67, complexity = 7)
+ 3 (found 'if' at line: 57, complexity = 10)
+ 1 (found 'logical operator' at line: 57, complexity = 11)
+ 3 (found 'if' at line: 62, complexity = 14)
+ 1 (found 'if' at line: 75, complexity = 15)
+ 1 (found 'if with lines >= 10' at line: 75, complexity = 16)
+ 1 (found 'if with lines >= 25' at line: 75, complexity = 17)
+ 2 (found 'range' at line: 77, complexity = 19)
+ 3 (found 'if' at line: 78, complexity = 22)
+ 1 (found 'else' at line: 80, complexity = 23)
+ 2 (found 'if' at line: 88, complexity = 25)
+ 2 (found 'if' at line: 97, complexity = 27)
+ 1 (found 'if with lines >= 10' at line: 97, complexity = 28)
+ 1 (found 'logical operator' at line: 97, complexity = 29)
+ 3 (found 'range' at line: 98, complexity = 32)
+ 4 (found 'range' at line: 99, complexity = 36)
+ 5 (found 'if' at line: 100, complexity = 41)
+ 3 (found 'range' at line: 106, complexity = 44)
+ 4 (found 'range' at line: 107, complexity = 48)
+ 5 (found 'if' at line: 108, complexity = 53)
563 = files
4366 = functions
100 = highest complexity
3.62 = overall average complexity
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
You can find all about it here:
https://dev.to/marcello_h/solve-code-complexity-in-go-56hg
I was looking at the cognitive code complexity of the anytype-heart (which is written in my favourite language), but there are some complex parts in there. (I use a max complexity of 11 in my own projects, but I've used 50 here)
Here's the result:
Beta Was this translation helpful? Give feedback.
All reactions