From 5df5508a856ba4e46702aff77ad334c8c99c9ffe Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Thu, 20 Nov 2025 07:56:56 +0100 Subject: [PATCH] chore: add govet, gocritic and revive --- .golangci.yml | 5 +++++ cmd/docs.go | 2 +- cmd/root.go | 4 ++-- cmd/utils.go | 11 ++++++----- diskcache/file_cache_test.go | 6 +++--- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 32d944f3..8819f48b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -2,8 +2,13 @@ version: "2" linters: default: standard + enable: + - gocritic + - govet + - revive exclusions: presets: - std-error-handling + - comments paths: - frontend/ diff --git a/cmd/docs.go b/cmd/docs.go index 7f4f536e..d65a29be 100644 --- a/cmd/docs.go +++ b/cmd/docs.go @@ -35,7 +35,7 @@ var docsCmd = &cobra.Command{ rootCmd.Root().DisableAutoGenTag = true - err = doc.GenMarkdownTreeCustom(cmd.Root(), tempDir, func(f string) string { + err = doc.GenMarkdownTreeCustom(cmd.Root(), tempDir, func(_ string) string { return "" }, func(s string) string { return s diff --git a/cmd/root.go b/cmd/root.go index b0ccd8f5..dd91c1b2 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -54,7 +54,7 @@ var ( ) // TODO(remove): remove after July 2026. -func migrateFlagNames(f *pflag.FlagSet, name string) pflag.NormalizedName { +func migrateFlagNames(_ *pflag.FlagSet, name string) pflag.NormalizedName { if newName, ok := flagNamesMigrations[name]; ok { if !warnedFlags[name] { @@ -146,7 +146,7 @@ The precedence of the configuration values are as follows: Also, if the database path doesn't exist, File Browser will enter into the quick setup mode and a new database will be bootstrapped and a new user created with the credentials from options "username" and "password".`, - RunE: withViperAndStore(func(cmd *cobra.Command, _ []string, v *viper.Viper, st *store) error { + RunE: withViperAndStore(func(_ *cobra.Command, _ []string, v *viper.Viper, st *store) error { if !st.databaseExisted { err := quickSetup(v, st.Storage) if err != nil { diff --git a/cmd/utils.go b/cmd/utils.go index eb953d32..ee637fa3 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -160,13 +160,14 @@ func withViperAndStore(fn func(cmd *cobra.Command, args []string, v *viper.Viper } exists, err := dbExists(path) - if err != nil { + switch { + case err != nil: return err - } else if exists && options.expectsNoDatabase { + case exists && options.expectsNoDatabase: log.Fatal(path + " already exists") - } else if !exists && !options.expectsNoDatabase && !options.allowsNoDatabase { + case !exists && !options.expectsNoDatabase && !options.allowsNoDatabase: log.Fatal(path + " does not exist. Please run 'filebrowser config init' first.") - } else if !exists && !options.expectsNoDatabase { + case !exists && !options.expectsNoDatabase: log.Println("WARNING: filebrowser.db can't be found. Initialing in " + strings.TrimSuffix(path, "filebrowser.db")) } @@ -193,7 +194,7 @@ func withViperAndStore(fn func(cmd *cobra.Command, args []string, v *viper.Viper } func withStore(fn func(cmd *cobra.Command, args []string, store *store) error, options storeOptions) cobraFunc { - return withViperAndStore(func(cmd *cobra.Command, args []string, v *viper.Viper, store *store) error { + return withViperAndStore(func(cmd *cobra.Command, args []string, _ *viper.Viper, store *store) error { return fn(cmd, args, store) }, options) } diff --git a/diskcache/file_cache_test.go b/diskcache/file_cache_test.go index 9a41052e..c6c750c0 100644 --- a/diskcache/file_cache_test.go +++ b/diskcache/file_cache_test.go @@ -25,12 +25,12 @@ func TestFileCache(t *testing.T) { // store new key err := cache.Store(ctx, key, []byte(value)) require.NoError(t, err) - checkValue(t, ctx, fs, filepath.Join(cacheRoot, cachedFilePath), cache, key, value) + checkValue(ctx, t, fs, filepath.Join(cacheRoot, cachedFilePath), cache, key, value) // update existing key err = cache.Store(ctx, key, []byte(newValue)) require.NoError(t, err) - checkValue(t, ctx, fs, filepath.Join(cacheRoot, cachedFilePath), cache, key, newValue) + checkValue(ctx, t, fs, filepath.Join(cacheRoot, cachedFilePath), cache, key, newValue) // delete key err = cache.Delete(ctx, key) @@ -40,7 +40,7 @@ func TestFileCache(t *testing.T) { require.False(t, exists) } -func checkValue(t *testing.T, ctx context.Context, fs afero.Fs, fileFullPath string, cache *FileCache, key, wantValue string) { +func checkValue(ctx context.Context, t *testing.T, fs afero.Fs, fileFullPath string, cache *FileCache, key, wantValue string) { t.Helper() // check actual file content b, err := afero.ReadFile(fs, fileFullPath)