Skip to content

Commit 9219328

Browse files
committed
fix: gomnd analyzer name
1 parent a7868b3 commit 9219328

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

pkg/golinters/gomnd.go

+17-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,23 @@ import (
99
)
1010

1111
func NewGoMND(settings *config.GoMndSettings) *goanalysis.Linter {
12+
// The constant is only used to force the analyzer name to use the same name as the linter.
13+
// This is required to avoid displaying the analyzer name inside the issue text.
14+
//
15+
// Alternative names cannot help here because of the linter configuration that uses `gomnd` as a name.
16+
// The complexity of handling alternative names at a lower level (i.e. `goanalysis.Linter`) isn't worth the cost.
17+
// The only way to handle it properly is to deprecate and "duplicate" the linter and its configuration,
18+
// for now, I don't know if it's worth the cost.
19+
// TODO(ldez): in v2, rename to mnd as the real analyzer name?
20+
const name = "gomnd"
21+
22+
a := mnd.Analyzer
23+
a.Name = name
24+
1225
var linterCfg map[string]map[string]any
1326

1427
if settings != nil {
15-
// TODO(ldez) For compatibility only, must be drop in v2.
28+
// Convert deprecated setting.
1629
if len(settings.Settings) > 0 {
1730
linterCfg = settings.Settings
1831
} else {
@@ -31,15 +44,15 @@ func NewGoMND(settings *config.GoMndSettings) *goanalysis.Linter {
3144
}
3245

3346
linterCfg = map[string]map[string]any{
34-
"mnd": cfg,
47+
a.Name: cfg,
3548
}
3649
}
3750
}
3851

3952
return goanalysis.NewLinter(
40-
"gomnd",
53+
a.Name,
4154
"An analyzer to detect magic numbers.",
42-
[]*analysis.Analyzer{mnd.Analyzer},
55+
[]*analysis.Analyzer{a},
4356
linterCfg,
4457
).WithLoadMode(goanalysis.LoadModeSyntax)
4558
}

0 commit comments

Comments
 (0)