{"id":13771557,"url":"https://github.com/kyoh86/scopelint","last_synced_at":"2025-05-11T04:30:46.305Z","repository":{"id":56157827,"uuid":"87769614","full_name":"kyoh86/scopelint","owner":"kyoh86","description":"scopelint checks for unpinned variables in go programs","archived":true,"fork":false,"pushed_at":"2021-04-14T23:36:54.000Z","size":158,"stargazers_count":115,"open_issues_count":0,"forks_count":6,"subscribers_count":8,"default_branch":"main","last_synced_at":"2024-11-17T07:34:17.579Z","etag":null,"topics":["cli-app","go","golang","golang-tools","gometalinter","lint","linter","unpinned-variables"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kyoh86.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":"2017-04-10T05:22:38.000Z","updated_at":"2023-08-23T07:14:46.000Z","dependencies_parsed_at":"2022-08-15T13:50:24.592Z","dependency_job_id":null,"html_url":"https://github.com/kyoh86/scopelint","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kyoh86%2Fscopelint","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kyoh86%2Fscopelint/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kyoh86%2Fscopelint/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kyoh86%2Fscopelint/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kyoh86","download_url":"https://codeload.github.com/kyoh86/scopelint/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253518941,"owners_count":21921074,"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":["cli-app","go","golang","golang-tools","gometalinter","lint","linter","unpinned-variables"],"created_at":"2024-08-03T17:00:52.739Z","updated_at":"2025-05-11T04:30:45.767Z","avatar_url":"https://github.com/kyoh86.png","language":"Go","funding_links":[],"categories":["Linters"],"sub_categories":["Bugs"],"readme":"# scopelint\n\n[![Go Report Card](https://goreportcard.com/badge/github.com/kyoh86/scopelint)](https://goreportcard.com/report/github.com/kyoh86/scopelint)\n[![CircleCI](https://img.shields.io/circleci/project/github/kyoh86/scopelint.svg)](https://circleci.com/gh/kyoh86/scopelint)\n[![Coverage Status](https://img.shields.io/codecov/c/github/kyoh86/scopelint.svg)](https://codecov.io/gh/kyoh86/scopelint)\n\n**scopelint** checks for unpinned variables in go programs.\n\n## OBSOLETED\n\nUse [looppointer](https://github.com/kyoh86/looppointer) or [exportloopref](https://github.com/kyoh86/exportloopref) instead.\n\nIf you want to find lints as nervous as possible (with some false-positives),\nyou should use [looppointer](https://github.com/kyoh86/looppointer).\n\nIf you want to find lints as accurately as possible (with some lints ignored),\nyou should use [exportloopref](https://github.com/kyoh86/exportloopref).\n\n## What's this?\n\nSample problem code from: https://github.com/kyoh86/scopelint/blob/master/example/readme.go\n\n```\n6  values := []string{\"a\", \"b\", \"c\"}\n7  var funcs []func()\n8  for _, val := range values {\n9  \tfuncs = append(funcs, func() {\n10 \t\tfmt.Println(val)\n11 \t})\n12 }\n13 for _, f := range funcs {\n14 \tf()\n15 }\n16 /*output:\n17 c\n18 c\n19 c\n20 */\n21 var copies []*string\n22 for _, val := range values {\n23 \tcopies = append(copies, \u0026val)\n24 }\n25 /*(in copies)\n26 \u0026\"c\"\n27 \u0026\"c\"\n28 \u0026\"c\"\n29 */\n```\n\nIn Go, the `val` variable in the above loops is actually a single variable.\nSo in many case (like the above), using it makes for us annoying bugs.\n\nYou can find them with `scopelint`, and fix it.\n\n```\n$ scopelint ./example/readme.go\nexample/readme.go:10:16: Using the variable on range scope \"val\" in function literal\nexample/readme.go:23:28: Using a reference for the variable on range scope \"val\"\nFound 2 lint problems; failing.\n```\n\n(Fixed sample):\n\n```go\nvalues := []string{\"a\", \"b\", \"c\"}\nvar funcs []func()\nfor _, val := range values {\n  val := val // pin!\n\tfuncs = append(funcs, func() {\n\t\tfmt.Println(val)\n\t})\n}\nfor _, f := range funcs {\n\tf()\n}\nvar copies []*string\nfor _, val := range values {\n  val := val // pin!\n\tcopies = append(copies, \u0026val)\n}\n```\n\n## Install\n\ngo get -u github.com/kyoh86/scopelint\n\n## Use\n\nGive the package paths of interest as arguments:\n\n```\nscopelint github.com/kyoh86/scopelint/example\n```\n\nTo check all packages recursively in the current directory:\n\n```\nscopelint ./...\n```\n\nAnd also, scopelint supports the following options:\n\n* The `--set-exit-status` flag makes it to set exit status to 1 if any problem variables are found (if you DO NOT it, set --no-set-exit-status)\n* The `--vendor` flag enables checking in the `vendor` directories (if you DO NOT it, set `--no-vendor` flag)\n* The `--test` flag enables checking in the `*_test.go` files\" (if you DO NOT it, set `--no-test` flag)\n\n### Nolint\n\nTo ignore issues from use an option comment like //scopelint:ignore.\nFor example, if it's used inline (not from the beginning of the line), it ignores issues only for the line.\n\n```go\nvar copies []*string\nfor _, val := range values {\n\tcopies = append(copies, \u0026val) //scopelint:ignore\n}\n```\n\nTo ignore issues for the block of code put it on the beginning of a line before the block:\n\n```go\nvar copies []*string\n//scopelint:ignore\nfor _, val := range values {\n\tcopies = append(copies, \u0026val)\n}\n```\n\nAlso, you can exclude all issues in a file by:\n\n```go\n//scopelint:ignore\npackage pkg\n```\n\nYou may add a comment explaining or justifying why //scopelint:ignore is being used on the same line as the flag itself:\n\n```go\n//scopelint:ignore // any comment\n```\n\n### Use with gometalinter\n\nscopelint can be used with [gometalinter](https://github.com/alecthomas/gometalinter) in `--linter` flag.\n\n`gometalinter --disable-all --linter 'scope:scopelint {path}:^(?P\u003cpath\u003e.*?\\.go):(?P\u003cline\u003e\\d+):(?P\u003ccol\u003e\\d+):\\s*(?P\u003cmessage\u003e.*)$'`\n\n## Exit Codes\n\nscopelint returns 1 if any problems were found in the checked files.\nIt returns 2 if there were any other failures.\n\n## Known Issues\n\n- False positive for for table tests [#4](https://github.com/kyoh86/scopelint/issues/4)\n    - I won't fix it because scopelint supports ignore them all. [=\u003e nolint](#Nolint)\n\n## TODO\n\n- Write tests\n- License (Some codes copied from [golint](https://github.com/golang/lint))\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkyoh86%2Fscopelint","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkyoh86%2Fscopelint","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkyoh86%2Fscopelint/lists"}