{"id":20887965,"url":"https://github.com/canop/codesort","last_synced_at":"2026-03-06T09:32:09.805Z","repository":{"id":228636825,"uuid":"774570538","full_name":"Canop/codesort","owner":"Canop","description":"codesort sorts code","archived":false,"fork":false,"pushed_at":"2025-02-02T10:03:20.000Z","size":1570,"stargazers_count":98,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-16T18:55:54.390Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Canop.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"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}},"created_at":"2024-03-19T19:29:20.000Z","updated_at":"2025-09-13T00:52:20.000Z","dependencies_parsed_at":"2024-03-28T20:28:41.190Z","dependency_job_id":"6f9ecbfc-d6b6-4cf7-bb8e-c8a06110ae73","html_url":"https://github.com/Canop/codesort","commit_stats":null,"previous_names":["canop/codesort"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Canop/codesort","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Canop%2Fcodesort","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Canop%2Fcodesort/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Canop%2Fcodesort/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Canop%2Fcodesort/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Canop","download_url":"https://codeload.github.com/Canop/codesort/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Canop%2Fcodesort/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30168981,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T07:56:45.623Z","status":"ssl_error","status_checked_at":"2026-03-06T07:55:55.621Z","response_time":250,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":"2024-11-18T08:23:34.071Z","updated_at":"2026-03-06T09:32:09.782Z","avatar_url":"https://github.com/Canop.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"## CodeSort\n\n[![AGPL][s2]][l2] [![Latest Version][s1]][l1] [![Chat on Miaou][s4]][l4]\n\n[s1]: https://img.shields.io/crates/v/codesort.svg\n[l1]: https://crates.io/crates/codesort\n\n[s2]: https://img.shields.io/badge/license-AGPL-blue.svg\n[l2]: LICENSE\n\n[s4]: https://miaou.dystroy.org/static/shields/room.svg\n[l4]: https://miaou.dystroy.org/3490?codesort\n\n\nYour code is full of lists: enum variants, struct fields, match arms, function declarations, etc.\n\nWhen a list grows, it's sometimes useful to sort it alphabetically, to help you keep track of the parts.\n\nOf course you can't just sort lines: the code wouldn't work anymore; comments and annotations would be lost, spacing would be off, etc.\n\nAnd sorting code manually is a tedious task.\n\n**codesort** can do it for you, with a shortcut on the desired part of the code, directly in your IDE.\n\nHere's the before and after of sorting around the cursor's line:\n\n![errors](doc/errors.png)\n\n## Examples\n\n\u003cdetails\u003e\u003csummary\u003eSort the variants of a rust enum\u003c/summary\u003e\n\u003cimg src=doc/cmd_result.png\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eSort the fields of a rust struct\u003c/summary\u003e\n\u003cimg src=doc/job.png\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eSort javascript function assignements\u003c/summary\u003e\n\u003cimg src=doc/notifs.png\u003e\n\u003ci\u003eHere, the range to sort has been visually selected.\u003c/i\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eSort the arms of a huge rust \u003ccode\u003ematch\u003c/code\u003e\u003c/summary\u003e\n\u003cimg src=doc/on_internal.png\u003e\n\u003c/details\u003e\n\n## Install codesort\n\nHaving Rust dev environment [installed](https://rustup.rs), run\n\n```\ncargo install codesort\n```\n\n## Usage\n\n#### Sort a range in a file\n\n```\ncodesort --range 6:26 src/my/file.rs\n```\n\n#### Sort around a line\n\nUnless you specifically want to exclude a part of the list from sorting (eg a field you want to keep at the end of a struct), you should prefer to use `--around` which selects the range for you.\n\nThe first example of this readme has been sorted with the following command:\n\n```\ncodesort --around 14 src/my/file.rs\n```\n\nAny other line number from `6` to `26` would have been fine, except the deeper lines `21` and `22`\n(if you sort around line `22`, you sort `start` and `end`, which is probably not desired).\n\n#### Sort from stdin, return to stdout\n\nWhen no path is provided to codesort, specify the language using `--lang`/`-l`:\n\n```\ncat some/file.js | codesort -l js\n```\n\n## Code Editor Integration\n\nBy default, **codesort** takes the code to sort from stdin and writes the sorted code to stdout.\n\nIt can sort either the whole input, a given range (with `--range`), or select the best range around a given line (using `--around`).\n\nYou can also change the input and output to be files, with `--src` and `--dst`.\n\nIf necessary, you can provide a filename to codesort for langage detection (the file doesn't have to exist, only the extension of the name will be used, eg `.js`).\n\nThose options make it easy to integrate codesort in any editor. See below for vim and IntelliJ (contributions welcome for other editors).\n\n### Use codesort in vim / neovim\n\n#### Sort the selection\n\nWhen you don't want to sort the whole range (for example because there's a specific entry that you want to keep at the beginning), you can specify the range.\n\nVisually select the selection, then type `:`, then `!codesort`.\nThis changes the input to\n\n```\n:'\u003c,'\u003e!codesort\n```\n\nPress the `enter` key: the selection is sorted with codesort.\n\n#### Add a binding to sort around the current line\n\nYou don't usually have to select the zone to sort.\nYou can ask codesort to automatically select the zone to sort around your current line.\n\nDefine this binding in your vim configuration:\n\n```\n\" sort the optimal range around the current line\n\" See https://github.com/Canop/codesort\nnnoremap \u003cLeader\u003ecs ma\u003cESC\u003e:execute \":%!codesort --around \".line('.').\" --detect \".shellescape(expand('%:t'))\u003cCR\u003e`a\n\n```\n\nTyping the leader key then 'cs' will automatically select the set of blocs around the current line and sort it.\n\nExplanation of the command:\n\n* the current position is saved in the `a` register with `ma`\n* the command including the line number is built then executed with `:execute`\n* the codesort command takes the current line number through `--around`\n* the codesort command takes the filename, for langage detection, through `--detect`\n* the previous position is then restored\n\n### Use codesort in IntelliJ\n\n#### sort on a range\n\nConfigure the shortcut (File -\u003e Settings -\u003e Tools -\u003e External tools) like this:\n\nArguments: `--range $SelectionStartLine$:$SelectionEndLine$ $FileDir$/$FileName$`\n\n\u003cdetails\u003e\u003csummary\u003eSettings Screenshot\u003c/summary\u003e\n\u003cimg src=doc/intellij-range.png\u003e\n\u003c/details\u003e\n\n\nTo use it: right-click selection -\u003e external tools -\u003e codesort\n\n#### sort around the current line\n\nArguments: `--around $LineNumber$ $FileDir$/$FileName$`\n\n\u003cdetails\u003e\u003csummary\u003eSettings Screenshot\u003c/summary\u003e\n\u003cimg src=doc/intellij-around.png\u003e\n\u003c/details\u003e\n\n## Supported Code kinds\n\n3 code analyzers are available now:\n\n* Rust / C / Zig\n* Java\n* JavaScript\n\n## Contribute\n\nCodesort is much tested on Rust, but would need tests and probably improvements for other languages.\n\nWhatever the language and use case, please come discuss on [Miaou](https://miaou.dystroy.org/3768).\n\n## More info\n\nHere's an article explaining how CodeSort works: https://dystroy.org/blog/sort-code/\n\n## Licence\n\n**codesort** is licenced under [AGPL-3.0](https://www.gnu.org/licenses/agpl-3.0.en.html).\n\nYou're free to use the **codesort** program to sort the code of your choice, even commercial.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcanop%2Fcodesort","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcanop%2Fcodesort","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcanop%2Fcodesort/lists"}