Linter configuration and linting.
This commit is contained in:
parent
fbb3733375
commit
71c80799d2
93
.golangci.yml
Normal file
93
.golangci.yml
Normal 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$
|
@ -32,3 +32,8 @@ tasks:
|
|||||||
desc: "Lints whole workspace."
|
desc: "Lints whole workspace."
|
||||||
cmds:
|
cmds:
|
||||||
- golangci-lint run client/...
|
- golangci-lint run client/...
|
||||||
|
|
||||||
|
test:
|
||||||
|
desc: "Test whole workspace"
|
||||||
|
cmds:
|
||||||
|
- go test -test.v ./...
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
//nolint:gosec
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -163,7 +163,7 @@ func (a *Application) launchStartupTasks() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shutdown stops application
|
// Shutdown stops application.
|
||||||
func (a *Application) Shutdown() error {
|
func (a *Application) Shutdown() error {
|
||||||
a.appLogger.Info("Stopping pztrn's Bunker...")
|
a.appLogger.Info("Stopping pztrn's Bunker...")
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ var (
|
|||||||
type Service interface {
|
type Service interface {
|
||||||
// Configure configures service. Called after ConnectDependencies and before LaunchStartupTasks.
|
// Configure configures service. Called after ConnectDependencies and before LaunchStartupTasks.
|
||||||
Configure() error
|
Configure() error
|
||||||
// ConnectDependencies gets neccessary dependencies.
|
// ConnectDependencies gets necessary dependencies.
|
||||||
ConnectDependencies() error
|
ConnectDependencies() error
|
||||||
// Initialize initializes service's internal state. Called while registering service with Application
|
// Initialize initializes service's internal state. Called while registering service with Application
|
||||||
// lifecycle controller.
|
// lifecycle controller.
|
||||||
|
@ -41,9 +41,7 @@ func Initialize(app *application.Application) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *database) Configure() error {
|
func (d *database) Configure() error {
|
||||||
if err := d.configureDBPath(); err != nil {
|
d.configureDBPath()
|
||||||
return fmt.Errorf("configure: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
db, err := sqlx.Open("sqlite", d.dbPath)
|
db, err := sqlx.Open("sqlite", d.dbPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -4,10 +4,8 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (d *database) configureDBPath() error {
|
func (d *database) configureDBPath() {
|
||||||
d.dbPath = filepath.Join(d.app.Fyne().Storage().RootURI().Path(), "database.sqlite3")
|
d.dbPath = filepath.Join(d.app.Fyne().Storage().RootURI().Path(), "database.sqlite3")
|
||||||
|
|
||||||
d.logger.Info("Database path configured.", "path", d.dbPath)
|
d.logger.Info("Database path configured.", "path", d.dbPath)
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ func (d *database) Exec(ctx context.Context, query string, params ...interface{}
|
|||||||
query = d.db.Rebind(query)
|
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 {
|
if _, err := d.db.ExecContext(ctx, query, params...); err != nil {
|
||||||
return fmt.Errorf("%w: failed to Exec(): %w", core.ErrDatabase, err)
|
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)
|
query = d.db.Rebind(query)
|
||||||
}
|
}
|
||||||
|
|
||||||
d.logger.Debug(
|
d.logger.Debug("Getting single data from database with query.", "query", query, "params", fmt.Sprintf("%+v", params))
|
||||||
"Getting single data from database with query.",
|
|
||||||
"query", query,
|
|
||||||
"params", fmt.Sprintf("%+v", params),
|
|
||||||
"module", "core/database",
|
|
||||||
)
|
|
||||||
|
|
||||||
if err := d.db.GetContext(ctx, target, query, params...); err != nil {
|
if err := d.db.GetContext(ctx, target, query, params...); err != nil {
|
||||||
return fmt.Errorf("%w: failed to Get(): %w", core.ErrDatabase, err)
|
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)
|
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 {
|
if _, err := d.db.NamedExecContext(ctx, query, param); err != nil {
|
||||||
return fmt.Errorf("%w: failed to NamedExec(): %w", core.ErrDatabase, err)
|
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)
|
query = d.db.Rebind(query)
|
||||||
}
|
}
|
||||||
|
|
||||||
d.logger.Debug(
|
d.logger.Debug("Selecting from database with query.", "query", query, "params", fmt.Sprintf("%+v", params))
|
||||||
"Selecting from database with query.",
|
|
||||||
"query", query,
|
|
||||||
"params", fmt.Sprintf("%+v", params),
|
|
||||||
"module", "core/database",
|
|
||||||
)
|
|
||||||
|
|
||||||
if err := d.db.SelectContext(ctx, target, query, params...); err != nil {
|
if err := d.db.SelectContext(ctx, target, query, params...); err != nil {
|
||||||
return fmt.Errorf("%w: failed to Select(): %w", core.ErrDatabase, err)
|
return fmt.Errorf("%w: failed to Select(): %w", core.ErrDatabase, err)
|
||||||
|
@ -54,7 +54,7 @@ func (m *mainWindow) generateSysInfoTab() *container.TabItem {
|
|||||||
for {
|
for {
|
||||||
//nolint:mnd
|
//nolint:mnd
|
||||||
if memoryTotal > 1024 {
|
if memoryTotal > 1024 {
|
||||||
memoryTotal = memoryTotal / 1024
|
memoryTotal /= 1024
|
||||||
memoryTotalDivCount++
|
memoryTotalDivCount++
|
||||||
|
|
||||||
continue
|
continue
|
||||||
@ -81,7 +81,7 @@ func (m *mainWindow) generateSysInfoTab() *container.TabItem {
|
|||||||
//nolint:mnd
|
//nolint:mnd
|
||||||
for {
|
for {
|
||||||
if memoryFree > 1024 {
|
if memoryFree > 1024 {
|
||||||
memoryFree = memoryFree / 1024
|
memoryFree /= 1024
|
||||||
memoryFreeDivCount++
|
memoryFreeDivCount++
|
||||||
|
|
||||||
continue
|
continue
|
||||||
|
@ -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{}) {
|
func (gl *GooseLogger) Fatalf(format string, v ...interface{}) {
|
||||||
gl.logger.Error(fmt.Sprintf(format, v...))
|
gl.logger.Error(fmt.Sprintf(format, v...))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Printf is a proxy for goose logging.
|
||||||
func (gl *GooseLogger) Printf(format string, v ...interface{}) {
|
func (gl *GooseLogger) Printf(format string, v ...interface{}) {
|
||||||
gl.logger.Info(fmt.Sprintf(format, v...))
|
gl.logger.Info(fmt.Sprintf(format, v...))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user