Skip to content

Commit 8a3fbff

Browse files
committed
review
1 parent c95ec05 commit 8a3fbff

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

Diff for: pkg/commands/internal/migrate/migrate_formatters.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ func toGoFumptSettings(old versionone.GoFumptSettings) versiontwo.GoFumptSetting
6969
func toGoImportsSettings(old versionone.GoImportsSettings) versiontwo.GoImportsSettings {
7070
var localPrefixes []string
7171

72-
if ptr.Deref(old.LocalPrefixes) != "" {
73-
localPrefixes = strings.Split(ptr.Deref(old.LocalPrefixes), ",")
72+
prefixes := ptr.Deref(old.LocalPrefixes)
73+
if prefixes != "" {
74+
localPrefixes = strings.Split(prefixes, ",")
7475
}
7576

7677
return versiontwo.GoImportsSettings{

Diff for: pkg/commands/internal/migrate/migrate_linter_names.go

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package migrate
22

33
import (
4+
"cmp"
45
"slices"
56

67
"github.com/golangci/golangci-lint/pkg/commands/internal/migrate/ptr"
@@ -718,9 +719,7 @@ func toNames(linters []LinterInfo) []string {
718719
results = append(results, linter.Name)
719720
}
720721

721-
slices.Sort(results)
722-
723-
return slices.Compact(results)
722+
return Unique(results)
724723
}
725724

726725
func removeLinters(linters, toRemove []LinterInfo) []LinterInfo {
@@ -852,9 +851,7 @@ func unknownLinterNames(names []string, linters []LinterInfo) []string {
852851
}
853852
}
854853

855-
slices.Sort(results)
856-
857-
return slices.Compact(results)
854+
return Unique(results)
858855
}
859856

860857
func convertStaticcheckLinterNames(names []string) []string {
@@ -869,9 +866,7 @@ func convertStaticcheckLinterNames(names []string) []string {
869866
results = append(results, name)
870867
}
871868

872-
slices.Sort(results)
873-
874-
return slices.Compact(results)
869+
return Unique(results)
875870
}
876871

877872
func onlyLinterNames(names []string) []string {
@@ -924,7 +919,9 @@ func convertAlternativeNames(names []string) []string {
924919
results = append(results, name)
925920
}
926921

927-
slices.Sort(results)
922+
return Unique(results)
923+
}
928924

929-
return slices.Compact(results)
925+
func Unique[S ~[]E, E cmp.Ordered](s S) S {
926+
return slices.Compact(slices.Sorted(slices.Values(s)))
930927
}

Diff for: pkg/commands/migrate.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ func newMigrateCommand(log logutils.Log, info BuildInfo) *migrateCommand {
7171
setupConfigFileFlagSet(fs, &c.opts.LoaderOptions)
7272

7373
fs.StringVar(&c.opts.format, "format", "",
74-
color.GreenString("By default, the file format is based on the configuration file extension.\n"+
75-
"Overrides file format detection.\nIt can be 'yml', 'yaml', 'toml', 'json'."))
74+
color.GreenString("Output file format.\nBy default, the format of the input configuration file is used.\n"+
75+
"It can be 'yml', 'yaml', 'toml', or 'json'."))
7676

7777
fs.BoolVar(&c.opts.skipValidation, "skip-validation", false,
78-
color.GreenString("Skip validation of the configuration file against the JSONSchema for v1."))
78+
color.GreenString("Skip validation of the configuration file against the JSON Schema for v1."))
7979

8080
c.cmd = migrateCmd
8181

@@ -101,7 +101,8 @@ func (c *migrateCommand) execute(_ *cobra.Command, _ []string) error {
101101
c.log.Infof("Migrating v1 configuration file: %s", srcPath)
102102

103103
ext := filepath.Ext(srcPath)
104-
if strings.TrimSpace(c.opts.format) != "" {
104+
105+
if c.opts.format != "" {
105106
ext = "." + strings.TrimPrefix(c.opts.format, ".")
106107
}
107108

@@ -126,6 +127,13 @@ func (c *migrateCommand) execute(_ *cobra.Command, _ []string) error {
126127
}
127128

128129
func (c *migrateCommand) preRunE(cmd *cobra.Command, _ []string) error {
130+
switch strings.ToLower(c.opts.format) {
131+
case "", "yml", "yaml", "toml", "json": //nolint:goconst // Constants are useless in this context.
132+
// Valid format.
133+
default:
134+
return fmt.Errorf("unsupported format: %s", c.opts.format)
135+
}
136+
129137
if c.opts.skipValidation {
130138
return nil
131139
}

0 commit comments

Comments
 (0)