Skip to content

Commit

Permalink
feat(gnovm): add gno fmt command (gnolang#2156)
Browse files Browse the repository at this point in the history
Co-authored-by: Manfred Touron <94029+moul@users.noreply.github.com>
  • Loading branch information
gfanton and moul committed Jul 23, 2024
1 parent 2e6f18a commit 5278b88
Show file tree
Hide file tree
Showing 94 changed files with 1,659 additions and 188 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@ jobs:
- run: make lint -C ./examples
# TODO: consider running lint on every other directories, maybe in "warning" mode?
# TODO: track coverage
fmt:
strategy:
fail-fast: false
matrix:
goversion: [ "1.22.x" ]
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.goversion }}
- run: |
make fmt -C ./examples
# Check if there are changes after running make fmt
git diff --exit-code || (echo "Some gno files are not formatted, please run 'make fmt'." && exit 1)
mod-tidy:
strategy:
fail-fast: false
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/gnofmt_template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
on:
workflow_call:
inputs:
path:
required: true
type: string
go-version:
required: true
type: string

jobs:
fmt:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ inputs.go-version }}
- name: Checkout code
uses: actions/checkout@v4
- name: Fmt
env:
GNOFMT_PATH: ${{ inputs.path }}
run: go run ./gnovm/cmd/gno fmt -v -diff $GNOFMT_PATH
6 changes: 6 additions & 0 deletions .github/workflows/gnovm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ jobs:
modulepath: "gnovm"
secrets:
codecov-token: ${{ secrets.CODECOV_TOKEN }}
fmt:
name: Run Gno Fmt
uses: ./.github/workflows/gnofmt_template.yml
with:
path: "gnovm/stdlibs/..."
go-version: "1.22.x"
9 changes: 2 additions & 7 deletions examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,9 @@ clean:
find . \( -name "*.gno.gen.go" -or -name ".*.gno.gen_test.go" \) -delete

.PHONY: fmt
GOFMT_FLAGS ?= -w
GNOFMT_FLAGS ?= -w
fmt:
go run -modfile ../misc/devdeps/go.mod mvdan.cc/gofumpt $(GOFMT_FLAGS) `find . -name "*.gno"`

.PHONY: imports
GOIMPORTS_FLAGS ?= -w
imports:
$(rundep) golang.org/x/tools/cmd/goimports $(GOIMPORTS_FLAGS) .
go run ../gnovm/cmd/gno fmt $(GNOFMT_FLAGS) ./...

.PHONY: tidy
tidy:
Expand Down
4 changes: 1 addition & 3 deletions examples/gno.land/p/demo/avl/tree_test.gno
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package avl

import (
"testing"
)
import "testing"

func TestNewTree(t *testing.T) {
tree := NewTree()
Expand Down
5 changes: 1 addition & 4 deletions examples/gno.land/p/demo/bf/bf_test.gno
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package bf

import (
"bytes"
"testing"
)
import "testing"

func TestExecuteBrainfuck(t *testing.T) {
testCases := []struct {
Expand Down
1 change: 0 additions & 1 deletion examples/gno.land/p/demo/cford32/cford32_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"io"
"math"
"strconv"
"strings"
"testing"
)
Expand Down
1 change: 0 additions & 1 deletion examples/gno.land/p/demo/grc/exts/vault/vault_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"std"
"time"

"gno.land/p/demo/grc/exts/vault"
"gno.land/p/demo/grc/grc20"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package grc1155

import (
"fmt"
"std"
"testing"

"gno.land/p/demo/users"
)

const dummyURI = "ipfs://xyz"
Expand Down
1 change: 0 additions & 1 deletion examples/gno.land/p/demo/grc/grc1155/gno.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ module gno.land/p/demo/grc/grc1155
require (
gno.land/p/demo/avl v0.0.0-latest
gno.land/p/demo/ufmt v0.0.0-latest
gno.land/p/demo/users v0.0.0-latest
)
3 changes: 0 additions & 3 deletions examples/gno.land/p/demo/grc/grc721/basic_nft_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ package grc721
import (
"std"
"testing"

"gno.land/p/demo/testutils"
"gno.land/p/demo/users"
)

var (
Expand Down
1 change: 0 additions & 1 deletion examples/gno.land/p/demo/grc/grc721/gno.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ require (
gno.land/p/demo/avl v0.0.0-latest
gno.land/p/demo/testutils v0.0.0-latest
gno.land/p/demo/ufmt v0.0.0-latest
gno.land/p/demo/users v0.0.0-latest
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"testing"

"gno.land/p/demo/testutils"
"gno.land/p/demo/users"
)

func TestSetMetadata(t *testing.T) {
Expand Down
2 changes: 0 additions & 2 deletions examples/gno.land/p/demo/grc/grc721/grc721_royalty_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"testing"

"gno.land/p/demo/testutils"
"gno.land/p/demo/ufmt"
"gno.land/p/demo/users"
)

func TestSetTokenRoyalty(t *testing.T) {
Expand Down
4 changes: 1 addition & 3 deletions examples/gno.land/p/demo/grc/grc721/igrc721_royalty.gno
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package grc721

import (
"std"
)
import "std"

// IGRC2981 follows the Ethereum standard
type IGRC2981 interface {
Expand Down
4 changes: 1 addition & 3 deletions examples/gno.land/p/demo/groups/groups.gno
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package groups

import (
"gno.land/r/demo/boards"
)
import "gno.land/r/demo/boards"

// TODO implement something and test.
type Group struct {
Expand Down
4 changes: 1 addition & 3 deletions examples/gno.land/p/demo/int256/absolute.gno
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package int256

import (
"gno.land/p/demo/uint256"
)
import "gno.land/p/demo/uint256"

// Abs returns |z|
func (z *Int) Abs() *uint256.Uint {
Expand Down
4 changes: 1 addition & 3 deletions examples/gno.land/p/demo/int256/arithmetic.gno
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package int256

import (
"gno.land/p/demo/uint256"
)
import "gno.land/p/demo/uint256"

func (z *Int) Add(x, y *Int) *Int {
z.initiateAbs()
Expand Down
6 changes: 2 additions & 4 deletions examples/gno.land/p/demo/int256/bitwise_test.gno
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package int256

import (
"gno.land/p/demo/uint256"
)

import (
"testing"

"gno.land/p/demo/uint256"
)

func TestOr(t *testing.T) {
Expand Down
4 changes: 1 addition & 3 deletions examples/gno.land/p/demo/int256/cmp_test.gno
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package int256

import (
"testing"
)
import "testing"

func TestEq(t *testing.T) {
tests := []struct {
Expand Down
4 changes: 1 addition & 3 deletions examples/gno.land/p/demo/int256/conversion.gno
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package int256

import (
"gno.land/p/demo/uint256"
)
import "gno.land/p/demo/uint256"

// SetInt64 sets z to x and returns z.
func (z *Int) SetInt64(x int64) *Int {
Expand Down
4 changes: 1 addition & 3 deletions examples/gno.land/p/demo/int256/int256_test.gno
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// ported from github.com/mempooler/int256
package int256

import (
"testing"
)
import "testing"

func TestSign(t *testing.T) {
tests := []struct {
Expand Down
4 changes: 1 addition & 3 deletions examples/gno.land/p/demo/json/buffer_test.gno
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package json

import (
"testing"
)
import "testing"

func TestBufferCurrent(t *testing.T) {
tests := []struct {
Expand Down
1 change: 0 additions & 1 deletion examples/gno.land/p/demo/json/decode_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package json

import (
"bytes"
"encoding/json"
"testing"
)

Expand Down
4 changes: 1 addition & 3 deletions examples/gno.land/p/demo/json/encode_test.gno
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package json

import (
"testing"
)
import "testing"

func TestMarshal_Primitive(t *testing.T) {
tests := []struct {
Expand Down
5 changes: 1 addition & 4 deletions examples/gno.land/p/demo/json/parser_test.gno
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package json

import (
"strconv"
"testing"
)
import "testing"

func TestParseStringLiteral(t *testing.T) {
tests := []struct {
Expand Down
4 changes: 1 addition & 3 deletions examples/gno.land/p/demo/json/path_test.gno
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package json

import (
"testing"
)
import "testing"

func TestParseJSONPath(t *testing.T) {
tests := []struct {
Expand Down
7 changes: 1 addition & 6 deletions examples/gno.land/p/demo/math_eval/int32/int32_test.gno
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package int32

import (
"std"
"testing"

"gno.land/p/demo/ufmt"
)
import "testing"

func TestOne(t *testing.T) {
ttt := []struct {
Expand Down
1 change: 0 additions & 1 deletion examples/gno.land/p/demo/merkle/merkle_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package merkle
import (
"fmt"
"testing"
"time"
)

type testData struct {
Expand Down
4 changes: 1 addition & 3 deletions examples/gno.land/p/demo/mux/response.gno
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package mux

import (
"strings"
)
import "strings"

// ResponseWriter represents the response writer.
type ResponseWriter struct {
Expand Down
5 changes: 1 addition & 4 deletions examples/gno.land/p/demo/mux/router_test.gno
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package mux

import (
"strings"
"testing"
)
import "testing"

func TestRouter_Render(t *testing.T) {
// Define handlers and route configuration
Expand Down
4 changes: 1 addition & 3 deletions examples/gno.land/p/demo/stack/stack_test.gno
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package stack

import (
"testing"
)
import "testing"

func TestStack(t *testing.T) {
s := New() // Empty stack
Expand Down
1 change: 0 additions & 1 deletion examples/gno.land/p/demo/tamagotchi/z0_filetest.gno
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"std"
"time"

"internal/os_test"
Expand Down
4 changes: 1 addition & 3 deletions examples/gno.land/p/demo/uint256/bitwise_test.gno
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package uint256

import (
"testing"
)
import "testing"

type logicOpTest struct {
name string
Expand Down
4 changes: 1 addition & 3 deletions examples/gno.land/p/demo/uint256/conversion_test.gno
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package uint256

import (
"testing"
)
import "testing"

func TestIsUint64(t *testing.T) {
tests := []struct {
Expand Down
4 changes: 1 addition & 3 deletions examples/gno.land/r/demo/art/millipede/millipede_test.gno
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package millipede

import (
"testing"
)
import "testing"

func TestRender(t *testing.T) {
cases := []struct {
Expand Down
4 changes: 1 addition & 3 deletions examples/gno.land/r/demo/echo/echo_test.gno
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package echo

import (
"testing"
)
import "testing"

func Test(t *testing.T) {
if Render("aa") != "aa" {
Expand Down
Loading

0 comments on commit 5278b88

Please sign in to comment.