@@ -9,10 +9,23 @@ import (
9
9
)
10
10
11
11
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
+
12
25
var linterCfg map [string ]map [string ]any
13
26
14
27
if settings != nil {
15
- // TODO(ldez) For compatibility only, must be drop in v2 .
28
+ // Convert deprecated setting .
16
29
if len (settings .Settings ) > 0 {
17
30
linterCfg = settings .Settings
18
31
} else {
@@ -31,15 +44,15 @@ func NewGoMND(settings *config.GoMndSettings) *goanalysis.Linter {
31
44
}
32
45
33
46
linterCfg = map [string ]map [string ]any {
34
- "mnd" : cfg ,
47
+ a . Name : cfg ,
35
48
}
36
49
}
37
50
}
38
51
39
52
return goanalysis .NewLinter (
40
- "gomnd" ,
53
+ a . Name ,
41
54
"An analyzer to detect magic numbers." ,
42
- []* analysis.Analyzer {mnd . Analyzer },
55
+ []* analysis.Analyzer {a },
43
56
linterCfg ,
44
57
).WithLoadMode (goanalysis .LoadModeSyntax )
45
58
}
0 commit comments