Skip to content

Commit 44fe2b3

Browse files
authored
sonar rules (spring-media#39)
* sonar rules
1 parent bdf66b1 commit 44fe2b3

File tree

4 files changed

+38
-21
lines changed

4 files changed

+38
-21
lines changed

index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ export const handler = (routeConfig: RouteConfig) => {
5656

5757
const extractEventProcessorMapping = (routeConfig: RouteConfig) => {
5858
const processorMap = new Map<string, EventProcessor>()
59-
for (let key of Object.keys(routeConfig)) {
60-
if (key === 'debug') continue
59+
for (const key of Object.keys(routeConfig)) {
60+
if (key === 'debug') {
61+
continue
62+
}
6163
try {
6264
processorMap.set(key, require(`./lib/${key}`))
6365
} catch (error) {

lib/proxyIntegration.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ export const process: ProcessMethod<ProxyIntegrationConfig, APIGatewayProxyEvent
115115
if (proxyIntegrationConfig.proxyPath) {
116116
event.path = (event.pathParameters || {})[proxyIntegrationConfig.proxyPath]
117117
if (proxyIntegrationConfig.debug) {
118-
console.log('proxy path is set: ' + proxyIntegrationConfig.proxyPath)
119-
console.log('proxy path with event path: ' + event.path)
118+
console.log(`proxy path is set: ${proxyIntegrationConfig.proxyPath}`)
119+
console.log(`proxy path with event path: ${event.path}`)
120120
}
121121
} else {
122122
event.path = normalizeRequestPath(event)
@@ -206,7 +206,7 @@ const findMatchingActionConfig = (httpMethod: string, httpPath: string, routeCon
206206

207207
const paths: ProxyIntegrationParams['paths'] = {}
208208
const matchingMethodRoutes = routeConfig.routes.filter(route => route.method === httpMethod)
209-
for (let route of matchingMethodRoutes) {
209+
for (const route of matchingMethodRoutes) {
210210
if (routeConfig.debug) {
211211
console.log(`Examining route ${route.path} to match ${httpPath}`)
212212
}
@@ -221,7 +221,7 @@ const findMatchingActionConfig = (httpMethod: string, httpPath: string, routeCon
221221
}
222222
return {
223223
action: route.action,
224-
paths: paths
224+
paths
225225
}
226226
}
227227
}
@@ -233,13 +233,15 @@ const findMatchingActionConfig = (httpMethod: string, httpPath: string, routeCon
233233
}
234234

235235
const extractPathValues = (pathExpression: string, httpPath: string) => {
236-
const pathValueRegex = new RegExp('^' + pathExpression.replace(/{[\w]+}|:[\w]+/g, '([^/]+)') + '$')
236+
const pathExpressionPattern = pathExpression.replace(/{[\w]+}|:[\w]+/g, '([^/]+)')
237+
const pathValueRegex = new RegExp(`^${pathExpressionPattern}$`)
237238
const pathValues = pathValueRegex.exec(httpPath)
238239
return pathValues && pathValues.length > 0 ? pathValues.slice(1) : null
239240
}
240241

241242
const extractPathNames = (pathExpression: string) => {
242-
const pathNameRegex = new RegExp('^' + pathExpression.replace(/{[\w.]+}|:[\w.]+/g, '[:{]([\\w]+)}?') + '$')
243+
const pathExpressionPattern = pathExpression.replace(/{[\w.]+}|:[\w.]+/g, '[:{]([\\w]+)}?')
244+
const pathNameRegex = new RegExp(`^${pathExpressionPattern}$`)
243245
const pathNames = pathNameRegex.exec(pathExpression)
244246
return pathNames && pathNames.length > 0 ? pathNames.slice(1) : null
245247
}

lib/sns.ts

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const process: ProcessMethod<SnsConfig, SnsEvent, Context, any> = (snsCon
2626
}
2727

2828
const sns = event.Records[0].Sns
29-
for (let routeConfig of snsConfig.routes) {
29+
for (const routeConfig of snsConfig.routes) {
3030
if (routeConfig.subject instanceof RegExp) {
3131
if (routeConfig.subject.test(sns.Subject)) {
3232
const result = routeConfig.action(sns, context)
@@ -65,17 +65,30 @@ const cfgExample = {
6565
"EventVersion": "1.0",
6666
"EventSubscriptionArn": "arn:aws:sns:eu-west-1:933782373565:production-escenic-updates:2fdd994c-f2b7-4c2f-a2f9-da83b590e0fc",
6767
"Sns": {
68-
"Type": "Notification",
69-
"MessageId": "0629603b-448e-5366-88b4-309d651495c5",
70-
"TopicArn": "arn:aws:sns:eu-west-1:933782373565:production-escenic-updates",
71-
"Subject": null,
72-
"Message": "{\"escenicId\":\"159526803\",\"model\":\"news\",\"status\":\"draft\"}",
73-
"Timestamp": "2016-11-16T08:56:58.227Z",
74-
"SignatureVersion": "1",
75-
"Signature": "dtXM9BlAJJhYkVObnKmzY012kjgl4uYHEPQ1DLUalBHnPNzkDf12YeVcvHmq0SF6QbdgGwSYw0SgtsOkBiW3WSxVosqEb5xKUWIbQhlXwKdZnzekUigsgl3d231RP+9U2Cvd4QUc6klH5P+CuQM/F70LBIIv74UmR2YNMaxWxrv7Q+ETmz/TF6Y5v8Ip3+GLikbu6wQ/F5g3IHO2Lm7cLpV/74odm48SQxoolh94TdgvtYaUnxNjFVlF8Js8trbRkr7DYTogh73cTwuR77Mo+K9GlYn53txiMW5rMl3KhVdw4U3L190gtBJVwgHbqcB60pmNdEAE9f4bEOohizfPhg==",
76-
"SigningCertUrl": "https://sns.eu-west-1.amazonaws.com/SimpleNotificationService-b95095beb82e8f6a046b3aafc7f4149a.pem",
77-
"UnsubscribeUrl": "https://sns.eu-west-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:eu-west-1:933782373565:production-escenic-updates:2fdd994c-f2b7-4c2f-a2f9-da83b590e0fc",
78-
"MessageAttributes": {}
68+
"Type": "Notification",
69+
"MessageId": "0629603b-448e-5366-88b4-309d651495c5",
70+
"TopicArn": "arn:aws:sns:eu-west-1:933782373565:production-escenic-updates",
71+
"Subject": null,
72+
"Message": "{\"escenicId\":\"159526803\",\"model\":\"news\",\"status\":\"draft\"}",
73+
"Timestamp": "2016-11-16T08:56:58.227Z",
74+
"SignatureVersion": "1",
75+
"Signature": "dtXM9BlAJJhYkVObnKgHbqcB60pmNdEAE9f4bEOohizfPhg==",
76+
"SigningCertUrl": "https://sns.eu-west-1.amazonaws.com/SimpleNotificationService-b95095beb82e8f6a046b3aafc7f4149a.pem",
77+
"UnsubscribeUrl": "https://sns.eu-west-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:eu-west-1:933782373565:production-escenic-updates:2fdd994c-f2b7-4c2f-a2f9-da83b590e0fc",
78+
"MessageAttributes": '{
79+
"stringAttribute": {
80+
"Type": "String",
81+
"Value": "stringvalue"
82+
},
83+
"binaryAttribute": {
84+
"Type": "Binary",
85+
"Value": "Ym9udmFsdWU="
86+
},
87+
"arrayAttribute": {
88+
"Type": "String",
89+
"Value": "[\"value1\", \"value2\"]"
90+
}
91+
}'
7992
}
8093
}
8194
]

lib/sqs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const process: ProcessMethod<SqsConfig, SqsEvent, Context, any> = (sqsCon
2727

2828
const records = event.Records
2929
const recordSourceArn = records[0].eventSourceARN
30-
for (let routeConfig of sqsConfig.routes) {
30+
for (const routeConfig of sqsConfig.routes) {
3131
if (routeConfig.source instanceof RegExp) {
3232
if (routeConfig.source.test(recordSourceArn)) {
3333
const result = routeConfig.action(records.map(record => record.body), context)

0 commit comments

Comments
 (0)