Skip to content

Commit 4f1cec4

Browse files
committed
fix(lint): convert file-scope oxlint disables to per-call (batch 1)
11 files converted from file-scope `/* oxlint-disable socket/<rule> */` to inline `oxlint-disable-next-line <rule> -- <reason>` per call site, per the new socket/no-file-scope-oxlint-disable rule. Several files were entirely `for...of` over non-array iterables (Map.entries, Object.entries, destructured tuples) where the prefer-cached-for-loop rule's autofix is unsafe; the new rule's per- call disable shape carries the per-site reason next to each loop. Files: scripts/util/{run-command,git-helpers,package}.mts, .github/actions/lib/read-pinned-version.mts, scripts/ci/{inline-action-versions-as-shas,generate-actions-allow-list}.mts, scripts/lint.mts, scripts/validation/npm-packages.mts (already clean after strip — emoji not in the rule's denylist), scripts/testing/validate-package-tests.mts (clean after strip; the file-scope block was the 3 lines pushing it over the 500-line cap), scripts/npm/{install-npm-packages,release-npm-packages}.mts (clean after strip).
1 parent fce50ac commit 4f1cec4

11 files changed

Lines changed: 18 additions & 14 deletions

.github/actions/lib/read-pinned-version.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* oxlint-disable socket/prefer-cached-for-loop -- iterates non-array iterables (Object.entries); the cached-length rewrite would be incorrect. */
21
/**
32
* @file Print the pinned version of a Socket package to stdout, reading from
43
* (in order):
@@ -63,6 +62,7 @@ const fromPackageJson = (pkg: string): string | undefined => {
6362
return undefined
6463
}
6564
const json = JSON.parse(readFileSync('package.json', 'utf8'))
65+
// oxlint-disable-next-line socket/prefer-cached-for-loop -- iterates a 2-element const tuple; cached-length form would obscure the literal pair.
6666
for (const field of ['dependencies', 'devDependencies'] as const) {
6767
const deps = json[field]
6868
if (deps && typeof deps[pkg] === 'string') {

scripts/ci/generate-actions-allow-list.mts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* @file Generate GitHub Actions allow list from workflow and action
33
* dependencies.
44
*/
5-
/* oxlint-disable socket/prefer-cached-for-loop -- iterates non-array iterables (Map / Object.entries); the cached-length rewrite would be incorrect. */
65

76
import { promises as fs } from 'node:fs'
87
import path from 'node:path'
@@ -79,6 +78,7 @@ async function main(): Promise<void> {
7978
for (let i = 0, { length } = workflowFiles; i < length; i += 1) {
8079
const file = workflowFiles[i]
8180
const deps = await extractDependencies(file)
81+
// oxlint-disable-next-line socket/prefer-cached-for-loop -- iterates Map.entries() (non-array iterable); cached-length would be incorrect.
8282
for (const { 0: key, 1: value } of deps.entries()) {
8383
allDependencies.set(key, value)
8484
}
@@ -98,6 +98,7 @@ async function main(): Promise<void> {
9898
)
9999
try {
100100
const deps = await extractDependencies(actionFile)
101+
// oxlint-disable-next-line socket/prefer-cached-for-loop -- iterates Map.entries() (non-array iterable); cached-length would be incorrect.
101102
for (const { 0: key, 1: value } of deps.entries()) {
102103
allDependencies.set(key, value)
103104
}
@@ -109,6 +110,8 @@ async function main(): Promise<void> {
109110
const socketDevActions = []
110111
const externalActions = []
111112

113+
// oxlint-disable-next-line socket/prefer-cached-for-loop -- iterates Map.values() (non-array iterable); cached-length would be incorrect.
114+
112115
for (const dep of allDependencies.values()) {
113116
if (dep.startsWith('SocketDev/')) {
114117
socketDevActions.push(dep)

scripts/ci/inline-action-versions-as-shas.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/**
22
* @file Convert GitHub Actions tags/branches to commit SHAs in workflow files.
33
*/
4-
/* oxlint-disable socket/prefer-cached-for-loop -- iterates `usesStatements.slice().reverse()` / non-array iterables; the cached-length rewrite would be incorrect or lose the reverse pass. */
54

65
import { existsSync, promises as fs } from 'node:fs'
76
import path from 'node:path'
@@ -131,6 +130,7 @@ export async function processFile(filePath, token, dryRun) {
131130
const changes = []
132131

133132
// Process in reverse order to maintain correct string positions.
133+
// oxlint-disable-next-line socket/prefer-cached-for-loop -- iterates a reversed slice; cached-length form would lose the reverse pass.
134134
for (const stmt of usesStatements.slice().reverse()) {
135135
const { fullMatch, indent, owner, ref: currentRef, repoPath } = stmt
136136

@@ -269,6 +269,7 @@ async function main(): Promise<void> {
269269
}
270270

271271
// Display changes.
272+
// oxlint-disable-next-line socket/prefer-cached-for-loop -- destructured loop variable; cached-length rewrite would scatter the destructure.
272273
for (const { changes, file } of processedFiles) {
273274
logger.error('')
274275
logger.info(`${path.relative(cwd, file)}:`)

scripts/lint.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* @file Unified lint runner with flag-based configuration. Provides smart
33
* linting that can target affected files or lint everything.
44
*/
5-
/* oxlint-disable socket/prefer-cached-for-loop -- iterates a configured linter list (destructured loop variable); the cached-length rewrite would be incorrect. */
65

76
import { existsSync, readFileSync } from 'node:fs'
87
import path from 'node:path'
@@ -188,6 +187,7 @@ export async function runLintOnFiles(
188187
},
189188
]
190189

190+
// oxlint-disable-next-line socket/prefer-cached-for-loop -- destructured linter-config tuple; cached-length rewrite would scatter the destructure.
191191
for (const { args, enabled } of linters) {
192192
if (!enabled) {
193193
continue
@@ -260,6 +260,7 @@ export async function runLintOnAll(options: LintOptions = {}): Promise<number> {
260260
},
261261
]
262262

263+
// oxlint-disable-next-line socket/prefer-cached-for-loop -- destructured linter-config tuple; cached-length rewrite would scatter the destructure.
263264
for (const { args } of linters) {
264265
const result = await runCommandQuiet('pnpm', args)
265266

scripts/npm/install-npm-packages.mts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* oxlint-disable socket/no-status-emoji -- intentional emoji output. */
2-
/* oxlint-disable socket/prefer-cached-for-loop -- iterates Dirent results inside async tasks; the cached-length rewrite is unsafe under await chains. */
31
/* max-file-lines: legitimate — monolithic npm-install driver (resolution + override application + nested traversal + progress UI). The phases share enough live state (tasks queue, override map, scoped-vs-unscoped branch) that splitting them produces a tangle of cross-file mutables. */
42

53
/**

scripts/npm/release-npm-packages.mts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* oxlint-disable socket/no-status-emoji -- intentional emoji output. */
2-
/* oxlint-disable socket/prefer-cached-for-loop -- iterates non-array iterables (state.warnings / state.changes / Object.entries); the cached-length rewrite would be incorrect. */
31

42
/**
53
* @file Detect package changes and bump versions for npm release.

scripts/testing/validate-package-tests.mts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* oxlint-disable socket/no-status-emoji -- intentional emoji output. */
2-
/* oxlint-disable socket/prefer-cached-for-loop -- iterates destructured records and async-settled results; the cached-length rewrite would be incorrect. */
31

42
/**
53
* @file Validates package overrides before release to catch test infrastructure

scripts/util/git-helpers.mts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* oxlint-disable socket/no-process-cwd-in-scripts-hooks -- every exported helper accepts a `cwd` parameter the caller can override; the `process.cwd()` defaults are convenience for ad-hoc invocations and don't bypass the anchor-on-script-location rule. */
21
/**
32
* @file Git helper functions for listing staged / unstaged / changed files. All
43
* returned paths are relative to the git top-level, so downstream glob
@@ -79,6 +78,7 @@ export function filterRelativeToRoot(
7978
/**
8079
* Get changed files synchronously (paths relative to git root).
8180
*/
81+
// oxlint-disable-next-line socket/no-process-cwd-in-scripts-hooks -- helper accepts cwd; process.cwd() is the ad-hoc-invocation default, not a bypass of the anchor-on-script-location rule.
8282
export function getChangedFilesSync(cwd = process.cwd()): string[] {
8383
try {
8484
const gitRoot = getGitRoot(cwd)
@@ -101,6 +101,7 @@ export function getChangedFilesSync(cwd = process.cwd()): string[] {
101101
/**
102102
* Get staged files (paths relative to git root).
103103
*/
104+
// oxlint-disable-next-line socket/no-process-cwd-in-scripts-hooks -- helper accepts cwd; process.cwd() is the ad-hoc-invocation default, not a bypass of the anchor-on-script-location rule.
104105
export async function getStagedFiles(cwd = process.cwd()): Promise<string[]> {
105106
try {
106107
const gitRoot = await getGitRootAsync(cwd)
@@ -120,6 +121,7 @@ export async function getStagedFiles(cwd = process.cwd()): Promise<string[]> {
120121
/**
121122
* Get staged files synchronously (paths relative to git root).
122123
*/
124+
// oxlint-disable-next-line socket/no-process-cwd-in-scripts-hooks -- helper accepts cwd; process.cwd() is the ad-hoc-invocation default, not a bypass of the anchor-on-script-location rule.
123125
export function getStagedFilesSync(cwd = process.cwd()): string[] {
124126
try {
125127
const gitRoot = getGitRoot(cwd)
@@ -142,6 +144,7 @@ export function getStagedFilesSync(cwd = process.cwd()): string[] {
142144
/**
143145
* Get unstaged files (paths relative to git root).
144146
*/
147+
// oxlint-disable-next-line socket/no-process-cwd-in-scripts-hooks -- helper accepts cwd; process.cwd() is the ad-hoc-invocation default, not a bypass of the anchor-on-script-location rule.
145148
export async function getUnstagedFiles(cwd = process.cwd()): Promise<string[]> {
146149
try {
147150
const gitRoot = await getGitRootAsync(cwd)
@@ -161,6 +164,7 @@ export async function getUnstagedFiles(cwd = process.cwd()): Promise<string[]> {
161164
/**
162165
* Get unstaged files synchronously (paths relative to git root).
163166
*/
167+
// oxlint-disable-next-line socket/no-process-cwd-in-scripts-hooks -- helper accepts cwd; process.cwd() is the ad-hoc-invocation default, not a bypass of the anchor-on-script-location rule.
164168
export function getUnstagedFilesSync(cwd = process.cwd()): string[] {
165169
try {
166170
const gitRoot = getGitRoot(cwd)
@@ -185,6 +189,7 @@ export function getUnstagedFilesSync(cwd = process.cwd()): string[] {
185189
*/
186190
export async function isUnstaged(
187191
pathname: string,
192+
// oxlint-disable-next-line socket/no-process-cwd-in-scripts-hooks -- multi-arg form: default for ad-hoc invocations only.
188193
cwd = process.cwd(),
189194
): Promise<boolean> {
190195
const files = await getUnstagedFiles(cwd)
@@ -194,6 +199,7 @@ export async function isUnstaged(
194199
/**
195200
* Check if a file is unstaged synchronously.
196201
*/
202+
// oxlint-disable-next-line socket/no-process-cwd-in-scripts-hooks -- helper accepts cwd; process.cwd() is the ad-hoc-invocation default, not a bypass of the anchor-on-script-location rule.
197203
export function isUnstagedSync(pathname: string, cwd = process.cwd()): boolean {
198204
const files = getUnstagedFilesSync(cwd)
199205
return files.includes(pathname)

scripts/util/package.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* max-file-lines: legitimate — shared package.json toolkit; every helper is co-consumed by multiple npm scripts and splitting would fan-out imports without a real domain seam (only ~22 LOC over the soft cap). */
2-
/* oxlint-disable socket/prefer-cached-for-loop -- iterates Object.entries() of script tables; the cached-length rewrite would be incorrect. */
32
/**
43
* @file Common utilities for working with package.json files. Provides helper
54
* functions for reading, updating, and managing package.json files across the
@@ -344,6 +343,7 @@ export async function installPackageForTesting(
344343

345344
// Preserve test:* scripts and the exact key 'tests', but not unrelated
346345
// names like 'testsuite' that merely begin with 'tests'.
346+
// oxlint-disable-next-line socket/prefer-cached-for-loop -- iterates Object.entries() (non-array iterable); cached-length would be incorrect.
347347
for (const { 0: key, 1: value } of Object.entries(originalScripts)) {
348348
if (
349349
(key.startsWith('test:') || key === 'tests') &&

scripts/util/run-command.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/**
22
* @file Utility for running shell commands with proper error handling.
33
*/
4-
/* oxlint-disable socket/prefer-cached-for-loop -- iterates a destructured command-list record; the cached-length rewrite would be incorrect. */
54

65
import process from 'node:process'
76

@@ -79,6 +78,7 @@ export interface CommandSpec {
7978
* Run multiple commands in sequence, stopping on first failure.
8079
*/
8180
export async function runSequence(commands: CommandSpec[]): Promise<number> {
81+
// oxlint-disable-next-line socket/prefer-cached-for-loop -- destructured command-list record; the cached-length rewrite would lose the destructuring shape.
8282
for (const { args = [], command, options = {} } of commands) {
8383
// eslint-disable-next-line no-await-in-loop
8484
const exitCode = await runCommand(command, args, options)

0 commit comments

Comments
 (0)