File tree 7 files changed +60
-5
lines changed
7 files changed +60
-5
lines changed Original file line number Diff line number Diff line change @@ -339,6 +339,20 @@ linters-settings:
339
339
simple : true
340
340
range-loops : true # Report preallocation suggestions on range loops, true by default
341
341
for-loops : false # Report preallocation suggestions on for loops, false by default
342
+ promlinter :
343
+ # Promlinter cannot infer all metrics name in static analysis. Enable strict mode
344
+ # will also include the errors caused by failing to parse the args.
345
+ strict : false
346
+ disabled-linters :
347
+ # Please refer to https://github.com/yeya24/promlinter#usage for detailed usage.
348
+ # - "Help"
349
+ # - "MetricUnits"
350
+ # - "Counter"
351
+ # - "HistogramSummaryReserved"
352
+ # - "MetricTypeInName"
353
+ # - "ReservedChars"
354
+ # - "CamelCase"
355
+ # - "lintUnitAbbreviations"
342
356
predeclared :
343
357
# comma-separated list of predeclared identifiers to not report on
344
358
ignore : " "
Original file line number Diff line number Diff line change @@ -73,7 +73,7 @@ require (
73
73
github.com/ultraware/whitespace v0.0.4
74
74
github.com/uudashr/gocognit v1.0.1
75
75
github.com/valyala/quicktemplate v1.6.3
76
- github.com/yeya24/promlinter v0.0.0-20201120174540-eec9e2ee3b40
76
+ github.com/yeya24/promlinter v0.0.0-20210328235706-000c7d74ddb3
77
77
golang.org/x/text v0.3.4 // indirect
78
78
golang.org/x/tools v0.1.0
79
79
gopkg.in/yaml.v2 v2.4.0
Original file line number Diff line number Diff line change @@ -452,9 +452,11 @@ type ForbidigoSettings struct {
452
452
type PredeclaredSettings struct {
453
453
Ignore string `mapstructure:"ignore"`
454
454
Qualified bool `mapstructure:"q"`
455
+ }
455
456
456
457
type PromlinterSettings struct {
457
- Strict bool `mapstructure:"strict"`
458
+ Strict bool `mapstructure:"strict"`
459
+ DisabledLinters []string `mapstructure:"disabled-linters"`
458
460
}
459
461
460
462
var defaultLintersSettings = LintersSettings {
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ func NewPromlinter() *goanalysis.Linter {
30
30
nil ,
31
31
).WithContextSetter (func (lintCtx * linter.Context ) {
32
32
strict := lintCtx .Cfg .LintersSettings .Promlinter .Strict
33
+ disabledLinters := lintCtx .Cfg .LintersSettings .Promlinter .DisabledLinters
33
34
34
35
analyzer .Run = func (pass * analysis.Pass ) (interface {}, error ) {
35
36
files := make ([]* ast.File , 0 )
@@ -41,7 +42,10 @@ func NewPromlinter() *goanalysis.Linter {
41
42
42
43
files = append (files , f )
43
44
}
44
- issues := promlinter .Run (pass .Fset , files , strict )
45
+ issues := promlinter .RunLint (pass .Fset , files , promlinter.Setting {
46
+ Strict : strict ,
47
+ DisabledLintFuncs : disabledLinters ,
48
+ })
45
49
46
50
if len (issues ) == 0 {
47
51
return nil , nil
@@ -66,5 +70,5 @@ func NewPromlinter() *goanalysis.Linter {
66
70
}
67
71
}).WithIssuesReporter (func (* linter.Context ) []goanalysis.Issue {
68
72
return resIssues
69
- }).WithLoadMode (goanalysis .LoadModeSyntax )
73
+ }).WithLoadMode (goanalysis .LoadModeNone )
70
74
}
Original file line number Diff line number Diff line change @@ -371,7 +371,6 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
371
371
WithURL ("https://github.com/charithe/durationcheck" ),
372
372
linter .NewConfig (golinters .NewPromlinter ()).
373
373
WithPresets (linter .PresetStyle ).
374
- WithAutoFix ().
375
374
WithURL ("https://github.com/yeya24/promlinter" ),
376
375
// nolintlint must be last because it looks at the results of all the previous linters for unused nolint directives
377
376
linter .NewConfig (golinters .NewNoLintLint ()).
Original file line number Diff line number Diff line change
1
+ //args: -Epromlinter
2
+ package testdata
3
+
4
+ import (
5
+ "github.com/prometheus/client_golang/prometheus"
6
+ "github.com/prometheus/client_golang/prometheus/promauto"
7
+ )
8
+
9
+ var (
10
+ _ = promauto .NewCounterVec (
11
+ prometheus.CounterOpts { // Metric: test_metric_name Error: counter metrics should have "_total" suffix
12
+ Name : "test_metric_name" ,
13
+ Help : "test help text" ,
14
+ }, []string {},
15
+ )
16
+
17
+ _ = promauto .NewCounterVec (
18
+ prometheus.CounterOpts { // Metric: test_metric_total Error: no help text
19
+ Name : "test_metric_total" ,
20
+ }, []string {},
21
+ )
22
+
23
+ _ = promauto .NewCounterVec (
24
+ prometheus.CounterOpts { // Metric: metric_type_in_name_counter_total Error: metric name should not include type 'counter'
25
+ Name : "metric_type_in_name_counter_total" ,
26
+ Help : "foo" ,
27
+ }, []string {},
28
+ )
29
+
30
+ _ = prometheus .NewHistogram (prometheus.HistogramOpts { // Metric: test_duration_milliseconds Error: use base unit "seconds" instead of "milliseconds"
31
+ Name : "test_duration_milliseconds" ,
32
+ Help : "" ,
33
+ })
34
+ )
You can’t perform that action at this time.
0 commit comments