Skip to content

Commit 59c953c

Browse files
authored
Update repo after transition from personal account (#3)
1 parent f7164a8 commit 59c953c

File tree

8 files changed

+123
-32
lines changed

8 files changed

+123
-32
lines changed

.github/dependabot.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "gomod"
4+
commit-message:
5+
prefix: "deps:"
6+
directory: "/"
7+
schedule:
8+
interval: "weekly"
9+
day: "sunday"
10+
time: "09:00"
11+
- package-ecosystem: "github-actions"
12+
commit-message:
13+
prefix: "ci:"
14+
directory: "/"
15+
schedule:
16+
interval: "weekly"
17+
day: "sunday"
18+
time: "09:00"

.github/workflows/build.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: build
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
9+
jobs:
10+
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Set up Go
17+
uses: actions/setup-go@v5
18+
with:
19+
go-version: 'stable'
20+
21+
- name: Go Format
22+
run: gofmt -s -w . && git diff --exit-code
23+
24+
- name: Go Tidy
25+
run: go mod tidy && git diff --exit-code
26+
27+
- name: Go Mod
28+
run: go mod download
29+
30+
- name: Build
31+
run: go build ./...
32+
33+
- name: Test
34+
run: go test -v -race -shuffle=on ./...

go.mod

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
module github.com/quasilyte/minformat
1+
module github.com/go-toolsmith/minformat
22

33
go 1.15
44

55
require (
6-
github.com/go-toolsmith/astcopy v1.0.0
7-
github.com/go-toolsmith/astequal v1.0.1 // indirect
8-
github.com/go-toolsmith/strparse v1.0.0
9-
github.com/google/go-cmp v0.5.6
6+
github.com/go-toolsmith/astequal v1.1.0 // indirect
7+
github.com/go-toolsmith/strparse v1.1.0
8+
github.com/google/go-cmp v0.6.0
109
)

go.sum

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

go/minformat/utils.go

Lines changed: 0 additions & 14 deletions
This file was deleted.
File renamed without changes.

go/minformat/minifier.go renamed to minifier.go

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func (m *minifier) printExpr(n ast.Expr) {
150150
if n.Low != nil {
151151
m.printExpr(n.Low)
152152
}
153-
m.out.WriteRune(':')
153+
m.out.WriteByte(':')
154154
if n.High != nil {
155155
m.printExpr(n.High)
156156
}
@@ -217,6 +217,9 @@ func (m *minifier) printExpr(n ast.Expr) {
217217
case *ast.InterfaceType:
218218
m.printInterfaceType(n)
219219

220+
case *ast.IndexListExpr:
221+
m.printIndexListExpr(n)
222+
220223
default:
221224
m.panicUnhandled("printExpr", n)
222225
}
@@ -476,6 +479,11 @@ func (m *minifier) printGenDecl(n *ast.GenDecl) {
476479
}
477480
case *ast.TypeSpec:
478481
m.out.WriteString(spec.Name.Name)
482+
if spec.TypeParams != nil {
483+
m.out.WriteString("[")
484+
m.printFieldList(spec.TypeParams, ',')
485+
m.out.WriteString("]")
486+
}
479487
if spec.Assign != token.NoPos {
480488
m.out.WriteByte('=')
481489
} else {
@@ -514,6 +522,12 @@ func (m *minifier) printBinaryExpr(n *ast.BinaryExpr) {
514522
}
515523
}
516524

525+
// Handle `x / Y` so we don't output it as `x/Y` (where Y is an expression).
526+
// TODO(cristaloleg): handle only a case when we dereference Y: `x / *y`.
527+
if n.Op == token.QUO {
528+
spaceBeforeY = true
529+
}
530+
517531
m.printExpr(n.X)
518532
m.out.WriteString(n.Op.String())
519533
if spaceBeforeY {
@@ -523,6 +537,11 @@ func (m *minifier) printBinaryExpr(n *ast.BinaryExpr) {
523537
}
524538

525539
func (m *minifier) printFuncType(n *ast.FuncType) {
540+
if n.TypeParams != nil {
541+
m.out.WriteString("[")
542+
m.printFieldList(n.TypeParams, ',')
543+
m.out.WriteString("]")
544+
}
526545
m.out.WriteString("(")
527546
m.printFieldList(n.Params, ',')
528547
m.out.WriteString(")")
@@ -560,6 +579,20 @@ func (m *minifier) printInterfaceType(n *ast.InterfaceType) {
560579
m.out.WriteByte('}')
561580
}
562581

582+
func (m *minifier) printIndexListExpr(n *ast.IndexListExpr) {
583+
m.printExpr(n.X)
584+
m.out.WriteString("[")
585+
586+
for i, ind := range n.Indices {
587+
if i > 0 {
588+
m.out.WriteByte(',')
589+
}
590+
m.printExpr(ind)
591+
}
592+
593+
m.out.WriteByte(']')
594+
}
595+
563596
func (m *minifier) printFieldList(n *ast.FieldList, sep byte) {
564597
for j, field := range n.List {
565598
for j, ident := range field.Names {
@@ -588,3 +621,12 @@ func (m *minifier) panicUnhandled(fn string, n interface{}) {
588621
}
589622
panic(fmt.Sprintf("<?>: %s: unhandled %T", fn, n))
590623
}
624+
625+
func leftmostExpr(n ast.Expr) ast.Expr {
626+
switch n := n.(type) {
627+
case *ast.BinaryExpr:
628+
return leftmostExpr(n.X)
629+
default:
630+
return n
631+
}
632+
}

go/minformat/minifier_test.go renamed to minifier_test.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ func TestGoroot(t *testing.T) {
256256
}
257257
f, err := parser.ParseFile(fset, filename, fileContents, 0)
258258
if err != nil {
259-
return nil
259+
return err
260260
}
261261
var minified bytes.Buffer
262262
if err := Node(&minified, fset, f); err != nil {
@@ -265,7 +265,7 @@ func TestGoroot(t *testing.T) {
265265
fset2 := token.NewFileSet()
266266
f2, err := parser.ParseFile(fset2, filename, minified.Bytes(), 0)
267267
if err != nil {
268-
return fmt.Errorf("re-parse minified: %w", err)
268+
return fmt.Errorf("re-parse minified: %w\nminified: %s", err, minified.String())
269269
}
270270
if diff := astDiff(f, f2); diff != "" {
271271
return fmt.Errorf("minified code produced different AST:\n%s", diff)
@@ -284,6 +284,18 @@ func TestGoroot(t *testing.T) {
284284
if !strings.HasSuffix(info.Name(), ".go") {
285285
return nil
286286
}
287+
// Skip some testdata dirs where not all files can be parsed.
288+
// TODO(cristaloleg): skip file when we cannot parse it with go/parser.
289+
if strings.Contains(path, "src/cmd/compile/internal/syntax/testdata") ||
290+
strings.Contains(path, "src/cmd/compile/internal/types2/testdata") ||
291+
strings.Contains(path, "src/cmd/go/internal/modindex/testdata") ||
292+
strings.Contains(path, "src/cmd/go/parser/testdata") ||
293+
strings.Contains(path, "src/cmd/internal/modindex/testdata") ||
294+
strings.Contains(path, "src/go/parser/testdata") ||
295+
strings.Contains(path, "src/internal/types/testdata") ||
296+
strings.Contains(path, "src/cmd/compile/internal/syntax/testdata/smoketest.go") {
297+
return nil
298+
}
287299
if err := visitFile(path); err != nil {
288300
return fmt.Errorf("%s: %w", path, err)
289301
}

0 commit comments

Comments
 (0)