Skip to content

Commit a20fa1f

Browse files
Use golangci-lint in Drone Pipelines (#255)
1 parent 2fa1676 commit a20fa1f

31 files changed

Lines changed: 202 additions & 205 deletions

.drone/drone.jsonnet

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
local golang = 'golang:1.16';
21
local grafana = 'grafana/grafana:8.0.3';
2+
local build = 'grafana/build-container:1.4.1';
33

44
// We'd like the same pipeline for testing pull requests as we do for building
55
// master. The only difference is their names and triggers.
@@ -14,9 +14,11 @@ local pipeline(name, trigger) = {
1414
steps: [
1515
{
1616
name: 'tests',
17-
image: golang,
17+
image: build,
1818
commands: [
1919
'sleep 5', // https://docs.drone.io/pipeline/docker/syntax/services/#initialization
20+
'golangci-lint --version',
21+
'golangci-lint run ./...',
2022
'make testacc',
2123
],
2224
environment: {

.drone/drone.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ platform:
99

1010
steps:
1111
- name: tests
12-
image: golang:1.16
12+
image: grafana/build-container:1.4.1
1313
commands:
1414
- sleep 5
15+
- golangci-lint --version
16+
- golangci-lint run ./...
1517
- make testacc
1618
environment:
1719
GRAFANA_AUTH: admin:admin
@@ -39,9 +41,11 @@ platform:
3941

4042
steps:
4143
- name: tests
42-
image: golang:1.16
44+
image: grafana/build-container:1.4.1
4345
commands:
4446
- sleep 5
47+
- golangci-lint --version
48+
- golangci-lint run ./...
4549
- make testacc
4650
environment:
4751
GRAFANA_AUTH: admin:admin
@@ -62,6 +66,6 @@ trigger:
6266

6367
---
6468
kind: signature
65-
hmac: c1a676f627f31e0a41b4f2625f9c55b37ec44fc6d4f31558909bde6f00a8bd5c
69+
hmac: e720237ec519da396e1c93fba1b538353b1df9d3965095a3230ff640ae5b4bdd
6670

6771
...

.golangci.toml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
[run]
2+
timeout = "10m"
3+
build-tags = [
4+
"cloud",
5+
"enterprise",
6+
]
7+
8+
[linters-settings.golint]
9+
min-confidence = 3
10+
11+
[linters-settings.goconst]
12+
min-len = 5
13+
min-occurrences = 5
14+
15+
[linters]
16+
disable-all = true
17+
enable = [
18+
"bodyclose",
19+
"deadcode",
20+
"depguard",
21+
"dogsled",
22+
"goconst",
23+
"gocritic",
24+
"goimports",
25+
"golint",
26+
"goprintffuncname",
27+
"gosec",
28+
"gosimple",
29+
"govet",
30+
"ineffassign",
31+
"misspell",
32+
"nakedret",
33+
"rowserrcheck",
34+
"exportloopref",
35+
"staticcheck",
36+
"structcheck",
37+
"stylecheck",
38+
"typecheck",
39+
"unconvert",
40+
"unused",
41+
"varcheck",
42+
"whitespace",
43+
"gocyclo",
44+
"unparam",
45+
]
46+
47+
[[issues.exclude-rules]]
48+
linters = ["stylecheck"]
49+
path = "_test.go"
50+
text = "ST1003: should not use underscores in Go names;"
51+
52+
[[issues.exclude-rules]]
53+
linters = ["gocritic"]
54+
text = "deprecatedComment: the proper format is `Deprecated: <text>`"
55+
56+
[[issues.exclude-rules]]
57+
linters = ["gosec"]
58+
text = "G402: TLS MinVersion too low."

grafana/data_source_synthetic_monitoring_probe.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
)
1212

1313
func dataSourceSyntheticMonitoringProbe() *schema.Resource {
14-
1514
probeSchema := datasourceSchemaFromResourceSchema(syntheticMonitoringProbe.Schema)
1615
addRequiredFieldsToSchema(probeSchema, "name")
1716
delete(probeSchema, "auth_token")

grafana/data_source_synthetic_monitoring_probes.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
)
99

1010
func dataSourceSyntheticMonitoringProbes() *schema.Resource {
11-
1211
return &schema.Resource{
1312
Description: "Data source for retrieving all probes.",
1413
ReadContext: dataSourceSyntheticMonitoringProbesRead,
@@ -26,7 +25,6 @@ func dataSourceSyntheticMonitoringProbes() *schema.Resource {
2625
}
2726

2827
func dataSourceSyntheticMonitoringProbesRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
29-
3028
c := meta.(*client).smapi
3129
var diags diag.Diagnostics
3230
prbs, err := c.ListProbes(ctx)

grafana/provider.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ type client struct {
134134

135135
func configure(version string, p *schema.Provider) func(context.Context, *schema.ResourceData) (interface{}, diag.Diagnostics) {
136136
return func(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
137-
138137
var diags diag.Diagnostics
139138
p.UserAgent("terraform-provider-grafana", version)
140139

@@ -188,8 +187,8 @@ func configure(version string, p *schema.Provider) func(context.Context, *schema
188187
c.gapi = gclient
189188

190189
smToken := d.Get("sm_access_token").(string)
191-
smUrl := d.Get("sm_url").(string)
192-
c.smapi = smapi.NewClient(smUrl, smToken, nil)
190+
smURL := d.Get("sm_url").(string)
191+
c.smapi = smapi.NewClient(smURL, smToken, nil)
193192

194193
return c, diags
195194
}

grafana/provider_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func init() {
3636
// Always allocate a new provider instance each invocation, otherwise gRPC
3737
// ProviderConfigure() can overwrite configuration during concurrent testing.
3838
testAccProviderFactories = map[string]func() (*schema.Provider, error){
39+
//nolint:unparam // error is always nil
3940
"grafana": func() (*schema.Provider, error) {
4041
return Provider("testacc")(), nil
4142
},

grafana/resource_alert_notification.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -149,23 +149,25 @@ func ReadAlertNotification(ctx context.Context, d *schema.ResourceData, meta int
149149
settings := map[string]interface{}{}
150150
for k, v := range alertNotification.Settings.(map[string]interface{}) {
151151
boolVal, ok := v.(bool)
152-
if ok && boolVal {
152+
switch {
153+
case ok && boolVal:
153154
settings[k] = "true"
154-
} else if ok && !boolVal {
155+
case ok && !boolVal:
155156
settings[k] = "false"
156-
} else {
157+
default:
157158
settings[k] = v
158159
}
159160
}
160161
secureSettings := map[string]interface{}{}
161162

162163
for k, v := range alertNotification.SecureFields.(map[string]interface{}) {
163164
boolVal, ok := v.(bool)
164-
if ok && boolVal {
165+
switch {
166+
case ok && boolVal:
165167
secureSettings[k] = "true"
166-
} else if ok && !boolVal {
168+
case ok && !boolVal:
167169
secureSettings[k] = "false"
168-
} else {
170+
default:
169171
secureSettings[k] = v
170172
}
171173
}
@@ -199,7 +201,7 @@ func DeleteAlertNotification(ctx context.Context, d *schema.ResourceData, meta i
199201
return diag.Diagnostics{}
200202
}
201203

202-
func makeAlertNotification(ctx context.Context, d *schema.ResourceData) (*gapi.AlertNotification, error) {
204+
func makeAlertNotification(_ context.Context, d *schema.ResourceData) (*gapi.AlertNotification, error) {
203205
idStr := d.Id()
204206
var id int64
205207
var err error
@@ -210,22 +212,24 @@ func makeAlertNotification(ctx context.Context, d *schema.ResourceData) (*gapi.A
210212
settings := map[string]interface{}{}
211213
for k, v := range d.Get("settings").(map[string]interface{}) {
212214
strVal, ok := v.(string)
213-
if ok && strVal == "true" {
215+
switch {
216+
case ok && strVal == "true":
214217
settings[k] = true
215-
} else if ok && strVal == "false" {
218+
case ok && strVal == "false":
216219
settings[k] = false
217-
} else {
220+
default:
218221
settings[k] = v
219222
}
220223
}
221224
secureSettings := map[string]interface{}{}
222225
for k, v := range d.Get("secure_settings").(map[string]interface{}) {
223226
strVal, ok := v.(string)
224-
if ok && strVal == "true" {
227+
switch {
228+
case ok && strVal == "true":
225229
secureSettings[k] = true
226-
} else if ok && strVal == "false" {
230+
case ok && strVal == "false":
227231
secureSettings[k] = false
228-
} else {
232+
default:
229233
secureSettings[k] = v
230234
}
231235
}

grafana/resource_alert_notification_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func TestAccAlertNotification_disableResolveMessage(t *testing.T) {
8686
})
8787
}
8888

89-
func TestAccAlertNotification_invalid_frequence(t *testing.T) {
89+
func TestAccAlertNotification_invalid_frequency(t *testing.T) {
9090
var alertNotification gapi.AlertNotification
9191

9292
resource.Test(t, resource.TestCase{
@@ -102,7 +102,7 @@ func TestAccAlertNotification_invalid_frequence(t *testing.T) {
102102
})
103103
}
104104

105-
func TestAccAlertNotification_reminder_no_frequence(t *testing.T) {
105+
func TestAccAlertNotification_reminder_no_frequency(t *testing.T) {
106106
var alertNotification gapi.AlertNotification
107107

108108
resource.Test(t, resource.TestCase{

grafana/resource_builtin_role_assignment.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package grafana
22

33
import (
44
"context"
5-
"errors"
65
"fmt"
76
"log"
87

@@ -77,10 +76,10 @@ func updateAssignments(d *schema.ResourceData, meta interface{}) diag.Diagnostic
7776
if err != nil {
7877
return diag.FromErr(err)
7978
}
80-
//compile the list of differences between current state and config
79+
// compile the list of differences between current state and config
8180
changes := roleChanges(stateRoles, configRoles)
8281
brName := d.Get("builtin_role").(string)
83-
//now we can make the corresponding updates so current state matches config
82+
// now we can make the corresponding updates so current state matches config
8483
if err := createOrRemove(meta, brName, changes); err != nil {
8584
return diag.FromErr(err)
8685
}
@@ -183,9 +182,8 @@ func roleChanges(rolesInState, rolesInConfig map[string]bool) []RoleChange {
183182
}
184183

185184
func collectRoles(d *schema.ResourceData) (map[string]bool, map[string]bool, error) {
186-
187185
errFn := func(uid string) error {
188-
return errors.New(fmt.Sprintf("Error: Role '%s' cannot be specified multiple times.", uid))
186+
return fmt.Errorf("error: Role '%s' cannot be specified multiple times", uid)
189187
}
190188

191189
rolesFn := func(roles interface{}) (map[string]bool, error) {
@@ -226,7 +224,7 @@ func createOrRemove(meta interface{}, name string, changes []RoleChange) error {
226224
err = client.DeleteBuiltInRoleAssignment(br)
227225
}
228226
if err != nil {
229-
return errors.New(fmt.Sprintf("Error with %s %v", name, err))
227+
return fmt.Errorf("error with %s %w", name, err)
230228
}
231229
}
232230
return nil

0 commit comments

Comments
 (0)