Skip to content

Commit e209c01

Browse files
committed
style(lint): lint-campaign wave 4 — 50 files (142→92 errors)
Per-file fixes via workflow fan-out across logger, eco parsers, manifest, external-tools, cacache, node wrappers, and their tests.
1 parent e9369a0 commit e209c01

57 files changed

Lines changed: 2306 additions & 2261 deletions

Some content is hidden

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

src/bin/check-primordials.ts

Lines changed: 99 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* oxlint-disable socket/sort-source-methods -- CLI handler with helper functions interleaved with module-level config constants; reordering would split state from its consumers. */
21
/**
32
* @file `socket-lib check primordials` handler. Loads a JSON config from disk
43
* (default `primordials-coverage.config.json` at the repo root, override with
@@ -63,92 +62,20 @@ interface ParsedArgs {
6362
readonly help: boolean
6463
}
6564

66-
export function parseArgs(argv: readonly string[]): ParsedArgs {
67-
const { values } = parseLibArgs({
68-
args: argv,
69-
strict: false,
70-
options: {
71-
config: { type: 'string', short: 'c' },
72-
explain: { type: 'boolean' },
73-
help: { type: 'boolean', short: 'h' },
74-
json: { type: 'boolean' },
75-
silent: { type: 'boolean' },
76-
},
77-
})
78-
// `config` is left undefined when neither `--config` nor `-c` was
79-
// passed, so the resolver below can fall back to the search list.
80-
// An explicit value short-circuits the search.
81-
const explicitConfig = values['config']
82-
return {
83-
config: typeof explicitConfig === 'string' ? explicitConfig : undefined,
84-
json: Boolean(values['json']),
85-
explain: Boolean(values['explain']),
86-
silent: Boolean(values['silent']),
87-
help: Boolean(values['help']),
88-
}
89-
}
90-
91-
/**
92-
* Pick the config file. Returns the explicit `--config` argument when given
93-
* (even if it doesn't exist — the caller will surface the error with the path
94-
* they typed). Otherwise probes the fallback list in order and returns the
95-
* first hit. Returns the head of the list when none exist, so the caller's
96-
* "config file not found" error message names the canonical default.
97-
*/
98-
export function resolveConfigPath(explicit: string | undefined): string {
99-
if (explicit !== undefined) {
100-
return explicit
101-
}
102-
for (let i = 0, { length } = FALLBACK_CONFIG_PATHS; i < length; i += 1) {
103-
const candidate = FALLBACK_CONFIG_PATHS[i]!
104-
if (existsSync(path.resolve(candidate))) {
105-
return candidate
106-
}
107-
}
108-
return FALLBACK_CONFIG_PATHS[0]!
109-
}
110-
111-
export function printHelp(): void {
112-
logger.log('socket-lib check primordials — primordials drift check')
113-
logger.log('')
114-
logger.log('Usage:')
115-
logger.log(' socket-lib check primordials [opts]')
116-
logger.log(' socket-lib check prim [opts] # short alias')
117-
logger.log('')
118-
logger.log('Options:')
119-
logger.log(
120-
` --config, -c <path> Config file. Default: ${DEFAULT_CONFIG_PATH}`,
121-
)
122-
logger.log(` (falls back to .config/socket-lib.json)`)
123-
logger.log(' --explain Print one detailed line per finding.')
124-
logger.log(' --json Machine-readable JSON output.')
125-
logger.log(' --silent Silent on success.')
126-
logger.log(' --help, -h Print this help.')
127-
logger.log('')
128-
logger.log('Config (.socket-lib.json — primordials section):')
129-
logger.log(' {')
130-
logger.log(' "primordials": {')
131-
logger.log(
132-
' "scanDirs": ["src", "additions/source-patched/lib"]',
133-
)
134-
logger.log(' }')
135-
logger.log(' }')
136-
logger.log('')
137-
logger.log('Only `scanDirs` is required. `aliasMap` and `nodeInternalOnly`')
138-
logger.log('default to the fleet-canonical sets and only need entries when')
139-
logger.log('your repo extends or overrides them.')
140-
logger.log('')
141-
logger.log('A bare object (no `primordials` section) is also accepted for')
142-
logger.log('repos that only run this one check.')
143-
}
144-
14565
interface RawConfig {
14666
scanDirs?: unknown | undefined
14767
aliasMap?: unknown | undefined
14868
nodeInternalOnly?: unknown | undefined
14969
socketLibPrimordialsPath?: unknown | undefined
15070
}
15171

72+
interface SerializedFinding {
73+
kind: PrimordialsFinding['kind']
74+
name: string
75+
files: readonly string[]
76+
hint: string
77+
}
78+
15279
export function loadConfig(configPath: string): PrimordialsCheckConfig {
15380
if (!existsSync(configPath)) {
15481
throw new ErrorCtor(`config file not found: ${configPath}`)
@@ -229,30 +156,65 @@ export function loadConfig(configPath: string): PrimordialsCheckConfig {
229156
}
230157
}
231158

232-
interface SerializedFinding {
233-
kind: PrimordialsFinding['kind']
234-
name: string
235-
files: readonly string[]
236-
hint: string
237-
}
238-
239-
export function serialize(result: PrimordialsCheckResult): {
240-
ok: boolean
241-
used: number
242-
findings: SerializedFinding[]
243-
} {
159+
export function parseArgs(argv: readonly string[]): ParsedArgs {
160+
const { values } = parseLibArgs({
161+
args: argv,
162+
strict: false,
163+
options: {
164+
config: { type: 'string', short: 'c' },
165+
explain: { type: 'boolean' },
166+
help: { type: 'boolean', short: 'h' },
167+
json: { type: 'boolean' },
168+
silent: { type: 'boolean' },
169+
},
170+
})
171+
// `config` is left undefined when neither `--config` nor `-c` was
172+
// passed, so the resolver below can fall back to the search list.
173+
// An explicit value short-circuits the search.
174+
const explicitConfig = values['config']
244175
return {
245-
ok: result.findings.length === 0,
246-
used: result.used.size,
247-
findings: result.findings.map(f => ({
248-
kind: f.kind,
249-
name: f.name,
250-
files: f.files,
251-
hint: f.hint,
252-
})),
176+
config: typeof explicitConfig === 'string' ? explicitConfig : undefined,
177+
json: Boolean(values['json']),
178+
explain: Boolean(values['explain']),
179+
silent: Boolean(values['silent']),
180+
help: Boolean(values['help']),
253181
}
254182
}
255183

184+
export function printHelp(): void {
185+
logger.log('socket-lib check primordials — primordials drift check')
186+
logger.log('')
187+
logger.log('Usage:')
188+
logger.log(' socket-lib check primordials [opts]')
189+
logger.log(' socket-lib check prim [opts] # short alias')
190+
logger.log('')
191+
logger.log('Options:')
192+
logger.log(
193+
` --config, -c <path> Config file. Default: ${DEFAULT_CONFIG_PATH}`,
194+
)
195+
logger.log(` (falls back to .config/socket-lib.json)`)
196+
logger.log(' --explain Print one detailed line per finding.')
197+
logger.log(' --json Machine-readable JSON output.')
198+
logger.log(' --silent Silent on success.')
199+
logger.log(' --help, -h Print this help.')
200+
logger.log('')
201+
logger.log('Config (.socket-lib.json — primordials section):')
202+
logger.log(' {')
203+
logger.log(' "primordials": {')
204+
logger.log(
205+
' "scanDirs": ["src", "additions/source-patched/lib"]',
206+
)
207+
logger.log(' }')
208+
logger.log(' }')
209+
logger.log('')
210+
logger.log('Only `scanDirs` is required. `aliasMap` and `nodeInternalOnly`')
211+
logger.log('default to the fleet-canonical sets and only need entries when')
212+
logger.log('your repo extends or overrides them.')
213+
logger.log('')
214+
logger.log('A bare object (no `primordials` section) is also accepted for')
215+
logger.log('repos that only run this one check.')
216+
}
217+
256218
export function renderHuman(
257219
result: PrimordialsCheckResult,
258220
args: ParsedArgs,
@@ -283,6 +245,26 @@ export function renderHuman(
283245
}
284246
}
285247

248+
/**
249+
* Pick the config file. Returns the explicit `--config` argument when given
250+
* (even if it doesn't exist — the caller will surface the error with the path
251+
* they typed). Otherwise probes the fallback list in order and returns the
252+
* first hit. Returns the head of the list when none exist, so the caller's
253+
* "config file not found" error message names the canonical default.
254+
*/
255+
export function resolveConfigPath(explicit: string | undefined): string {
256+
if (explicit !== undefined) {
257+
return explicit
258+
}
259+
for (let i = 0, { length } = FALLBACK_CONFIG_PATHS; i < length; i += 1) {
260+
const candidate = FALLBACK_CONFIG_PATHS[i]!
261+
if (existsSync(path.resolve(candidate))) {
262+
return candidate
263+
}
264+
}
265+
return FALLBACK_CONFIG_PATHS[0]!
266+
}
267+
286268
export async function runCheckPrimordials(
287269
argv: readonly string[],
288270
): Promise<number> {
@@ -312,3 +294,20 @@ export async function runCheckPrimordials(
312294
}
313295
return result.findings.length === 0 ? 0 : 1
314296
}
297+
298+
export function serialize(result: PrimordialsCheckResult): {
299+
ok: boolean
300+
used: number
301+
findings: SerializedFinding[]
302+
} {
303+
return {
304+
ok: result.findings.length === 0,
305+
used: result.used.size,
306+
findings: result.findings.map(f => ({
307+
kind: f.kind,
308+
name: f.name,
309+
files: f.files,
310+
hint: f.hint,
311+
})),
312+
}
313+
}

src/cacache/read.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export async function get(
3333
'Cache key cannot contain wildcards (*). Wildcards are only supported in clear({ prefix: "pattern*" }).',
3434
)
3535
}
36-
const cacache = getCacache() as any
36+
const cacache = getCacache()
3737
/* c8 ignore next - External cacache call */
3838
return await cacache.get(getSocketCacacheDir(), key, options)
3939
}

src/cacache/write.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export async function remove(key: string): Promise<unknown> {
5353
'Cache key cannot contain wildcards (*). Use clear({ prefix: "pattern*" }) to remove multiple entries.',
5454
)
5555
}
56-
const cacache = getCacache() as any
56+
const cacache = getCacache()
5757
/* c8 ignore next - External cacache call */
5858
return await cacache.rm.entry(getSocketCacacheDir(), key)
5959
}

src/compression/_internal.ts

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* oxlint-disable socket/sort-source-methods -- internal helpers ordered by call graph; type/const declarations sandwiched between them block autofix. */
21
/**
32
* @file Private internals for `compression/*` modules — `resolveFileArgs`
43
* disambiguates the `(src, dest, options?)` vs `(src, options)` calling
@@ -10,32 +9,11 @@
109
import path from 'node:path'
1110

1211
import { ErrorCtor } from '../primordials/error'
12+
import { ObjectFreeze } from '../primordials/object'
1313
import { StringPrototypeToLowerCase } from '../primordials/string'
1414

1515
import type { CompressFileOptions, CompressOptions } from './types'
1616

17-
import { ObjectFreeze } from '../primordials/object'
18-
19-
/**
20-
* Strip the trailing extension from a filename when it matches one of `exts`.
21-
* Returns the input unchanged when the trailing extname isn't in the set.
22-
* Case-insensitive on the extension — preserves the rest of the path's casing.
23-
*
24-
* The `exts` set decides what counts. Pass `BROTLI_EXTS` / `GZIP_EXTS` for the
25-
* canonical compression sets, or your own set for custom classifiers.
26-
*
27-
* Generic — it does NOT know that `.tgz` is short for `.tar.gz`. Callers that
28-
* need that convention compose this with their own follow-up (see
29-
* `decompressGzipFile` for the canonical example).
30-
*/
31-
export function stripExt(filePath: string, exts: ReadonlySet<string>): string {
32-
const ext = path.extname(filePath)
33-
if (!exts.has(StringPrototypeToLowerCase(ext))) {
34-
return filePath
35-
}
36-
return filePath.slice(0, -ext.length)
37-
}
38-
3917
export interface ResolvedFileArgs {
4018
destPath: string
4119
options: CompressOptions | undefined
@@ -82,3 +60,23 @@ export function resolveFileArgs(
8260
`${fnName}: missing destPath; pass an explicit destination or { inPlace: true }`,
8361
)
8462
}
63+
64+
/**
65+
* Strip the trailing extension from a filename when it matches one of `exts`.
66+
* Returns the input unchanged when the trailing extname isn't in the set.
67+
* Case-insensitive on the extension — preserves the rest of the path's casing.
68+
*
69+
* The `exts` set decides what counts. Pass `BROTLI_EXTS` / `GZIP_EXTS` for the
70+
* canonical compression sets, or your own set for custom classifiers.
71+
*
72+
* Generic — it does NOT know that `.tgz` is short for `.tar.gz`. Callers that
73+
* need that convention compose this with their own follow-up (see
74+
* `decompressGzipFile` for the canonical example).
75+
*/
76+
export function stripExt(filePath: string, exts: ReadonlySet<string>): string {
77+
const ext = path.extname(filePath)
78+
if (!exts.has(StringPrototypeToLowerCase(ext))) {
79+
return filePath
80+
}
81+
return filePath.slice(0, -ext.length)
82+
}

src/debug/_internal.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { getNodeUtil } from '../node/util'
2323
// New code should import getNodeUtil from '@socketsecurity/lib/node/util'.
2424
export { getNodeUtil as getUtil } from '../node/util'
2525

26-
let _pointingTriangle: string | undefined
26+
let pointingTriangle: string | undefined
2727

2828
/**
2929
* Custom log function for debug output.
@@ -67,10 +67,10 @@ export function customLog(...args: unknown[]) {
6767
one of the 5 debug functions hits the body. The unicode-fallback
6868
arm also fires only on terminals without unicode support. */
6969
export function getPointingTriangle(): string {
70-
if (_pointingTriangle === undefined) {
70+
if (pointingTriangle === undefined) {
7171
const supported = isUnicodeSupported()
72-
_pointingTriangle = supported ? '▸' : '>'
72+
pointingTriangle = supported ? '▸' : '>'
7373
}
74-
return _pointingTriangle
74+
return pointingTriangle
7575
}
7676
/* c8 ignore stop */

src/eco/cargo/parse-lockfile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* (parseCargoLock)
2828
* 4. **Cargo's own lockfile encoder** — the source of truth for the format we're
2929
* parsing:
30-
* https://github.com/rust-lang/cargo/blob/master/src/cargo/core/resolver/encode.rs
30+
* https://github.com/rust-lang/cargo/blob/0.86.0/src/cargo/core/resolver/encode.rs
3131
* Lockfile format docs:
3232
* https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
3333
* https://doc.rust-lang.org/cargo/reference/resolver.html#lockfile-format

src/eco/manifest/analyze-lockfile.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export function jsAnalyzeLockfile(lockfile: ParsedLockfile): LockfileStats {
4646
}) as unknown as LockfileStats
4747
}
4848

49-
const _smol = getSmolManifest()
49+
const smol = getSmolManifest()
5050

5151
export const analyzeLockfile: (lockfile: ParsedLockfile) => LockfileStats =
52-
_smol ? _smol.analyzeLockfile : jsAnalyzeLockfile
52+
smol ? smol.analyzeLockfile : jsAnalyzeLockfile

src/eco/manifest/find-packages.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ export function jsFindPackages(
5151
return result
5252
}
5353

54-
const _smol = getSmolManifest()
54+
const smol = getSmolManifest()
5555

5656
export const findPackages: (
5757
lockfile: ParsedLockfile,
5858
pattern: string | RegExp,
59-
) => readonly PackageRef[] = _smol ? _smol.findPackages : jsFindPackages
59+
) => readonly PackageRef[] = smol ? smol.findPackages : jsFindPackages

src/eco/manifest/get-package-versions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ export function jsGetPackageVersions(
3030
return result
3131
}
3232

33-
const _smol = getSmolManifest()
33+
const smol = getSmolManifest()
3434

3535
export const getPackageVersions: (
3636
lockfile: ParsedLockfile,
3737
name: string,
38-
) => readonly PackageRef[] = _smol
39-
? _smol.getPackageVersions
38+
) => readonly PackageRef[] = smol
39+
? smol.getPackageVersions
4040
: jsGetPackageVersions

0 commit comments

Comments
 (0)