Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
4meepo authored Jul 7, 2023
1 parent ffa1884 commit 0cc0fd4
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,35 @@ type FooBar struct {
}
```



## Usage

By default tagalign will only align tags, but not sort them. But alignment and sort can work together or separately.

* As a Golangci Linter (Recommended)

Tagalign is a built-in linter in [Golangci Lint](https://golangci-lint.run/usage/linters/#tagalign) since `v1.53`.
> Note: In order to have the best experience, add the `--fix` flag to `golangci-lint` to enabled the aufofix feature.
* Standalone Mode

Install it using `GO` or download it [here](https://github.com/4meepo/tagalign/releases).
```bash
go install github.com/4meepo/tagalign/cmd/tagalign
```
Run it in your terminal.
```bash
# Only align tags.
tagalign -fix {package path}
# Only sort tags with fixed order.
tagalign -fix -noalign -sort -order "json,xml" {package path}
# Align and sort together.
tagalign -fix -sort -order "json,xml" {package path}
```

## Sort Tag

In addition to alignment, it can also sort tags with fixed order. If we enable sort with fixed order `json,xml`, the following code

```go
Expand All @@ -63,31 +92,6 @@ type SortExample struct {

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.

## Install

```bash
go install github.com/4meepo/tagalign/cmd/tagalign
```

## Usage

By default tagalign will only align tags, but not sort them. But alignment and sort can work together or separately.

If you don't want to align tags, you can use `-noalign` to disable alignment.

You can use `-sort` to enable sort and `-order` to set the fixed order of tags.

```bash
# Only align tags.
tagalign -fix {package path}
# Only sort tags with fixed order.
tagalign -fix -noalign -sort -order "json,xml" {package path}
# Align and sort together.
tagalign -fix -sort -order "json,xml" {package path}
```

TODO: integrate with golangci-lint

## Reference

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

0 comments on commit 0cc0fd4

Please sign in to comment.