Skip to content

Commit

Permalink
refactor: fix no-lonely-if
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed Dec 8, 2023
1 parent 74130b9 commit 2b15f42
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 32 deletions.
1 change: 0 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ module.exports = {
'unicorn/no-array-for-each': 'off',
'unicorn/no-array-reduce': 'off',
'unicorn/no-await-expression-member': 'off',
'unicorn/no-lonely-if': 'off',
'unicorn/no-new-array': 'off',
'unicorn/no-null': 'off',
'unicorn/no-static-only-class': 'off',
Expand Down
55 changes: 28 additions & 27 deletions src/events/http/HttpServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -748,33 +748,34 @@ export default class HttpServer {
// If there is a responseTemplate, we apply it to the result
const { responseTemplates } = chosenResponse

if (typeof responseTemplates === 'object') {
if (keys(responseTemplates).length > 0) {
// BAD IMPLEMENTATION: first key in responseTemplates
const responseTemplate = responseTemplates[responseContentType]

if (responseTemplate && responseTemplate !== '\n') {
log.debug('_____ RESPONSE TEMPLATE PROCCESSING _____')
log.debug(`Using responseTemplate '${responseContentType}'`)

try {
const reponseContext = new VelocityContext(
request,
stage,
result,
).getContext()

result = renderVelocityTemplateObject(
{
root: responseTemplate,
},
reponseContext,
).root
} catch (error) {
log.error(
`Error while parsing responseTemplate '${responseContentType}' for lambda ${functionKey}:\n${error.stack}`,
)
}
if (
typeof responseTemplates === 'object' &&
keys(responseTemplates).length > 0
) {
// BAD IMPLEMENTATION: first key in responseTemplates
const responseTemplate = responseTemplates[responseContentType]

if (responseTemplate && responseTemplate !== '\n') {
log.debug('_____ RESPONSE TEMPLATE PROCCESSING _____')
log.debug(`Using responseTemplate '${responseContentType}'`)

try {
const reponseContext = new VelocityContext(
request,
stage,
result,
).getContext()

result = renderVelocityTemplateObject(
{
root: responseTemplate,
},
reponseContext,
).root
} catch (error) {
log.error(
`Error while parsing responseTemplate '${responseContentType}' for lambda ${functionKey}:\n${error.stack}`,
)
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/lambda/routes/invocations/InvocationsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,8 @@ export default class InvocationsController {
}

// Checking if the result of the Lambda Invoke is a primitive string to wrap it. this is for future post-processing such as Step Functions Tasks
if (result) {
if (typeof result === 'string') {
result = `"${result}"`
}
if (result && typeof result === 'string') {
result = `"${result}"`
}

// result is actually the Payload.
Expand Down

0 comments on commit 2b15f42

Please sign in to comment.