Skip to content

Commit

Permalink
chore: update linter (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
b00f authored Jul 11, 2024
1 parent edbb251 commit 810ed69
Show file tree
Hide file tree
Showing 67 changed files with 974 additions and 512 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ jobs:
run: go mod vendor

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.54
run: |
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
make check
173 changes: 173 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
linters:
enable:
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- unused
- asasalint
- asciicheck
- bidichk
- bodyclose
- contextcheck
- decorder
- dogsled
- dupword
- durationcheck
- errchkjson
- errname
- errorlint
- exhaustive
- exportloopref
- forbidigo
- gci
- ginkgolinter
- gocheckcompilerdirectives
- gocritic
- gocyclo
- godot
- gofmt
- gofumpt
- goheader
- goimports
- gomoddirectives
- gomodguard
- goprintffuncname
- gosec
- gosmopolitan
- grouper
- importas
- lll
- loggercheck
- maintidx
- makezero
- mirror
- misspell
- musttag
- nakedret
- nilerr
- nilnil
- noctx
- nolintlint
- nosprintfhostport
- prealloc
- predeclared
- promlinter
- reassign
- revive
- rowserrcheck
- sqlclosecheck
- stylecheck
- tagalign
- tenv
- testableexamples
- thelper
- tparallel
- unconvert
- unparam
- usestdlibvars
- wastedassign
- whitespace
- zerologlint

linters-settings:
gosimple:
checks: ["all"]

revive:
enable-all-rules: true
rules:
- name: unused-receiver
disabled: true

- name: "exported"
disabled: true

- name: package-comments
disabled: true

- name: "add-constant"
disabled: true

- name: "line-length-limit"
disabled: true

- name: "cognitive-complexity"
disabled: true

- name: "function-length"
disabled: true

- name: "cyclomatic"
disabled: true

- name: max-public-structs
disabled: true

- name: "deep-exit"
disabled: true

- name: "confusing-naming"
disabled: true

- name: "function-result-limit"
disabled: true

- name: unhandled-error
arguments:
- "fmt.Printf"
- "fmt.Println"
- "fmt.Fprintf"
- "strings.Builder.WriteString"
- "strings.Builder.WriteRune"
- "strings.Builder.WriteByte"
- "bytes.Buffer.Write"
- "bytes.Buffer.WriteString"

gosec:
excludes:
- G304
- G204

stylecheck:
# TODO: enable ST1000 (at least one file in a package should have a package comment)
checks: ["all", "-ST1000"]

govet:
enable-all: true
disable: ["fieldalignment"]

settings:
shadow:
strict: true

predeclared:
# Comma-separated list of predeclared identifiers to not report on.
# Default: ""
ignore: "len"
# Include method names and field names (i.e., qualified names) in checks.
# Default: false
q: true

gocritic:
disabled-checks:
- ifElseChain
- unnamedResult
- builtinShadow
enabled-tags:
- diagnostic
- style
- performance

issues:
exclude-use-default: false
exclude-rules:
- path: _test.go
linters:
- maintidx
- forbidigo

- linters:
- govet
text: "shadow: declaration of \"err\" shadows"
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ devtools:
@echo "Installing devtools"
go install golang.org/x/tools/cmd/goimports@latest
go install mvdan.cc/gofumpt@latest
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.1
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
go install go.uber.org/mock/mockgen@latest
go install github.com/bufbuild/buf/cmd/buf@latest

Expand All @@ -42,19 +42,19 @@ check:
build: build-cli build-discord build-grpc build-telegram build-http

build-cli:
go build -o build/pagu-cli ./cmd/cli
go build -o build/pagu-cli ./cmd/cli

build-discord:
go build -o build/pagu-discord ./cmd/discord
go build -o build/pagu-discord ./cmd/discord

build-grpc:
go build -o build/pagu-grpc ./cmd/grpc
go build -o build/pagu-grpc ./cmd/grpc

build-telegram:
go build -o build/pagu-telegram ./cmd/telegram

build-http:
go build -o build/pagu-http ./cmd/http
go build -o build/pagu-http ./cmd/http

### pre commit
pre-commit: mock proto fmt check unit_test
Expand Down
24 changes: 11 additions & 13 deletions cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,23 @@ import (
"os"
"strings"

"github.com/pagu-project/Pagu/internal/entity"

"github.com/pagu-project/Pagu/internal/engine"
"github.com/pagu-project/Pagu/pkg/log"

"github.com/pactus-project/pactus/crypto"
pagu "github.com/pagu-project/Pagu"
pCmd "github.com/pagu-project/Pagu/cmd"
pagucmd "github.com/pagu-project/Pagu/cmd"
"github.com/pagu-project/Pagu/config"
cobra "github.com/spf13/cobra"
"github.com/pagu-project/Pagu/internal/engine"
"github.com/pagu-project/Pagu/internal/entity"
"github.com/pagu-project/Pagu/pkg/log"
"github.com/spf13/cobra"
)

var configPath string

const PROMPT = "\n>> "

func run(cmd *cobra.Command, args []string) {
func run(cmd *cobra.Command, _ []string) {
configs, err := config.Load(configPath)
pCmd.ExitOnError(cmd, err)
pagucmd.ExitOnError(cmd, err)

log.InitGlobalLogger(configs.Logger)

Expand All @@ -32,7 +30,7 @@ func run(cmd *cobra.Command, args []string) {
}

botEngine, err := engine.NewBotEngine(configs)
pCmd.ExitOnError(cmd, err)
pagucmd.ExitOnError(cmd, err)

botEngine.RegisterAllCommands()
botEngine.Start()
Expand All @@ -45,15 +43,15 @@ func run(cmd *cobra.Command, args []string) {
input, _ := reader.ReadString('\n')
input = strings.TrimSuffix(input, "\n")

if strings.ToLower(input) == "exit" {
if strings.EqualFold(input, "exit") {
cmd.Println("exiting from cli")

return
}

inputs := strings.Split(input, " ")

response := botEngine.Run(entity.AppIdCLI, "0", inputs)
response := botEngine.Run(entity.AppIDCLI, "0", inputs)

cmd.Printf("%v\n%v", response.Title, response.Message)
}
Expand All @@ -68,5 +66,5 @@ func main() {

rootCmd.PersistentFlags().StringVarP(&configPath, "config", "c", "./config.yml", "config path ./config.yml")
err := rootCmd.Execute()
pCmd.ExitOnError(rootCmd, err)
pagucmd.ExitOnError(rootCmd, err)
}
15 changes: 7 additions & 8 deletions cmd/discord/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import (
"os/signal"
"syscall"

pagucmd "github.com/pagu-project/Pagu/cmd"
"github.com/pagu-project/Pagu/config"
"github.com/pagu-project/Pagu/internal/engine"
"github.com/pagu-project/Pagu/internal/platforms/discord"
"github.com/pagu-project/Pagu/pkg/log"

pCmd "github.com/pagu-project/Pagu/cmd"
"github.com/pagu-project/Pagu/config"
"github.com/spf13/cobra"
)

Expand All @@ -25,30 +24,30 @@ func runCommand(parentCmd *cobra.Command) {
run.Run = func(cmd *cobra.Command, _ []string) {
// load configuration.
configs, err := config.Load(configPath)
pCmd.ExitOnError(cmd, err)
pagucmd.ExitOnError(cmd, err)

// Initialize global logger.
log.InitGlobalLogger(configs.Logger)

// starting botEngine.
botEngine, err := engine.NewBotEngine(configs)
pCmd.ExitOnError(cmd, err)
pagucmd.ExitOnError(cmd, err)

botEngine.RegisterAllCommands()
botEngine.Start()

discordBot, err := discord.NewDiscordBot(botEngine, configs.DiscordBot, configs.BotName)
pCmd.ExitOnError(cmd, err)
pagucmd.ExitOnError(cmd, err)

err = discordBot.Start()
pCmd.ExitOnError(cmd, err)
pagucmd.ExitOnError(cmd, err)

sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-sigChan

if err := discordBot.Stop(); err != nil {
pCmd.ExitOnError(cmd, err)
pagucmd.ExitOnError(cmd, err)
}

botEngine.Stop()
Expand Down
13 changes: 6 additions & 7 deletions cmd/grpc/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import (
"os/signal"
"syscall"

pagucmd "github.com/pagu-project/Pagu/cmd"
"github.com/pagu-project/Pagu/config"
"github.com/pagu-project/Pagu/internal/delivery/grpc"
"github.com/pagu-project/Pagu/internal/engine"
"github.com/pagu-project/Pagu/pkg/log"

pCmd "github.com/pagu-project/Pagu/cmd"
"github.com/pagu-project/Pagu/config"
"github.com/spf13/cobra"
)

Expand All @@ -25,29 +24,29 @@ func runCommand(parentCmd *cobra.Command) {
run.Run = func(cmd *cobra.Command, _ []string) {
// load configuration.
config, err := config.Load("")
pCmd.ExitOnError(cmd, err)
pagucmd.ExitOnError(cmd, err)

// Initialize global logger.
log.InitGlobalLogger(config.Logger)

// starting botEngine.
botEngine, err := engine.NewBotEngine(config)
pCmd.ExitOnError(cmd, err)
pagucmd.ExitOnError(cmd, err)

botEngine.RegisterAllCommands()
botEngine.Start()

grpcServer := grpc.NewServer(botEngine, config.GRPC)

err = grpcServer.Start()
pCmd.ExitOnError(cmd, err)
pagucmd.ExitOnError(cmd, err)

sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-sigChan

if err := grpcServer.Stop(); err != nil {
pCmd.ExitOnError(cmd, err)
pagucmd.ExitOnError(cmd, err)
}

botEngine.Stop()
Expand Down
Loading

0 comments on commit 810ed69

Please sign in to comment.