nestif
1.0.0
G. Ann Campbell의인지 복잡성 백서에 의해 정의 된 규칙을 기반으로 복잡성을 계산하여 Go Code의 IF 진술을 중첩 한 보고서.
코드를 읽기 어렵게 만드는 진술을 찾아서 리팩터 할 부분을 명확히하는 데 도움이됩니다.
go get github.com/nakabonne/nestif/cmd/nestif
nestif 이미 Golangci-Lint와 통합되어 있습니다. 거기에 지침을 참조하고 활성화하십시오.
nestif ... 글로벌 운영자가 지원되고, 위는 다음과 같습니다.
nestif ./...하나 이상의 파일 및 디렉토리는 단일 명령으로 지정할 수 있습니다.
nestif dir/foo.go dir2 dir3/...패키지도 지정할 수 있습니다.
nestif github.com/foo/bar example.com/bar/baz usage: nestif [<flag> ...] <Go files or directories or packages> ...
-e, --exclude-dirs strings regexps of directories to be excluded for checking; comma-separated list
--json emit json format
--min int minimum complexity to show (default 1)
--top int show only the top N most complex if statements (default 10)
-v, --verbose verbose output
당신이 쓴다 고 가정 해 봅시다 :
package main
func _ () {
if foo {
if bar {
}
}
if baz == "baz" {
if qux {
if quux {
}
}
}
}그리고 Nestif에게 제공하십시오.
$ nestif foo.go
foo.go:9:2: `if baz == "baz"` is nested (complexity: 3)
foo.go:4:2: `if foo` is nested (complexity: 1) 결과는 복잡성의 하강 순서로 정렬됩니다. 또한 기본적으로 상위 10 개가 가장 복잡한 IF 문 만 표시되며 -top 플래그로 표시 할 수를 지정할 수 있습니다.
인지 복잡성의 중첩 규칙에 따라 IF 문의 복잡성을 계산합니다. 코드가 더 깊게 네트로 작성 될수록, 추론하기가 더 어려울 수 있으므로, 그 중첩 증분을 평가합니다.
if condition1 {
if condition2 { // +1
if condition3 { // +2
if condition4 { // +3
}
}
}
} IF를 읽을 때 정신적 비용이 이미 지불 되었기 때문에 다른 곳에서 복잡성을 증가 시키면 그렇지 else else if .
if condition1 {
if condition2 { // +1
if condition3 { // +2
} else if condition4 { // +1
} else { // +1
if condition5 { // +3
}
}
}
}인지 복잡성에 대한 자세한 내용은인지 복잡성 : G. Ann Campbell의 새로운 이해력 백서를 측정하는 새로운 방법을 참조하십시오.