Skip to content

Commit

Permalink
style: fixes lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
moltar committed Aug 9, 2021
1 parent 7c74a36 commit 0b2b7ab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/jest-polly.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe('jest-polly', () => {
expect(message).toBe(RESPONSE)
})

// eslint-disable-next-line sonarjs/no-identical-functions
// eslint-disable-next-line radar/no-identical-functions
it('does not expand previously stringified JSON response', async () => {
expect.assertions(1)

Expand Down Expand Up @@ -141,7 +141,7 @@ describe('jest-polly', () => {
expect(message).toStrictEqual({})
})

// eslint-disable-next-line sonarjs/no-identical-functions
// eslint-disable-next-line radar/no-identical-functions
it('expands JSON request to JSON object', async () => {
expect.assertions(1)

Expand Down
22 changes: 12 additions & 10 deletions src/secrets-sanitizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,20 @@ export function normalizeSecrets(secrets: Secrets): NormalizedSecrets {
return secrets
}

const accumulator: NormalizedSecrets = {}
const normalizedSecrets: NormalizedSecrets = {}

secrets
// eslint-disable-next-line unicorn/no-array-callback-reference
.filter(isDefined) // removes undefines
.filter((secret) => typeof secret === 'string' && !!secret) // non-empty string
.forEach((secret) => Object.assign(accumulator, { [secret]: 'x' }))
const definedSecrets = secrets
.filter(isDefined)
.filter((secret) => typeof secret === 'string' && !!secret)

return accumulator
for (const secret of definedSecrets) {
Object.assign(normalizedSecrets, { [secret]: 'x' })
}

return normalizedSecrets
}

// eslint-disable-next-line sonarjs/cognitive-complexity
// eslint-disable-next-line radar/cognitive-complexity
export function sanitize(recording: JsonObject, secrets: NormalizedSecrets): JsonObject {
const accumulator: JsonObject = merge({}, recording)

Expand All @@ -48,15 +50,15 @@ export function sanitize(recording: JsonObject, secrets: NormalizedSecrets): Jso
}

if (Array.isArray(value)) {
value.forEach((value_, index) => {
for (const [index, value_] of value.entries()) {
if (typeof value_ === 'string') {
value[index] = replaceAll(value_, secrets)
}

if (typeof value_ === 'object' && !Array.isArray(value_) && value_ !== null) {
value[index] = sanitize(value_, secrets)
}
})
}
}
}

Expand Down

0 comments on commit 0b2b7ab

Please sign in to comment.