@@ -9,10 +9,23 @@ import (
99)
1010
1111func 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