Skip to content

Commit

Permalink
Update repo after transition from personal account (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg authored Dec 31, 2023
1 parent f7164a8 commit 59c953c
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 32 deletions.
18 changes: 18 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: 2
updates:
- package-ecosystem: "gomod"
commit-message:
prefix: "deps:"
directory: "/"
schedule:
interval: "weekly"
day: "sunday"
time: "09:00"
- package-ecosystem: "github-actions"
commit-message:
prefix: "ci:"
directory: "/"
schedule:
interval: "weekly"
day: "sunday"
time: "09:00"
34 changes: 34 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: build

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 'stable'

- name: Go Format
run: gofmt -s -w . && git diff --exit-code

- name: Go Tidy
run: go mod tidy && git diff --exit-code

- name: Go Mod
run: go mod download

- name: Build
run: go build ./...

- name: Test
run: go test -v -race -shuffle=on ./...
9 changes: 4 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
module github.com/quasilyte/minformat
module github.com/go-toolsmith/minformat

go 1.15

require (
github.com/go-toolsmith/astcopy v1.0.0
github.com/go-toolsmith/astequal v1.0.1 // indirect
github.com/go-toolsmith/strparse v1.0.0
github.com/google/go-cmp v0.5.6
github.com/go-toolsmith/astequal v1.1.0 // indirect
github.com/go-toolsmith/strparse v1.1.0
github.com/google/go-cmp v0.6.0
)
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
github.com/go-toolsmith/astcopy v1.0.0 h1:OMgl1b1MEpjFQ1m5ztEO06rz5CUd3oBv9RF7+DyvdG8=
github.com/go-toolsmith/astcopy v1.0.0/go.mod h1:vrgyG+5Bxrnz4MZWPF+pI4R8h3qKRjjyvV/DSez4WVQ=
github.com/go-toolsmith/astequal v1.0.0/go.mod h1:H+xSiq0+LtiDC11+h1G32h7Of5O3CYFJ99GVbS5lDKY=
github.com/go-toolsmith/astequal v1.0.1 h1:JbSszi42Jiqu36Gnf363HWS9MTEAz67vTQLponh3Moc=
github.com/go-toolsmith/astequal v1.0.1/go.mod h1:4oGA3EZXTVItV/ipGiOx7NWkY5veFfcsOJVS2YxltLw=
github.com/go-toolsmith/strparse v1.0.0 h1:Vcw78DnpCAKlM20kSbAyO4mPfJn/lyYA4BJUDxe2Jb4=
github.com/go-toolsmith/astequal v1.0.3/go.mod h1:9Ai4UglvtR+4up+bAD4+hCj7iTo4m/OXVTSLnCyTAx4=
github.com/go-toolsmith/astequal v1.1.0 h1:kHKm1AWqClYn15R0K1KKE4RG614D46n+nqUQ06E1dTw=
github.com/go-toolsmith/astequal v1.1.0/go.mod h1:sedf7VIdCL22LD8qIvv7Nn9MuWJruQA/ysswh64lffQ=
github.com/go-toolsmith/strparse v1.0.0/go.mod h1:YI2nUKP9YGZnL/L1/DLFBfixrcjslWct4wyljWhSRy8=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
github.com/go-toolsmith/strparse v1.1.0 h1:GAioeZUK9TGxnLS+qfdqNbA4z0SSm5zVNtCQiyP2Bvw=
github.com/go-toolsmith/strparse v1.1.0/go.mod h1:7ksGy58fsaQkGQlY8WVoBFNyEPMGuJin1rfoPS4lBSQ=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
golang.org/x/exp/typeparams v0.0.0-20220428152302-39d4317da171/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk=
golang.org/x/exp/typeparams v0.0.0-20230203172020-98cc5a0785f9 h1:6WHiuFL9FNjg8RljAaT7FNUuKDbvMqS1i5cr2OE2sLQ=
golang.org/x/exp/typeparams v0.0.0-20230203172020-98cc5a0785f9/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk=
14 changes: 0 additions & 14 deletions go/minformat/utils.go

This file was deleted.

File renamed without changes.
44 changes: 43 additions & 1 deletion go/minformat/minifier.go → minifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (m *minifier) printExpr(n ast.Expr) {
if n.Low != nil {
m.printExpr(n.Low)
}
m.out.WriteRune(':')
m.out.WriteByte(':')
if n.High != nil {
m.printExpr(n.High)
}
Expand Down Expand Up @@ -217,6 +217,9 @@ func (m *minifier) printExpr(n ast.Expr) {
case *ast.InterfaceType:
m.printInterfaceType(n)

case *ast.IndexListExpr:
m.printIndexListExpr(n)

default:
m.panicUnhandled("printExpr", n)
}
Expand Down Expand Up @@ -476,6 +479,11 @@ func (m *minifier) printGenDecl(n *ast.GenDecl) {
}
case *ast.TypeSpec:
m.out.WriteString(spec.Name.Name)
if spec.TypeParams != nil {
m.out.WriteString("[")
m.printFieldList(spec.TypeParams, ',')
m.out.WriteString("]")
}
if spec.Assign != token.NoPos {
m.out.WriteByte('=')
} else {
Expand Down Expand Up @@ -514,6 +522,12 @@ func (m *minifier) printBinaryExpr(n *ast.BinaryExpr) {
}
}

// Handle `x / Y` so we don't output it as `x/Y` (where Y is an expression).
// TODO(cristaloleg): handle only a case when we dereference Y: `x / *y`.
if n.Op == token.QUO {
spaceBeforeY = true
}

m.printExpr(n.X)
m.out.WriteString(n.Op.String())
if spaceBeforeY {
Expand All @@ -523,6 +537,11 @@ func (m *minifier) printBinaryExpr(n *ast.BinaryExpr) {
}

func (m *minifier) printFuncType(n *ast.FuncType) {
if n.TypeParams != nil {
m.out.WriteString("[")
m.printFieldList(n.TypeParams, ',')
m.out.WriteString("]")
}
m.out.WriteString("(")
m.printFieldList(n.Params, ',')
m.out.WriteString(")")
Expand Down Expand Up @@ -560,6 +579,20 @@ func (m *minifier) printInterfaceType(n *ast.InterfaceType) {
m.out.WriteByte('}')
}

func (m *minifier) printIndexListExpr(n *ast.IndexListExpr) {
m.printExpr(n.X)
m.out.WriteString("[")

for i, ind := range n.Indices {
if i > 0 {
m.out.WriteByte(',')
}
m.printExpr(ind)
}

m.out.WriteByte(']')
}

func (m *minifier) printFieldList(n *ast.FieldList, sep byte) {
for j, field := range n.List {
for j, ident := range field.Names {
Expand Down Expand Up @@ -588,3 +621,12 @@ func (m *minifier) panicUnhandled(fn string, n interface{}) {
}
panic(fmt.Sprintf("<?>: %s: unhandled %T", fn, n))
}

func leftmostExpr(n ast.Expr) ast.Expr {
switch n := n.(type) {
case *ast.BinaryExpr:
return leftmostExpr(n.X)
default:
return n
}
}
16 changes: 14 additions & 2 deletions go/minformat/minifier_test.go → minifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func TestGoroot(t *testing.T) {
}
f, err := parser.ParseFile(fset, filename, fileContents, 0)
if err != nil {
return nil
return err
}
var minified bytes.Buffer
if err := Node(&minified, fset, f); err != nil {
Expand All @@ -265,7 +265,7 @@ func TestGoroot(t *testing.T) {
fset2 := token.NewFileSet()
f2, err := parser.ParseFile(fset2, filename, minified.Bytes(), 0)
if err != nil {
return fmt.Errorf("re-parse minified: %w", err)
return fmt.Errorf("re-parse minified: %w\nminified: %s", err, minified.String())
}
if diff := astDiff(f, f2); diff != "" {
return fmt.Errorf("minified code produced different AST:\n%s", diff)
Expand All @@ -284,6 +284,18 @@ func TestGoroot(t *testing.T) {
if !strings.HasSuffix(info.Name(), ".go") {
return nil
}
// Skip some testdata dirs where not all files can be parsed.
// TODO(cristaloleg): skip file when we cannot parse it with go/parser.
if strings.Contains(path, "src/cmd/compile/internal/syntax/testdata") ||
strings.Contains(path, "src/cmd/compile/internal/types2/testdata") ||
strings.Contains(path, "src/cmd/go/internal/modindex/testdata") ||
strings.Contains(path, "src/cmd/go/parser/testdata") ||
strings.Contains(path, "src/cmd/internal/modindex/testdata") ||
strings.Contains(path, "src/go/parser/testdata") ||
strings.Contains(path, "src/internal/types/testdata") ||
strings.Contains(path, "src/cmd/compile/internal/syntax/testdata/smoketest.go") {
return nil
}
if err := visitFile(path); err != nil {
return fmt.Errorf("%s: %w", path, err)
}
Expand Down

0 comments on commit 59c953c

Please sign in to comment.