Skip to content

Commit

Permalink
⚡️ [RUMF-1043] forbid array spread
Browse files Browse the repository at this point in the history
  • Loading branch information
BenoitZugmeyer committed Feb 17, 2022
1 parent ccddfa0 commit 9f58edd
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ module.exports = {
selector: 'ObjectExpression > SpreadElement',
message: 'Object spread is not authorized. Please use "assign" from the core package utils instead.',
},
{
selector: 'ArrayExpression > SpreadElement',
message: 'Array spread is not authorized. Please use .concat instead.',
},
],
},
},
Expand Down
5 changes: 5 additions & 0 deletions eslint-local-rules/disallowSideEffects.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ function isAllowedCallExpression({ callee }) {
return true
}

// Allow ".concat()"
if (callee.type === 'MemberExpression' && callee.property.name === 'concat') {
return true
}

return false
}

Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/domain/console/consoleObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ function createConsoleObservable(api: ConsoleApiName) {

function buildConsoleLog(params: unknown[], api: ConsoleApiName, handlingStack: string): ConsoleLog {
const log: ConsoleLog = {
message: [`console ${api}:`, ...params].map((param) => formatConsoleParameters(param)).join(' '),
message: [`console ${api}:` as unknown]
.concat(params)
.map((param) => formatConsoleParameters(param))
.join(' '),
api,
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/transport/batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class Batch {

flush(reason?: string) {
if (this.bufferMessageCount !== 0) {
const messages = [...this.pushOnlyBuffer, ...objectValues(this.upsertBuffer)]
const messages = this.pushOnlyBuffer.concat(objectValues(this.upsertBuffer))
this.request.send(messages.join('\n'), this.bufferBytesSize, reason)
this.pushOnlyBuffer = []
this.upsertBuffer = {}
Expand Down
5 changes: 2 additions & 3 deletions packages/rum-core/src/domain/assembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ const VIEW_EVENTS_MODIFIABLE_FIELD_PATHS = [
'resource.url',
]

const OTHER_EVENTS_MODIFIABLE_FIELD_PATHS = [
...VIEW_EVENTS_MODIFIABLE_FIELD_PATHS,
const OTHER_EVENTS_MODIFIABLE_FIELD_PATHS = VIEW_EVENTS_MODIFIABLE_FIELD_PATHS.concat([
// User-customizable field
'context',
]
])

type Mutable<T> = { -readonly [P in keyof T]: T[P] }

Expand Down

0 comments on commit 9f58edd

Please sign in to comment.