{"id":20548068,"url":"https://github.com/lusingander/cargo-sort-derives","last_synced_at":"2025-04-14T10:42:57.501Z","repository":{"id":253502110,"uuid":"843716491","full_name":"lusingander/cargo-sort-derives","owner":"lusingander","description":"Cargo subcommand to sort derive attributes 📦","archived":false,"fork":false,"pushed_at":"2025-04-12T01:54:20.000Z","size":649,"stargazers_count":18,"open_issues_count":2,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-12T02:51:48.537Z","etag":null,"topics":["cargo","cargo-plugin","cargo-subcommand","derive"],"latest_commit_sha":null,"homepage":"https://lusingander.github.io/cargo-sort-derives/","language":"Rust","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/lusingander.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":"2024-08-17T07:44:59.000Z","updated_at":"2025-04-12T01:54:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"06e8197b-7ec2-4b26-8413-24032eeec60a","html_url":"https://github.com/lusingander/cargo-sort-derives","commit_stats":null,"previous_names":["lusingander/cargo-sort-derives"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lusingander%2Fcargo-sort-derives","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lusingander%2Fcargo-sort-derives/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lusingander%2Fcargo-sort-derives/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lusingander%2Fcargo-sort-derives/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lusingander","download_url":"https://codeload.github.com/lusingander/cargo-sort-derives/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248509892,"owners_count":21116125,"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":["cargo","cargo-plugin","cargo-subcommand","derive"],"created_at":"2024-11-16T02:11:54.247Z","updated_at":"2025-04-14T10:42:57.495Z","avatar_url":"https://github.com/lusingander.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# cargo-sort-derives\n\n[![Crate Status](https://img.shields.io/crates/v/cargo-sort-derives.svg)](https://crates.io/crates/cargo-sort-derives)\n\nCargo subcommand to sort derive attributes\n\n## About\n\nA Cargo subcommand that helps you consistently order `derive` attributes in your Rust code.\n\nThis tool ensures that the `derive` attributes in your structs and enums are sorted in a consistent.\n\n## Installation\n\n```\n$ cargo install --locked cargo-sort-derives\n```\n\n## Usage\n\n```\nUsage: cargo sort-derives [OPTIONS]\n\nOptions:\n  -p, --path \u003cFILE\u003e    The path to the file to sort\n                       If not specified, all .rs files in the current directory will be sorted\n      --order \u003cVALUE\u003e  Define the custom order of derive attributes, separated by commas (e.g. \"Debug, Clone, Copy\")\n                       Any derives not listed will appear at the end in alphabetical order by default\n      --preserve       Preserve the original order for unspecified derive attributes (only applies when --order is used)\n      --check          Check if the derive attributes are sorted\n      --color \u003cTYPE\u003e   Use colored output [default: auto] [possible values: auto, always, never]\n      --config \u003cFILE\u003e  The path to the config file\n  -h, --help           Print help\n  -V, --version        Print version\n```\n\n### Basic\n\n\u003cimg src=\"./img/basic.gif\" width=600\u003e\n\nThe following command sorts the `derive` attributes in the `.rs` files in the current directory:\n\n```\n$ cargo sort-derives\n```\n\nThis will reorder the `derive` attributes as follows:\n\n```rs\n// Before:\n#[derive(Debug, Clone, Copy, Default, Eq)]\nstruct Example;\n\n// After: sorted alphabetically\n#[derive(Clone, Copy, Debug, Default, Eq)]\nstruct Example;\n```\n\nBy default, it is sorted alphabetically.\n\n### Specifying the order\n\n\u003cimg src=\"./img/order.gif\" width=600\u003e\n\n```\n$ cargo sort-derives --order \"Eq, Clone, Default\"\n```\n\nThis will reorder the `derive` attributes as follows:\n\n```rs\n// Before:\n#[derive(Debug, Clone, Copy, Default, Eq)]\nstruct Example;\n\n// After: \"Eq, Clone, Default\" are sorted in that order, the rest are sorted alphabetically\n#[derive(Eq, Clone, Default, Copy, Debug)]\nstruct Example;\n```\n\nAny derives not listed will appear at the end in alphabetical order.\n\nThe `--preserve` option allows you to maintain the original order of `derive` attributes that are not specified in the `--order` option.\n\n```\n$ cargo sort-derives --order \"Eq, Clone, Default\" --preserve\n```\n\nThis will reorder the `derive` attributes as follows:\n\n```rs\n// Before:\n#[derive(Debug, Clone, Copy, Default, Eq)]\nstruct Example;\n\n// After: \"Eq, Clone, Default\" are sorted in that order, the rest keep the original order\n#[derive(Eq, Clone, Default, Debug, Copy)]\nstruct Example;\n```\n\nYou can also specify the order in the `order` section of the [config file](#config).\n\n#### Ellipsis\n\nIf you specify an ellipsis (`...`), the `derive` attributes before it will be placed at the beginning, the elements after it will be placed at the end, and the remaining will be sorted alphabetically (if `--preserve` option is not specified).\n\n```\n$ cargo sort-derives --order \"Eq, ..., Default, Clone\"\n```\n\nThis will reorder the `derive` attributes as follows:\n\n```rs\n// Before:\n#[derive(Debug, Clone, Copy, Default, Eq)]\nstruct Example;\n\n// After: \"Eq\" at the beginning, \"Default, Clone\" at the end, in that order, with the rest in between in alphabetical order.\n#[derive(Eq, Copy, Debug, Default, Clone)]\nstruct Example;\n```\n\nEllipsis (`...`) cannot be specified multiple times.\n\n### Check without updates\n\n\u003cimg src=\"./img/check.gif\" width=600\u003e\n\n```\n$ cargo sort-derives --check\n```\n\nThis checks if the `derive` attributes in your `.rs` files are sorted correctly.\n\nIf the attributes are out of order, the command will exit with a non-zero status code, indicating that the files need to be updated.\n\n### Process only specific files\n\n```\n$ cargo sort-derives --path ./path/to/file.rs\n```\n\nYou can sort only the files specified by the `--path` option.\n\nYou cannot specify a directory or multiple paths. Also, all [exclusions](#exclude-targets) are ignored.\n\n### Exclude targets\n\nIf the `.gitignore` or `.ignore` file exists, the files listed there will be excluded.\n\nYou can specify files to exclude in the `exclude` section of the [config file](#config).\n\n### Ignore lines and ranges\n\nYou can exclude parts of your code from being sorted by including certain strings:\n\n- `sort-derives-disable-next-line`: Ignore the next line of this string\n- `sort-derives-disable-start` / `sort-derives-disable-end`: Ignore the lines between start and end\n\n### Config\n\nIf `.sort-derives.toml` or `sort-derives.toml` exists in the current directory, the config will be loaded.\n\nYou can also specify a configuration file with the `--config` option. In this case, the specified file will be read with priority.\n\n#### Format\n\nThe config file uses the following format:\n\n```toml\n# Define the custom order of derive attributes.\n# The command line option `--order` will override this setting if specified.\n# type: array of strings | string\norder = [\n  \"Eq\",\n  \"Clone\",\n  \"Default\",\n]\n# Alternatively, it can be set as a comma separated string, similar to the `--order`.\n# order = \"Eq, Clone, Default\"\n\n# Preserve the original order for unspecified derive attributes (only applies when custom order is used)\n# The command line option `--preserve` will override this setting if specified.\n# type: boolean\npreserve = true\n\n# Specify file path patterns to exclude from processing using the .gitignore format.\n# https://git-scm.com/docs/gitignore/en#_pattern_format\n# type: array of strings\nexclude = [\n  \"generated.rs\",\n  \"/tests/*\",\n]\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flusingander%2Fcargo-sort-derives","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flusingander%2Fcargo-sort-derives","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flusingander%2Fcargo-sort-derives/lists"}