Linter configuration and linting.
Some checks failed
Linting and tests / Tests (push) Failing after 1m22s
Linting and tests / Linting (push) Failing after 1m32s

This commit is contained in:
Stanislav Nikitin 2025-09-11 02:30:15 +05:00
parent fbb3733375
commit 71c80799d2
Signed by: pztrn
GPG Key ID: 1E944A0F0568B550
10 changed files with 111 additions and 24 deletions

93
.golangci.yml Normal file
View File

@ -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$

View File

@ -32,3 +32,8 @@ tasks:
desc: "Lints whole workspace."
cmds:
- golangci-lint run client/...
test:
desc: "Test whole workspace"
cmds:
- go test -test.v ./...

View File

@ -1,3 +1,4 @@
//nolint:gosec
package main
import (

View File

@ -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...")

View File

@ -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.

View File

@ -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 {

View File

@ -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
}

View File

@ -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)

View File

@ -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

View File

@ -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...))
}