Skip to content

Commit c00463e

Browse files
committed
quality: clear prefer-exists-sync — stat-for-metadata triage
35 → 0 prefer-exists-sync violations. All are legitimate stat calls that read metadata (size, mtime) or discriminate file type (isFile, isDirectory, isSymbolicLink) — not pure existence checks. * src/fs/inspect.ts: whole file is the stat-wrapper surface; file- level oxlint-disable. * src/fs/find-up.ts: needs isFile()/isDirectory() to filter results by type; file-level disable. * src/dlx/binary.ts: DLX cache uses stat for size/mtime metadata; file-level disable. * src/dlx/detect.ts, src/ipc.ts, src/process-lock.ts, src/fs/validate.ts: inline disables — single sites, each with a one-line `--` explanation (mtime for cache, lstat for symlink discrimination, accessSync(R_OK) for permission, etc.). * scripts/build-externals/bundler.mts, scripts/validate/file-size.mts: inline disables — both read stats.size for logging / size limits. * test/unit/fs.test.mts, test/unit/process-lock.test.mts, test/unit/ipc.test.mts, test/unit/dlx/package.test.mts, test/integration/fs.test.mts: file-level disables — tests verify stat output (mtime stability, isDirectory/isFile transitions, size growth), not existence. Net: 352 → 317 violations. Remaining: 280 sort-source-methods (blocked on #65), 36 no-status-emoji (intentional test/rule-plugin/ coverage UI), 1 no-placeholders (rule plugin's fixture file).
1 parent a4fe6db commit c00463e

14 files changed

Lines changed: 22 additions & 1 deletion

File tree

scripts/build-externals/bundler.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export async function bundlePackage(packageName, outputPath, options = {}) {
103103
${contentWithoutStrict}`
104104
await fs.writeFile(outputPath, finalContent)
105105

106-
// Get file size for logging.
106+
// oxlint-disable-next-line socket/prefer-exists-sync -- need size for logging.
107107
const stats = await fs.stat(outputPath)
108108
const sizeKB = Math.round(stats.size / 1024)
109109
if (!quiet) {

scripts/validate/file-size.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export async function scanDirectory(dir, violations = []) {
7676
}
7777
} else if (entry.isFile()) {
7878
try {
79+
// oxlint-disable-next-line socket/prefer-exists-sync -- need size for size-limit check.
7980
const stats = await fs.stat(fullPath)
8081
if (stats.size > MAX_FILE_SIZE) {
8182
const relativePath = path.relative(rootPath, fullPath)

src/dlx/binary.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/** @fileoverview DLX binary execution utilities for Socket ecosystem. */
22

3+
/* oxlint-disable socket/prefer-exists-sync -- DLX binary metadata uses stat for size/mtime; not existence-only checks. */
4+
35
import process from 'node:process'
46

57
import { getArch, WIN32 } from '../constants/platform'

src/dlx/detect.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ export function readPackageJson(packageJsonPath: string): object | undefined {
166166

167167
let mtimeMs = 0
168168
try {
169+
// oxlint-disable-next-line socket/prefer-exists-sync -- need mtimeMs for cache invalidation, not just existence.
169170
mtimeMs = fs.statSync(packageJsonPath).mtimeMs
170171
} catch {
171172
packageJsonContentCache.delete(packageJsonPath)

src/fs/find-up.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* `/.foo` was never found. The current shape visits root, then breaks.
77
*/
88

9+
/* oxlint-disable socket/prefer-exists-sync -- needs stat to discriminate file vs directory matches via isFile()/isDirectory(). */
10+
911
import process from 'node:process'
1012

1113
import { isArray } from '../arrays'

src/fs/inspect.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* directly.
99
*/
1010

11+
/* oxlint-disable socket/prefer-exists-sync -- this module IS the stat-wrapper surface; callers use these for type discrimination (isFile/isDirectory) or metadata, not pure existence checks. */
12+
1113
import { defaultIgnore } from '../globs/defaults'
1214
import { getGlobMatcher } from '../globs/matcher'
1315
import { getNodeFs } from '../node/fs'

src/fs/validate.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export function validateFiles(
5252

5353
for (const filepath of filepaths) {
5454
try {
55+
// oxlint-disable-next-line socket/prefer-exists-sync -- accessSync(R_OK) checks read permission, not just existence.
5556
fs.accessSync(filepath, R_OK)
5657
validPaths.push(filepath)
5758
} catch {

src/ipc.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export async function ensureIpcDirectory(filePath: string): Promise<void> {
6767
return
6868
}
6969
/* c8 ignore stop */
70+
// oxlint-disable-next-line socket/prefer-exists-sync -- need lstat to discriminate symlink/dir via isDirectory().
7071
const stats = await fs.promises.lstat(dir)
7172
// Defensive: mkdir just succeeded so dir is a directory.
7273
/* c8 ignore start */

src/process-lock.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ class ProcessLockManager {
234234
try {
235235
// Use single statSync call instead of existsSync + statSync.
236236
// throwIfNoEntry: false returns undefined if path doesn't exist.
237+
// oxlint-disable-next-line socket/prefer-exists-sync -- need mtimeMs for staleness check; existsSync would discard the metadata.
237238
const stats = getFs().statSync(lockPath, { throwIfNoEntry: false })
238239
if (!stats) {
239240
return false

test/integration/fs.test.mts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* Used by Socket CLI for config files, package.json manipulation, and cache.
1010
*/
1111

12+
/* oxlint-disable socket/prefer-exists-sync -- tests verify stat output (isFile/isDirectory/mtime/size), not existence. */
13+
1214
import fs from 'node:fs/promises'
1315
import os from 'node:os'
1416
import path from 'node:path'

0 commit comments

Comments
 (0)