{"id":16218107,"url":"https://github.com/quasilyte/fileprivate","last_synced_at":"2025-03-19T10:30:55.703Z","repository":{"id":57696284,"uuid":"491848436","full_name":"quasilyte/fileprivate","owner":"quasilyte","description":"A Go linter that enforces more strict members access rules inside packages","archived":false,"fork":false,"pushed_at":"2022-05-13T12:57:42.000Z","size":12,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-02-28T17:57:23.436Z","etag":null,"topics":["codestructure","codestyle","conventions","go","golang","incapsulation","linter","opinionated"],"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/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}},"created_at":"2022-05-13T10:07:07.000Z","updated_at":"2023-06-10T12:39:19.000Z","dependencies_parsed_at":"2022-09-15T20:50:30.580Z","dependency_job_id":null,"html_url":"https://github.com/quasilyte/fileprivate","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quasilyte%2Ffileprivate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quasilyte%2Ffileprivate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quasilyte%2Ffileprivate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quasilyte%2Ffileprivate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/quasilyte","download_url":"https://codeload.github.com/quasilyte/fileprivate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243982182,"owners_count":20378605,"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":["codestructure","codestyle","conventions","go","golang","incapsulation","linter","opinionated"],"created_at":"2024-10-10T11:48:31.127Z","updated_at":"2025-03-19T10:30:55.454Z","avatar_url":"https://github.com/quasilyte.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fileprivate\n\nA Go linter that enforces more strict members access rules inside packages.\n\n## Installation\n\n```bash\n$ go install github.com/quasilyte/fileprivate/cmd/fileprivate@latest\n```\n\n## How to use?\n\nRun it over a package(s) you want to check.\n\n```bash\n# Check \"dbconn\" package:\n$ fileprivate ./dbconn\n\n# Check all packages reachable from this root:\n$ fileprivate ./...\n```\n\n## What exactly does it do?\n\nIt checks that **unexported** types **unexported** members are not accessed wildly inside a signle package.\n\nThere are two exceptions to this rule to keep things pragmatic:\n\n* If the usage occurs in the same file then it's OK\n* If type `T` member is accessed from a `T` method declaration from another file\n\nThis code will trigger a warning:\n\n```go\n// file1.go\n\ntype data struct {\n    name string\n}\n```\n```go\n// file2.go\n\nfunc f(d *date) string {\n    return d.name // accessing data.name member outside of the suggested context\n}\n```\n\nLet's fix it:\n\n```diff\n type data struct {\n-    name string\n+    Name string \n }\n```\n\nFixed code example:\n\n```go\n// file1.go\n\ntype data struct {\n    Name string\n}\n```\n```go\n// file2.go\n\nfunc f(d *date) string {\n    return d.Name\n}\n```\n\nNote: since fileprivate reports unexported types, it's never a breaking change to rename a field or a method. All changes are package-local\nand are invisible to the package users.\n\n## Rationale\n\nGo has no concepts of file-protected and/or type-private.\n\nWhat benefits do we get:\n\n* When refactoring comes, it's easier to move those types in another package: we already made necessary APIs exported and regulated the ways that object\n  is used inside its original package.\n* For big package that can't be split into parts that's the way to keep things sane and avoid unfortunate incapsulation violations.\n\nKeep in mind that this tool is not suitable for every Go code base out there. I would also not recommend adding it to your CI pipeline unless\nevery member of your project agrees with it. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquasilyte%2Ffileprivate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fquasilyte%2Ffileprivate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquasilyte%2Ffileprivate/lists"}