Skip to content

Commit 0cc0fd4

Browse files
authored
Update README.md
1 parent ffa1884 commit 0cc0fd4

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

README.md

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,35 @@ type FooBar struct {
4141
}
4242
```
4343

44+
45+
46+
## Usage
47+
48+
By default tagalign will only align tags, but not sort them. But alignment and sort can work together or separately.
49+
50+
* As a Golangci Linter (Recommended)
51+
52+
Tagalign is a built-in linter in [Golangci Lint](https://golangci-lint.run/usage/linters/#tagalign) since `v1.53`.
53+
> Note: In order to have the best experience, add the `--fix` flag to `golangci-lint` to enabled the aufofix feature.
54+
55+
* Standalone Mode
56+
57+
Install it using `GO` or download it [here](https://github.com/4meepo/tagalign/releases).
58+
```bash
59+
go install github.com/4meepo/tagalign/cmd/tagalign
60+
```
61+
Run it in your terminal.
62+
```bash
63+
# Only align tags.
64+
tagalign -fix {package path}
65+
# Only sort tags with fixed order.
66+
tagalign -fix -noalign -sort -order "json,xml" {package path}
67+
# Align and sort together.
68+
tagalign -fix -sort -order "json,xml" {package path}
69+
```
70+
71+
## Sort Tag
72+
4473
In addition to alignment, it can also sort tags with fixed order. If we enable sort with fixed order `json,xml`, the following code
4574

4675
```go
@@ -63,31 +92,6 @@ type SortExample struct {
6392

6493
The fixed order is `json,xml`, so the tags `json` and `xml` will be sorted and aligned first, and the rest tags will be sorted and aligned in the dictionary order.
6594

66-
## Install
67-
68-
```bash
69-
go install github.com/4meepo/tagalign/cmd/tagalign
70-
```
71-
72-
## Usage
73-
74-
By default tagalign will only align tags, but not sort them. But alignment and sort can work together or separately.
75-
76-
If you don't want to align tags, you can use `-noalign` to disable alignment.
77-
78-
You can use `-sort` to enable sort and `-order` to set the fixed order of tags.
79-
80-
```bash
81-
# Only align tags.
82-
tagalign -fix {package path}
83-
# Only sort tags with fixed order.
84-
tagalign -fix -noalign -sort -order "json,xml" {package path}
85-
# Align and sort together.
86-
tagalign -fix -sort -order "json,xml" {package path}
87-
```
88-
89-
TODO: integrate with golangci-lint
90-
9195
## Reference
9296

9397
[Golang AST Visualizer](http://goast.yuroyoro.net/)

0 commit comments

Comments
 (0)