{"id":13563005,"url":"https://github.com/daixiang0/gci","last_synced_at":"2025-05-13T19:06:32.805Z","repository":{"id":37753981,"uuid":"279745783","full_name":"daixiang0/gci","owner":"daixiang0","description":"GCI, a tool that control golang package import order and make it always deterministic.","archived":false,"fork":false,"pushed_at":"2025-03-31T05:06:57.000Z","size":232,"stargazers_count":478,"open_issues_count":22,"forks_count":66,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-28T00:46:57.237Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/daixiang0.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}},"created_at":"2020-07-15T02:50:07.000Z","updated_at":"2025-04-25T10:25:31.000Z","dependencies_parsed_at":"2023-02-10T01:16:43.906Z","dependency_job_id":"66aefcba-235f-4763-97e6-e367bc97323b","html_url":"https://github.com/daixiang0/gci","commit_stats":null,"previous_names":[],"tags_count":53,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daixiang0%2Fgci","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daixiang0%2Fgci/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daixiang0%2Fgci/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daixiang0%2Fgci/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daixiang0","download_url":"https://codeload.github.com/daixiang0/gci/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254010810,"owners_count":21998993,"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":[],"created_at":"2024-08-01T13:01:14.160Z","updated_at":"2025-05-13T19:06:32.779Z","avatar_url":"https://github.com/daixiang0.png","language":"Go","funding_links":[],"categories":["Imports formatters","Go"],"sub_categories":[],"readme":"# GCI\n\nGCI, a tool that controls Go package import order and makes it always deterministic.\n\nThe desired output format is highly configurable and allows for more custom formatting than `goimport` does.\n\nGCI considers a import block based on AST as below:\n\n```\nDoc\nName Path Comment\n```\n\nAll comments will keep as they were, except the isolated comment blocks.\n\nThe isolated comment blocks like below:\n\n```\nimport (\n  \"fmt\"\n  // this line is isolated comment\n\n  // those lines belong to one\n  // isolated comment blocks\n\n  \"github.com/daixiang0/gci\"\n)\n```\n\nGCI splits all import blocks into different sections, now support six section type:\n\n- standard: Go official imports, like \"fmt\"\n- custom: Custom section, use full and the longest match (match full string first, if multiple matches, use the longest one)\n- default: All rest import blocks\n- blank: Put blank imports together in a separate group\n- dot: Put dot imports together in a separate group\n- alias: Put alias imports together in a separate group\n- localmodule: Put imports from local packages in a separate group\n\nThe priority is standard \u003e default \u003e custom \u003e blank \u003e dot \u003e alias \u003e localmodule, all sections sort alphabetically inside.\nBy default, blank, dot, and alias sections are not used, and the corresponding lines end up in the other groups.\n\nAll import blocks use one TAB(`\\t`) as Indent.\n\nSince v0.9.0, GCI always puts C import block as the first.\n\n**Note**:\n\n`nolint` is hard to handle at section level, GCI will consider it as a single comment.\n\n### LocalModule\n\nLocal module detection is done via reading the module name from the `go.mod`\nfile in *the directory where `gci` is invoked*. This means:\n\n  - This mode works when `gci` is invoked from a module root (i.e. directory\n    containing `go.mod`)\n  - This mode doesn't work with a multi-module setup, i.e. when `gci` is invoked\n    from a directory containing `go.work` (though it would work if invoked from\n    within one of the modules in the workspace)\n\n## Installation\n\nTo download and install the highest available release version -\n\n```shell\ngo install github.com/daixiang0/gci@latest\n```\n\nYou may also specify a specific version, for example:\n\n```shell\ngo install github.com/daixiang0/gci@v0.11.2\n```\n\n## Usage\n\nNow GCI provides two command line methods, mainly for backward compatibility.\n\n### New style\n\nGCI supports three modes of operation\n\n\u003e **Note**\n\u003e\n\u003e Since v0.10.0, the `-s` and `--section` flag can only be used multiple times to specify multiple sections.\n\u003e For example, you could use `-s standard,default` before, but now you must use `-s standard -s default`.\n\u003e This breaking change makes it possible for the project to support specifying multiple custom prefixes. (Please see below.)\n\n```shell\n$ gci print -h\nPrint outputs the formatted file. If you want to apply the changes to a file use write instead!\n\nUsage:\n  gci print path... [flags]\n\nAliases:\n  print, output\n\nFlags:\n      --custom-order          Enable custom order of sections\n  -d, --debug                 Enables debug output from the formatter\n  -h, --help                  help for print\n  -s, --section stringArray   Sections define how inputs will be processed. Section names are case-insensitive and may contain parameters in (). The section order is standard \u003e default \u003e custom \u003e blank \u003e dot \u003e alias \u003e localmodule. The default value is [standard,default].\n                              standard - standard section that Go provides officially, like \"fmt\"\n                              Prefix(github.com/daixiang0) - custom section, groups all imports with the specified Prefix. Imports will be matched to the longest Prefix. Multiple custom prefixes may be provided, they will be rendered as distinct sections separated by newline. You can regroup multiple prefixes by separating them with comma: Prefix(github.com/daixiang0,gitlab.com/daixiang0,daixiang0)\n                              default - default section, contains all rest imports\n                              blank - blank section, contains all blank imports.\n                              dot - dot section, contains all dot imports. (default [standard,default])\n                              alias - alias section, contains all alias imports.\n                              localmodule: localmodule section, contains all imports from local packages\n      --skip-generated        Skip generated files\n      --skip-vendor           Skip files inside vendor directory\n```\n\n```shell\n$ gci write -h\nWrite modifies the specified files in-place\n\nUsage:\n  gci write path... [flags]\n\nAliases:\n  write, overwrite\n\nFlags:\n      --custom-order          Enable custom order of sections\n  -d, --debug                 Enables debug output from the formatter\n  -h, --help                  help for write\n  -s, --section stringArray   Sections define how inputs will be processed. Section names are case-insensitive and may contain parameters in (). The section order is standard \u003e default \u003e custom \u003e blank \u003e dot \u003e alias \u003e localmodule. The default value is [standard,default].\n                              standard - standard section that Go provides officially, like \"fmt\"\n                              Prefix(github.com/daixiang0) - custom section, groups all imports with the specified Prefix. Imports will be matched to the longest Prefix. Multiple custom prefixes may be provided, they will be rendered as distinct sections separated by newline. You can regroup multiple prefixes by separating them with comma: Prefix(github.com/daixiang0,gitlab.com/daixiang0,daixiang0)\n                              default - default section, contains all rest imports\n                              blank - blank section, contains all blank imports.\n                              dot - dot section, contains all dot imports. (default [standard,default])\n                              alias - alias section, contains all alias imports.\n                              localmodule: localmodule section, contains all imports from local packages\n      --skip-generated        Skip generated files\n      --skip-vendor           Skip files inside vendor directory\n```\n\n```shell\n$ gci list -h\nPrints the filenames that need to be formatted. If you want to show the diff use diff instead, and if you want to apply the changes use write instead\n\nUsage:\n  gci list path... [flags]\n\nFlags:\n      --custom-order          Enable custom order of sections\n  -d, --debug                 Enables debug output from the formatter\n  -h, --help                  help for list\n  -s, --section stringArray   Sections define how inputs will be processed. Section names are case-insensitive and may contain parameters in (). The section order is standard \u003e default \u003e custom \u003e blank \u003e dot \u003e alias \u003e localmodule. The default value is [standard,default].\n                              standard - standard section that Go provides officially, like \"fmt\"\n                              Prefix(github.com/daixiang0) - custom section, groups all imports with the specified Prefix. Imports will be matched to the longest Prefix. Multiple custom prefixes may be provided, they will be rendered as distinct sections separated by newline. You can regroup multiple prefixes by separating them with comma: Prefix(github.com/daixiang0,gitlab.com/daixiang0,daixiang0)\n                              default - default section, contains all rest imports\n                              blank - blank section, contains all blank imports.\n                              dot - dot section, contains all dot imports. (default [standard,default])\n                              alias - alias section, contains all alias imports.\n                              localmodule: localmodule section, contains all imports from local packages\n      --skip-generated        Skip generated files\n      --skip-vendor           Skip files inside vendor directory\n```\n\n```shell\n$ gci diff -h\nDiff prints a patch in the style of the diff tool that contains the required changes to the file to make it adhere to the specified formatting.\n\nUsage:\n  gci diff path... [flags]\n\nFlags:\n      --custom-order          Enable custom order of sections\n  -d, --debug                 Enables debug output from the formatter\n  -h, --help                  help for diff\n  -s, --section stringArray   Sections define how inputs will be processed. Section names are case-insensitive and may contain parameters in (). The section order is standard \u003e default \u003e custom \u003e blank \u003e dot \u003e alias \u003e localmodule. The default value is [standard,default].\n                              standard - standard section that Go provides officially, like \"fmt\"\n                              Prefix(github.com/daixiang0) - custom section, groups all imports with the specified Prefix. Imports will be matched to the longest Prefix. Multiple custom prefixes may be provided, they will be rendered as distinct sections separated by newline. You can regroup multiple prefixes by separating them with comma: Prefix(github.com/daixiang0,gitlab.com/daixiang0,daixiang0)\n                              default - default section, contains all rest imports\n                              blank - blank section, contains all blank imports.\n                              dot - dot section, contains all dot imports. (default [standard,default])\n                              alias - alias section, contains all alias imports.\n                              localmodule: localmodule section, contains all imports from local packages\n      --skip-generated        Skip generated files\n      --skip-vendor           Skip files inside vendor directory\n```\n\n### Old style\n\n```shell\nGci enables automatic formatting of imports in a deterministic manner\nIf you want to integrate this as part of your CI take a look at golangci-lint.\n\nUsage:\n  gci [-diff | -write] [--local localPackageURLs] path... [flags]\n  gci [command]\n\nAvailable Commands:\n  completion  Generate the autocompletion script for the specified shell\n  diff        Prints a git style diff to STDOUT\n  help        Help about any command\n  list        Prints filenames that need to be formatted to STDOUT\n  print       Outputs the formatted file to STDOUT\n  write       Formats the specified files in-place\n\nFlags:\n  -d, --diff            display diffs instead of rewriting files\n  -h, --help            help for gci\n  -l, --local strings   put imports beginning with this string after 3rd-party packages, separate imports by comma\n  -v, --version         version for gci\n  -w, --write           write result to (source) file instead of stdout\n\nUse \"gci [command] --help\" for more information about a command.\n```\n\n**Note**::\n\nThe old style is only for local tests, will be deprecated, please uses new style, `golangci-lint` uses new style as well.\n\n## Examples\n\nRun `gci write -s standard -s default -s \"prefix(github.com/daixiang0/gci)\" main.go` and you will handle following cases:\n\n### simple case\n\n```go\npackage main\nimport (\n  \"golang.org/x/tools\"\n\n  \"fmt\"\n\n  \"github.com/daixiang0/gci\"\n)\n```\n\nto\n\n```go\npackage main\nimport (\n    \"fmt\"\n\n    \"golang.org/x/tools\"\n\n    \"github.com/daixiang0/gci\"\n)\n```\n\n### with alias\n\n```go\npackage main\nimport (\n  \"fmt\"\n  go \"github.com/golang\"\n  \"github.com/daixiang0/gci\"\n)\n```\n\nto\n\n```go\npackage main\nimport (\n  \"fmt\"\n\n  go \"github.com/golang\"\n\n  \"github.com/daixiang0/gci\"\n)\n```\n\n### with blank and dot grouping enabled\n\n```go\npackage main\nimport (\n  \"fmt\"\n  go \"github.com/golang\"\n  _ \"github.com/golang/blank\"\n  . \"github.com/golang/dot\"\n  \"github.com/daixiang0/gci\"\n  _ \"github.com/daixiang0/gci/blank\"\n  . \"github.com/daixiang0/gci/dot\"\n)\n```\n\nto\n\n```go\npackage main\nimport (\n  \"fmt\"\n\n  go \"github.com/golang\"\n\n  \"github.com/daixiang0/gci\"\n\n  _ \"github.com/daixiang0/gci/blank\"\n  _ \"github.com/golang/blank\"\n\n  . \"github.com/daixiang0/gci/dot\"\n  . \"github.com/golang/dot\"\n)\n```\n\n### with alias grouping enabled\n\n```go\npackage main\n\nimport (\n\ttesting \"github.com/daixiang0/test\"\n\t\"fmt\"\n\n\tg \"github.com/golang\"\n\n\t\"github.com/daixiang0/gci\"\n\t\"github.com/daixiang0/gci/subtest\"\n)\n```\n\nto\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/daixiang0/gci\"\n\t\"github.com/daixiang0/gci/subtest\"\n\n\ttesting \"github.com/daixiang0/test\"\n\tg \"github.com/golang\"\n)\n```\n\n### with localmodule grouping enabled\n\nAssuming this is run on the root of this repo (i.e. where\n`github.com/daixiang0/gci` is a local module)\n\n```go\npackage main\n\nimport (\n\t\"os\"\n\t\"github.com/daixiang0/gci/cmd/gci\"\n)\n```\n\nto\n\n```go\npackage main\n\nimport (\n\t\"os\"\n\n\t\"github.com/daixiang0/gci/cmd/gci\"\n)\n```\n\n## TODO\n\n- Ensure only one blank between `Name` and `Path` in an import block\n- Ensure only one blank between `Path` and `Comment` in an import block\n- Format comments\n- Add more testcases\n- Support imports completion (please use `goimports` first then use GCI)\n- Optimize comments\n- Remove Analyzer layer and fully use analyzer syntax\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaixiang0%2Fgci","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaixiang0%2Fgci","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaixiang0%2Fgci/lists"}