{"id":15527558,"url":"https://github.com/elliotchance/ghost","last_synced_at":"2025-04-23T12:27:49.022Z","repository":{"id":137290360,"uuid":"151817344","full_name":"elliotchance/ghost","owner":"elliotchance","description":"👻 Locate and fix overly complex lines of code in Go.","archived":false,"fork":false,"pushed_at":"2018-10-15T11:19:44.000Z","size":23,"stargazers_count":52,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-29T23:41:11.803Z","etag":null,"topics":["go","golang","linter"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elliotchance.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2018-10-06T07:52:55.000Z","updated_at":"2024-09-27T11:35:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"be6aa21a-1030-4355-b47c-0e332902fa76","html_url":"https://github.com/elliotchance/ghost","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elliotchance%2Fghost","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elliotchance%2Fghost/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elliotchance%2Fghost/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elliotchance%2Fghost/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elliotchance","download_url":"https://codeload.github.com/elliotchance/ghost/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250433211,"owners_count":21429836,"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":["go","golang","linter"],"created_at":"2024-10-02T11:07:07.515Z","updated_at":"2025-04-23T12:27:48.999Z","avatar_url":"https://github.com/elliotchance.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"👻 ghost\n========\n\n[![Build Status](https://travis-ci.org/elliotchance/ghost.svg?branch=master)](https://travis-ci.org/elliotchance/ghost)\n\n`ghost` is a command-line tool for locating overly complex lines of code in Go.\n\nIt is designed with the intention that code should strive to be written in a\nlinear, rather than nested way. This makes code easier to understand, highlights\nduplicate logic and ultimately leads to less bugs.\n\n\nInstallation\n------------\n\n```bash\ngo get -u github.com/elliotchance/ghost\n```\n\n\nUsage\n-----\n\nPass one or multiple Go files:\n\n```bash\nghost file1.go file2.go\n```\n\n### CLI Options\n\n- `-ignore-tests` - Ignore test files.\n- `-max-line-complexity` - The maximum allowed line complexity. (default 5)\n- `-never-fail` - Always exit with 0.\n\n\nExample\n-------\n\nThe output of ghost (with default options) describes that line 50 is too\ncomplex:\n\n```\njaro.go:50: complexity is 8 (in JaroWinkler)\n```\n\nThe line is:\n\n```go\nprefixSize = int(math.Min(float64(len(a)), math.Min(float64(prefixSize), float64(len(b)))))\n```\n\nThere is nothing logically incorrect with that line, but it is long, difficult\nto understand and can be tricky to inspect with a debugger.\n\nThere are lots of different ways the above code can be rewritten. For me, once I\nunderstand what it's really doing I can create the function:\n\n```go\nfunc minInt(values ...int) int {\n\tsort.Ints(values)\n\n\treturn values[0]\n}\n```\n\nNow it can be simply written as:\n\n```go\nprefixSize = minInt(prefixSize, len(a), len(b))\n```\n\n\nIgnoring Lines\n--------------\n\nAny comment that contains the string `ghost:ignore` will cause the next\nproceeding line to be ignored:\n\n```go\n// ghost:ignore\na := lastName[baz() : foo + bar : qux()]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felliotchance%2Fghost","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felliotchance%2Fghost","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felliotchance%2Fghost/lists"}