{"id":23328869,"url":"https://github.com/tkrajina/golongfuncs","last_synced_at":"2025-08-22T22:33:22.993Z","repository":{"id":57491416,"uuid":"102931795","full_name":"tkrajina/golongfuncs","owner":"tkrajina","description":"Find long/complex Golang functions in your code","archived":false,"fork":false,"pushed_at":"2024-06-02T21:47:26.000Z","size":31,"stargazers_count":29,"open_issues_count":2,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-06-20T13:35:23.547Z","etag":null,"topics":["command-line","go","golang","static-analysis"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tkrajina.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2017-09-09T06:15:06.000Z","updated_at":"2024-06-02T09:30:22.000Z","dependencies_parsed_at":"2024-06-20T13:13:32.329Z","dependency_job_id":null,"html_url":"https://github.com/tkrajina/golongfuncs","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkrajina%2Fgolongfuncs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkrajina%2Fgolongfuncs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkrajina%2Fgolongfuncs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkrajina%2Fgolongfuncs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tkrajina","download_url":"https://codeload.github.com/tkrajina/golongfuncs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230646979,"owners_count":18258807,"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":["command-line","go","golang","static-analysis"],"created_at":"2024-12-20T21:28:52.749Z","updated_at":"2024-12-20T21:28:53.364Z","avatar_url":"https://github.com/tkrajina.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/tkrajina/golongfuncs.svg?branch=master)](https://travis-ci.org/tkrajina/golongfuncs)\n\n# GoLongFuncs\n\n`golongfuncs` is a tool for searching \"long\" functions by various measures (and combinations of measures).\n\nThis tool can help you to answer questions line:\n\n* What are the longest functions with **total complexity** more than *x*?\n* What are the longest functions with complexity **per line of code** more than *x*?\n* What are functions with the biggest **number of nested blocks**?\n* What are functions with the biggest number of **control flow statements**?\n* What are the longest functions with **max block nesting** more than *n*?\n* What are the functions with the most **variables defined**?\n* What are the functions with the most **variables and assignments**?\n* etc.\n\nIn other words, it will help you filter long **and complex** functions from those that are just **long**.\n\n## Installation\n\n    go install  github.com/tkrajina/golongfuncs/...\n\n## Measures\n\nThis tool can calculate the following function \"length\" and \"complexity\" measures:\n\n* `lines`: Number of lines **without empty lines, lines ending blocks (containing only `}`), and comments**,\n* `total_lines`: Number of lines **including empty lines and comments**,\n* `len`: Number of characters in the function (without comments and empty lines).\n* `total_len`: Number of characters in the function (with comments and empty lines).\n* `comments`: Number of comments. Multiline comments are counted once,\n* `comment_lines`: Number of comment lines,\n* `complexity`: [Cyclomatic complexity](https://en.wikipedia.org/wiki/Cyclomatic_complexity) (from [gocyclo](https://github.com/fzipp/gocyclo)),\n* `max_nesting`: Max nested blocks depth (note, struct initializations are not counted),\n* `total_nesting`: Total nesting (in other words, if the code is formatted properly -- every indentation tab is counted once)\n* `in_params`: The number of function input parameters\n* `out_params`: The number of function output parameters\n* `variables`: The number of variables in the scope of the function (without function arguments and function receivers)\n* `assignments`: The number of assignments in the function (including variable declarations, `:=`, `=`, `+=`, `-=`...)\n* `control`: The number of control flow statements (`if`, `else`, `switch`, `case`, `default`, `select` and `defer`)\n* `todos`: The number \"TODO\" tags found in comments (including function body and the commend preceding the function). Tags are `HACK`, `TODO`, `NOTE`, `FIXME`, `ASAP`, `ISSUE`, `BUG` and `WTF`.\n\nIn addition to those, you can combine measures. For example:\n\n* `complexity/lines`: Calculates average complexity per line of code.\n* `total_nesting/total_lines`: Calculates average nesting (indentation) per line.\n* `comment_lines/total_lines`: Calculates lines of functions per line.\n* etc.\n\nTo calculate any of those measure for your Golang code:\n\n    $ golongfuncs +variable\n    $ golongfuncs +total_nesting\n    $ golongfuncs +lines\n    $ golongfuncs +lines,complexity\n    $ golongfuncs +lines,complexity,complexity/lines\n\nCalling just `golongfuncs` (without arguments) is an alias for `golongfuncs +lines`.\n\n## Usage examples\n\n    $ golongfuncs [flags] +[types] [paths...]\n\nFind longest functions:\n\n    $ golongfuncs \u003cgo_file\u003e\n    $ golongfuncs \u003cdirectory\u003e\n    $ golongfuncs \u003cdirectory\u003e/...\n\nIf path is not specified, golongfuncs assumes it is `./...`.\n\nShow multiple measures:\n\n    $ golongfuncs +lines\n    $ golongfuncs +lines,in_params\n    $ golongfuncs +lines,in_params,complexity/lines\n    $ golongfuncs +lines +in_params +complexity/lines\n\nIf multiple measures are specified, the results are sorted by the first column (in this example `lines`):\n\nBy default the result shows only the top 20 results. Change that with `-top`:\n\n    $ golongfuncs -top 50\n\nBy default, functions shorter than 10 lines are ignored. You can change that with `-min-lines \u003cn\u003e`.\n\nThe 100 most complex functions:\n\n    $ golongfuncs -top 100 +complexity ./...\n\nThe most complex functions longer than 50 lines:\n\n    $ golongfuncs -min-lines 50 +complexity ./...\n\nFind long functions, but calculate also their complexity, avg complexity and avg nesting:\n\n    $ golongfuncs +lines,complexity,complexity/lines,total_nesting/total_lines .\n          ExampleVeryLongfunction golongfuncs/runner_test.go:118:1       lines=305.0    complexity=1.0    complexity/lines=0.1    total_nesting/total_lines=1.0\n       ExampleVeryComplexFunction golongfuncs/runner_test.go:10:1         lines=69.0   complexity=44.0    complexity/lines=0.6    total_nesting/total_lines=6.7\n                       printStats main.go:54:1                            lines=21.0    complexity=9.0    complexity/lines=0.4    total_nesting/total_lines=2.5\n                             main main.go:12:1                            lines=19.0    complexity=3.0    complexity/lines=0.2    total_nesting/total_lines=1.0\n                        TestLines golongfuncs/runner_test.go:476:1        lines=15.0    complexity=2.0    complexity/lines=0.1    total_nesting/total_lines=0.9\n                       NewVisitor golongfuncs/runner.go:94:1              lines=15.0    complexity=3.0    complexity/lines=0.2    total_nesting/total_lines=1.0\n                              Get golongfuncs/models.go:34:1              lines=15.0    complexity=7.0    complexity/lines=0.5    total_nesting/total_lines=1.7\n                      TestNesting golongfuncs/runner_test.go:438:1        lines=15.0    complexity=2.0    complexity/lines=0.1    total_nesting/total_lines=0.9\n\nYou can see that `ExampleVeryLongfunction` is long (305 lines), but average complexity is low (0.1) and avg nesting is 1.0.\nAvg nesting 1.0 means that there are **no nested blocks** in this function. If half the lines were in a nested block (for example a big `if \u0026lt;expr\u0026gt; { ...code... }` block of code) the avg nesting would be 1.5.\n\nThe `ExampleVeryComplexFunction` is shorter (69 lines) but with an average complexity (per line of code) of 0.6 and avg nesting 6.7 and that is probably a good hint that the function needs refactoring.\n\nFind functions longer than 5 lines with avg nesting (per line of code) bigger than 5 and include total lines count and lines count:\n\n    $ golongfuncs +total_nesting/total_lines,total_lines,lines -threshold 5 .\n            ExampleVeryComplexFunction golongfuncs/runner_test.go:10:1             total_nesting/total_lines=6.7  total_lines=108.0   lines=69.0\n\nFind functions with longest average line length:\n\n    $ golongfuncs +len/lines ./...\n    $ golongfuncs +total_len/total_lines ./...\n\nTests and vendored files are ignored, use `-include-tests` and `-include-vendor` if you want to measure them.\n\nArbitrary files/directories can be ignored with `-ignore \"\u003cregexp\u003e\"`. For example, if you want to ignore Golang files containing `_generated.go`: `-ignore \"^.*_generated.go$\"`.\n\nFunctions can be ignored with `-ignore-func \"regexp\"`.\n\n# License\n\nThis tool is licensed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftkrajina%2Fgolongfuncs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftkrajina%2Fgolongfuncs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftkrajina%2Fgolongfuncs/lists"}