{"id":48749001,"url":"https://github.com/maksym-arutyunyan/keepsorted","last_synced_at":"2026-04-19T19:08:10.033Z","repository":{"id":247738621,"uuid":"826657881","full_name":"maksym-arutyunyan/keepsorted","owner":"maksym-arutyunyan","description":"A tool for sorting blocks of lines in code files","archived":false,"fork":false,"pushed_at":"2026-04-06T17:59:33.000Z","size":210,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-04-06T19:23:36.665Z","etag":null,"topics":["code","comand-line","sorting"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maksym-arutyunyan.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","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":"AGENTS.md","dco":null,"cla":null}},"created_at":"2024-07-10T06:09:56.000Z","updated_at":"2026-04-06T17:59:36.000Z","dependencies_parsed_at":"2024-07-17T22:44:08.690Z","dependency_job_id":"366f7ee6-799a-4e25-ac72-bce6a441353c","html_url":"https://github.com/maksym-arutyunyan/keepsorted","commit_stats":null,"previous_names":["maksym-arutyunyan/keepsorted"],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/maksym-arutyunyan/keepsorted","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maksym-arutyunyan%2Fkeepsorted","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maksym-arutyunyan%2Fkeepsorted/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maksym-arutyunyan%2Fkeepsorted/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maksym-arutyunyan%2Fkeepsorted/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maksym-arutyunyan","download_url":"https://codeload.github.com/maksym-arutyunyan/keepsorted/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maksym-arutyunyan%2Fkeepsorted/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32018815,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T20:23:30.271Z","status":"online","status_checked_at":"2026-04-19T02:00:07.110Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["code","comand-line","sorting"],"created_at":"2026-04-12T15:15:36.685Z","updated_at":"2026-04-19T19:08:10.027Z","avatar_url":"https://github.com/maksym-arutyunyan.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# keepsorted\n\n[![keepsorted GitHub Actions][gh-image]][gh-checks]\n[![keepsorted on crates.io][cratesio-image]][cratesio]\n\n```shell\ncargo install keepsorted\n```\n\n- [Source code](https://github.com/maksym-arutyunyan/keepsorted)\n- [Issue tracker](https://github.com/maksym-arutyunyan/keepsorted/issues)\n\n## Overview\n\n`keepsorted` sorts lists of lines while keeping nearby comments with the lines\nthat follow them. Add a comment like **`Keep sorted`** and the tool will reorder\nthe next block. Some file types are sorted automatically.\n\n## Usage\n\nCheck a single file:\n\n```shell\nkeepsorted --check file.txt\n```\n\nCheck a directory recursively:\n\n```shell\nkeepsorted --check --recursive .\n```\n\nCheck only git-tracked files:\n\n```shell\ngit ls-files | xargs -n1 keepsorted --check\n```\n\nFix files in place (default mode):\n\n```shell\nkeepsorted file.txt\n```\n\n### Modes\n\n- `--fix` (default): Rewrites files in place.\n- `--check`: Verifies files are sorted. Returns exit code 4 if not.\n- `--diff`: Prints a diff of changes without modifying files.\n\n### Keywords\n\n- `Keep sorted` or `keepsorted: keep sorted` – sort the next block.\n- `keepsorted: ignore file` – skip the whole file.\n- `keepsorted: ignore block` – skip a single block.\n\nMarkers work with `#`, `//`, or `--` comments. Generic files support any of these.\nBazel files require `#`.\n`Cargo.toml` is sorted automatically.\n`.gitignore` and `CODEOWNERS` require `--features` (see below).\n\n### Examples\n\n#### Generic text (Python)\n\n```py\n# Keep sorted\n# comment B\nb\n# comment A\na\n```\n\nbecomes\n\n```py\n# Keep sorted\n# comment A\na\n# comment B\nb\n```\n\n#### Generic text (C++)\n\n```cpp\n// Keep sorted\n// comment two\nsecond\n// comment one\nfirst\n```\n\nbecomes\n\n```cpp\n// Keep sorted\n// comment one\nfirst\n// comment two\nsecond\n```\n\n#### Generic text (SQL/Lua)\n\n```sql\n-- Keep sorted\n-- c comment\nc\n-- a comment\na\n```\n\nbecomes\n\n```sql\n-- Keep sorted\n-- a comment\na\n-- c comment\nc\n```\n\n#### Bazel\n\n```bazel\nsrcs = [\n    # Keep sorted\n    \"b\",\n    # note for a\n    \"a\",\n]\n```\n\nbecomes\n\n```bazel\nsrcs = [\n    # Keep sorted\n    # note for a\n    \"a\",\n    \"b\",\n]\n```\n\n#### Cargo.toml\n\n```toml\n[dependencies]\nb = \"2\"\na = \"1\"\n\n# keepsorted: ignore block\n[dev-dependencies]\nz = \"1\"\ny = \"2\"\n```\n\nbecomes\n\n```toml\n[dependencies]\na = \"1\"\nb = \"2\"\n\n# keepsorted: ignore block\n[dev-dependencies]\nz = \"1\"\ny = \"2\"\n```\n\n#### .gitignore\n\n```gitignore\n# Build\n/b\n/a\n```\n\nbecomes\n\n```gitignore\n# Build\n/a\n/b\n```\n\n#### CODEOWNERS\n\n```codeowners\n# Team\nb\n# Lead\na\n```\n\nbecomes\n\n```codeowners\n# Lead\na\n# Team\nb\n```\n\n### Experimental features\n\nThe following features are behind flags because sorting might change behaviour:\n\n- `gitignore` and `codeowners` – order matters, so enable with care.\n- `rust_derive_alphabetical` and `rust_derive_canonical` – temporary helpers to\n  reorder `#[derive(...)]` attributes. `cargo fmt` does not yet sort derives\n  ([rust-lang/rustfmt#6574](https://github.com/rust-lang/rustfmt/issues/6574)).\n  These features are hidden behind flags and only perform alphabetical or\n  canonical ordering. Users have been requesting derive sorting since 2017, so\n  `keepsorted` fills the gap for now. Consider upvoting the issue if you want\n  built-in support.\n\nEnable features with `--features`:\n\n```shell\nkeepsorted file --features gitignore,rust_derive_canonical\n```\n\n### Limitations\n\n`keepsorted` intentionally does **not**:\n\n- Handle advanced directory traversal or ignore rules automatically.\n- Act as a full-fledged parser for every file type.\n- Handle ignore files or exclude paths automatically.\n- Automatically detect project structure or configuration files.\n- Replace formatting tools like `rustfmt` or `prettier`.\n\n[cratesio]: https://crates.io/crates/keepsorted\n[cratesio-image]: https://img.shields.io/crates/v/keepsorted.svg\n[gh-checks]: https://github.com/maksym-arutyunyan/keepsorted/actions/workflows/workflow.yaml\n[gh-image]: https://github.com/maksym-arutyunyan/keepsorted/workflows/CI/badge.svg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaksym-arutyunyan%2Fkeepsorted","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaksym-arutyunyan%2Fkeepsorted","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaksym-arutyunyan%2Fkeepsorted/lists"}