aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/uudashr/gocognit/README.md
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2023-12-05 15:10:03 +0100
committerTaras Madan <tarasmadan@google.com>2023-12-06 11:31:44 +0000
commit2ab72b4feef2c97f22f90cfbf9e45a6cfcd08bda (patch)
treea6d19b94b6399fcc00a6cfa430885cd349dd1533 /vendor/github.com/uudashr/gocognit/README.md
parente08e8f492d31d672cc245944c185f8aadf2ee695 (diff)
vendor: updates
Diffstat (limited to 'vendor/github.com/uudashr/gocognit/README.md')
-rw-r--r--vendor/github.com/uudashr/gocognit/README.md56
1 files changed, 45 insertions, 11 deletions
diff --git a/vendor/github.com/uudashr/gocognit/README.md b/vendor/github.com/uudashr/gocognit/README.md
index 1e028c789..57f31cf74 100644
--- a/vendor/github.com/uudashr/gocognit/README.md
+++ b/vendor/github.com/uudashr/gocognit/README.md
@@ -1,6 +1,6 @@
[![GoDoc](https://godoc.org/github.com/uudashr/gocognit?status.svg)](https://godoc.org/github.com/uudashr/gocognit)
# Gocognit
-Gocognit calculates cognitive complexities of functions in Go source code. A measurement of how hard does the code is intuitively to understand.
+Gocognit calculates cognitive complexities of functions (and methods) in Go source code. A measurement of how hard does the code is intuitively to understand.
## Understanding the complexity
@@ -37,10 +37,10 @@ func GetWords(number int) string {
As you see above codes are the same, but the second code are easier to understand, that is why the cognitive complexity score are lower compare to the first one.
-## Comparison with cyclometic complexity
+## Comparison with cyclomatic complexity
### Example 1
-#### Cyclometic complexity
+#### Cyclomatic complexity
```go
func GetWords(number int) string { // +1
switch number {
@@ -160,16 +160,40 @@ $ go get github.com/uudashr/gocognit/cmd/gocognit
```
$ gocognit
Calculate cognitive complexities of Go functions.
+
Usage:
- gocognit [flags] <Go file or directory> ...
+
+ gocognit [<flag> ...] <Go file or directory> ...
+
Flags:
- -over N show functions with complexity > N only and
- return exit code 1 if the set is non-empty
- -top N show the top N most complex functions only
- -avg show the average complexity over all functions,
- not depending on whether -over or -top are set
-The output fields for each line are:
-<complexity> <package> <function> <file:row:column>
+
+ -over N show functions with complexity > N only
+ and return exit code 1 if the output is non-empty
+ -top N show the top N most complex functions only
+ -avg show the average complexity over all functions,
+ not depending on whether -over or -top are set
+ -json encode the output as JSON
+ -f format string the format to use
+ (default "{{.PkgName}}.{{.FuncName}}:{{.Complexity}}:{{.Pos}}")
+
+The (default) output fields for each line are:
+
+ <complexity> <package> <function> <file:row:column>
+
+The (default) output fields for each line are:
+
+ {{.Complexity}} {{.PkgName}} {{.FuncName}} {{.Pos}}
+
+or equal to <complexity> <package> <function> <file:row:column>
+
+The struct being passed to the template is:
+
+ type Stat struct {
+ PkgName string
+ FuncName string
+ Complexity int
+ Pos token.Position
+ }
```
Examples:
@@ -180,6 +204,7 @@ $ gocognit main.go
$ gocognit -top 10 src/
$ gocognit -over 25 docker
$ gocognit -avg .
+$ gocognit -ignore "_test|testdata" .
```
The output fields for each line are:
@@ -187,6 +212,15 @@ The output fields for each line are:
<complexity> <package> <function> <file:row:column>
```
+## Ignore individual functions
+Ignore individual functions by specifying `gocognit:ignore` directive.
+```go
+//gocognit:ignore
+func IgnoreMe() {
+ // ...
+}
+```
+
## Related project
- [Gocyclo](https://github.com/fzipp/gocyclo) where the code are based on.
- [Cognitive Complexity: A new way of measuring understandability](https://www.sonarsource.com/docs/CognitiveComplexity.pdf) white paper by G. Ann Campbell. \ No newline at end of file