Skip to content

Commit 1ba09af

Browse files
authored
enable stylecheck linter (#396)
* enable stylecheck linter * add IAM * fix typo in .yml that creeped back in
1 parent f9e86f1 commit 1ba09af

33 files changed

+118
-95
lines changed

.golangci.yml

+7
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,15 @@ linters:
1212
- typecheck
1313
- unused
1414
- varcheck
15+
- stylecheck
1516

1617
run:
1718
skip-files:
1819
# These were code-generated, and cannot be changed without breaking RPC compatibility.
1920
- lambda/messages/*.go
21+
22+
linters-settings:
23+
stylecheck:
24+
go: "1.17"
25+
checks: ["all"]
26+
initialisms: ["AWS", "ARN", "IAM", "MQTT", "ACL", "API", "ASCII", "CPU", "CSS", "DNS", "EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID", "IP", "JSON", "QPS", "RAM", "RPC", "SLA", "SMTP", "SQL", "SSH", "TCP", "TLS", "TTL", "UDP", "UI", "GID", "UID", "UUID", "URI", "URL", "UTF8", "VM", "XML", "XMPP", "XSRF", "XSS", "SIP", "RTP", "AMQP", "DB", "TS"]

events/activemq_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import (
1111

1212
func TestActiveMQEventMarshaling(t *testing.T) {
1313
// 1. read JSON from file
14-
inputJson := test.ReadJSONFromFile(t, "./testdata/activemq-event.json")
14+
inputJSON := test.ReadJSONFromFile(t, "./testdata/activemq-event.json")
1515

1616
// 2. de-serialize into Go object
1717
var inputEvent ActiveMQEvent
18-
if err := json.Unmarshal(inputJson, &inputEvent); err != nil {
18+
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
1919
t.Errorf("could not unmarshal event. details: %v", err)
2020
}
2121

@@ -32,13 +32,13 @@ func TestActiveMQEventMarshaling(t *testing.T) {
3232
assert.Equal(t, false, message.Redelivered)
3333

3434
// 4. serialize to JSON
35-
outputJson, err := json.Marshal(inputEvent)
35+
outputJSON, err := json.Marshal(inputEvent)
3636
if err != nil {
3737
t.Errorf("could not marshal event. details: %v", err)
3838
}
3939

4040
// 5. check result
41-
assert.JSONEq(t, string(inputJson), string(outputJson))
41+
assert.JSONEq(t, string(inputJSON), string(outputJSON))
4242
}
4343

4444
func TestActiveMQMarshalingMalformedJson(t *testing.T) {

events/alb.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type ALBTargetGroupRequestContext struct {
2020

2121
// ELBContext contains the information to identify the ARN invoking the lambda
2222
type ELBContext struct {
23-
TargetGroupArn string `json:"targetGroupArn"`
23+
TargetGroupArn string `json:"targetGroupArn"` //nolint: stylecheck
2424
}
2525

2626
// ALBTargetGroupResponse configures the response to be returned by the ALB Lambda target group for the request

events/apigw.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ type APIGatewayRequestIdentity struct {
141141
SourceIP string `json:"sourceIp"`
142142
CognitoAuthenticationType string `json:"cognitoAuthenticationType"`
143143
CognitoAuthenticationProvider string `json:"cognitoAuthenticationProvider"`
144-
UserArn string `json:"userArn"`
144+
UserArn string `json:"userArn"` //nolint: stylecheck
145145
UserAgent string `json:"userAgent"`
146146
User string `json:"user"`
147147
}
@@ -258,13 +258,13 @@ type APIGatewayCustomAuthorizerRequestTypeRequestContext struct {
258258
type APIGatewayCustomAuthorizerRequest struct {
259259
Type string `json:"type"`
260260
AuthorizationToken string `json:"authorizationToken"`
261-
MethodArn string `json:"methodArn"`
261+
MethodArn string `json:"methodArn"` //nolint: stylecheck
262262
}
263263

264264
// APIGatewayCustomAuthorizerRequestTypeRequest contains data coming in to a custom API Gateway authorizer function.
265265
type APIGatewayCustomAuthorizerRequestTypeRequest struct {
266266
Type string `json:"type"`
267-
MethodArn string `json:"methodArn"`
267+
MethodArn string `json:"methodArn"` //nolint: stylecheck
268268
Resource string `json:"resource"`
269269
Path string `json:"path"`
270270
HTTPMethod string `json:"httpMethod"`

events/attributevalue.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type DynamoDBAttributeValue struct {
2020

2121
// This struct represents DynamoDBAttributeValue which doesn't
2222
// implement fmt.Stringer interface and safely `fmt.Sprintf`able
23-
type dynamoDbAttributeValue DynamoDBAttributeValue
23+
type dynamoDbAttributeValue DynamoDBAttributeValue //nolint: stylecheck
2424

2525
// Binary provides access to an attribute of type Binary.
2626
// Method panics if the attribute is not of type Binary.

events/autoscaling_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@ func TestAutoScalingEventMarshaling(t *testing.T) {
1818

1919
t.Logf("Running test for %s\n", sampleFile)
2020
// 1. read JSON from file
21-
inputJson := test.ReadJSONFromFile(t, "./testdata/"+sampleFile)
21+
inputJSON := test.ReadJSONFromFile(t, "./testdata/"+sampleFile)
2222

2323
// 2. de-serialize into Go object
2424
var inputEvent AutoScalingEvent
25-
if err := json.Unmarshal(inputJson, &inputEvent); err != nil {
25+
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
2626
t.Errorf("could not unmarshal event. details: %v", err)
2727
}
2828
// 3. serialize to JSON
29-
outputJson, err := json.Marshal(inputEvent)
29+
outputJSON, err := json.Marshal(inputEvent)
3030
if err != nil {
3131
t.Errorf("could not marshal event. details: %v", err)
3232
}
3333
// 4. check result
34-
assert.JSONEq(t, string(inputJson), string(outputJson))
34+
assert.JSONEq(t, string(inputJSON), string(outputJSON))
3535
}
3636

3737
}

events/cloudwatch_logs_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
func TestCloudwatchLogs(t *testing.T) {
1212
for _, test := range []struct {
1313
name string
14-
eventJson string
14+
eventJSON string
1515
expectError bool
1616
expectCloudwatchEventData CloudwatchLogsEvent
1717
}{
@@ -27,10 +27,10 @@ func TestCloudwatchLogs(t *testing.T) {
2727
} {
2828
test := test
2929
t.Run(test.name, func(t *testing.T) {
30-
inputJson := tst.ReadJSONFromFile(t, test.eventJson)
30+
inputJSON := tst.ReadJSONFromFile(t, test.eventJSON)
3131

3232
var inputEvent CloudwatchLogsEvent
33-
err := json.Unmarshal(inputJson, &inputEvent)
33+
err := json.Unmarshal(inputJSON, &inputEvent)
3434

3535
if err != nil && !test.expectError {
3636
t.Errorf("could not unmarshal event. details: %v", err)
@@ -50,7 +50,7 @@ func TestCloudwatchLogs(t *testing.T) {
5050
func TestCloudwatchLogsParse(t *testing.T) {
5151
for _, test := range []struct {
5252
name string
53-
eventJson string
53+
eventJSON string
5454
expectError bool
5555
expectCloudwatchLogsData CloudwatchLogsData
5656
}{
@@ -74,10 +74,10 @@ func TestCloudwatchLogsParse(t *testing.T) {
7474
} {
7575
test := test
7676
t.Run(test.name, func(t *testing.T) {
77-
inputJson := tst.ReadJSONFromFile(t, test.eventJson)
77+
inputJSON := tst.ReadJSONFromFile(t, test.eventJSON)
7878

7979
var inputEvent CloudwatchLogsEvent
80-
if err := json.Unmarshal(inputJson, &inputEvent); err != nil {
80+
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
8181
t.Errorf("could not unmarshal event. details: %v", err)
8282
}
8383

events/code_commit.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type CodeCommitRecord struct {
5252
EventPartNumber uint64 `json:"eventPartNumber"`
5353
CodeCommit CodeCommitCodeCommit `json:"codecommit"`
5454
EventName string `json:"eventName"`
55-
EventTriggerConfigId string `json:"eventTriggerConfigId"`
55+
EventTriggerConfigId string `json:"eventTriggerConfigId"` //nolint: stylecheck
5656
EventSourceARN string `json:"eventSourceARN"`
5757
UserIdentityARN string `json:"userIdentityARN"`
5858
EventSource string `json:"eventSource"`

events/config.go

+17-10
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@ package events
44

55
// ConfigEvent contains data from an event sent from AWS Config
66
type ConfigEvent struct {
7-
AccountID string `json:"accountId"` // The ID of the AWS account that owns the rule
8-
ConfigRuleArn string `json:"configRuleArn"` // The ARN that AWS Config assigned to the rule
9-
ConfigRuleID string `json:"configRuleId"`
10-
ConfigRuleName string `json:"configRuleName"` // The name that you assigned to the rule that caused AWS Config to publish the event
11-
EventLeftScope bool `json:"eventLeftScope"` // A boolean value that indicates whether the AWS resource to be evaluated has been removed from the rule's scope
12-
ExecutionRoleArn string `json:"executionRoleArn"`
13-
InvokingEvent string `json:"invokingEvent"` // If the event is published in response to a resource configuration change, this value contains a JSON configuration item
14-
ResultToken string `json:"resultToken"` // A token that the function must pass to AWS Config with the PutEvaluations call
15-
RuleParameters string `json:"ruleParameters"` // Key/value pairs that the function processes as part of its evaluation logic
16-
Version string `json:"version"`
7+
// The ID of the AWS account that owns the rule
8+
AccountID string `json:"accountId"`
9+
// The ARN that AWS Config assigned to the rule
10+
ConfigRuleArn string `json:"configRuleArn"` //nolint:stylecheck
11+
ConfigRuleID string `json:"configRuleId"` //nolint:stylecheck
12+
// The name that you assigned to the rule that caused AWS Config to publish the event
13+
ConfigRuleName string `json:"configRuleName"`
14+
// A boolean value that indicates whether the AWS resource to be evaluated has been removed from the rule's scope
15+
EventLeftScope bool `json:"eventLeftScope"`
16+
ExecutionRoleArn string `json:"executionRoleArn"` //nolint:stylecheck
17+
// If the event is published in response to a resource configuration change, this value contains a JSON configuration item
18+
InvokingEvent string `json:"invokingEvent"`
19+
// A token that the function must pass to AWS Config with the PutEvaluations call
20+
ResultToken string `json:"resultToken"`
21+
// Key/value pairs that the function processes as part of its evaluation logic
22+
RuleParameters string `json:"ruleParameters"`
23+
Version string `json:"version"`
1724
}

events/connect_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ import (
1313
func TestConnectMarshaling(t *testing.T) {
1414

1515
// 1. read JSON from file
16-
inputJson := test.ReadJSONFromFile(t, "./testdata/connect-event.json")
16+
inputJSON := test.ReadJSONFromFile(t, "./testdata/connect-event.json")
1717

1818
// 2. de-serialize into Go object
1919
var inputEvent ConnectEvent
20-
if err := json.Unmarshal(inputJson, &inputEvent); err != nil {
20+
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
2121
t.Errorf("could not unmarshal event. details: %v", err)
2222
}
2323

2424
// 3. serialize to JSON
25-
outputJson, err := json.Marshal(inputEvent)
25+
outputJSON, err := json.Marshal(inputEvent)
2626
if err != nil {
2727
t.Errorf("could not marshal event. details: %v", err)
2828
}
2929

3030
// 4. check result
31-
assert.JSONEq(t, string(inputJson), string(outputJson))
31+
assert.JSONEq(t, string(inputJSON), string(outputJSON))
3232
}
3333

3434
func TestConnectMarshalingMalformedJson(t *testing.T) {

events/dynamodb.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type DynamoDBEventRecord struct {
4343
EventVersion string `json:"eventVersion"`
4444

4545
// The event source ARN of DynamoDB
46-
EventSourceArn string `json:"eventSourceARN"`
46+
EventSourceArn string `json:"eventSourceARN"` //nolint: stylecheck
4747

4848
// Items that are deleted by the Time to Live process after expiration have
4949
// the following fields:

events/dynamodb_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ import (
1313
func TestDynamoDBEventMarshaling(t *testing.T) {
1414

1515
// 1. read JSON from file
16-
inputJson := test.ReadJSONFromFile(t, "./testdata/dynamodb-event.json")
16+
inputJSON := test.ReadJSONFromFile(t, "./testdata/dynamodb-event.json")
1717

1818
// 2. de-serialize into Go object
1919
var inputEvent DynamoDBEvent
20-
if err := json.Unmarshal(inputJson, &inputEvent); err != nil {
20+
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
2121
t.Errorf("could not unmarshal event. details: %v", err)
2222
}
2323

2424
// 3. serialize to JSON
25-
outputJson, err := json.Marshal(inputEvent)
25+
outputJSON, err := json.Marshal(inputEvent)
2626
if err != nil {
2727
t.Errorf("could not marshal event. details: %v", err)
2828
}
2929

3030
// 4. check result
31-
assert.JSONEq(t, string(inputJson), string(outputJson))
31+
assert.JSONEq(t, string(inputJSON), string(outputJSON))
3232
}
3333

3434
func TestDynamoDBEventMarshalingMalformedJson(t *testing.T) {

events/ecr_scan_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import (
1111

1212
func TestECRScanEventMarshaling(t *testing.T) {
1313
// 1. read JSON from file
14-
inputJson := test.ReadJSONFromFile(t, "./testdata/ecr-image-scan-event.json")
14+
inputJSON := test.ReadJSONFromFile(t, "./testdata/ecr-image-scan-event.json")
1515

1616
// 2. de-serialize into Go object
1717
var inputEvent ECRScanEvent
18-
if err := json.Unmarshal(inputJson, &inputEvent); err != nil {
18+
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
1919
t.Errorf("could not unmarshal event. details: %v", err)
2020
}
2121

@@ -42,13 +42,13 @@ func TestECRScanEventMarshaling(t *testing.T) {
4242
assert.Equal(t, int64(0), detail.FindingSeverityCounts.Undefined)
4343

4444
// 4. serialize to JSON
45-
outputJson, err := json.Marshal(inputEvent)
45+
outputJSON, err := json.Marshal(inputEvent)
4646
if err != nil {
4747
t.Errorf("could not marshal event. details: %v", err)
4848
}
4949

5050
// 5. check result
51-
assert.JSONEq(t, string(inputJson), string(outputJson))
51+
assert.JSONEq(t, string(inputJSON), string(outputJSON))
5252
}
5353

5454
func TestECRScanMarshalingMalformedJson(t *testing.T) {

events/firehose.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ package events
55
// KinesisFirehoseEvent represents the input event from Amazon Kinesis Firehose. It is used as the input parameter.
66
type KinesisFirehoseEvent struct {
77
InvocationID string `json:"invocationId"`
8-
DeliveryStreamArn string `json:"deliveryStreamArn"`
9-
SourceKinesisStreamArn string `json:"sourceKinesisStreamArn"`
8+
DeliveryStreamArn string `json:"deliveryStreamArn"` //nolint: stylecheck
9+
SourceKinesisStreamArn string `json:"sourceKinesisStreamArn"` //nolint: stylecheck
1010
Region string `json:"region"`
1111
Records []KinesisFirehoseEventRecord `json:"records"`
1212
}

events/firehose_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,29 @@ func TestFirehoseResponseMarshaling(t *testing.T) {
2121

2222
func testMarshaling(t *testing.T, inputEvent interface{}, jsonFile string) {
2323
// 1. read JSON from file
24-
inputJson := test.ReadJSONFromFile(t, jsonFile)
24+
inputJSON := test.ReadJSONFromFile(t, jsonFile)
2525

2626
// 2. de-serialize into Go object
27-
if err := json.Unmarshal(inputJson, &inputEvent); err != nil {
27+
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
2828
t.Errorf("could not unmarshal event. details: %v", err)
2929
}
3030

3131
// 3. serialize to JSON
32-
outputJson, err := json.Marshal(inputEvent)
32+
outputJSON, err := json.Marshal(inputEvent)
3333
if err != nil {
3434
t.Errorf("could not marshal event. details: %v", err)
3535
}
3636

3737
// 4. check result
38-
assert.JSONEq(t, string(inputJson), string(outputJson))
38+
assert.JSONEq(t, string(inputJSON), string(outputJSON))
3939
}
4040

4141
func TestSampleTransformation(t *testing.T) {
42-
inputJson := test.ReadJSONFromFile(t, "./testdata/kinesis-firehose-event.json")
42+
inputJSON := test.ReadJSONFromFile(t, "./testdata/kinesis-firehose-event.json")
4343

4444
// de-serialize into Go object
4545
var inputEvent KinesisFirehoseEvent
46-
if err := json.Unmarshal(inputJson, &inputEvent); err != nil {
46+
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
4747
t.Errorf("could not unmarshal event. details: %v", err)
4848
}
4949

events/iot_1_click_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ import (
1212
func TestIoTOneClickEventMalformedJson(t *testing.T) {
1313

1414
// 1. read JSON from file
15-
inputJson := test.ReadJSONFromFile(t, "./testdata/iot-1-click-event.json")
15+
inputJSON := test.ReadJSONFromFile(t, "./testdata/iot-1-click-event.json")
1616

1717
// 2. de-serialize into Go object
1818
var inputEvent IoTOneClickEvent
19-
if err := json.Unmarshal(inputJson, &inputEvent); err != nil {
19+
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
2020
t.Errorf("could not unmarshal event. details: %v", err)
2121
}
2222

2323
// 3. serialize to JSON
24-
outputJson, err := json.Marshal(inputEvent)
24+
outputJSON, err := json.Marshal(inputEvent)
2525
if err != nil {
2626
t.Errorf("could not marshal event. details: %v", err)
2727
}
2828
// 4. check result
29-
assert.JSONEq(t, string(inputJson), string(outputJson))
29+
assert.JSONEq(t, string(inputJSON), string(outputJSON))
3030
}
3131

3232
func TestIoTOneClickEventMarshaling(t *testing.T) {

events/iot_button_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ import (
1212
func TestIoTButtonMalformedJson(t *testing.T) {
1313

1414
// 1. read JSON from file
15-
inputJson := test.ReadJSONFromFile(t, "./testdata/iot-button-event.json")
15+
inputJSON := test.ReadJSONFromFile(t, "./testdata/iot-button-event.json")
1616

1717
// 2. de-serialize into Go object
1818
var inputEvent IoTButtonEvent
19-
if err := json.Unmarshal(inputJson, &inputEvent); err != nil {
19+
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
2020
t.Errorf("could not unmarshal event. details: %v", err)
2121
}
2222

2323
// 3. serialize to JSON
24-
outputJson, err := json.Marshal(inputEvent)
24+
outputJSON, err := json.Marshal(inputEvent)
2525
if err != nil {
2626
t.Errorf("could not marshal event. details: %v", err)
2727
}
2828
// 4. check result
29-
assert.JSONEq(t, string(inputJson), string(outputJson))
29+
assert.JSONEq(t, string(inputJSON), string(outputJSON))
3030
}
3131

3232
func TestIoTButtonEventMarshaling(t *testing.T) {

0 commit comments

Comments
 (0)