From 4056e56abf826f4431a7fde84b040b6f271cb46e Mon Sep 17 00:00:00 2001 From: x1unix Date: Thu, 20 Aug 2020 00:48:11 +0300 Subject: [PATCH 1/3] add GolangCi linter and fix lint issues --- .golangci.yml | 5 +++++ cmd/playground/main.go | 3 +-- pkg/analyzer/package_test.go | 4 ++-- pkg/analyzer/scanner_test.go | 4 ++-- pkg/analyzer/sym_index.go | 3 ++- pkg/analyzer/sym_index_test.go | 2 +- pkg/compiler/storage/local.go | 2 +- pkg/langserver/request.go | 3 +-- pkg/testutil/errors.go | 1 - 9 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 .golangci.yml diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..db70442a --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,5 @@ +run: + tests: false + skip-dirs: + - pkg/worker + - cmd/webworker diff --git a/cmd/playground/main.go b/cmd/playground/main.go index 8346305c..91ab6d89 100644 --- a/cmd/playground/main.go +++ b/cmd/playground/main.go @@ -52,7 +52,7 @@ func main() { flag.Parse() l := getLogger(args.debug) - defer l.Sync() + defer l.Sync() //nolint:errcheck if err := start(goRoot, args); err != nil { l.Sugar().Fatal(err) } @@ -143,7 +143,6 @@ func startHttpServer(ctx context.Context, wg *sync.WaitGroup, server *http.Serve if err := server.Shutdown(shutdownCtx); err != nil { logger.Errorf("Could not gracefully shutdown the server: %v\n", err) } - return }() wg.Add(1) diff --git a/pkg/analyzer/package_test.go b/pkg/analyzer/package_test.go index 5bbd4999..c4cfe108 100644 --- a/pkg/analyzer/package_test.go +++ b/pkg/analyzer/package_test.go @@ -29,8 +29,8 @@ func TestPackage_SymbolByChar(t *testing.T) { pkg := Package{ Synopsis: "test doc", PackageSummary: PackageSummary{ - Functions: newSymbolIndex(allFuncs), - Values: newSymbolIndex(allSyms), + Functions: NewSymbolIndex(allFuncs), + Values: NewSymbolIndex(allSyms), }, } diff --git a/pkg/analyzer/scanner_test.go b/pkg/analyzer/scanner_test.go index 6e8f48b9..eaece01a 100644 --- a/pkg/analyzer/scanner_test.go +++ b/pkg/analyzer/scanner_test.go @@ -10,7 +10,7 @@ import ( // should be in sync with "testdata/src" !!! var examplePackageSummary = PackageSummary{ - Functions: newSymbolIndex([]*CompletionItem{ + Functions: NewSymbolIndex([]*CompletionItem{ { Label: "SomeFunc", Kind: Function, @@ -71,7 +71,7 @@ var examplePackageSummary = PackageSummary{ Documentation: NewMarkdownString("FuncUnnamedParams is function with unnamed params\n\n"), }, }), - Values: newSymbolIndex([]*CompletionItem{ + Values: NewSymbolIndex([]*CompletionItem{ { Label: "SomeConst", Kind: Constant, diff --git a/pkg/analyzer/sym_index.go b/pkg/analyzer/sym_index.go index 791bd9ea..f482aa96 100644 --- a/pkg/analyzer/sym_index.go +++ b/pkg/analyzer/sym_index.go @@ -20,7 +20,8 @@ func emptySymbolIndex() SymbolIndex { } } -func newSymbolIndex(items []*CompletionItem) SymbolIndex { +// NewSymbolIndex creates a new symbol index from completion items +func NewSymbolIndex(items []*CompletionItem) SymbolIndex { idx := SymbolIndex{ Symbols: items, nameMap: make(map[string]*CompletionItem, len(items)), diff --git a/pkg/analyzer/sym_index_test.go b/pkg/analyzer/sym_index_test.go index b2ec507b..41521458 100644 --- a/pkg/analyzer/sym_index_test.go +++ b/pkg/analyzer/sym_index_test.go @@ -13,7 +13,7 @@ func TestSymbolIndex(t *testing.T) { {Label: "baz"}, } - index := newSymbolIndex(syms) + index := NewSymbolIndex(syms) require.Equal(t, syms, index.Symbols) require.Equal(t, len(syms), index.Len()) diff --git a/pkg/compiler/storage/local.go b/pkg/compiler/storage/local.go index 8187114b..a42bb6f6 100644 --- a/pkg/compiler/storage/local.go +++ b/pkg/compiler/storage/local.go @@ -96,7 +96,7 @@ func (s LocalStorage) getOutputLocation(id ArtifactID) string { // HasItem implements storage interface func (s LocalStorage) HasItem(id ArtifactID) (bool, error) { s.useLock.Lock() - s.useLock.Unlock() + defer s.useLock.Unlock() fPath := s.getOutputLocation(id) _, err := os.Stat(fPath) if err != nil { diff --git a/pkg/langserver/request.go b/pkg/langserver/request.go index 1ed664a7..e1c5b553 100644 --- a/pkg/langserver/request.go +++ b/pkg/langserver/request.go @@ -114,8 +114,7 @@ func WriteJSON(w http.ResponseWriter, i interface{}) { w.Header().Add("Content-Type", "application/json") w.WriteHeader(http.StatusOK) - w.Write(data) - return + _, _ = w.Write(data) } func shouldFormatCode(r *http.Request) (bool, error) { diff --git a/pkg/testutil/errors.go b/pkg/testutil/errors.go index 1bc78f25..0106a0e4 100644 --- a/pkg/testutil/errors.go +++ b/pkg/testutil/errors.go @@ -15,5 +15,4 @@ func ContainsError(t *testing.T, err error, msg string) { if emsg := err.Error(); !strings.Contains(emsg, msg) { t.Fatalf("error %q should include %q", emsg, msg) } - return } From 4625b9895ad0756b9872866d4686489d87f684ce Mon Sep 17 00:00:00 2001 From: x1unix Date: Thu, 20 Aug 2020 00:48:25 +0300 Subject: [PATCH 2/3] add build constraints for WASM files --- cmd/webworker/webworker.go | 2 ++ pkg/worker/args.go | 2 ++ pkg/worker/callback.go | 2 ++ pkg/worker/worker.go | 2 ++ 4 files changed, 8 insertions(+) diff --git a/cmd/webworker/webworker.go b/cmd/webworker/webworker.go index a44d84d3..895bdc39 100644 --- a/cmd/webworker/webworker.go +++ b/cmd/webworker/webworker.go @@ -1,3 +1,5 @@ +// +build js + package main import ( diff --git a/pkg/worker/args.go b/pkg/worker/args.go index cbb7619a..3d9afba9 100644 --- a/pkg/worker/args.go +++ b/pkg/worker/args.go @@ -1,3 +1,5 @@ +// +build js + package worker import ( diff --git a/pkg/worker/callback.go b/pkg/worker/callback.go index 8e6d81c8..aa0e39d6 100644 --- a/pkg/worker/callback.go +++ b/pkg/worker/callback.go @@ -1,3 +1,5 @@ +// +build js + package worker import "syscall/js" diff --git a/pkg/worker/worker.go b/pkg/worker/worker.go index bad19084..d4fd0af6 100644 --- a/pkg/worker/worker.go +++ b/pkg/worker/worker.go @@ -1,3 +1,5 @@ +// +build js + // Package worker contains Go web-worker WASM module bridge methods package worker From 0176407980178213450f71815b8e44b509a72976 Mon Sep 17 00:00:00 2001 From: x1unix Date: Thu, 20 Aug 2020 01:28:19 +0300 Subject: [PATCH 3/3] Add merge request check and coverage submit --- .github/workflows/coverage.yml | 35 +++++++++++++++++++ .github/workflows/pull_request.yml | 25 +++++++++++++ .github/workflows/{master.yml => release.yml} | 0 3 files changed, 60 insertions(+) create mode 100644 .github/workflows/coverage.yml create mode 100644 .github/workflows/pull_request.yml rename .github/workflows/{master.yml => release.yml} (100%) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 00000000..8e40bf71 --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,35 @@ +# +# Code coverage report +# +# Reports tests code coverage to coveralls. +# Uses COVERALLS_TOKEN env var from GitHub repo secrets. +# +# see: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions +# + +name: Submit code coverage +on: + push: + branches: + - master +env: + GO111MODULE: on +jobs: + coverage: + runs-on: ubuntu-latest + steps: + - name: Setup Go + uses: actions/setup-go@v2 + with: + go-version: '^1.14.4' + - uses: actions/checkout@v2 + - run: go version + - name: install + run: | + go get golang.org/x/tools/cmd/cover + - name: Test + run: cat tools/cover.txt | xargs go test -v -covermode=count -coverprofile=coverage.out + - name: Send coverage + uses: shogo82148/actions-goveralls@v1 + with: + path-to-profile: coverage.out diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml new file mode 100644 index 00000000..7ce7e8c2 --- /dev/null +++ b/.github/workflows/pull_request.yml @@ -0,0 +1,25 @@ +# +# Pull request check workflow +# +# Runs linter and tests on source branch to check code quality. +# +# see: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions +# + +name: Check Pull Request +on: [pull_request] +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v1 + with: + version: v1.27 + - name: Setup Go + uses: actions/setup-go@v2 + with: + go-version: '^1.14.4' + - run: go version + - run: go test ./... diff --git a/.github/workflows/master.yml b/.github/workflows/release.yml similarity index 100% rename from .github/workflows/master.yml rename to .github/workflows/release.yml