Skip to content

Commit ac9eefe

Browse files
committed
fix(lint): convert cached-length for-loops over iterables to for-of
Drop manual cached-length for-loops at call sites the new `socket/no-cached-for-on-iterable` rule catches. Pure mechanical swap to `for (const item of X)`; no logic change.
1 parent ada8a9a commit ac9eefe

2 files changed

Lines changed: 11 additions & 12 deletions

File tree

scripts/util/suppress-warnings.mts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ export function setupSuppression() {
2121
process.emitWarning = (warning, ...args) => {
2222
// Check both string warnings and warning objects.
2323
if (typeof warning === 'string') {
24-
// Check if any suppressed warning type matches.
25-
for (let i = 0, { length } = suppressedWarnings; i < length; i += 1) {
26-
const suppressedType = suppressedWarnings[i]
24+
// `suppressedWarnings` is a Set — iterate with for...of
25+
// since the body only needs each element, not an index.
26+
for (const suppressedType of suppressedWarnings) {
2727
if (warning.includes(suppressedType)) {
2828
return
2929
}

scripts/validation/bundle-deps.mts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -320,26 +320,26 @@ export async function validateBundleDeps() {
320320
const externals = await extractExternalPackages(file)
321321
const bundled = await extractBundledPackages(file)
322322

323-
for (let i = 0, { length } = externals; i < length; i += 1) {
324-
const ext = externals[i]
323+
// `externals` and `bundled` are Sets — use for...of, not the
324+
// cached-length for-loop.
325+
for (const ext of externals) {
325326
const packageName = getPackageName(ext)
326327
if (packageName && !BUILTIN_MODULES.has(packageName)) {
327328
allExternals.add(packageName)
328329
}
329330
}
330331

331-
for (let i = 0, { length } = bundled; i < length; i += 1) {
332-
const bun = bundled[i]
332+
for (const bun of bundled) {
333333
allBundled.add(bun)
334334
}
335335
}
336336

337337
const violations = []
338338
const warnings = []
339339

340-
// Validate external packages are in dependencies or peerDependencies
341-
for (let i = 0, { length } = allExternals; i < length; i += 1) {
342-
const packageName = allExternals[i]
340+
// Validate external packages are in dependencies or peerDependencies.
341+
// `allExternals` / `allBundled` are Sets — use for...of.
342+
for (const packageName of allExternals) {
343343
if (!dependencies.has(packageName) && !peerDependencies.has(packageName)) {
344344
violations.push({
345345
type: 'external-not-in-deps',
@@ -353,8 +353,7 @@ export async function validateBundleDeps() {
353353
}
354354

355355
// Validate bundled packages are in devDependencies (not dependencies)
356-
for (let i = 0, { length } = allBundled; i < length; i += 1) {
357-
const packageName = allBundled[i]
356+
for (const packageName of allBundled) {
358357
if (dependencies.has(packageName)) {
359358
violations.push({
360359
type: 'bundled-in-deps',

0 commit comments

Comments
 (0)