Update golangci-lint linters
continuous-integration/drone/push Build is passing Details

This commit is contained in:
IamTheFij 2022-11-10 13:30:30 -08:00
parent e62c83eed8
commit ed3689eae1
6 changed files with 35 additions and 38 deletions

View File

@ -1,16 +1,13 @@
--- ---
linters: linters:
enable: enable:
- deadcode
- errcheck - errcheck
- gosimple - gosimple
- govet - govet
- ineffassign - ineffassign
- staticcheck - staticcheck
- structcheck
- typecheck - typecheck
- unused - unused
- varcheck
- asciicheck - asciicheck
- bidichk - bidichk
@ -26,7 +23,7 @@ linters:
- errname - errname
- errorlint - errorlint
- exhaustive - exhaustive
- exhaustivestruct - exhaustruct
- exportloopref - exportloopref
- forcetypeassert - forcetypeassert
- funlen - funlen
@ -47,7 +44,6 @@ linters:
- goprintffuncname - goprintffuncname
- gosec - gosec
- grouper - grouper
- ifshort
- importas - importas
# - ireturn # - ireturn
- lll - lll
@ -91,22 +87,23 @@ linters:
- interfacer - interfacer
- maligned - maligned
- scopelint - scopelint
- ifshort
- varcheck
- structcheck
- deadcode
- exhaustivestruct
linters-settings: linters-settings:
# gosec:
# excludes:
# - G204
gomnd: gomnd:
settings: settings:
mnd: mnd:
ignored-functions: math.* ignored-functions: math.*
issues: issues:
fix: true
exclude-rules: exclude-rules:
- path: _test\.go - path: _test\.go
linters: linters:
- errcheck - errcheck
- gosec - gosec
- funlen - funlen
# Enable autofix
fix: true

View File

@ -27,12 +27,12 @@ func TestResticConfigValidate(t *testing.T) {
{ {
name: "missing passphrase", name: "missing passphrase",
expectedErr: main.ErrMutuallyExclusive, expectedErr: main.ErrMutuallyExclusive,
config: main.ResticConfig{}, //nolint:exhaustivestruct config: main.ResticConfig{}, //nolint:exhaustruct
}, },
{ {
name: "passphrase no file", name: "passphrase no file",
expectedErr: nil, expectedErr: nil,
//nolint:exhaustivestruct //nolint:exhaustruct
config: main.ResticConfig{ config: main.ResticConfig{
Passphrase: "shh", Passphrase: "shh",
}, },
@ -40,7 +40,7 @@ func TestResticConfigValidate(t *testing.T) {
{ {
name: "file no passphrase", name: "file no passphrase",
expectedErr: nil, expectedErr: nil,
//nolint:exhaustivestruct //nolint:exhaustruct
config: main.ResticConfig{ config: main.ResticConfig{
GlobalOpts: &main.ResticGlobalOpts{ GlobalOpts: &main.ResticGlobalOpts{
PasswordFile: "file", PasswordFile: "file",
@ -50,7 +50,7 @@ func TestResticConfigValidate(t *testing.T) {
{ {
name: "file and passphrase", name: "file and passphrase",
expectedErr: main.ErrMutuallyExclusive, expectedErr: main.ErrMutuallyExclusive,
//nolint:exhaustivestruct //nolint:exhaustruct
config: main.ResticConfig{ config: main.ResticConfig{
Passphrase: "shh", Passphrase: "shh",
GlobalOpts: &main.ResticGlobalOpts{ GlobalOpts: &main.ResticGlobalOpts{
@ -89,7 +89,7 @@ func TestJobValidation(t *testing.T) {
Schedule: "@daily", Schedule: "@daily",
Config: ValidResticConfig(), Config: ValidResticConfig(),
Tasks: []main.JobTask{}, Tasks: []main.JobTask{},
Backup: main.BackupFilesTask{Paths: []string{"/test"}}, //nolint:exhaustivestruct Backup: main.BackupFilesTask{Paths: []string{"/test"}}, //nolint:exhaustruct
Forget: nil, Forget: nil,
MySQL: []main.JobTaskMySQL{}, MySQL: []main.JobTaskMySQL{},
Sqlite: []main.JobTaskSqlite{}, Sqlite: []main.JobTaskSqlite{},
@ -103,7 +103,7 @@ func TestJobValidation(t *testing.T) {
Schedule: "@daily", Schedule: "@daily",
Config: ValidResticConfig(), Config: ValidResticConfig(),
Tasks: []main.JobTask{}, Tasks: []main.JobTask{},
Backup: main.BackupFilesTask{Paths: []string{"/test"}}, //nolint:exhaustivestruct Backup: main.BackupFilesTask{Paths: []string{"/test"}}, //nolint:exhaustruct
Forget: nil, Forget: nil,
MySQL: []main.JobTaskMySQL{}, MySQL: []main.JobTaskMySQL{},
Sqlite: []main.JobTaskSqlite{}, Sqlite: []main.JobTaskSqlite{},
@ -117,7 +117,7 @@ func TestJobValidation(t *testing.T) {
Schedule: "shrug", Schedule: "shrug",
Config: ValidResticConfig(), Config: ValidResticConfig(),
Tasks: []main.JobTask{}, Tasks: []main.JobTask{},
Backup: main.BackupFilesTask{Paths: []string{"/test"}}, //nolint:exhaustivestruct Backup: main.BackupFilesTask{Paths: []string{"/test"}}, //nolint:exhaustruct
Forget: nil, Forget: nil,
MySQL: []main.JobTaskMySQL{}, MySQL: []main.JobTaskMySQL{},
Sqlite: []main.JobTaskSqlite{}, Sqlite: []main.JobTaskSqlite{},
@ -129,9 +129,9 @@ func TestJobValidation(t *testing.T) {
job: main.Job{ job: main.Job{
Name: "Test job", Name: "Test job",
Schedule: "@daily", Schedule: "@daily",
Config: main.ResticConfig{}, //nolint:exhaustivestruct Config: main.ResticConfig{}, //nolint:exhaustruct
Tasks: []main.JobTask{}, Tasks: []main.JobTask{},
Backup: main.BackupFilesTask{Paths: []string{"/test"}}, //nolint:exhaustivestruct Backup: main.BackupFilesTask{Paths: []string{"/test"}}, //nolint:exhaustruct
Forget: nil, Forget: nil,
MySQL: []main.JobTaskMySQL{}, MySQL: []main.JobTaskMySQL{},
Sqlite: []main.JobTaskSqlite{}, Sqlite: []main.JobTaskSqlite{},
@ -145,7 +145,7 @@ func TestJobValidation(t *testing.T) {
Schedule: "@daily", Schedule: "@daily",
Config: ValidResticConfig(), Config: ValidResticConfig(),
Tasks: []main.JobTask{{}}, Tasks: []main.JobTask{{}},
Backup: main.BackupFilesTask{Paths: []string{"/test"}}, //nolint:exhaustivestruct Backup: main.BackupFilesTask{Paths: []string{"/test"}}, //nolint:exhaustruct
Forget: nil, Forget: nil,
MySQL: []main.JobTaskMySQL{}, MySQL: []main.JobTaskMySQL{},
Sqlite: []main.JobTaskSqlite{}, Sqlite: []main.JobTaskSqlite{},
@ -159,7 +159,7 @@ func TestJobValidation(t *testing.T) {
Schedule: "@daily", Schedule: "@daily",
Config: ValidResticConfig(), Config: ValidResticConfig(),
Tasks: []main.JobTask{}, Tasks: []main.JobTask{},
Backup: main.BackupFilesTask{Paths: []string{"/test"}}, //nolint:exhaustivestruct Backup: main.BackupFilesTask{Paths: []string{"/test"}}, //nolint:exhaustruct
Forget: nil, Forget: nil,
MySQL: []main.JobTaskMySQL{{}}, MySQL: []main.JobTaskMySQL{{}},
Sqlite: []main.JobTaskSqlite{}, Sqlite: []main.JobTaskSqlite{},
@ -173,7 +173,7 @@ func TestJobValidation(t *testing.T) {
Schedule: "@daily", Schedule: "@daily",
Config: ValidResticConfig(), Config: ValidResticConfig(),
Tasks: []main.JobTask{}, Tasks: []main.JobTask{},
Backup: main.BackupFilesTask{Paths: []string{"/test"}}, //nolint:exhaustivestruct Backup: main.BackupFilesTask{Paths: []string{"/test"}}, //nolint:exhaustruct
Forget: nil, Forget: nil,
MySQL: []main.JobTaskMySQL{}, MySQL: []main.JobTaskMySQL{},
Sqlite: []main.JobTaskSqlite{{}}, Sqlite: []main.JobTaskSqlite{{}},
@ -212,7 +212,7 @@ func TestConfigValidation(t *testing.T) {
Schedule: "@daily", Schedule: "@daily",
Config: ValidResticConfig(), Config: ValidResticConfig(),
Tasks: []main.JobTask{}, Tasks: []main.JobTask{},
Backup: main.BackupFilesTask{Paths: []string{"/test"}}, //nolint:exhaustivestruct Backup: main.BackupFilesTask{Paths: []string{"/test"}}, //nolint:exhaustruct
MySQL: []main.JobTaskMySQL{}, MySQL: []main.JobTaskMySQL{},
Sqlite: []main.JobTaskSqlite{}, Sqlite: []main.JobTaskSqlite{},
}}}, }}},
@ -230,7 +230,7 @@ func TestConfigValidation(t *testing.T) {
Schedule: "@daily", Schedule: "@daily",
Config: ValidResticConfig(), Config: ValidResticConfig(),
Tasks: []main.JobTask{}, Tasks: []main.JobTask{},
Backup: main.BackupFilesTask{Paths: []string{"/test"}}, //nolint:exhaustivestruct Backup: main.BackupFilesTask{Paths: []string{"/test"}}, //nolint:exhaustruct
Forget: nil, Forget: nil,
MySQL: []main.JobTaskMySQL{}, MySQL: []main.JobTaskMySQL{},
Sqlite: []main.JobTaskSqlite{}, Sqlite: []main.JobTaskSqlite{},

View File

@ -49,7 +49,7 @@ func TestRunJobs(t *testing.T) {
Schedule: "@daily", Schedule: "@daily",
Config: ValidResticConfig(), Config: ValidResticConfig(),
Tasks: []main.JobTask{}, Tasks: []main.JobTask{},
Backup: main.BackupFilesTask{Paths: []string{"/test"}}, //nolint:exhaustivestruct Backup: main.BackupFilesTask{Paths: []string{"/test"}}, //nolint:exhaustruct
Forget: nil, Forget: nil,
MySQL: []main.JobTaskMySQL{}, MySQL: []main.JobTaskMySQL{},
Sqlite: []main.JobTaskSqlite{}, Sqlite: []main.JobTaskSqlite{},

View File

@ -160,19 +160,19 @@ func TestBuildEnv(t *testing.T) {
}{ }{
{ {
name: "No Env", name: "No Env",
cmd: main.Restic{}, //nolint:exhaustivestruct cmd: main.Restic{}, //nolint:exhaustruct
expected: os.Environ(), expected: os.Environ(),
}, },
{ {
name: "SetEnv", name: "SetEnv",
cmd: main.Restic{ //nolint:exhaustivestruct cmd: main.Restic{ //nolint:exhaustruct
Env: map[string]string{"TestKey": "Value"}, Env: map[string]string{"TestKey": "Value"},
}, },
expected: append(os.Environ(), "TestKey=Value"), expected: append(os.Environ(), "TestKey=Value"),
}, },
{ {
name: "SetEnv", name: "SetEnv",
cmd: main.Restic{ //nolint:exhaustivestruct cmd: main.Restic{ //nolint:exhaustruct
Passphrase: "Shhhhhhhh!!", Passphrase: "Shhhhhhhh!!",
}, },
expected: append(os.Environ(), "RESTIC_PASSWORD=Shhhhhhhh!!"), expected: append(os.Environ(), "RESTIC_PASSWORD=Shhhhhhhh!!"),
@ -210,7 +210,7 @@ func TestResticInterface(t *testing.T) {
Repo: repoDir, Repo: repoDir,
Env: map[string]string{}, Env: map[string]string{},
Passphrase: "Correct.Horse.Battery.Staple", Passphrase: "Correct.Horse.Battery.Staple",
//nolint:exhaustivestruct //nolint:exhaustruct
GlobalOpts: &main.ResticGlobalOpts{ GlobalOpts: &main.ResticGlobalOpts{
CacheDir: cacheDir, CacheDir: cacheDir,
Options: map[string]string{ Options: map[string]string{
@ -231,7 +231,7 @@ func TestResticInterface(t *testing.T) {
} }
// Try to backup when repo is not initialized // Try to backup when repo is not initialized
err = restic.Backup([]string{dataDir}, main.BackupOpts{}) //nolint:exhaustivestruct err = restic.Backup([]string{dataDir}, main.BackupOpts{}) //nolint:exhaustruct
if !errors.Is(err, main.ErrRepoNotFound) { if !errors.Is(err, main.ErrRepoNotFound) {
AssertEqualFail(t, "unexpected error creating making backup", nil, err) AssertEqualFail(t, "unexpected error creating making backup", nil, err)
} }
@ -245,7 +245,7 @@ func TestResticInterface(t *testing.T) {
AssertEqualFail(t, "unexpected error reinitializing repo", nil, err) AssertEqualFail(t, "unexpected error reinitializing repo", nil, err)
// Backup for real this time // Backup for real this time
err = restic.Backup([]string{dataDir}, main.BackupOpts{Tags: []string{"test"}}) //nolint:exhaustivestruct err = restic.Backup([]string{dataDir}, main.BackupOpts{Tags: []string{"test"}}) //nolint:exhaustruct
AssertEqualFail(t, "unexpected error creating making backup", nil, err) AssertEqualFail(t, "unexpected error creating making backup", nil, err)
// Check snapshots // Check snapshots
@ -259,7 +259,7 @@ func TestResticInterface(t *testing.T) {
AssertEqual(t, "unexpected snapshot value: tags", []string{"test"}, snapshots[0].Tags) AssertEqual(t, "unexpected snapshot value: tags", []string{"test"}, snapshots[0].Tags)
// Backup again // Backup again
err = restic.Backup([]string{dataDir}, main.BackupOpts{}) //nolint:exhaustivestruct err = restic.Backup([]string{dataDir}, main.BackupOpts{}) //nolint:exhaustruct
AssertEqualFail(t, "unexpected error creating making second backup", nil, err) AssertEqualFail(t, "unexpected error creating making second backup", nil, err)
// Check for second backup // Check for second backup
@ -268,7 +268,7 @@ func TestResticInterface(t *testing.T) {
AssertEqual(t, "unexpected number of snapshots", 2, len(snapshots)) AssertEqual(t, "unexpected number of snapshots", 2, len(snapshots))
// Forget one backup // Forget one backup
err = restic.Forget(main.ForgetOpts{KeepLast: 1, Prune: true}) //nolint:exhaustivestruct err = restic.Forget(main.ForgetOpts{KeepLast: 1, Prune: true}) //nolint:exhaustruct
AssertEqualFail(t, "unexpected error forgetting snapshot", nil, err) AssertEqualFail(t, "unexpected error forgetting snapshot", nil, err)
// Check forgotten snapshot // Check forgotten snapshot
@ -290,7 +290,7 @@ func TestResticInterface(t *testing.T) {
AssertEqualFail(t, "incorrect value in test file (we expect the unexpected!)", "unexpected", string(value)) AssertEqualFail(t, "incorrect value in test file (we expect the unexpected!)", "unexpected", string(value))
// Restore files // Restore files
err = restic.Restore("latest", main.RestoreOpts{Target: restoreTarget}) //nolint:exhaustivestruct err = restic.Restore("latest", main.RestoreOpts{Target: restoreTarget}) //nolint:exhaustruct
AssertEqualFail(t, "unexpected error restoring latest snapshot", nil, err) AssertEqualFail(t, "unexpected error restoring latest snapshot", nil, err)
// Check restored values // Check restored values

View File

@ -230,7 +230,7 @@ type BackupFilesTask struct {
func (t BackupFilesTask) RunBackup(cfg TaskConfig) error { func (t BackupFilesTask) RunBackup(cfg TaskConfig) error {
if t.BackupOpts == nil { if t.BackupOpts == nil {
t.BackupOpts = &BackupOpts{} //nolint:exhaustivestruct t.BackupOpts = &BackupOpts{} //nolint:exhaustruct
} }
if err := cfg.Restic.Backup(cfg.BackupPaths, *t.BackupOpts); err != nil { if err := cfg.Restic.Backup(cfg.BackupPaths, *t.BackupOpts); err != nil {
@ -245,7 +245,7 @@ func (t BackupFilesTask) RunBackup(cfg TaskConfig) error {
func (t BackupFilesTask) RunRestore(cfg TaskConfig) error { func (t BackupFilesTask) RunRestore(cfg TaskConfig) error {
if t.RestoreOpts == nil { if t.RestoreOpts == nil {
t.RestoreOpts = &RestoreOpts{} //nolint:exhaustivestruct t.RestoreOpts = &RestoreOpts{} //nolint:exhaustruct
} }
// TODO: Make the snapshot configurable // TODO: Make the snapshot configurable

View File

@ -120,7 +120,7 @@ func TestJobTaskSql(t *testing.T) {
}{ }{
{ {
name: "mysql simple", name: "mysql simple",
//nolint:exhaustivestruct //nolint:exhaustruct
task: main.JobTaskMySQL{ task: main.JobTaskMySQL{
Name: "simple", Name: "simple",
DumpToPath: "./simple.sql", DumpToPath: "./simple.sql",
@ -133,7 +133,7 @@ func TestJobTaskSql(t *testing.T) {
}, },
{ {
name: "mysql tables no database", name: "mysql tables no database",
//nolint:exhaustivestruct //nolint:exhaustruct
task: main.JobTaskMySQL{ task: main.JobTaskMySQL{
Name: "name", Name: "name",
Tables: []string{"table1", "table2"}, Tables: []string{"table1", "table2"},