-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
175b582
commit d9c3680
Showing
1 changed file
with
56 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,61 @@ | ||
# keepsorted | ||
|
||
`keepsorted` is a simple command-line tool to sort blocks of lines in your code files. | ||
`keepsorted` is a command-line tool for sorting blocks of lines in your code files. | ||
|
||
It looks for the comment `# Keep sorted` and sorts the lines that follow it. | ||
It sorts lines following the comment `# Keep sorted`. | ||
|
||
For some files, like `Cargo.toml`, `.gitignore`, and `CODEOWNERS`, it works without needing the `# Keep sorted` comment. It automatically sorts sections like dependencies in `Cargo.toml` and blocks separated by newlines in the other files, keeping comments in place. | ||
For some files, like `Cargo.toml`, `.gitignore`, and `CODEOWNERS`, it sorts automatically without needing the `# Keep sorted` comment. It handles sections and blocks separated by newlines while preserving comments. | ||
|
||
For some examples look at `./tests/e2e-tests/`. | ||
See examples in `./tests/e2e-tests/`. | ||
|
||
## Supported Files | ||
|
||
### Generic Text Files | ||
|
||
Sort blocks starting with `# Keep sorted` or `// Keep sorted` and ending with a newline. | ||
|
||
```txt | ||
# Names | ||
# Keep sorted | ||
Alice | ||
Bob | ||
Conrad | ||
// Colors | ||
// Keep sorted | ||
Blue | ||
Green | ||
Red | ||
``` | ||
|
||
### Bazel | ||
|
||
Sort blocks inside `[...]` starting with `# Keep sorted`. | ||
|
||
```bazel | ||
DEPENDENCIES = [ | ||
# Keep sorted | ||
"a", | ||
"b", | ||
] | ||
``` | ||
|
||
### Cargo.toml | ||
|
||
Sort blocks starting with `[dependencies]`, `[dev-dependencies]`, etc., and ending with an empty line. | ||
|
||
```toml | ||
[dependencies] | ||
a = "0.1.0" | ||
b = { workspace = true } | ||
``` | ||
|
||
### .gitignore & CODEOWNERS | ||
|
||
*NOTE: These features are experimental and require feature flags:* | ||
|
||
```shell | ||
$ keepsorted <path> --features gitignore,codeowners | ||
``` | ||
|
||
Sort blocks separated by empty lines, keeping comments in place (except the opening block comment). |