{"id":37112082,"url":"https://github.com/0xjac/structfield","last_synced_at":"2026-01-14T13:16:07.921Z","repository":{"id":56855374,"uuid":"525790010","full_name":"0xjac/structfield","owner":"0xjac","description":"Go linter to check the struct literal to use field name","archived":false,"fork":true,"pushed_at":"2022-08-17T12:57:15.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-06-20T15:03:08.777Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"uudashr/structfield","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/0xjac.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}},"created_at":"2022-08-17T12:52:05.000Z","updated_at":"2022-08-17T12:57:18.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/0xjac/structfield","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/0xjac/structfield","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xjac%2Fstructfield","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xjac%2Fstructfield/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xjac%2Fstructfield/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xjac%2Fstructfield/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/0xjac","download_url":"https://codeload.github.com/0xjac/structfield/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xjac%2Fstructfield/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28420936,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T10:47:48.104Z","status":"ssl_error","status_checked_at":"2026-01-14T10:46:19.031Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2026-01-14T13:16:07.078Z","updated_at":"2026-01-14T13:16:07.914Z","avatar_url":"https://github.com/0xjac.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![GoDoc](https://godoc.org/github.com/uudashr/structfield?status.svg)](https://godoc.org/github.com/uudashr/structfield)\n# Structfield\nFind struct literals using non-labeled fields.\n\nThe structfield analysis reports the usage of struct literal using non-labeled fields more than defined limit (default: 2). The non-labeled field above the limit considered has higher cognitive load (harder to understand and rememeber).\n\n## Understanding Struct Literal\n\nGiven code, variable assigned using struct literal:\n```go\nacc := Account{\n    \"john.smith@example.com\",\n    \"John Smith\",\n    []Permission{\n        Permission{\"account\", \"read\"},\n        Permission{\"account\", \"write\"},\n    },\n    true,\n    false,\n}\n```\n\nAbove code is harder to understand, hard to guess the field name since we have to remember exact order of the fields. The workaround is you have to always look the declaration of the `Account` type.\n\nSuggestion is to refactor the code to:\n```go\nacc := Account{\n    Email: \"john.smith@example.com\",\n    Name: \"John Smith\",\n    Permission: []Permission{\n        Permission{\"account\", \"read\"}, // Non-labeled here is still ok\n        Permission{\"account\", \"write\"},\n    },\n    Verified: true,\n    Deactivated: false,\n}\n```\n\nThe limit set to 2, which considered easy to understand and remember.\n\n## Benefits\nBy using the labeled fields you several benefits\n\n1. The fields doesn't have to be in order\n2. You don't have to declare the value if it's a default value\n\nExample:\n```go\nacc := Account{\n    Email: \"john.smith@example.com\",\n    Name: \"John Smith\",\n    Permission: []Permission{\n        Permission{\"account\", \"read\"}, // Non-labeled here is still ok\n        Permission{\"account\", \"write\"},\n    },\n    Verified: true,\n    Deactivated: false,\n}\n```\n\ncan be simplified into:\n```go\nacc := Account{\n    Name: \"John Smith\", // `Name` come first\n    Email: \"john.smith@example.com\",\n    Permission: []Permission{\n        Permission{\"account\", \"read\"}, // Non-labeled here is still ok\n        Permission{\"account\", \"write\"},\n    },\n    Verified: true,\n    // Remove the `Deactivated: false` since it use default value\n}\n```\n\n## Installation\n```\n$ go install github.com/uudashr/structfield/cmd/structfield@latest\n```\n\nor\n\n```\n$ go get github.com/uudashr/structfield/cmd/structfield\n```\n\n## Usage\n\n```\n$ structfield -limit 2 testdata/src/a/*.go\ntestdata/src/a/a.go:20:9: Found 4 non-labeled fields on struct literal (\u003e 2)\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0xjac%2Fstructfield","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F0xjac%2Fstructfield","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0xjac%2Fstructfield/lists"}