#cargo #subcommand #dependencies #sort #check

app cargo-sort-ck

Check if tables and items in a .toml file are lexically sorted

16 releases (5 stable)

✓ Uses Rust 2018 edition

2.0.0 Mar 16, 2020
1.5.0 Mar 13, 2020
1.1.0 Dec 4, 2019
1.0.0 Jul 14, 2019
0.1.2 Jun 24, 2019

#22 in Cargo plugins

Download history 81/week @ 2019-12-01 193/week @ 2019-12-08 72/week @ 2019-12-15 18/week @ 2019-12-22 10/week @ 2019-12-29 62/week @ 2020-01-05 148/week @ 2020-01-12 76/week @ 2020-01-19 43/week @ 2020-01-26 77/week @ 2020-02-02 18/week @ 2020-02-09 33/week @ 2020-02-16 103/week @ 2020-02-23 10/week @ 2020-03-01 51/week @ 2020-03-08 57/week @ 2020-03-15

236 downloads per month

MIT/Apache

12KB
162 lines

Cargo Sort Check

Build Status Latest Version

A tool to check that your Cargo.toml dependencies are sorted alphabetically. Project created as a solution to @dtolnay's request for implementation #29. Cross platform implementation, windows compatible. Terminal coloring works on both cmd.exe and powershell. Checks/sorts by key in tables and also nested table headers (does not sort the items in a nested header, sorts the table itself). cargo sort-ck uses toml-parse to turn the toml file into a rowan syntax tree, it then sorts tokens keeping whitespace and comments intact. If the print or write options are used the tree is lightly formatted, fixing only formatting issues the sorting causes.

The print and write options may result in improperly formatted toml please file an issue.

Use

There are three modes cargo-sort-ck can be used in:

  • default
    • no flags set cargo-sort-ck will pass (exit 0) if .toml is sorted or fail if not (exit 1).
  • -p or --print
    • will print the sorted toml file to stdout.
  • -w or --write
    • will rewrite the toml file, I would like to eventually add some kind of check like cargo fix to warn if file is uncommitted/unsaved?.

included in sort check is:

["dependencies"]
["dev-dependencies"]
["build-dependencies"]
["workspace.members"]
["workspace.exclude"]

if you have a header to add open a PR's, they are welcomed.

Install

cargo install cargo-sort-ck

Run

Defaults to current dir but any path can be passed in.

Cargo Sort Check 
Devin R <devin.ragotzy@gmail.com>
Ensure Cargo.toml dependency tables are sorted.

USAGE:
    cargo-sort-ck [FLAGS] [CWD]

FLAGS:
        --crlf       output uses windows style line endings (\\r\\n)
    -h, --help       Prints help information
    -p, --print      prints Cargo.toml, lexically sorted, to the screen
    -V, --version    Prints version information
    -w, --write      rewrites Cargo.toml file so it is lexically sorted

ARGS:
    <CWD>...    Sets cwd, must contain Cargo.toml

Thanks to dspicher for issue #4 you can now invoke cargo sort check as a cargo subcommand

cargo sort-ck [FLAGS] [path]

Wildcard expansion is supported so you can do this

cargo-sort-ck [FLAGS] [path/to/*/Cargo.toml | path/to/*]

or any other pattern that is supported by your terminal. This also means multiple paths work.

cargo-sort-ck [FLAGS] path/to/a path/to/b path/to/c/Cargo.toml

These are all valid, file name and extension can be used on some of the paths but not others, if left off the defaults to Cargo.toml.

Examples

[dependencies]
a="0.1.1"
# comments will stay with the item
c="0.1.1"

# if this key value is moved the whitespace before and after will stick
# unless it is at the end of a table then it is formatted.
b="0.1.1"

[dependencies.alpha]
version="0"

[build-dependencies]
foo="0"
bar="0"

# comments will also stay with header
[dependencies.zed]
version="0"

[dependencies.beta]
version="0"

[dev-dependencies]
bar="0"
foo="0"

Will sort to, or fail until organized like so

[dependencies]
a="0.1.1"

# if this key value is moved the whitespace before and after will stick
# unless it is at the end of a table then it is formatted.
b="0.1.1"
# comments will stay with the item
c="0.1.1"

[dependencies.alpha]
version="0"

[dependencies.beta]
version="0"

# comments will also stay with header
[dependencies.zed]
version="0"

[build-dependencies]
bar="0"
foo="0"

[dev-dependencies]
bar="0"
foo="0"

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~2MB
~30K SLoC