{"id":13493517,"url":"https://github.com/fzipp/gocyclo","last_synced_at":"2025-04-29T18:30:13.294Z","repository":{"id":13421437,"uuid":"16110085","full_name":"fzipp/gocyclo","owner":"fzipp","description":"Calculate cyclomatic complexities of functions in Go source code.","archived":false,"fork":false,"pushed_at":"2024-07-07T15:26:09.000Z","size":60,"stargazers_count":1433,"open_issues_count":10,"forks_count":83,"subscribers_count":22,"default_branch":"main","last_synced_at":"2025-04-09T01:22:46.799Z","etag":null,"topics":["code-metrics","cyclomatic-complexity","go","golang","mccabe","mccabe-metric","software-metrics"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fzipp.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-01-21T17:05:17.000Z","updated_at":"2025-04-08T10:41:45.000Z","dependencies_parsed_at":"2024-10-29T10:57:19.478Z","dependency_job_id":null,"html_url":"https://github.com/fzipp/gocyclo","commit_stats":{"total_commits":71,"total_committers":4,"mean_commits":17.75,"dds":0.04225352112676062,"last_synced_commit":"bd5027b8d09c3b5683043a8d35f3af367201753e"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fzipp%2Fgocyclo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fzipp%2Fgocyclo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fzipp%2Fgocyclo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fzipp%2Fgocyclo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fzipp","download_url":"https://codeload.github.com/fzipp/gocyclo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251559614,"owners_count":21609043,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-metrics","cyclomatic-complexity","go","golang","mccabe","mccabe-metric","software-metrics"],"created_at":"2024-07-31T19:01:16.056Z","updated_at":"2025-04-29T18:30:13.267Z","avatar_url":"https://github.com/fzipp.png","language":"Go","funding_links":[],"categories":["Programming Languages","Misc","Go","Repositories"],"sub_categories":[],"readme":"# gocyclo\n\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/fzipp/gocyclo)](https://pkg.go.dev/github.com/fzipp/gocyclo)\n![Build Status](https://github.com/fzipp/gocyclo/workflows/build/badge.svg)\n[![Go Report Card](https://goreportcard.com/badge/github.com/fzipp/gocyclo)](https://goreportcard.com/report/github.com/fzipp/gocyclo)\n\nGocyclo calculates\n[cyclomatic complexities](https://en.wikipedia.org/wiki/Cyclomatic_complexity)\nof functions in Go source code.\n\nCyclomatic complexity is a\n[code quality metric](https://en.wikipedia.org/wiki/Software_metric)\nwhich can be used to identify code that needs refactoring.\nIt measures the number of linearly independent paths through a function's\nsource code.\n\nThe cyclomatic complexity of a function is calculated according to the\nfollowing rules:\n\n```\n 1 is the base complexity of a function\n+1 for each 'if', 'for', 'case', '\u0026\u0026' or '||'\n```\n\nA function with a higher cyclomatic complexity requires more test cases to\ncover all possible paths and is potentially harder to understand. The\ncomplexity can be reduced by applying common refactoring techniques that lead\nto smaller functions.\n\n## Installation\n\nTo install the `gocyclo` command, run\n\n```\n$ go install github.com/fzipp/gocyclo/cmd/gocyclo@latest\n```\n\nand put the resulting binary in one of your PATH directories if\n`$GOPATH/bin` isn't already in your PATH.\n\n## Usage\n\n```\nCalculate cyclomatic complexities of Go functions.\nUsage:\n    gocyclo [flags] \u003cGo file or directory\u003e ...\n\nFlags:\n    -over N               show functions with complexity \u003e N only and\n                          return exit code 1 if the set is non-empty\n    -top N                show the top N most complex functions only\n    -avg, -avg-short      show the average complexity over all functions;\n                          the short option prints the value without a label\n    -ignore REGEX         exclude files matching the given regular expression\n\nThe output fields for each line are:\n\u003ccomplexity\u003e \u003cpackage\u003e \u003cfunction\u003e \u003cfile:line:column\u003e\n```\n\n## Examples\n\n```\n$ gocyclo .\n$ gocyclo main.go\n$ gocyclo -top 10 src/\n$ gocyclo -over 25 docker\n$ gocyclo -avg .\n$ gocyclo -top 20 -ignore \"_test|Godeps|vendor/\" .\n$ gocyclo -over 3 -avg gocyclo/\n```\n\nExample output:\n\n```\n9 gocyclo (*complexityVisitor).Visit complexity.go:30:1\n8 main main cmd/gocyclo/main.go:53:1\n7 gocyclo (*fileAnalyzer).analyzeDecl analyze.go:96:1\n4 gocyclo Analyze analyze.go:24:1\n4 gocyclo parseDirectives directives.go:27:1\n4 gocyclo (Stats).SortAndFilter stats.go:52:1\nAverage: 2.72\n```\n\nNote that the average is calculated over all analyzed functions,\nnot just the printed ones.\n\n### Ignoring individual functions\n\nIndividual functions can be ignored with a `gocyclo:ignore` directive:\n\n```\n//gocyclo:ignore\nfunc f1() {\n\t// ...\n}\n    \n//gocyclo:ignore\nvar f2 = func() {\n\t// ...\n}\n```\n\n## License\n\nThis project is free and open source software licensed under the\n[BSD 3-Clause License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffzipp%2Fgocyclo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffzipp%2Fgocyclo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffzipp%2Fgocyclo/lists"}