Skip to content

Commit

Permalink
update readme (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
maksym-arutyunyan authored Aug 8, 2024
1 parent 175b582 commit d9c3680
Showing 1 changed file with 56 additions and 4 deletions.
60 changes: 56 additions & 4 deletions README.md
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).

0 comments on commit d9c3680

Please sign in to comment.