From 0cc0fd499aa647901b7a97c65904bb6f305cbb84 Mon Sep 17 00:00:00 2001 From: Yifei Liu <28745416+4meepo@users.noreply.github.com> Date: Fri, 7 Jul 2023 16:29:53 +0800 Subject: [PATCH] Update README.md --- README.md | 54 +++++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 9181e7a..0c40ea5 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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/)