{"id":19036725,"url":"https://github.com/loov/enumcheck","last_synced_at":"2025-04-16T08:43:29.024Z","repository":{"id":57489221,"uuid":"199045078","full_name":"loov/enumcheck","owner":"loov","description":"Allows to mark Go enum types as exhaustive.","archived":false,"fork":false,"pushed_at":"2024-09-04T14:01:14.000Z","size":49,"stargazers_count":33,"open_issues_count":4,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-10T09:04:42.764Z","etag":null,"topics":["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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/loov.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":"2019-07-26T15:59:56.000Z","updated_at":"2024-09-04T14:01:17.000Z","dependencies_parsed_at":"2022-08-29T20:30:42.637Z","dependency_job_id":null,"html_url":"https://github.com/loov/enumcheck","commit_stats":null,"previous_names":["loov/checkenum"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loov%2Fenumcheck","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loov%2Fenumcheck/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loov%2Fenumcheck/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loov%2Fenumcheck/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loov","download_url":"https://codeload.github.com/loov/enumcheck/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249221599,"owners_count":21232432,"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","static-analysis"],"created_at":"2024-11-08T21:55:15.197Z","updated_at":"2025-04-16T08:43:28.999Z","avatar_url":"https://github.com/loov.png","language":"Go","readme":"# enumcheck\n\n***This is still a WIP, so exact behavior may change.***\n\nAnalyzer for exhaustive enum switches.\n\nTo install:\n\n```\ngo install loov.dev/enumcheck@latest\n```\n\nThis package reports errors for:\n\n``` go\n//enumcheck:exhaustive\ntype Letter byte\n\nconst (\n\tAlpha Letter = iota\n\tBeta\n\tGamma\n)\n\nfunc Switch(x Letter) {\n\tswitch x { // error: \"missing cases Beta, Gamma and default\"\n\tcase Alpha:\n\t\tfmt.Println(\"alpha\")\n\tcase 4: // error: \"implicit conversion of 4 to Letter\"\n\t\tfmt.Println(\"beta\")\n\t}\n}\n\nfunc Assignment() {\n    var x Letter\n    x = 123 // error: \"implicit conversion of 123 to Letter\n}\n\n```\n\nThis can also be used with types:\n\n``` go\n//enumcheck:exhaustive\ntype Expr interface{}\n\nvar _ Expr = Add{}\nvar _ Expr = Mul{}\n\ntype Add []Expr\ntype Mul []Expr\n\ntype Invalid []Expr\n\nfunc Switch(x Expr) {\n\tswitch x.(type) { // error: \"missing cases Mul\"\n\tcase Add:\n\t\tfmt.Println(\"alpha\")\n\tcase Invalid: // error: \"implicit conversion of Invalid to Expr\"\n\t\tfmt.Println(\"beta\")\n\tdefault:\n\t\tfmt.Println(\"unknown\")\n\t}\n}\n\nfunc Assignment() {\n\tvar x Expr\n\tx = 3 // error: \"implicit conversion of 3 to Expr\n\t_ = x\n}\n```\n\nOr with structs:\n\n``` go\n//enumcheck:exhaustive\ntype Option struct{ value string }\n\nvar (\n\tTrue  = Option{\"true\"}\n\tFalse = Option{\"false\"}\n\tMaybe = Option{\"maybe\"}\n)\n\nfunc DayNonExhaustive() {\n\tvar day Option\n\n\tswitch day { // want \"missing cases False, Maybe and default\"\n\tcase Option{\"invalid\"}: // want \"invalid enum for enumstruct.Option\"\n\t\tfmt.Println(\"beta\")\n\tcase True:\n\t\tfmt.Println(\"beta\")\n\t}\n}\n```\n\nMode `//enumcheck:relaxed` allows to make \"default\" case optional:\n\n``` go\n//enumcheck:relaxed\ntype Option string\n\nvar (\n\tAlpha = Option(\"alpha\")\n\tBeta  = Option(\"beta\")\n)\n\nfunc Relaxed() {\n\tvar day Option\n\tswitch day {\n\tcase Alpha:\n\t\tfmt.Println(\"alpha\")\n\tcase Beta:\n\t\tfmt.Println(\"beta\")\n\t}\n}\n```\n\nMode `//enumcheck:silent` allows to silence reports for switch statements:\n\n``` go\n//enumcheck:silent\ntype Option string\n\nvar (\n\tAlpha = Option(\"alpha\")\n\tBeta  = Option(\"beta\")\n)\n\nfunc NoErrorHere() {\n\tvar day Option\n\tswitch day {\n\tcase Beta:\n\t\tfmt.Println(\"beta\")\n\t}\n}\n\nfunc EnablePerSwitch() {\n\tvar day Option\n\tswitch day { //enumcheck:exhaustive\n\tcase Beta:\n\t\tfmt.Println(\"beta\")\n\t}\n}\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floov%2Fenumcheck","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floov%2Fenumcheck","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floov%2Fenumcheck/lists"}