golongfuncs 는 다양한 측정 (및 측정 조합)으로 "긴"기능을 검색하는 도구입니다.
이 도구는 질문 라인에 답변하는 데 도움이 될 수 있습니다.
다시 말해, 그것은 길고 긴 기능을 길고 복잡한 기능을 필터링하는 데 도움이됩니다.
go install github.com/tkrajina/golongfuncs/...
이 도구는 다음과 같은 함수 "길이"및 "복잡성"측정을 계산할 수 있습니다.
lines : 빈 줄이없는 줄 수, 줄 끝 블록 (전용 } ) 및 주석 ,total_lines : 빈 줄 및 주석을 포함한 줄 수,len : 함수의 문자 수 (주석과 빈 줄 없음).total_len : 함수의 문자 수 (주석 및 빈 줄 포함).comments : 댓글 수. 다중 댓글은 한 번 계산됩니다.comment_lines : 댓글 줄 수,complexity : 순환 복잡성 (Gocyclo),max_nesting : MAX 중첩 블록 깊이 (참고, 구조 초기화는 계산되지 않음),total_nesting : Total Nesting (즉, 코드가 제대로 형식화되면 모든 압입 탭이 한 번 계산됩니다)in_params : 함수 입력 매개 변수 수out_params : 기능 출력 매개 변수 수variables : 함수 범위의 변수 수 (함수 인수 및 기능 수신기 없음)assignments : 함수의 할당 수 (변수 선언 포함 := , = , += , -= ...)control : 제어 흐름 문의 수 ( if , else , switch , case , default , select and defer )todos : 댓글에서 찾은 숫자 "TODO"태그 (함수 본문 및 기능 앞에 칭찬 포함). 태그는 HACK , TODO , NOTE , FIXME , ASAP , ISSUE , BUG 및 WTF 입니다.그것 외에도 조치를 결합 할 수 있습니다. 예를 들어:
complexity/lines : 코드 줄 당 평균 복잡성을 계산합니다.total_nesting/total_lines : 줄 당 평균 중첩 (압입)을 계산합니다.comment_lines/total_lines : 라인 당 함수 라인을 계산합니다.Golang 코드의 해당 측정 값을 계산하려면 다음과 같습니다.
$ golongfuncs +variable
$ golongfuncs +total_nesting
$ golongfuncs +lines
$ golongfuncs +lines,complexity
$ golongfuncs +lines,complexity,complexity/lines
golongfuncs (인수없이) 만 부르는 것은 golongfuncs +lines 의 별칭입니다.
$ golongfuncs [flags] +[types] [paths...]
가장 긴 기능 찾기 :
$ golongfuncs <go_file>
$ golongfuncs <directory>
$ golongfuncs <directory>/...
경로가 지정되지 않으면 GolongFuncs는 ./... 이라고 가정합니다.
여러 조치 표시 :
$ golongfuncs +lines
$ golongfuncs +lines,in_params
$ golongfuncs +lines,in_params,complexity/lines
$ golongfuncs +lines +in_params +complexity/lines
여러 측정 값이 지정되면 결과는 첫 번째 열 (이 lines 에서)으로 정렬됩니다.
기본적으로 결과는 상위 20 개의 결과 만 표시됩니다. -top 으로 변경하십시오.
$ golongfuncs -top 50
기본적으로 10 줄보다 짧은 함수는 무시됩니다. -min-lines <n> 으로 변경할 수 있습니다.
가장 복잡한 100 가지 기능 :
$ golongfuncs -top 100 +complexity ./...
가장 복잡한 기능은 50 라인보다 긴 기능입니다.
$ golongfuncs -min-lines 50 +complexity ./...
긴 기능을 찾지 만 복잡성, AVG 복잡성 및 AVG 중첩도 계산합니다.
$ golongfuncs +lines,complexity,complexity/lines,total_nesting/total_lines .
ExampleVeryLongfunction golongfuncs/runner_test.go:118:1 lines=305.0 complexity=1.0 complexity/lines=0.1 total_nesting/total_lines=1.0
ExampleVeryComplexFunction golongfuncs/runner_test.go:10:1 lines=69.0 complexity=44.0 complexity/lines=0.6 total_nesting/total_lines=6.7
printStats main.go:54:1 lines=21.0 complexity=9.0 complexity/lines=0.4 total_nesting/total_lines=2.5
main main.go:12:1 lines=19.0 complexity=3.0 complexity/lines=0.2 total_nesting/total_lines=1.0
TestLines golongfuncs/runner_test.go:476:1 lines=15.0 complexity=2.0 complexity/lines=0.1 total_nesting/total_lines=0.9
NewVisitor golongfuncs/runner.go:94:1 lines=15.0 complexity=3.0 complexity/lines=0.2 total_nesting/total_lines=1.0
Get golongfuncs/models.go:34:1 lines=15.0 complexity=7.0 complexity/lines=0.5 total_nesting/total_lines=1.7
TestNesting golongfuncs/runner_test.go:438:1 lines=15.0 complexity=2.0 complexity/lines=0.1 total_nesting/total_lines=0.9
ExampleVeryLongfunction 이 길지만 (305 라인) 평균 복잡성이 낮고 (0.1), AVG 중첩은 1.0입니다. AVG 중첩 1.0 은이 기능에 중첩 블록이 없음 을 의미합니다. 라인의 절반이 중첩 된 블록 (예 : 큰 if <expr> { ...code... } 코드 블록)에 있으면 AVG 중첩은 1.5입니다.
ExampleVeryComplexFunction ComplexFunction은 짧지 만 (69 라인) 평균 복잡성 (코드 한 줄 당)은 0.6이고 AVG Nesting 6.7은 아마도 기능에 리팩토링이 필요하다는 좋은 힌트 일 것입니다.
AVG 중첩 (코드 한 줄 당)이 5 개보다 5 라인보다 긴 함수를 5 개보다 큽니다. 총 라인 수와 라인 수가 포함됩니다.
$ golongfuncs +total_nesting/total_lines,total_lines,lines -threshold 5 .
ExampleVeryComplexFunction golongfuncs/runner_test.go:10:1 total_nesting/total_lines=6.7 total_lines=108.0 lines=69.0
평균 라인 길이가 가장 긴 기능을 찾으십시오.
$ golongfuncs +len/lines ./...
$ golongfuncs +total_len/total_lines ./...
테스트 및 자급 파일은 무시됩니다. 측정하려면 -include-tests 및 -include-vendor 사용합니다.
임의의 파일/디렉토리는 -ignore "<regexp>" 로 무시할 수 있습니다. 예를 들어, _generated.go : -ignore "^.*_generated.go$" 포함 된 Golang 파일을 무시하려면.
-ignore-func "regexp" 로 함수를 무시할 수 있습니다.
이 도구는 Apache 라이센스, 버전 2.0에 따라 라이센스가 부여됩니다.