Skip to content

Commit d308b93

Browse files
authored
chore: activate unicorn/no-array-for-each eslint rule (#7403)
This uses autofixes with manual improvements afterwards.
1 parent 9ea0f34 commit d308b93

File tree

84 files changed

+405
-295
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+405
-295
lines changed

eslint.config.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,6 @@ export default [
474474
'unicorn/expiring-todo-comments': 'off',
475475
'unicorn/explicit-length-check': 'off', // 68 errors
476476
'unicorn/filename-case': ['off', { case: 'kebabCase' }], // 59 errors
477-
'unicorn/no-array-for-each': 'off', // 122 errors
478477
'unicorn/prefer-at': 'off', // 17 errors | Difficult to fix
479478
'unicorn/prevent-abbreviations': 'off', // too strict
480479

packages/datadog-core/src/utils/src/pick.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
module.exports = function pick (object, props) {
44
const result = {}
5-
props.forEach(prop => {
5+
for (const prop of props) {
66
if (Object.hasOwn(object, prop)) {
77
result[prop] = object[prop]
88
}
9-
})
9+
}
1010
return result
1111
}

packages/datadog-instrumentations/src/apollo-server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ function wrapExecuteHTTPGraphQLRequest (originalExecuteHTTPGraphQLRequest) {
3232
// This method is expected to return response data
3333
// with headers, status and body
3434
const headers = new HeaderMap()
35-
Object.keys(abortData.headers).forEach(key => {
35+
for (const key of Object.keys(abortData.headers)) {
3636
headers.set(key, abortData.headers[key])
37-
})
37+
}
3838

3939
resolve({
4040
headers,

packages/datadog-instrumentations/src/child_process.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function returnSpawnSyncError (error, context) {
3737
return context.result
3838
}
3939

40-
names.forEach(name => {
40+
for (const name of names) {
4141
addHook({ name }, childProcess => {
4242
if (!patched) {
4343
patched = true
@@ -49,7 +49,7 @@ names.forEach(name => {
4949

5050
return childProcess
5151
})
52-
})
52+
}
5353

5454
function normalizeArgs (args, shell) {
5555
const childProcessInfo = {

packages/datadog-instrumentations/src/confluentinc-kafka-javascript.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,15 @@ function instrumentBaseModule (module) {
117117
if (typeof callback === 'function') {
118118
return consume.call(this, numMessages, function wrappedCallback (err, messages) {
119119
if (messages && messages.length > 0) {
120-
messages.forEach(message => {
120+
for (const message of messages) {
121121
ctx.topic = message?.topic
122122
ctx.partition = message?.partition
123123
ctx.message = message
124124

125125
// TODO: We should be using publish here instead of runStores but we need bindStart to be called
126126
channels.consumerStart.runStores(ctx, () => {})
127127
updateLatestOffset(message?.topic, message?.partition, message?.offset, groupId)
128-
})
128+
}
129129
}
130130

131131
if (err) {

packages/datadog-instrumentations/src/couchbase.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ function getQueryResource (q) {
2020
}
2121

2222
function wrapAllNames (names, action) {
23-
names.forEach(name => action(name))
23+
for (const name of names) {
24+
action(name)
25+
}
2426
}
2527

2628
function wrapCallback (callback, ctx, channelPrefix) {

packages/datadog-instrumentations/src/fs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const paramsByFileHandleMethods = {
8585
writev: ['buffers', 'position'],
8686
}
8787
const names = ['fs', 'node:fs']
88-
names.forEach(name => {
88+
for (const name of names) {
8989
addHook({ name }, fs => {
9090
const asyncMethods = Object.keys(paramsByMethod)
9191
const syncMethods = asyncMethods.map(name => `${name}Sync`)
@@ -114,7 +114,7 @@ names.forEach(name => {
114114

115115
return fs
116116
})
117-
})
117+
}
118118
function isFirstMethodReturningFileHandle (original) {
119119
return !kHandle && original.name === 'open'
120120
}

packages/datadog-instrumentations/src/graphql.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,12 @@ function wrapFields (type) {
295295

296296
patchedTypes.add(type)
297297

298-
Object.keys(type._fields).forEach(key => {
298+
for (const key of Object.keys(type._fields)) {
299299
const field = type._fields[key]
300300

301301
wrapFieldResolve(field)
302302
wrapFieldType(field)
303-
})
303+
}
304304
}
305305

306306
function wrapFieldResolve (field) {
@@ -321,7 +321,7 @@ function wrapFieldType (field) {
321321
}
322322

323323
function finishResolvers ({ fields }) {
324-
Object.keys(fields).reverse().forEach(key => {
324+
for (const key of Object.keys(fields).reverse()) {
325325
const field = fields[key]
326326
field.ctx.finishTime = field.finishTime
327327
field.ctx.field = field
@@ -330,7 +330,7 @@ function finishResolvers ({ fields }) {
330330
resolveErrorCh.publish(field.ctx)
331331
}
332332
finishResolveCh.publish(field.ctx)
333-
})
333+
}
334334
}
335335

336336
addHook({ name: '@graphql-tools/executor', versions: ['>=0.0.14'] }, executor => {

packages/datadog-instrumentations/src/grpc/client.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,18 @@ function wrapClientConstructor (ServiceClient, methods, hasPeer = false) {
6363

6464
if (typeof methods !== 'object' || 'format' in methods) return
6565

66-
Object.keys(methods)
67-
.forEach(name => {
68-
if (!methods[name]) return
66+
for (const [name, method] of Object.entries(methods)) {
67+
if (!method) continue
6968

70-
const originalName = methods[name].originalName
71-
const path = methods[name].path
72-
const type = getType(methods[name])
69+
const { originalName, path } = method
70+
const type = getType(method)
7371

74-
if (methods[name]) {
75-
proto[name] = wrapMethod(proto[name], path, type, hasPeer)
76-
}
72+
proto[name] = wrapMethod(proto[name], path, type, hasPeer)
7773

78-
if (originalName) {
79-
proto[originalName] = wrapMethod(proto[originalName], path, type, hasPeer)
80-
}
81-
})
74+
if (originalName) {
75+
proto[originalName] = wrapMethod(proto[originalName], path, type, hasPeer)
76+
}
77+
}
8278
}
8379

8480
function wrapMethod (method, path, type, hasPeer) {

packages/datadog-instrumentations/src/helpers/router-helper.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ function wrapRouteMethodsAndPublish (route, paths, publish) {
202202

203203
const uniquePaths = new Set(filteredPaths)
204204

205-
METHODS.forEach(method => {
206-
if (typeof route[method] !== 'function') return
205+
for (const method of METHODS) {
206+
if (typeof route[method] !== 'function') continue
207207

208208
shimmer.wrap(route, method, (originalMethod) => function wrappedRouteMethod (...args) {
209209
const normalizedMethod = normalizeMethodName(method)
@@ -217,7 +217,7 @@ function wrapRouteMethodsAndPublish (route, paths, publish) {
217217

218218
return originalMethod.apply(this, args)
219219
})
220-
})
220+
}
221221
}
222222

223223
module.exports = {

0 commit comments

Comments
 (0)