From 71c80799d213fcf0c06416e1d24beac06c47caff Mon Sep 17 00:00:00 2001 From: "Stanislav N. aka pztrn" Date: Thu, 11 Sep 2025 02:30:15 +0500 Subject: [PATCH] Linter configuration and linting. --- .golangci.yml | 93 +++++++++++++++++++ Taskfile.yml | 5 + client/cmd/translations_checker/main.go | 1 + client/internal/application/application.go | 2 +- client/internal/application/service.go | 2 +- .../services/core/database/database.go | 4 +- .../internal/services/core/database/dbpath.go | 4 +- .../services/core/database/queries.go | 18 +--- .../core/mainwindow/about_dialog_sys_info.go | 4 +- commons/goose_logger.go | 2 + 10 files changed, 111 insertions(+), 24 deletions(-) create mode 100644 .golangci.yml diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..0d768bb --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,93 @@ +--- +version: "2" + +linters: + default: all + disable: + - containedctx + - depguard + - exhaustruct + - gochecknoglobals + - interfacebloat + - ireturn + - mnd + - testpackage + - tparallel + - unused + - varnamelen + - noinlineerr + - wsl + settings: + cyclop: + max-complexity: 30 + package-average: 30 + forbidigo: + forbid: + - pattern: ^(fmt\.Print(|f|ln)|print|println)$ + - pattern: ^time\.Now\(\)($|\.F|\.A|\.B|\.L|\.UTC\(\)\.I|,|\))(# Calls of time\.Now() without \.UTC() is prohibited\.)? + funlen: + lines: 200 + statements: 60 + ignore-comments: true + gocyclo: + min-complexity: 20 + govet: + enable-all: true + funcorder: + constructor: true + struct-method: false + alphabetical: true + lll: + line-length: 120 + nestif: + min-complexity: 20 + tagliatelle: + case: + rules: + json: snake + yaml: camel + use-field-name: true + wsl_v5: + allow-first-in-block: true + allow-whole-block: false + branch-max-lines: 2 + exclusions: + generated: lax + rules: + - linters: + - gosec + path: .+_test\.go + - linters: + - godox + text: TODO + - linters: + - govet + text: declaration of "err" shadows + - path: (.+)\.go$ + text: ST1000 + - path: (.+)\.go$ + text: package-comments + - linters: + - cyclop + path: (.+)_test\.go + paths: + - third_party$ + - builtin$ + - examples$ +issues: + max-issues-per-linter: 0 + max-same-issues: 0 +formatters: + enable: + - gofmt + - gofumpt + settings: + gofumpt: + module-path: "bunker" + extra-rules: true + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/Taskfile.yml b/Taskfile.yml index b8857bd..328263e 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -32,3 +32,8 @@ tasks: desc: "Lints whole workspace." cmds: - golangci-lint run client/... + + test: + desc: "Test whole workspace" + cmds: + - go test -test.v ./... diff --git a/client/cmd/translations_checker/main.go b/client/cmd/translations_checker/main.go index f38bdd8..1477f0b 100644 --- a/client/cmd/translations_checker/main.go +++ b/client/cmd/translations_checker/main.go @@ -1,3 +1,4 @@ +//nolint:gosec package main import ( diff --git a/client/internal/application/application.go b/client/internal/application/application.go index 3a5c6d9..0e5f832 100644 --- a/client/internal/application/application.go +++ b/client/internal/application/application.go @@ -163,7 +163,7 @@ func (a *Application) launchStartupTasks() error { return nil } -// Shutdown stops application +// Shutdown stops application. func (a *Application) Shutdown() error { a.appLogger.Info("Stopping pztrn's Bunker...") diff --git a/client/internal/application/service.go b/client/internal/application/service.go index 62bea37..e196301 100644 --- a/client/internal/application/service.go +++ b/client/internal/application/service.go @@ -17,7 +17,7 @@ var ( type Service interface { // Configure configures service. Called after ConnectDependencies and before LaunchStartupTasks. Configure() error - // ConnectDependencies gets neccessary dependencies. + // ConnectDependencies gets necessary dependencies. ConnectDependencies() error // Initialize initializes service's internal state. Called while registering service with Application // lifecycle controller. diff --git a/client/internal/services/core/database/database.go b/client/internal/services/core/database/database.go index 6abc96f..82adc7e 100644 --- a/client/internal/services/core/database/database.go +++ b/client/internal/services/core/database/database.go @@ -41,9 +41,7 @@ func Initialize(app *application.Application) error { } func (d *database) Configure() error { - if err := d.configureDBPath(); err != nil { - return fmt.Errorf("configure: %w", err) - } + d.configureDBPath() db, err := sqlx.Open("sqlite", d.dbPath) if err != nil { diff --git a/client/internal/services/core/database/dbpath.go b/client/internal/services/core/database/dbpath.go index 70aa988..548d459 100644 --- a/client/internal/services/core/database/dbpath.go +++ b/client/internal/services/core/database/dbpath.go @@ -4,10 +4,8 @@ import ( "path/filepath" ) -func (d *database) configureDBPath() error { +func (d *database) configureDBPath() { d.dbPath = filepath.Join(d.app.Fyne().Storage().RootURI().Path(), "database.sqlite3") d.logger.Info("Database path configured.", "path", d.dbPath) - - return nil } diff --git a/client/internal/services/core/database/queries.go b/client/internal/services/core/database/queries.go index 570a007..2112cfc 100644 --- a/client/internal/services/core/database/queries.go +++ b/client/internal/services/core/database/queries.go @@ -14,7 +14,7 @@ func (d *database) Exec(ctx context.Context, query string, params ...interface{} query = d.db.Rebind(query) } - d.logger.Debug("Executing query.", "query", query, "params", fmt.Sprintf("%+v", params), "module", "core/database") + d.logger.Debug("Executing query.", "query", query, "params", fmt.Sprintf("%+v", params)) if _, err := d.db.ExecContext(ctx, query, params...); err != nil { return fmt.Errorf("%w: failed to Exec(): %w", core.ErrDatabase, err) @@ -29,12 +29,7 @@ func (d *database) Get(ctx context.Context, target interface{}, query string, pa query = d.db.Rebind(query) } - d.logger.Debug( - "Getting single data from database with query.", - "query", query, - "params", fmt.Sprintf("%+v", params), - "module", "core/database", - ) + d.logger.Debug("Getting single data from database with query.", "query", query, "params", fmt.Sprintf("%+v", params)) if err := d.db.GetContext(ctx, target, query, params...); err != nil { return fmt.Errorf("%w: failed to Get(): %w", core.ErrDatabase, err) @@ -49,7 +44,7 @@ func (d *database) NamedExec(ctx context.Context, query string, param interface{ query = d.db.Rebind(query) } - d.logger.Debug("Executing named query.", "query", query, "params", fmt.Sprintf("%+v", param), "module", "core/database") + d.logger.Debug("Executing named query.", "query", query, "params", fmt.Sprintf("%+v", param)) if _, err := d.db.NamedExecContext(ctx, query, param); err != nil { return fmt.Errorf("%w: failed to NamedExec(): %w", core.ErrDatabase, err) @@ -64,12 +59,7 @@ func (d *database) Select(ctx context.Context, target interface{}, query string, query = d.db.Rebind(query) } - d.logger.Debug( - "Selecting from database with query.", - "query", query, - "params", fmt.Sprintf("%+v", params), - "module", "core/database", - ) + d.logger.Debug("Selecting from database with query.", "query", query, "params", fmt.Sprintf("%+v", params)) if err := d.db.SelectContext(ctx, target, query, params...); err != nil { return fmt.Errorf("%w: failed to Select(): %w", core.ErrDatabase, err) diff --git a/client/internal/services/core/mainwindow/about_dialog_sys_info.go b/client/internal/services/core/mainwindow/about_dialog_sys_info.go index c454724..cc01222 100644 --- a/client/internal/services/core/mainwindow/about_dialog_sys_info.go +++ b/client/internal/services/core/mainwindow/about_dialog_sys_info.go @@ -54,7 +54,7 @@ func (m *mainWindow) generateSysInfoTab() *container.TabItem { for { //nolint:mnd if memoryTotal > 1024 { - memoryTotal = memoryTotal / 1024 + memoryTotal /= 1024 memoryTotalDivCount++ continue @@ -81,7 +81,7 @@ func (m *mainWindow) generateSysInfoTab() *container.TabItem { //nolint:mnd for { if memoryFree > 1024 { - memoryFree = memoryFree / 1024 + memoryFree /= 1024 memoryFreeDivCount++ continue diff --git a/commons/goose_logger.go b/commons/goose_logger.go index de3a369..c1b8b93 100644 --- a/commons/goose_logger.go +++ b/commons/goose_logger.go @@ -17,10 +17,12 @@ func NewGooseLogger(logger *slog.Logger) *GooseLogger { } } +// Fatalf is a proxy for goose logging. func (gl *GooseLogger) Fatalf(format string, v ...interface{}) { gl.logger.Error(fmt.Sprintf(format, v...)) } +// Printf is a proxy for goose logging. func (gl *GooseLogger) Printf(format string, v ...interface{}) { gl.logger.Info(fmt.Sprintf(format, v...)) }