Skip to content

Commit

Permalink
Merge pull request #84 from KenshiTech/fix-errcheck-80
Browse files Browse the repository at this point in the history
feat: fix all linters and add ci to check linters
  • Loading branch information
logicalangel authored Mar 25, 2024
2 parents ed1d97d + 2ef9644 commit 8bde094
Show file tree
Hide file tree
Showing 47 changed files with 721 additions and 683 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Go

on:
push:
branches: [ "develop", "main" ]
pull_request:
branches: [ "develop", "main" ]

jobs:

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

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21.5'
cache: false

- name: Install Tools
working-directory: "src"
run: make tools

- name: Lint
working-directory: "src"
run: make lint

- name: Error Check
working-directory: "src"
run: make errors
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ docker/pgadmin
node_trace.*
src/bin
conf.*.private
.idea
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/unchained.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion conf.broker.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ rpc:
plugins:
uniswap:
schedule:
ethereum: 5000
ethereum: 5s

tokens:
- name: ethereum
Expand Down
2 changes: 1 addition & 1 deletion conf.remote.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ rpc:
plugins:
uniswap:
schedule:
ethereum: 5000
ethereum: 5s

tokens:
- name: ethereum
Expand Down
8 changes: 4 additions & 4 deletions conf.standalone.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ rpc:
plugins:
logs:
schedule:
arbitrum: 100
ethereum: 5000
arbitrum: 100ms
ethereum: 5s

events:
- name: DAI
Expand All @@ -39,8 +39,8 @@ plugins:

uniswap:
schedule:
arbitrum: 100
ethereum: 5000
arbitrum: 100ms
ethereum: 5s

tokens:
- name: ethereum
Expand Down
2 changes: 1 addition & 1 deletion conf.worker.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ rpc:
plugins:
uniswap:
schedule:
ethereum: 5000
ethereum: 5s

tokens:
- name: ethereum
Expand Down
4 changes: 1 addition & 3 deletions go.work
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
go 1.22

toolchain go1.22.0
go 1.22.1

use (
./src
Expand Down
2 changes: 1 addition & 1 deletion quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ rpc:
plugins:
uniswap:
schedule:
ethereum: 5000
ethereum: 5s

tokens:
- name: ethereum
Expand Down
39 changes: 29 additions & 10 deletions src/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ run:

linters-settings:
cyclop:
max-complexity: 30
package-average: 10.0
max-complexity: 35
package-average: 13.0

gosec:
excludes:
- G601
errcheck:
check-type-assertions: true

Expand Down Expand Up @@ -47,11 +50,19 @@ linters-settings:
- "^gopkg.in/yaml.v3.Node$"

funlen:
lines: 100
statements: 50
# should be decreased to 30
lines: 200
statements: 150
ignore-comments: true

# should be decreased to 30
gocognit:
min-complexity: 20
min-complexity: 110

gocyclo:
# Minimal code complexity to report.
# Default: 30 (but we recommend 10-20)
min-complexity: 31

gocritic:
settings:
Expand Down Expand Up @@ -135,14 +146,13 @@ linters:
- forbidigo
- funlen
- gocheckcompilerdirectives
- gochecknoinits
# - gochecknoinits
- gocognit
- goconst
- gocritic
- gocyclo
- godot
- goimports
- gomnd
- gomoddirectives
- gomodguard
- goprintffuncname
Expand All @@ -163,7 +173,7 @@ linters:
- predeclared
- promlinter
- reassign
- revive
# - revive
- rowserrcheck
- sqlclosecheck
- stylecheck
Expand All @@ -175,7 +185,6 @@ linters:
- usestdlibvars
- wastedassign
- whitespace
- godox
- interfacebloat
- tagalign
- containedctx
Expand All @@ -184,13 +193,23 @@ linters:
issues:
max-same-issues: 50
exclude-rules:
- text: 'shadow: declaration of "(err|ctx|ok)" shadows declaration at'
linters: [ govet ]
- source: "(noinspection|TODO)"
linters: [ godot ]
- source: "//noinspection"
linters: [ gocritic ]
- path: "cmd/"
- path: "cmd"
linters:
- funlen
- forbidigo
- path: "ent"
linters:
- gomnd
- forbidigo
- path: "config"
linters:
- gomnd
- path: "_test\\.go"
linters:
- bodyclose
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ tools:
check: errors imports fmt lint

errors:
errcheck -ignoretests -blank ./...
errcheck -ignoretests -ignoregenerated -blank ./...

lint:
$(CURDIR)/bin/golangci-lint run
Expand Down
3 changes: 1 addition & 2 deletions src/cmd/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/spf13/cobra"
)

// brokerCmd represents the broker command
// brokerCmd represents the broker command.
var brokerCmd = &cobra.Command{
Use: "broker",
Short: "Run the Unchained client in broker mode",
Expand Down Expand Up @@ -47,5 +47,4 @@ func init() {
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// brokerCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")

}
9 changes: 6 additions & 3 deletions src/cmd/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ import (
"github.com/spf13/cobra"
)

// consumerCmd represents the consumer command
// consumerCmd represents the consumer command.
var consumerCmd = &cobra.Command{
Use: "consumer",
Short: "Run the Unchained client in consumer mode",
Long: `Run the Unchained client in consumer mode`,

PreRun: func(cmd *cobra.Command, args []string) {
config.Config.BindPFlag("broker.uri", cmd.Flags().Lookup("broker"))
err := config.Config.BindPFlag("broker.uri", cmd.Flags().Lookup("broker"))
if err != nil {
panic(err)
}
},

Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -49,7 +52,7 @@ var consumerCmd = &cobra.Command{
logs.Setup()
client.StartClient()
consumers.StartConsumer()
client.ClientBlock()
client.Listen()
},
}

Expand Down
15 changes: 12 additions & 3 deletions src/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"os"

"github.com/ethereum/go-ethereum/log"

"github.com/KenshiTech/unchained/constants"
"github.com/spf13/cobra"
)
Expand All @@ -13,7 +15,7 @@ var secretsPath string
var contextPath string
var printVersion bool

// rootCmd represents the base command when called without any subcommands
// rootCmd represents the base command when called without any subcommands.
var rootCmd = &cobra.Command{
Use: "unchained",
Short: "Unchained is the universal data validation and processing protocol",
Expand Down Expand Up @@ -52,6 +54,13 @@ func init() {
rootCmd.PersistentFlags().StringVarP(&configPath, "config", "c", "./conf.yaml", "Config file")
rootCmd.PersistentFlags().StringVarP(&secretsPath, "secrets", "s", "./secrets.yaml", "Secrets file")
rootCmd.PersistentFlags().StringVarP(&contextPath, "context", "x", "./context", "Context DB")
rootCmd.MarkFlagFilename("config", "yaml")
rootCmd.MarkFlagRequired("config")
err := rootCmd.MarkFlagFilename("config", "yaml")
if err != nil {
log.Warn("no config flag")
}

err = rootCmd.MarkFlagRequired("config")
if err != nil {
log.Warn("no config flag")
}
}
9 changes: 6 additions & 3 deletions src/cmd/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ import (
"github.com/spf13/cobra"
)

// workerCmd represents the worker command
// workerCmd represents the worker command.
var workerCmd = &cobra.Command{
Use: "worker",
Short: "Run the Unchained client in worker mode",
Long: `Run the Unchained client in worker mode`,

PreRun: func(cmd *cobra.Command, args []string) {
config.Config.BindPFlag("broker.uri", cmd.Flags().Lookup("broker"))
err := config.Config.BindPFlag("broker.uri", cmd.Flags().Lookup("broker"))
if err != nil {
panic(err)
}
},

Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -49,7 +52,7 @@ var workerCmd = &cobra.Command{
logs.Setup()
logs.Start()
persistence.Start(contextPath)
client.ClientBlock()
client.Listen()
},
}

Expand Down
17 changes: 10 additions & 7 deletions src/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,28 @@ func init() {
Secrets = viper.New()
}

func LoadConfig(ConfigFileName string, SecretsFileName string) {
func LoadConfig(configFileName string, secretsFileName string) {
defaults()

Config.SetConfigFile(ConfigFileName)
Config.SetConfigFile(configFileName)
err := Config.ReadInConfig()

if err != nil {
if os.IsNotExist(err) {
Config.WriteConfig()
} else {
isNotExist := os.IsNotExist(err)
if !isNotExist {
panic(err)
}

err = Config.WriteConfig()
if err != nil {
panic(err)
}
}

Secrets.SetConfigFile(SecretsFileName)
Secrets.SetConfigFile(secretsFileName)
err = Secrets.MergeInConfig()

if err != nil && os.IsExist(err) {
panic(err)
}

}
Loading

0 comments on commit 8bde094

Please sign in to comment.