Skip to content

Commit

Permalink
refactor: bup eslint-plugin-unicorn, fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed Sep 20, 2023
1 parent 4606829 commit c93dd98
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 50 deletions.
54 changes: 22 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"dependencies": {
"@aws-sdk/client-lambda": "^3.414.0",
"@hapi/boom": "^10.0.1",
"@hapi/h2o2": "^10.0.3",
"@hapi/h2o2": "^10.0.4",
"@hapi/hapi": "^21.3.2",
"@serverless/utils": "^6.15.0",
"array-unflat-js": "^0.1.3",
Expand Down Expand Up @@ -111,7 +111,7 @@
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-unicorn": "^46.0.1",
"eslint-plugin-unicorn": "^48.0.1",
"git-list-updated": "^1.2.1",
"husky": "^8.0.3",
"lint-staged": "^14.0.1",
Expand Down
6 changes: 3 additions & 3 deletions src/ServerlessOffline.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,13 @@ export default class ServerlessOffline {

// Parse CORS options
this.#options.corsAllowHeaders = this.#options.corsAllowHeaders
.replace(/\s/g, '')
.replaceAll(' ', '')
.split(',')
this.#options.corsAllowOrigin = this.#options.corsAllowOrigin
.replace(/\s/g, '')
.replaceAll(' ', '')
.split(',')
this.#options.corsExposedHeaders = this.#options.corsExposedHeaders
.replace(/\s/g, '')
.replaceAll(' ', '')
.split(',')

this.#options.corsConfig = {
Expand Down
2 changes: 1 addition & 1 deletion src/events/authMatchPolicyResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default function authMatchPolicyResource(policyResource, resource) {
// for the requested resource and the resource defined in the policy
// Need to create a regex replacing ? with one character and * with any number of characters
const regExp = new RegExp(
parsedPolicyResource.path.replace(/\*/g, '.*').replace(/\?/g, '.'),
parsedPolicyResource.path.replaceAll('*', '.*').replaceAll('?', '.'),
)

return regExp.test(parsedResource.path)
Expand Down
2 changes: 1 addition & 1 deletion src/events/http/Endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const defaultResponseTemplate = readFileSync(

function getResponseContentType(fep) {
if (fep.response && fep.response.headers['Content-Type']) {
return fep.response.headers['Content-Type'].replace(/'/gm, '')
return fep.response.headers['Content-Type'].replaceAll(/'/gm, '')
}

return 'application/json'
Expand Down
7 changes: 0 additions & 7 deletions src/events/http/javaHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ function javaMatches(value) {
return this.match(new RegExp(value, 'm'))
}

function javaReplaceAll(oldValue, newValue) {
return this.replace(new RegExp(oldValue, 'gm'), newValue)
}

function javaReplaceFirst(oldValue, newValue) {
return this.replace(new RegExp(oldValue, 'm'), newValue)
}
Expand Down Expand Up @@ -74,7 +70,6 @@ const {
equalsIgnoreCase,
matches,
regionMatches,
replaceAll,
replaceFirst,
},
} = String
Expand All @@ -85,7 +80,6 @@ export default function runInPollutedScope(runScope) {
prototype.equalsIgnoreCase = javaEqualsIgnoreCase
prototype.matches = javaMatches
prototype.regionMatches = javaRegionMatches
prototype.replaceAll = javaReplaceAll
prototype.replaceFirst = javaReplaceFirst

const result = runScope()
Expand All @@ -95,7 +89,6 @@ export default function runInPollutedScope(runScope) {
prototype.equalsIgnoreCase = equalsIgnoreCase
prototype.matches = matches
prototype.regionMatches = regionMatches
prototype.replaceAll = replaceAll
prototype.replaceFirst = replaceFirst

return result
Expand Down
4 changes: 2 additions & 2 deletions src/events/http/lambda-events/VelocityContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const { assign, entries, fromEntries } = Object

function escapeJavaScript(x) {
if (typeof x === 'string') {
return jsEscapeString(x).replace(/\\n/g, '\n') // See #26,
return jsEscapeString(x).replaceAll('\\n', '\n') // See #26,
}

if (isPlainObject(x)) {
Expand Down Expand Up @@ -136,7 +136,7 @@ export default class VelocityContext {
Buffer.from(x.toString(), 'binary').toString('base64'),
escapeJavaScript,
parseJson: parse,
urlDecode: (x) => decodeURIComponent(x.replace(/\+/g, ' ')),
urlDecode: (x) => decodeURIComponent(x.replaceAll('+', ' ')),
urlEncode: encodeURI,
},
}
Expand Down
2 changes: 1 addition & 1 deletion src/events/schedule/ScheduleEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class ScheduleEvent {
source = 'aws.events'

// format of aws displaying the time, e.g.: 2020-02-09T14:13:57Z
time = new Date().toISOString().replace(/\.(.*)(?=Z)/g, '')
time = new Date().toISOString().replaceAll(/\.(.*)(?=Z)/g, '')

version = '0'

Expand Down
2 changes: 1 addition & 1 deletion src/utils/generateHapiPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function generateHapiPath(path, options, serverless) {
hapiPath = hapiPath.slice(0, -1)
}

hapiPath = hapiPath.replace(/\+}/g, '*}')
hapiPath = hapiPath.replaceAll('+}', '*}')

return hapiPath
}
Expand Down

0 comments on commit c93dd98

Please sign in to comment.