Skip to content

Improvement/add more linters #2045

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 34 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ca4f0ee
add format section in .golangci-lint and format code
Saurabh2402 Jul 23, 2025
1e6860a
Merge branch 'develop' of https://github.com/Saurabh2402/digger into โ€ฆ
Saurabh2402 Jul 23, 2025
eaa833c
format code merged after sync
Saurabh2402 Jul 23, 2025
e0e4159
add staticcheck linter in .golangci.yml
Saurabh2402 Jul 23, 2025
cb49375
staticcheck: lint files with autofix
Saurabh2402 Jul 23, 2025
085e6cb
staticcheck backend/ : lint files
Saurabh2402 Jul 23, 2025
f97fd09
staticcheck background/projects-refresh-service/ : lint files
Saurabh2402 Jul 23, 2025
c2e2662
staticcheck cli/ : lint files with autofix
Saurabh2402 Jul 23, 2025
c0450d7
staticcheck cli/ : remove duplicate imports
Saurabh2402 Jul 23, 2025
40456a7
staticcheck ee/backend/ : lint files
Saurabh2402 Jul 23, 2025
d14b69d
staticcheck ee/cli/ : lint files
Saurabh2402 Jul 23, 2025
75dae15
staticcheck libs/ : lint files with autofix
Saurabh2402 Jul 23, 2025
1064fb0
staticcheck libs/ : lint files remove deprecated ioutils
Saurabh2402 Jul 23, 2025
7142c0f
staticcheck next/ : lint files with autofix
Saurabh2402 Jul 23, 2025
3ebc86c
staticcheck next/ : lint files remove duplicate imports
Saurabh2402 Jul 23, 2025
84ec2d6
govet: add linter
Saurabh2402 Jul 23, 2025
a15d209
govet: lint backend/
Saurabh2402 Jul 23, 2025
3e1d8ff
โš ๏ธ possible fix: return error
Saurabh2402 Jul 23, 2025
cb3538f
govet: lint ee/drift/
Saurabh2402 Jul 23, 2025
ddd7e0e
govet: lint libs/
Saurabh2402 Jul 23, 2025
613f9ee
โš ๏ธ possible fix: return error
Saurabh2402 Jul 23, 2025
54d08c0
gocritic: add linter
Saurabh2402 Jul 23, 2025
f37d2c0
gocritic: lint backend/ : [rename local variable like Org -> org]
Saurabh2402 Jul 23, 2025
5773953
gocritic: lint cli/ : [rename `local` variables like - SCMRepository โ€ฆ
Saurabh2402 Jul 23, 2025
62dfd24
gocritic : lint ee/*
Saurabh2402 Jul 23, 2025
0eb9f9a
gocritic: lint libs/ : rename local function variables in camelcase
Saurabh2402 Jul 23, 2025
994da92
gocritic: lint next/ : rename local function variables in camelcase
Saurabh2402 Jul 23, 2025
c5b4030
gocritic: lint next/dbgen
Saurabh2402 Jul 23, 2025
2c1bfc6
whitespace: add linter and lint whole code
Saurabh2402 Jul 23, 2025
f5cf5d8
add linters:
Saurabh2402 Jul 23, 2025
6c8e49d
1. unconvert: remove redundant typeconversions like string(some_str_vโ€ฆ
Saurabh2402 Jul 23, 2025
904f069
misspell: add linter and locale = UK english
Saurabh2402 Jul 23, 2025
76a2b2b
tagalign: add linter
Saurabh2402 Jul 23, 2025
6dc94a7
thelper: add linter and lint _test.go files
Saurabh2402 Jul 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# See for configurations: https://golangci-lint.run/usage/configuration/
version: 2
# See: https://golangci-lint.run/usage/formatters/
formatters:
default: none
enable:
- gofmt # https://pkg.go.dev/cmd/gofmt
- gofumpt # https://github.com/mvdan/gofumpt
- goimports # https://pkg.go.dev/golang.org/x/tools/cmd/goimports

settings:
gofmt:
simplify: true # Simplify code: gofmt with `-s` option.

gofumpt:
# Module path which contains the source code being formatted.
# Default: ""
module-path: github.com/diggerhq/digger # Should match with module in go.mod
# Choose whether to use the extra rules.
# Default: false
extra-rules: true

# See: https://golangci-lint.run/usage/linters/
linters:
default: none
enable:
- staticcheck
- govet
- gocritic
- whitespace
- mirror
- unconvert
- usestdlibvars
- misspell
- tagalign
- thelper

settings:
misspell:
locale: UK
16 changes: 8 additions & 8 deletions backend/bootstrap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ import (
"path/filepath"
"runtime"
"runtime/pprof"
"time"

"github.com/diggerhq/digger/backend/config"
"github.com/diggerhq/digger/backend/segment"
"github.com/diggerhq/digger/backend/utils"
pprof_gin "github.com/gin-contrib/pprof"
sloggin "github.com/samber/slog-gin"

"time"

"github.com/diggerhq/digger/backend/controllers"
"github.com/diggerhq/digger/backend/middleware"
"github.com/diggerhq/digger/backend/models"
Expand All @@ -38,7 +37,7 @@ func setupProfiler(r *gin.Engine) {
pprof_gin.Register(r)

// Create profiles directory if it doesn't exist
if err := os.MkdirAll("/tmp/profiles", 0755); err != nil {
if err := os.MkdirAll("/tmp/profiles", 0o755); err != nil {
slog.Error("Failed to create profiles directory", "error", err)
panic(err)
}
Expand Down Expand Up @@ -115,7 +114,7 @@ func Bootstrap(templates embed.FS, diggerController controllers.DiggerController
slog.Error("Sentry initialization failed", "error", err)
}

//database migrations
// database migrations
models.ConnectDatabase()

r := gin.Default()
Expand Down Expand Up @@ -262,13 +261,14 @@ func initLogging() {
logLevel := os.Getenv("DIGGER_LOG_LEVEL")
var level slog.Leveler

if logLevel == "DEBUG" {
switch logLevel {
case "DEBUG":
level = slog.LevelDebug
} else if logLevel == "WARN" {
case "WARN":
level = slog.LevelWarn
} else if logLevel == "ERROR" {
case "ERROR":
level = slog.LevelError
} else {
default:
level = slog.LevelInfo
}

Expand Down
2 changes: 1 addition & 1 deletion backend/ci_backends/ci_backends.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

type CiBackend interface {
TriggerWorkflow(spec spec.Spec, runName string, vcsToken string) error
TriggerWorkflow(spec spec.Spec, runName, vcsToken string) error
GetWorkflowUrl(spec spec.Spec) (string, error)
}

Expand Down
2 changes: 1 addition & 1 deletion backend/ci_backends/github_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type GithubActionCi struct {
Client *github.Client
}

func (g GithubActionCi) TriggerWorkflow(spec spec.Spec, runName string, vcsToken string) error {
func (g GithubActionCi) TriggerWorkflow(spec spec.Spec, runName, vcsToken string) error {
slog.Info("TriggerGithubWorkflow", "repoOwner", spec.VCS.RepoOwner, "repoName", spec.VCS.RepoName, "commentId", spec.CommentId)
client := g.Client
specBytes, err := json.Marshal(spec)
Expand Down
3 changes: 2 additions & 1 deletion backend/config/config.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package config

import (
"github.com/spf13/cast"
"os"
"strings"
"time"

"github.com/spf13/cast"

"github.com/spf13/viper"
)

Expand Down
3 changes: 2 additions & 1 deletion backend/controllers/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package controllers
import (
"errors"
"fmt"
"net/http"

"github.com/diggerhq/digger/backend/middleware"
"github.com/diggerhq/digger/backend/models"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
"net/http"
)

func GetActivity(c *gin.Context) {
Expand Down
5 changes: 3 additions & 2 deletions backend/controllers/billing.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package controllers

import (
"errors"
"log/slog"
"net/http"

"github.com/diggerhq/digger/backend/middleware"
"github.com/diggerhq/digger/backend/models"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
"log/slog"
"net/http"
)

func BillingStatusApi(c *gin.Context) {
Expand Down
4 changes: 2 additions & 2 deletions backend/controllers/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package controllers

import (
"fmt"
"github.com/diggerhq/digger/libs/git_utils"
"log/slog"
"net/http"
"os"
"path"
"strings"

"github.com/diggerhq/digger/libs/git_utils"

"github.com/diggerhq/digger/backend/models"
"github.com/diggerhq/digger/backend/utils"
dg_configuration "github.com/diggerhq/digger/libs/digger_config"
Expand Down Expand Up @@ -78,7 +79,6 @@ func (d DiggerController) UpdateRepoCache(c *gin.Context) {
}
return nil
})

if err != nil {
slog.Error("Could not load digger config", "error", err)
return
Expand Down
3 changes: 1 addition & 2 deletions backend/controllers/connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func CreateVCSConnectionApi(c *gin.Context) {
}

type CreateVCSConnectionRequest struct {
VCS string `json:"type" binding:"required"`
VCS string `binding:"required" json:"type"`
Name string `json:"connection_name"`
BitbucketAccessToken string `json:"bitbucket_access_token"`
BitbucketWebhookSecret string `json:"bitbucket_webhook_secret"`
Expand Down Expand Up @@ -123,7 +123,6 @@ func CreateVCSConnectionApi(c *gin.Context) {
slog.Error("Could not create VCS connection", "error", err)
c.JSON(http.StatusInternalServerError, gin.H{"error": "Could not create VCS connection"})
return

}

slog.Info("Created VCS connection", "connectionId", connection.ID, "organisationId", org.ID)
Expand Down
Loading