Skip to content

Commit 91c19d7

Browse files
committed
fix(lint): clear new socket/* rule violations from the fleet cascade
Apply autofixes from `socket/prefer-cached-for-loop`, `socket/prefer-node-builtin-imports`, and `socket/sort-equality-disjunctions` across the script and config surface, plus manual rewrites where the autofix bailed (destructured `for...of`, non-bare iterable expressions, and nested `for (const pattern of ESCALATION_PATTERNS)` loops). Notable fixups: - `packages/iocraft/index.mjs`: the `prefer-node-builtin-imports` autofix rewrote `import { arch, platform } from 'node:os'` to `import os from 'node:os'` but didn't update the call sites — fix them to `os.platform()` / `os.arch()` so the module still runs. - `packages/iocraft/index.mjs`: restore `export default iocraft` with an inline disable. The umbrella package's documented public API is `import iocraft from '@socketaddon/iocraft'`; switching to a named export would be a breaking consumer-visible change. - `.config/vitest.config.mts`: inline disable for `no-default-export` — Vitest config files must use `export default defineConfig(...)`. - `scripts/publish.mts`: bypass the `max-file-lines` soft cap with the documented `max-file-lines: legitimate` marker. The file is a linear publish-orchestration script whose phases (download/verify, stage, rewrite deps, dry-run, publish, cleanup) are best read top to bottom; splitting would scatter the per-phase context. - Add `!` non-null assertions on the new indexed accesses introduced by the cached-length for-loop rewrites so `noUncheckedIndexedAccess` still passes.
1 parent 89dcfdd commit 91c19d7

7 files changed

Lines changed: 41 additions & 17 deletions

File tree

.config/vitest.config.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const isCoverageEnabled =
99
process.env['COVERAGE'] === 'true' ||
1010
process.argv.some(arg => arg.includes('coverage'))
1111

12+
// oxlint-disable-next-line socket/no-default-export -- Vitest config files must use `export default`.
1213
export default defineConfig({
1314
test: {
1415
deps: {

packages/iocraft/index.mjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
*/
77

88
import { createRequire } from 'node:module'
9-
import { arch, platform } from 'node:os'
9+
import os from 'node:os'
1010

1111
const require = createRequire(import.meta.url)
1212

1313
export function getPlatformIdentifier() {
14-
const platformName = platform()
15-
const archName = arch()
14+
const platformName = os.platform()
15+
const archName = os.arch()
1616

1717
if (
1818
platformName !== 'darwin' &&
@@ -80,4 +80,5 @@ export function loadNativeAddon() {
8080

8181
const iocraft = loadNativeAddon()
8282

83+
// oxlint-disable-next-line socket/no-default-export -- Published package public API (`@socketaddon/iocraft`); the documented consumer pattern is `import iocraft from '@socketaddon/iocraft'`.
8384
export default iocraft

scripts/check.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import process from 'node:process'
1616

1717
const args = process.argv.slice(2)
1818
const forwardedArgs = args.filter(
19-
a => a === '--all' || a === '--staged' || a === '--fix' || a === '--quiet',
19+
a => a === '--all' || a === '--fix' || a === '--quiet' || a === '--staged',
2020
)
2121

2222
try {

scripts/clean.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ const PATTERNS: readonly string[] = ['coverage', 'dist', 'packages/*/.cache']
2222
const root = process.cwd()
2323
let removed = 0
2424

25-
for (const pattern of PATTERNS) {
25+
for (let i = 0, { length } = PATTERNS; i < length; i += 1) {
26+
const pattern = PATTERNS[i]!
2627
for await (const match of glob(pattern, { cwd: root })) {
2728
const target = path.resolve(root, match)
2829
await safeDelete(target)

scripts/lint.mts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,14 @@ export function runFiles(files: string[]): number {
144144
}
145145

146146
export function shouldEscalate(files: string[]): boolean {
147-
for (const f of files) {
148-
for (const pattern of ESCALATION_PATTERNS) {
147+
for (let i = 0, { length } = files; i < length; i += 1) {
148+
const f = files[i]!
149+
for (
150+
let j = 0, { length: patternsLength } = ESCALATION_PATTERNS;
151+
j < patternsLength;
152+
j += 1
153+
) {
154+
const pattern = ESCALATION_PATTERNS[j]!
149155
if (pattern.test(f)) {
150156
return true
151157
}

scripts/publish.mts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* max-file-lines: legitimate -- Linear publish-orchestration script: download/verify, stage, rewrite deps, dry-run, publish, cleanup. Splitting would scatter the per-phase context across files and obscure the order-of-operations the file header documents. */
12
/**
23
* Publish all `@socketaddon/*` packages to npm.
34
*
@@ -271,7 +272,8 @@ export function readWorkspaceCatalog(
271272
const lines = yaml.split('\n')
272273
const catalog: Record<string, string> = { __proto__: null as never }
273274
let inCatalog = false
274-
for (const line of lines) {
275+
for (let i = 0, { length } = lines; i < length; i += 1) {
276+
const line = lines[i]!
275277
if (line === 'catalog:') {
276278
inCatalog = true
277279
continue
@@ -309,11 +311,13 @@ export function rewriteDeps(
309311
'peerDependencies',
310312
'optionalDependencies',
311313
] as const
312-
for (const block of blocks) {
314+
for (let i = 0, { length } = blocks; i < length; i += 1) {
315+
const block = blocks[i]!
313316
const deps = pj[block] as Record<string, string> | undefined
314317
if (!deps) {
315318
continue
316319
}
320+
// oxlint-disable-next-line socket/prefer-cached-for-loop -- `Object.entries(deps)` is a one-shot iterator; a cached-length loop would need a Map/Array materialization that defeats the optimization.
317321
for (const [name, spec] of Object.entries(deps)) {
318322
if (
319323
spec === 'workspace:*' ||
@@ -431,7 +435,8 @@ async function main(): Promise<void> {
431435
)
432436
// Include all per-platform packages in the version map so the umbrella's
433437
// optionalDependencies can resolve even if --platforms filters the publish set.
434-
for (const { dir } of PER_PLATFORM_PACKAGES) {
438+
for (let i = 0, { length } = PER_PLATFORM_PACKAGES; i < length; i += 1) {
439+
const { dir } = PER_PLATFORM_PACKAGES[i]!
435440
if (!filteredPerPlatform.some(p => p.dir === dir)) {
436441
const info = readPackage(dir)
437442
workspaceVersions.set(info.name, info.version)
@@ -441,7 +446,8 @@ async function main(): Promise<void> {
441446

442447
const stagingDirs: string[] = []
443448
const cleanup = (): void => {
444-
for (const d of stagingDirs) {
449+
for (let i = 0, { length } = stagingDirs; i < length; i += 1) {
450+
const d = stagingDirs[i]!
445451
try {
446452
safeDeleteSync(d)
447453
} catch {
@@ -472,16 +478,18 @@ async function main(): Promise<void> {
472478

473479
try {
474480
// Per-platform first.
475-
for (const pkg of allPackages.filter(p => p.releaseSuffix)) {
476-
await publishPackage(pkg, ctx)
481+
const perPlatformPkgs = allPackages.filter(p => p.releaseSuffix)
482+
for (let i = 0, { length } = perPlatformPkgs; i < length; i += 1) {
483+
await publishPackage(perPlatformPkgs[i]!, ctx)
477484
}
478485
// Umbrella last so its optionalDependencies can resolve.
479486
const umbrella = allPackages.find(p => !p.releaseSuffix)
480487
if (umbrella) {
481488
await publishPackage(umbrella, ctx)
482489
}
483490
} finally {
484-
for (const d of stagingDirs) {
491+
for (let i = 0, { length } = stagingDirs; i < length; i += 1) {
492+
const d = stagingDirs[i]!
485493
await safeDelete(d)
486494
}
487495
}

scripts/test.mts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ export function gitFiles(command: string): string[] {
7272

7373
export function resolveTestPatterns(files: string[]): string[] {
7474
const patterns = new Set<string>()
75-
for (const f of files) {
75+
for (let i = 0, { length } = files; i < length; i += 1) {
76+
const f = files[i]!
7677
if (/^packages\/[^/]+\/test\/.*\.test\.(m?[jt]s)$/.test(f)) {
7778
patterns.add(f)
7879
continue
@@ -126,8 +127,14 @@ export function runScoped(patterns: string[]): number {
126127
}
127128

128129
export function shouldEscalate(files: string[]): boolean {
129-
for (const f of files) {
130-
for (const pattern of ESCALATION_PATTERNS) {
130+
for (let i = 0, { length } = files; i < length; i += 1) {
131+
const f = files[i]!
132+
for (
133+
let j = 0, { length: patternsLength } = ESCALATION_PATTERNS;
134+
j < patternsLength;
135+
j += 1
136+
) {
137+
const pattern = ESCALATION_PATTERNS[j]!
131138
if (pattern.test(f)) {
132139
return true
133140
}

0 commit comments

Comments
 (0)