{"id":36667772,"url":"https://github.com/jiftechnify/untypedconst","last_synced_at":"2026-01-12T10:36:59.106Z","repository":{"id":65661908,"uuid":"441850146","full_name":"jiftechnify/untypedconst","owner":"jiftechnify","description":"A Go linter checks suspicious usage of untyped const","archived":false,"fork":false,"pushed_at":"2025-12-15T05:22:15.000Z","size":59,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-12-18T01:24:16.891Z","etag":null,"topics":[],"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/jiftechnify.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,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-12-26T09:06:51.000Z","updated_at":"2025-12-15T05:22:18.000Z","dependencies_parsed_at":"2025-12-15T08:07:01.462Z","dependency_job_id":null,"html_url":"https://github.com/jiftechnify/untypedconst","commit_stats":null,"previous_names":["jiftechnify/nakedliteral"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/jiftechnify/untypedconst","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jiftechnify%2Funtypedconst","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jiftechnify%2Funtypedconst/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jiftechnify%2Funtypedconst/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jiftechnify%2Funtypedconst/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jiftechnify","download_url":"https://codeload.github.com/jiftechnify/untypedconst/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jiftechnify%2Funtypedconst/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28338695,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T06:09:07.588Z","status":"ssl_error","status_checked_at":"2026-01-12T06:05:18.301Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5: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-12T10:36:58.190Z","updated_at":"2026-01-12T10:36:59.096Z","avatar_url":"https://github.com/jiftechnify.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# untypedconst\n\nA Go linter checks that [untyped constant expressions](https://go.dev/blog/constants) are used as values of [defined type](https://go.dev/ref/spec#Type_definitions) (a.k.a. named type).\n\n## Usage\n\n```bash\n# as a standalone linter\ngo install github.com/jiftechnify/untypedconst/cmd/untypedconst@latest\nuntypedconst ./...\n\n# with `go vet`\ngo install github.com/jiftechnify/untypedconst/cmd/untypedconst@latest\ngo vet -vettool=$(which untypedconst) ./...\n```\n\n\u003cdetails\u003e\n\u003csummary\u003eRun as a golangci-lint's custom linter\u003c/summary\u003e\n\n### Run as a `golangci-lint`'s custom linter \n\nYou can also run **untypedconst** as a custom linter of [golangci-lint](https://golangci-lint.run/) with the following steps.\nPlease refer to [the official document](https://golangci-lint.run/docs/plugins/module-plugins/) for details.\n\n1. Create `.custom-gcl.yml` under the root directory of your project:\n\n    ```yaml\n    version: v2.5.0\n    plugins:\n      - module: \"github.com/jiftechnify/untypedconst\"\n        import: \"github.com/jiftechnify/untypedconst/cmd/gciplugin\"\n        version: \"latest\" # or specify a specific version e.g. \"v0.2.0\"\n    ```\n\n2. Run `golangci-lint custom` to build a custom `golangci-lint` binary with **untypedconst** included as a plugin.\n    - By default, the output path of the binary is `./custom-gcl`. You can change it by specifying `destination` field in `.custom-gcl.yml`. \n\n3. Add lines of configuration to your `.golangci.yml` to enable **untypedconst**:\n\n    ```yaml\n    # for golangci-lint v2.x\n    version: \"2\"\n\n    linters:\n      enable:\n        - untypedconst\n\n      settings:\n        custom:\n          untypedconst:\n            type: \"module\"\n            description: \"Detects suspicious usage of untyped constants\"\n    ```\n\n    ```yaml\n    # for golangci-lint v1.x\n    linters:\n      enable:\n        - untypedconst\n\n    linters-settings:\n      custom:\n        untypedconst:\n          type: \"module\"\n          description: \"Detects suspicious usage of untyped constants\"\n    ```\n\n4. Run the custom `golangci-lint` executable against your codebase:\n\n    ```bash\n    ./custom-gcl run ./...\n    ```\n\u003c/details\u003e\n\n## Motivation\n\nWhen you want to define enums in Go, you should go through following steps:\n\n1. Define an \"defined type\" for the enum.\n2. Define enum variants as values of the type you defined in 1.\n\nOr, you should write a code like this:\n\n```go\ntype TrafficLight int\n\nconst (\n    None TrafficLight = iota // 0\n    Green                    // 1\n    Yellow                   // 2\n    Red                      // 3\n)\n```\n\nThen you use it like:\n\n```go\nfunc next(tl TrafficLight) TrafficLight {\n    switch tl {\n    case Green:\n        return Yellow\n    case Yellow:\n        return Red\n    case Red:\n        return Green\n    case None:\n        return None\n    default:\n        panic(\"boom!\")\n    }\n}\n\nfunc good() {\n    tl := next(Green) // tl == Yellow\n}\n```\n\nSo far so good, until you write a code like this by accident:\n\n```go\nfunc bad() {\n    tl := next(4) // it compiles, unfortunately \n    // =\u003e boom!\n}\n```\n\nIn the code above, `4` is an **\"untyped constant\"**, and when you \"use\" it (assign it to a variable, pass it to a function, etc.), it is assigned the most suited type from the context, i.e. `TrafficLight`. So types match and **it compiles despite the actual value is out of the range of `TrafficLight`!** It's a pity that Go compiler doesn't come with a feature that prevents us from breaking codes in such a way.\n\n**untypedconst** (indirectly) detects such a mistake by checking whether you don't use untyped constants in places that require values of some defined type:\n\n```go\nfunc bad() {\n    tl := next(4)\n    // =\u003e passing untyped constant to parameter of defined type \"TrafficLight\"\n}\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjiftechnify%2Funtypedconst","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjiftechnify%2Funtypedconst","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjiftechnify%2Funtypedconst/lists"}