Skip to content

Commit

Permalink
enable stylecheck linter (#396)
Browse files Browse the repository at this point in the history
* enable stylecheck linter

* add IAM

* fix typo in .yml that creeped back in
  • Loading branch information
bmoffatt committed Sep 17, 2021
1 parent f9e86f1 commit 1ba09af
Show file tree
Hide file tree
Showing 33 changed files with 118 additions and 95 deletions.
7 changes: 7 additions & 0 deletions .golangci.yml
Expand Up @@ -12,8 +12,15 @@ linters:
- typecheck
- unused
- varcheck
- stylecheck

run:
skip-files:
# These were code-generated, and cannot be changed without breaking RPC compatibility.
- lambda/messages/*.go

linters-settings:
stylecheck:
go: "1.17"
checks: ["all"]
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"]
8 changes: 4 additions & 4 deletions events/activemq_test.go
Expand Up @@ -11,11 +11,11 @@ import (

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

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

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

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

// 5. check result
assert.JSONEq(t, string(inputJson), string(outputJson))
assert.JSONEq(t, string(inputJSON), string(outputJSON))
}

func TestActiveMQMarshalingMalformedJson(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion events/alb.go
Expand Up @@ -20,7 +20,7 @@ type ALBTargetGroupRequestContext struct {

// ELBContext contains the information to identify the ARN invoking the lambda
type ELBContext struct {
TargetGroupArn string `json:"targetGroupArn"`
TargetGroupArn string `json:"targetGroupArn"` //nolint: stylecheck
}

// ALBTargetGroupResponse configures the response to be returned by the ALB Lambda target group for the request
Expand Down
6 changes: 3 additions & 3 deletions events/apigw.go
Expand Up @@ -141,7 +141,7 @@ type APIGatewayRequestIdentity struct {
SourceIP string `json:"sourceIp"`
CognitoAuthenticationType string `json:"cognitoAuthenticationType"`
CognitoAuthenticationProvider string `json:"cognitoAuthenticationProvider"`
UserArn string `json:"userArn"`
UserArn string `json:"userArn"` //nolint: stylecheck
UserAgent string `json:"userAgent"`
User string `json:"user"`
}
Expand Down Expand Up @@ -258,13 +258,13 @@ type APIGatewayCustomAuthorizerRequestTypeRequestContext struct {
type APIGatewayCustomAuthorizerRequest struct {
Type string `json:"type"`
AuthorizationToken string `json:"authorizationToken"`
MethodArn string `json:"methodArn"`
MethodArn string `json:"methodArn"` //nolint: stylecheck
}

// APIGatewayCustomAuthorizerRequestTypeRequest contains data coming in to a custom API Gateway authorizer function.
type APIGatewayCustomAuthorizerRequestTypeRequest struct {
Type string `json:"type"`
MethodArn string `json:"methodArn"`
MethodArn string `json:"methodArn"` //nolint: stylecheck
Resource string `json:"resource"`
Path string `json:"path"`
HTTPMethod string `json:"httpMethod"`
Expand Down
2 changes: 1 addition & 1 deletion events/attributevalue.go
Expand Up @@ -20,7 +20,7 @@ type DynamoDBAttributeValue struct {

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

// Binary provides access to an attribute of type Binary.
// Method panics if the attribute is not of type Binary.
Expand Down
8 changes: 4 additions & 4 deletions events/autoscaling_test.go
Expand Up @@ -18,20 +18,20 @@ func TestAutoScalingEventMarshaling(t *testing.T) {

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

// 2. de-serialize into Go object
var inputEvent AutoScalingEvent
if err := json.Unmarshal(inputJson, &inputEvent); err != nil {
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
t.Errorf("could not unmarshal event. details: %v", err)
}
// 3. serialize to JSON
outputJson, err := json.Marshal(inputEvent)
outputJSON, err := json.Marshal(inputEvent)
if err != nil {
t.Errorf("could not marshal event. details: %v", err)
}
// 4. check result
assert.JSONEq(t, string(inputJson), string(outputJson))
assert.JSONEq(t, string(inputJSON), string(outputJSON))
}

}
Expand Down
12 changes: 6 additions & 6 deletions events/cloudwatch_logs_test.go
Expand Up @@ -11,7 +11,7 @@ import (
func TestCloudwatchLogs(t *testing.T) {
for _, test := range []struct {
name string
eventJson string
eventJSON string
expectError bool
expectCloudwatchEventData CloudwatchLogsEvent
}{
Expand All @@ -27,10 +27,10 @@ func TestCloudwatchLogs(t *testing.T) {
} {
test := test
t.Run(test.name, func(t *testing.T) {
inputJson := tst.ReadJSONFromFile(t, test.eventJson)
inputJSON := tst.ReadJSONFromFile(t, test.eventJSON)

var inputEvent CloudwatchLogsEvent
err := json.Unmarshal(inputJson, &inputEvent)
err := json.Unmarshal(inputJSON, &inputEvent)

if err != nil && !test.expectError {
t.Errorf("could not unmarshal event. details: %v", err)
Expand All @@ -50,7 +50,7 @@ func TestCloudwatchLogs(t *testing.T) {
func TestCloudwatchLogsParse(t *testing.T) {
for _, test := range []struct {
name string
eventJson string
eventJSON string
expectError bool
expectCloudwatchLogsData CloudwatchLogsData
}{
Expand All @@ -74,10 +74,10 @@ func TestCloudwatchLogsParse(t *testing.T) {
} {
test := test
t.Run(test.name, func(t *testing.T) {
inputJson := tst.ReadJSONFromFile(t, test.eventJson)
inputJSON := tst.ReadJSONFromFile(t, test.eventJSON)

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

Expand Down
2 changes: 1 addition & 1 deletion events/code_commit.go
Expand Up @@ -52,7 +52,7 @@ type CodeCommitRecord struct {
EventPartNumber uint64 `json:"eventPartNumber"`
CodeCommit CodeCommitCodeCommit `json:"codecommit"`
EventName string `json:"eventName"`
EventTriggerConfigId string `json:"eventTriggerConfigId"`
EventTriggerConfigId string `json:"eventTriggerConfigId"` //nolint: stylecheck
EventSourceARN string `json:"eventSourceARN"`
UserIdentityARN string `json:"userIdentityARN"`
EventSource string `json:"eventSource"`
Expand Down
27 changes: 17 additions & 10 deletions events/config.go
Expand Up @@ -4,14 +4,21 @@ package events

// ConfigEvent contains data from an event sent from AWS Config
type ConfigEvent struct {
AccountID string `json:"accountId"` // The ID of the AWS account that owns the rule
ConfigRuleArn string `json:"configRuleArn"` // The ARN that AWS Config assigned to the rule
ConfigRuleID string `json:"configRuleId"`
ConfigRuleName string `json:"configRuleName"` // The name that you assigned to the rule that caused AWS Config to publish the event
EventLeftScope bool `json:"eventLeftScope"` // A boolean value that indicates whether the AWS resource to be evaluated has been removed from the rule's scope
ExecutionRoleArn string `json:"executionRoleArn"`
InvokingEvent string `json:"invokingEvent"` // If the event is published in response to a resource configuration change, this value contains a JSON configuration item
ResultToken string `json:"resultToken"` // A token that the function must pass to AWS Config with the PutEvaluations call
RuleParameters string `json:"ruleParameters"` // Key/value pairs that the function processes as part of its evaluation logic
Version string `json:"version"`
// The ID of the AWS account that owns the rule
AccountID string `json:"accountId"`
// The ARN that AWS Config assigned to the rule
ConfigRuleArn string `json:"configRuleArn"` //nolint:stylecheck
ConfigRuleID string `json:"configRuleId"` //nolint:stylecheck
// The name that you assigned to the rule that caused AWS Config to publish the event
ConfigRuleName string `json:"configRuleName"`
// A boolean value that indicates whether the AWS resource to be evaluated has been removed from the rule's scope
EventLeftScope bool `json:"eventLeftScope"`
ExecutionRoleArn string `json:"executionRoleArn"` //nolint:stylecheck
// If the event is published in response to a resource configuration change, this value contains a JSON configuration item
InvokingEvent string `json:"invokingEvent"`
// A token that the function must pass to AWS Config with the PutEvaluations call
ResultToken string `json:"resultToken"`
// Key/value pairs that the function processes as part of its evaluation logic
RuleParameters string `json:"ruleParameters"`
Version string `json:"version"`
}
8 changes: 4 additions & 4 deletions events/connect_test.go
Expand Up @@ -13,22 +13,22 @@ import (
func TestConnectMarshaling(t *testing.T) {

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

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

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

// 4. check result
assert.JSONEq(t, string(inputJson), string(outputJson))
assert.JSONEq(t, string(inputJSON), string(outputJSON))
}

func TestConnectMarshalingMalformedJson(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion events/dynamodb.go
Expand Up @@ -43,7 +43,7 @@ type DynamoDBEventRecord struct {
EventVersion string `json:"eventVersion"`

// The event source ARN of DynamoDB
EventSourceArn string `json:"eventSourceARN"`
EventSourceArn string `json:"eventSourceARN"` //nolint: stylecheck

// Items that are deleted by the Time to Live process after expiration have
// the following fields:
Expand Down
8 changes: 4 additions & 4 deletions events/dynamodb_test.go
Expand Up @@ -13,22 +13,22 @@ import (
func TestDynamoDBEventMarshaling(t *testing.T) {

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

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

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

// 4. check result
assert.JSONEq(t, string(inputJson), string(outputJson))
assert.JSONEq(t, string(inputJSON), string(outputJSON))
}

func TestDynamoDBEventMarshalingMalformedJson(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions events/ecr_scan_test.go
Expand Up @@ -11,11 +11,11 @@ import (

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

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

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

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

// 5. check result
assert.JSONEq(t, string(inputJson), string(outputJson))
assert.JSONEq(t, string(inputJSON), string(outputJSON))
}

func TestECRScanMarshalingMalformedJson(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions events/firehose.go
Expand Up @@ -5,8 +5,8 @@ package events
// KinesisFirehoseEvent represents the input event from Amazon Kinesis Firehose. It is used as the input parameter.
type KinesisFirehoseEvent struct {
InvocationID string `json:"invocationId"`
DeliveryStreamArn string `json:"deliveryStreamArn"`
SourceKinesisStreamArn string `json:"sourceKinesisStreamArn"`
DeliveryStreamArn string `json:"deliveryStreamArn"` //nolint: stylecheck
SourceKinesisStreamArn string `json:"sourceKinesisStreamArn"` //nolint: stylecheck
Region string `json:"region"`
Records []KinesisFirehoseEventRecord `json:"records"`
}
Expand Down
12 changes: 6 additions & 6 deletions events/firehose_test.go
Expand Up @@ -21,29 +21,29 @@ func TestFirehoseResponseMarshaling(t *testing.T) {

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

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

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

// 4. check result
assert.JSONEq(t, string(inputJson), string(outputJson))
assert.JSONEq(t, string(inputJSON), string(outputJSON))
}

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

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

Expand Down
8 changes: 4 additions & 4 deletions events/iot_1_click_test.go
Expand Up @@ -12,21 +12,21 @@ import (
func TestIoTOneClickEventMalformedJson(t *testing.T) {

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

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

// 3. serialize to JSON
outputJson, err := json.Marshal(inputEvent)
outputJSON, err := json.Marshal(inputEvent)
if err != nil {
t.Errorf("could not marshal event. details: %v", err)
}
// 4. check result
assert.JSONEq(t, string(inputJson), string(outputJson))
assert.JSONEq(t, string(inputJSON), string(outputJSON))
}

func TestIoTOneClickEventMarshaling(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions events/iot_button_test.go
Expand Up @@ -12,21 +12,21 @@ import (
func TestIoTButtonMalformedJson(t *testing.T) {

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

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

// 3. serialize to JSON
outputJson, err := json.Marshal(inputEvent)
outputJSON, err := json.Marshal(inputEvent)
if err != nil {
t.Errorf("could not marshal event. details: %v", err)
}
// 4. check result
assert.JSONEq(t, string(inputJson), string(outputJson))
assert.JSONEq(t, string(inputJSON), string(outputJSON))
}

func TestIoTButtonEventMarshaling(t *testing.T) {
Expand Down

0 comments on commit 1ba09af

Please sign in to comment.