Skip to content

Commit

Permalink
Merge pull request #90 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 2.0.0
  • Loading branch information
andyone authored Aug 11, 2023
2 parents afea246 + 8c67574 commit 80fa353
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 89 deletions.
41 changes: 22 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,28 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
SRC_DIR: src/github.com/${{ github.repository }}

jobs:
Go:
name: Go
runs-on: ubuntu-latest

strategy:
matrix:
go: [ '1.18.x', '1.19.x', '1.20.x' ]
go: [ '1.18.x', '1.19.x', '1.20.x', '1.21.x' ]

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}

- name: Checkout
uses: actions/checkout@v3
with:
path: ${{env.SRC_DIR}}

- name: Download dependencies
working-directory: ${{env.SRC_DIR}}
run: make deps

- name: Run tests
working-directory: ${{env.SRC_DIR}}
run: make all

Aligo:
Expand All @@ -62,22 +55,32 @@ jobs:
needs: Go

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.19.x'

- name: Checkout
uses: actions/checkout@v3
with:
path: ${{env.SRC_DIR}}

- name: Download dependencies
working-directory: ${{env.SRC_DIR}}
run: make deps

- name: Check Golang sources with Aligo
uses: essentialkaos/aligo-action@v1
uses: essentialkaos/aligo-action@v2
with:
path: ${{env.SRC_DIR}}
files: ./...

Typos:
name: Typos
runs-on: ubuntu-latest

needs: Go

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Check spelling
continue-on-error: true
uses: crate-ci/typos@master
2 changes: 2 additions & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[files]
extend-exclude = ["go.sum"]
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
################################################################################

# This Makefile generated by GoMakeGen 2.1.0 using next command:
# This Makefile generated by GoMakeGen 2.2.0 using next command:
# gomakegen --mod .
#
# More info: https://kaos.sh/gomakegen
Expand Down Expand Up @@ -94,6 +94,6 @@ help: ## Show this info
| sed 's/ifdef //' \
| awk 'BEGIN {FS = " .*?## "}; {printf " \033[32m%-14s\033[0m %s\n", $$1, $$2}'
@echo -e ''
@echo -e '\033[90mGenerated by GoMakeGen 2.1.0\033[0m\n'
@echo -e '\033[90mGenerated by GoMakeGen 2.2.0\033[0m\n'

################################################################################
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#### From source

To build the `aligo` from scratch, make sure you have a working Go 1.18+ workspace (_[instructions](https://golang.org/doc/install)_), then:
To build the `aligo` from scratch, make sure you have a working Go 1.18+ workspace (_[instructions](https://go.dev/doc/install)_), then:

```
go install github.com/essentialkaos/aligo@latest
Expand Down
6 changes: 3 additions & 3 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
// App info
const (
APP = "aligo"
VER = "1.6.1"
VER = "2.0.0"
DESC = "Utility for viewing and checking Golang struct alignment"
)

Expand Down Expand Up @@ -153,7 +153,7 @@ func prepare() {
inspect.Sizes = types.SizesFor("gc", arch)

if inspect.Sizes == nil {
printErrorAndExit("Uknown arch %s", arch)
printErrorAndExit("Unknown arch %s", arch)
}
}

Expand Down Expand Up @@ -205,7 +205,7 @@ func printWarn(f string, a ...interface{}) {
fmtc.Fprintf(os.Stderr, "{y}"+f+"{!}\n", a...)
}

// printErrorAndExit print error mesage and exit with exit code 1
// printErrorAndExit print error message and exit with exit code 1
func printErrorAndExit(f string, a ...interface{}) {
printError(f, a...)
os.Exit(1)
Expand Down
38 changes: 20 additions & 18 deletions cli/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ package cli

import (
"fmt"
"path/filepath"
"strings"

"github.com/essentialkaos/ek/v12/fmtc"
"github.com/essentialkaos/ek/v12/fmtutil"
"github.com/essentialkaos/ek/v12/mathutil"
"github.com/essentialkaos/ek/v12/strutil"

"github.com/essentialkaos/aligo/inspect"
"github.com/essentialkaos/aligo/report"
Expand Down Expand Up @@ -47,9 +47,6 @@ func PrintFull(r *report.Report) {
printPackageInfo(pkg, false)
}
}

fmtutil.Separator(true)
fmtc.NewLine()
}

// PrintStruct prints info about struct
Expand All @@ -71,9 +68,6 @@ func PrintStruct(r *report.Report, strName string, optimal bool) {

printPackageSeparator(pkg.Path)
printStructInfo(str, optimal)

fmtutil.Separator(true)
fmtc.NewLine()
}

// Check checks report for problems
Expand All @@ -96,9 +90,6 @@ func Check(r *report.Report) bool {

if !hasProblems {
fmtc.Println("{g}All structs are well aligned{!}")
} else {
fmtutil.Separator(true)
fmtc.NewLine()
}

return hasProblems
Expand All @@ -114,7 +105,7 @@ func NewRenderer(fields []*report.Field, detailed bool) *Renderer {

for _, field := range fields {
mName = mathutil.Max(mName, len(field.Name))
mType = mathutil.Max(mType, len(strutil.Ellipsis(field.Type, MAX_TYPE_SIZE)))
mType = mathutil.Max(mType, len(filepath.Base(field.Type))+1)
mTag = mathutil.Max(mTag, len(field.Tag))
mComm = mathutil.Max(mComm, len(field.Comment))
}
Expand All @@ -123,7 +114,7 @@ func NewRenderer(fields []*report.Field, detailed bool) *Renderer {
mTag += 2
}

r.format = fmt.Sprintf(" %%-%ds", mName)
r.format = fmt.Sprintf(" %%-%ds", mName)

if mTag > 0 || mComm > 0 || !detailed {
r.format += fmt.Sprintf(" {*}%%-%ds{!}", mType)
Expand Down Expand Up @@ -167,7 +158,11 @@ func (r *Renderer) PrintField(f *report.Field) {
fComment = f.Comment
}

fType = strutil.Ellipsis(f.Type, MAX_TYPE_SIZE)
fType = filepath.Base(f.Type)

if strings.HasPrefix(f.Type, "*") {
fType = "*" + fType
}

switch {
case r.hasTags && r.hasComments:
Expand Down Expand Up @@ -213,7 +208,7 @@ func printPackageSeparator(path string) {
path = "{GOPATH}" + path[1:]
}

fmtutil.Separator(false, path)
fmtc.Printf("{s}{@*} ••• %s{!}\n\n", fmtutil.Align(path, fmtutil.LEFT, 86))
}

// printPackageInfo prints package info
Expand All @@ -239,12 +234,12 @@ func printStructSizeInfo(str *report.Struct, optimal bool) {
} else {
if str.Size != str.OptimalSize {
fmtc.Printf(
"{s-}// %s:%d | Size: %d (Optimal: %d){!}\n",
" {s-}// %s:%d | Size: %d (Optimal: %d){!}\n",
str.Position.File, str.Position.Line, str.Size, str.OptimalSize,
)
} else {
fmtc.Printf(
"{s-}// %s:%d | Size: %d{!}\n",
" {s-}// %s:%d | Size: %d{!}\n",
str.Position.File, str.Position.Line, str.Size,
)
}
Expand All @@ -255,17 +250,23 @@ func printStructSizeInfo(str *report.Struct, optimal bool) {
func printStructInfo(str *report.Struct, optimal bool) {
printStructSizeInfo(str, optimal)

fmtc.Printf("type {*}%s{!} struct {s}{{!}\n", str.Name)
if str.Size == 0 {
fmtc.Printf(" type {*}%s{!} struct {s}{ }{!}\n\n", str.Name)
return
}

fmtc.Printf(" type {*}%s{!} struct {s}{{!}\n", str.Name)

if optimal {
printAlignedFieldsInfo(str.AlignedFields)
} else {
printCurrentFieldsInfo(str.Fields)
}

fmtc.Println("{s}}{!}\n")
fmtc.Println(" {s}}{!}\n")
}

// printAlignedFieldsInfo prints aligned field data
func printAlignedFieldsInfo(fields []*report.Field) {
r := NewRenderer(fields, true)

Expand All @@ -275,6 +276,7 @@ func printAlignedFieldsInfo(fields []*report.Field) {
}
}

// printCurrentFieldsInfo prints current field data
func printCurrentFieldsInfo(fields []*report.Field) {
r := NewRenderer(fields, false)

Expand Down
11 changes: 7 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ module github.com/essentialkaos/aligo
go 1.18

require (
github.com/essentialkaos/depsy v1.0.0
github.com/essentialkaos/ek/v12 v12.63.0
github.com/essentialkaos/depsy v1.1.0
github.com/essentialkaos/ek/v12 v12.75.1
github.com/kisielk/gotool v1.0.0
golang.org/x/tools v0.7.0
golang.org/x/tools v0.12.0
)

require golang.org/x/sys v0.6.0 // indirect
require (
golang.org/x/mod v0.12.0 // indirect
golang.org/x/sys v0.11.0 // indirect
)
22 changes: 12 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
github.com/essentialkaos/check v1.4.0 h1:kWdFxu9odCxUqo1NNFNJmguGrDHgwi3A8daXX1nkuKk=
github.com/essentialkaos/depsy v1.0.0 h1:FikBtTnNhk+xFO/hFr+CfiKs6QnA3wMD6tGL0XTEUkc=
github.com/essentialkaos/depsy v1.0.0/go.mod h1:XVsB2eVUonEzmLKQP3ig2P6v2+WcHVgJ10zm0JLqFMM=
github.com/essentialkaos/ek/v12 v12.63.0 h1:9yaEu5W3bx//9y52ShqYCoFDKOcwEdrnvgSkUYyatgI=
github.com/essentialkaos/ek/v12 v12.63.0/go.mod h1:9MlSuHpewu7OZ9tM9dLFHvoA8dflBIUPCA0Ctt97wRs=
github.com/essentialkaos/depsy v1.1.0 h1:U6dp687UkQwXlZU17Hg2KMxbp3nfZAoZ8duaeUFYvJI=
github.com/essentialkaos/depsy v1.1.0/go.mod h1:kpiTAV17dyByVnrbNaMcZt2jRwvuXClUYOzpyJQwtG8=
github.com/essentialkaos/ek/v12 v12.75.1 h1:HE8/uWED+QgyT6HIcRULqjMYWKhqQ1rkfa/ozcva1eQ=
github.com/essentialkaos/ek/v12 v12.75.1/go.mod h1:juDcZWOWaj1QmYShZkT9RzdqJ3n0tmeP/iq4sw5fQF0=
github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
golang.org/x/mod v0.9.0 h1:KENHtAZL2y3NLMYZeHY9DW8HW8V+kQyJsY/V9JlKvCs=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/tools v0.7.0 h1:W4OVu8VVOaIO0yzWMNdepAulS7YfoS3Zabrm8DOXXU4=
golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/tools v0.12.0 h1:YW6HUoUmYBpwSgyaGaZq1fHjrBjX1rlpZ54T6mu2kss=
golang.org/x/tools v0.12.0/go.mod h1:Sc0INKfu04TlqNoRA1hgpFZbhYXHPr4V5DzpSBTPqQM=
Loading

0 comments on commit 80fa353

Please sign in to comment.