{"id":13722973,"url":"https://github.com/quasilyte/go-parsefix","last_synced_at":"2025-08-02T15:07:34.214Z","repository":{"id":85823247,"uuid":"134950136","full_name":"quasilyte/go-parsefix","owner":"quasilyte","description":"Fixes simple parse errors automatically. Works great in combination with goimports.","archived":false,"fork":false,"pushed_at":"2019-12-05T19:09:47.000Z","size":31,"stargazers_count":82,"open_issues_count":10,"forks_count":4,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-04-30T07:19:34.697Z","etag":null,"topics":["autofix","go","golang","parsing","tools","utility"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/quasilyte.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2018-05-26T10:03:51.000Z","updated_at":"2023-08-30T08:10:31.000Z","dependencies_parsed_at":"2023-03-13T06:54:05.149Z","dependency_job_id":null,"html_url":"https://github.com/quasilyte/go-parsefix","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/quasilyte/go-parsefix","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quasilyte%2Fgo-parsefix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quasilyte%2Fgo-parsefix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quasilyte%2Fgo-parsefix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quasilyte%2Fgo-parsefix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/quasilyte","download_url":"https://codeload.github.com/quasilyte/go-parsefix/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quasilyte%2Fgo-parsefix/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268408194,"owners_count":24245576,"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","status":"online","status_checked_at":"2025-08-02T02:00:12.353Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["autofix","go","golang","parsing","tools","utility"],"created_at":"2024-08-03T01:01:35.075Z","updated_at":"2025-08-02T15:07:34.093Z","avatar_url":"https://github.com/quasilyte.png","language":"Go","funding_links":[],"categories":["Code formatters"],"sub_categories":[],"readme":"# go-parsefix\n\n[![Go Report Card](https://goreportcard.com/badge/github.com/quasilyte/go-parsefix)](https://goreportcard.com/report/github.com/quasilyte/go-parsefix)\n[![GoDoc](https://godoc.org/github.com/quasilyte/go-parsefix/parsefix?status.svg)](https://godoc.org/github.com/quasilyte/go-parsefix/parsefix)\n[![Build Status](https://travis-ci.org/quasilyte/go-parsefix.svg?branch=master)](https://travis-ci.org/quasilyte/go-parsefix.svg?branch=master)\n\nFixes simple parse errors automatically. Works great in combination with [goimports](https://godoc.org/golang.org/x/tools/cmd/goimports).\n\n## Installation\n\n```bash\ngo get -v github.com/quasilyte/go-parsefix/cmd/parsefix\n```\n\nNotes:\n\n1. You need `go` command to be installed.\n2. Executable is saved at your `$(go env GOPATH)/bin` by default.\n\nDo `parsefix -help` to see usage and flags documentation.\n\n## Motivation\n\nSometimes you miss a trailing comma.\u003cbr\u003e\nThe other time it's a missing `;` or `}`.\u003cbr\u003e\nIf you're a beginner, you'll probably put `{` on a wrong line several times,\u003cbr\u003e\nbreaking the `gofmt` due to the parsing errors.\n\nStop interrupting yourself with such nuisances!\u003cbr\u003e\nLet `parsefix` perform it's magic.\n\nYou do `ctrl+s` in your favourite IDE/editor, it tries to do `gofmt` (or `goimports`), which fails due\nto parsing errors, then plugin invokes `parsefix`, which could fix all those issues so `gofmt`\ncan be executed again successfully. In the end, you don't even notice that there were a minor parsing\nerror at all. It's just re-formatted and cleaned up.\n\n**Note**: in bright future we could fix **more** errors, not less, as parsing errors\ncould be improved in some cases to avoid too vague descriptions that are not\nprecise enough to perform action with high confidence.\n\n## What can be fixed\n\n`parsefix` does not do anything too smart. It only follows safe suggestions from\nerror messages that usually lead to fixed source code.\n\nNote that it fixes *parsing* errors, not semantic or type errors.\nSometimes it performs not quite right actions, for example, it could insert a `,` where `:`\nwould make more sense, but you will notice that in the *typecheck* phase.\nThe best part is that *typecheck* could actually run over your previously unparsable code.\nType checker usually gives far more precise and concise error messages.\n\n### Fix misplaced opening brace\n\n```go\nfunc f()\n{\n}\n// =\u003e\nfunc f() {\n}\n```\n\n### Fix missing range keyword\n\n```go\nfor x := xs {\n}\n=\u003e\nfor x := range xs {\n}\n```\n\n### Fix missing comma\n\n```go\nxs := []string{\n\t\"a\"\n\t\"b\"\n}\n// =\u003e\nxs := []string{\n\t\"a\",\n\t\"b\",\n}\n\nxs := []int{1 2}\n// =\u003e\nxs := []int{1, 2}\n\nfoo(1 2)\n// =\u003e\nfoo(1, 2)\n\nfunc f(a int b int32) {}\n// =\u003e\nfunc f(a int, b int32) {}\n```\n\n### Fix missing colon\n\n```go\nswitch v {\ncase 1\n\treturn a\ncase 2\n\treturn b\n}\n// =\u003e\nswitch v {\ncase 1:\n\treturn a\ncase 2:\n\treturn b\n}\n```\n\n### Fix missing semicolon\n\n```go\nx++ y++\n// =\u003e\nx++; y++\n\nif x := 1 x != y {\n}\n// =\u003e\nif x := 1; x != y {\n}\n```\n\n### Fix misplaced tokens\n\n```go\nfunc f() {\n\t:=\n\tg()\n}\n// =\u003e\nfunc f() {\n\tg()\n}\n```\n\n### Fix illegal characters\n\n```go\nfunc f() {\n\t$ g()\n\t🔥 g()\n\t# g()\n\t№ g()\n}\n// =\u003e\nfunc f() {\n\tg()\n\tg()\n\tg()\n\tg()\n}\n```\n## Problems\n\nSome parsing errors drive Go parser mad.  \nA single typo causes multiple parts of the source file to issue parsing errors.  \nThis could lead to false-positives, unfortunately.\n\nIt would also be great to fix things like `var x := y` to `var x = y`, but\nthere is no way to do so currently, as messages for this kinds of errors are ambiguous and\ndo not mention `:=` at all.\n\nMaybe `parsefix` will learn to avoid those in future.\nWe need more user feedback and bug reports.\n\n## Integration\n\nFor ease of integration there are two modes:\n\n1. Accept (full) filename, parse file, try to fix errors that are found during parsing.\n2. Accept (full) filename + list of parsing errors, try to fix all provided errors. This is useful if you already have parsing errors and want to speedup things a little bit (avoids re-parsing). Filename is used to filter errors. Caller may provide errors for multiple files, but only those that match filename will be addressed.\n\nFixed file contents are printed to `stdout` by default.  \nFlag `-i` causes `parsefix` to overwrite `-f` contents.\n\nExit code:\n* 0 if at least one issue was fixed.\n* 1 and no output if no issues were fixed. With `-i` no re-write is done.\n* 2 and no output if there were no parsing issues at all. With `-i` no re-write is done.\n* 3 some error occured, message is printed to stderr.\n\nExamples:\n```bash\n# Uses 1st mode. parsefix does parsing itself and prints fixed code to stdout.\nparsefix -f=foo/main.go\n\n# Uses 2nd mode. No parsing is done by the parsefix.\nparsefix -f=foo/main.go \"foo/main.go:9:3: expected '{', found 'EOF'\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquasilyte%2Fgo-parsefix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fquasilyte%2Fgo-parsefix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquasilyte%2Fgo-parsefix/lists"}