Skip to content

Commit

Permalink
Merge pull request #391 from onflow/bastian/lint
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent authored Jun 13, 2024
2 parents adad770 + b0d8d8d commit b51ee70
Show file tree
Hide file tree
Showing 21 changed files with 183 additions and 105 deletions.
105 changes: 95 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ on:

env:
GO_VERSION: '1.22'
GOLANGCI_LINT_VERSION: 'v1.59'

jobs:
paths-filter:
Expand Down Expand Up @@ -57,9 +58,30 @@ jobs:
restore-keys: |
${{ runner.os }}-go-
- name: Test
run: make test-test
working-directory: test
run: make test
- name: Check tidy
run: make check-tidy-test
working-directory: test
run: make check-tidy

lint-test:
needs: paths-filter
if: ${{ needs.paths-filter.outputs.test == 'true' }}
name: Lint (Test Framework)
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6
with:
working-directory: test
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: ${{ env.GOLANGCI_LINT_VERSION }}
args: -v --timeout=5m
# https://github.com/golangci/golangci-lint-action/issues/244
skip-cache: true

test-lint:
needs: paths-filter
Expand All @@ -80,9 +102,30 @@ jobs:
restore-keys: |
${{ runner.os }}-go-
- name: Test
run: make test-lint
working-directory: lint
run: make test
- name: Check tidy
run: make check-tidy-lint
working-directory: lint
run: make check-tidy

lint-lint:
needs: paths-filter
if: ${{ needs.paths-filter.outputs.lint == 'true' }}
name: Lint (Lint)
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6
with:
working-directory: lint
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: ${{ env.GOLANGCI_LINT_VERSION }}
args: -v --timeout=5m
# https://github.com/golangci/golangci-lint-action/issues/244
skip-cache: true

test-languageserver:
needs: paths-filter
Expand Down Expand Up @@ -111,9 +154,30 @@ jobs:
working-directory: languageserver
run: make build
- name: Test
run: make test-languageserver
working-directory: languageserver
run: make test
- name: Check tidy
run: make check-tidy-languageserver
working-directory: languageserver
run: make check-tidy

lint-languageserver:
needs: paths-filter
if: ${{ needs.paths-filter.outputs.languageserver == 'true' }}
name: Lint (Language Server)
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6
with:
working-directory: languageserver
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: ${{ env.GOLANGCI_LINT_VERSION }}
args: -v --timeout=5m
# https://github.com/golangci/golangci-lint-action/issues/244
skip-cache: true

test-docgen:
needs: paths-filter
Expand All @@ -136,12 +200,33 @@ jobs:
restore-keys: |
${{ runner.os }}-go-
- name: Test
run: make test-docgen
working-directory: docgen
run: make test
- name: Check tidy
run: make check-tidy-docgen
working-directory: docgen
run: make check-tidy

lint-docgen:
needs: paths-filter
if: ${{ needs.paths-filter.outputs.docgen == 'true' }}
name: Lint (Docgen)
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6
with:
working-directory: docgen
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: ${{ env.GOLANGCI_LINT_VERSION }}
args: -v --timeout=5m
# https://github.com/golangci/golangci-lint-action/issues/244
skip-cache: true

lint:
name: Lint
check-license-headers:
name: Check license headers
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
Expand Down
35 changes: 35 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
linters:
disable-all: true
enable:
- govet
- gosimple
- errcheck
- staticcheck
- ineffassign
- typecheck
- misspell
- unused
- exportloopref
- gocritic
- gofmt
- goimports
- unconvert
- nilerr
- forbidigo
- bidichk
- asciicheck

issues:
max-issues-per-linter: 0
max-same-issues: 0

linters-settings:
gocritic:
disabled-checks:
- ifElseChain # style
- singleCaseSwitch # style
- unslice # false positives
- commentFormatting # does not detect commented out code
- exitAfterDefer
goimports:
local-prefixes: github.com/onflow/cadence-tools
63 changes: 0 additions & 63 deletions Makefile

This file was deleted.

2 changes: 1 addition & 1 deletion docgen/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ func main() {
log.Fatal(err)
}

fmt.Println(fmt.Sprintf("Docs generated at: %s", outputDir))
_, _ = fmt.Fprintf(os.Stdout, "Docs generated at: %s\n", outputDir)
}
5 changes: 4 additions & 1 deletion docgen/doc_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (
"github.com/onflow/cadence/runtime/ast"
"github.com/onflow/cadence/runtime/common"
"github.com/onflow/cadence/runtime/parser"
"golang.org/x/text/cases"
"golang.org/x/text/language"

"github.com/onflow/cadence-tools/docgen/templates"
)
Expand Down Expand Up @@ -316,7 +318,8 @@ func (ASTDeclarationTemplateFunctions) DeclKeywords(declaration ast.Declaration)
}

func (ASTDeclarationTemplateFunctions) DeclTypeTitle(declaration ast.Declaration) string {
return strings.Title(declaration.DeclarationKind().Keywords())
return cases.Title(language.English).
String(declaration.DeclarationKind().Keywords())
}

func (ASTDeclarationTemplateFunctions) GenInitializer(declaration ast.Declaration) bool {
Expand Down
1 change: 1 addition & 0 deletions docgen/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.18
require (
github.com/onflow/cadence v0.28.0
github.com/stretchr/testify v1.7.3
golang.org/x/text v0.3.7
)

require (
Expand Down
1 change: 1 addition & 0 deletions docgen/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ go.opentelemetry.io/otel v1.8.0 h1:zcvBFizPbpa1q7FehvFiHbQwGzmPILebO0tyqIR5Djg=
go.uber.org/goleak v1.1.10 h1:z+mqJhf6ss6BSfSM671tgKyZBFPTTJM+HLxnhPC3wu0=
golang.org/x/lint v0.0.0-20200302205851-738671d3881b h1:Wh+f8QHJXR411sJR8/vRBTZ7YapZaRvUcLFFJhusH0k=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.1.11 h1:loJ25fNOEhSXfHrpoGj91eCUThwdNX6u24rO1xnNteY=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
1 change: 0 additions & 1 deletion docgen/templates/markdown-templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
var mdTemplateFiles embed.FS

// MarkdownTemplateProvider is a provider for the markdown template files.
//
type MarkdownTemplateProvider struct {
}

Expand Down
1 change: 0 additions & 1 deletion docgen/templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package templates
// TemplateProvider is a template provider interface that has to be
// implemented by all the template providers of the document generator.
// e.g: Markdown templates.
//
type TemplateProvider interface {
Get(templateName string) (string, error)
}
4 changes: 2 additions & 2 deletions docgen/test/doc_gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ func TestFunctionDocFormatting(t *testing.T) {

docFiles, err := docGen.GenerateInMemory(string(content))
require.NoError(t, err)
require.Len(t, docFiles, 1)
assert.Len(t, docFiles, 1)

expectedContent, err := os.ReadFile(path.Join("outputs", "sample3_output.md"))

require.NoError(t, err)
assert.Equal(t, string(expectedContent), string(docFiles["index.md"]))
}
3 changes: 2 additions & 1 deletion languageserver/cmd/languageserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
package main

import (
"github.com/onflow/cadence-tools/languageserver"
"github.com/spf13/pflag"

"github.com/onflow/cadence-tools/languageserver"
)

var enableFlowClientFlag = pflag.Bool("enable-flow-client", true, "enable Flow client functionality")
Expand Down
8 changes: 5 additions & 3 deletions languageserver/languageserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
package languageserver

import (
"fmt"
"os"

"github.com/mattn/go-isatty"
Expand All @@ -33,9 +34,10 @@ import (

func RunWithStdio(enableFlowClient bool) {
if isatty.IsTerminal(os.Stdout.Fd()) {
print(
"This program implements the Language Server Protocol for Cadence.\n" +
"Please check the documentation on how to run it.\n" +
_, _ = fmt.Fprint(
os.Stdout,
"This program implements the Language Server Protocol for Cadence.\n"+
"Please check the documentation on how to run it.\n"+
"It does nothing in a terminal, it should be run with an editor/IDE.\n",
)
os.Exit(1)
Expand Down
Loading

0 comments on commit b51ee70

Please sign in to comment.