Skip to content

Commit 7319f31

Browse files
committed
refactor: drop leading underscores from module-private identifiers
Per the fleet's socket/no-underscore-identifier rule, 12 module-private identifiers in scripts/ and test/ had leading underscores stripped: - scripts/constants/{node,utils}.mts: platform, gitExecPath, tsxExecPath, defaultWhichOptions, licenseContent, gitIgnorePatterns, ignoreGlobs - scripts/util/{tests,packages,templates}.mts: cliArgs, cachedTestNpmPackageJson, templates - test/npm/{has-symbols,json-stable-stringify}.test.mts: key, jsonStableStringifyModule One rule-interaction tweak: test/npm/has-symbols.test.mts renamed `_key` to `key`. The loop body uses the binding only as a sentinel (if a `for...in` enumerates ANY key, the test fails). After the rename, eslint/no-unused-vars + TS6133 would flag it; the `expect.fail()` message now interpolates `String(key)`, preserving test intent while marking the binding as used. Also: allowlist acorn.wasm in the local scripts/validation/file-size.mts (mirrors the wheelhouse-canonical fix; socket-registry has its own validator path). Verified: pnpm run check --all passes; pnpm test = 2184 tests, all green.
1 parent 70cae99 commit 7319f31

9 files changed

Lines changed: 69 additions & 51 deletions

File tree

pnpm-lock.yaml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/constants/node.mts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
import os from 'node:os'
66

7-
const _platform = os.platform()
8-
export const DARWIN = _platform === 'darwin'
9-
export const WIN32 = _platform === 'win32'
7+
const platform = os.platform()
8+
export const DARWIN = platform === 'darwin'
9+
export const WIN32 = platform === 'win32'
1010

1111
export const NEWLINE = os.EOL
1212

scripts/constants/utils.mts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,78 +20,78 @@ import {
2020
/**
2121
* Get cached default which command options with augmented PATH.
2222
*/
23-
let _defaultWhichOptions: { path: string } | undefined
23+
let defaultWhichOptions: { path: string } | undefined
2424
export function getDefaultWhichOptions(): { path: string } {
25-
if (_defaultWhichOptions === undefined) {
26-
_defaultWhichOptions = {
25+
if (defaultWhichOptions === undefined) {
26+
defaultWhichOptions = {
2727
__proto__: null,
2828
path: `${ROOT_NODE_MODULES_BIN_PATH}${path.delimiter}${process.env['PATH']}`,
2929
} as { path: string }
3030
}
31-
return _defaultWhichOptions!
31+
return defaultWhichOptions!
3232
}
3333

3434
/**
3535
* Get root LICENSE file content.
3636
*/
37-
let _licenseContent: string | undefined
37+
let licenseContent: string | undefined
3838
export function getLicenseContent(): string {
39-
if (_licenseContent === undefined) {
40-
_licenseContent = readFileSync(ROOT_LICENSE_PATH, 'utf8')
39+
if (licenseContent === undefined) {
40+
licenseContent = readFileSync(ROOT_LICENSE_PATH, 'utf8')
4141
}
42-
return _licenseContent!
42+
return licenseContent!
4343
}
4444

4545
/**
4646
* Get git executable path.
4747
*/
48-
let _gitExecPath: string | undefined
48+
let gitExecPath: string | undefined
4949
export function getGitExecPath(): string {
50-
if (_gitExecPath === undefined) {
51-
_gitExecPath = which.sync('git', getDefaultWhichOptions())
50+
if (gitExecPath === undefined) {
51+
gitExecPath = which.sync('git', getDefaultWhichOptions())
5252
}
53-
return _gitExecPath!
53+
return gitExecPath!
5454
}
5555

5656
/**
5757
* Get tsx executable path.
5858
*/
59-
let _tsxExecPath: string | undefined
59+
let tsxExecPath: string | undefined
6060
export function getTsxExecPath(): string {
61-
if (_tsxExecPath === undefined) {
61+
if (tsxExecPath === undefined) {
6262
const tsxPath = path.join(ROOT_NODE_MODULES_BIN_PATH, 'tsx')
6363
if (existsSync(tsxPath)) {
64-
_tsxExecPath = tsxPath
64+
tsxExecPath = tsxPath
6565
} else {
66-
_tsxExecPath = which.sync('tsx', getDefaultWhichOptions())
66+
tsxExecPath = which.sync('tsx', getDefaultWhichOptions())
6767
}
6868
}
69-
return _tsxExecPath!
69+
return tsxExecPath!
7070
}
7171

7272
/**
7373
* Parse gitignore file and return ignore patterns.
7474
*/
75-
let _gitIgnorePatterns: string[] | undefined
75+
let gitIgnorePatterns: string[] | undefined
7676
export function getGitIgnorePatterns(): string[] {
77-
if (_gitIgnorePatterns === undefined) {
77+
if (gitIgnorePatterns === undefined) {
7878
const gitignorePath = path.join(ROOT_PATH, '.gitignore')
7979
const content = readFileSync(gitignorePath, 'utf8')
80-
_gitIgnorePatterns = content
80+
gitIgnorePatterns = content
8181
.split('\n')
8282
.map(line => line.trim())
8383
.filter(line => line && !line.startsWith('#'))
8484
}
85-
return _gitIgnorePatterns!
85+
return gitIgnorePatterns!
8686
}
8787

8888
/**
8989
* Get merged ignore globs from gitignore and standard exclusions.
9090
*/
91-
let _ignoreGlobs: readonly string[] | undefined
91+
let ignoreGlobs: readonly string[] | undefined
9292
export function getIgnoreGlobs(): readonly string[] {
93-
if (_ignoreGlobs === undefined) {
94-
_ignoreGlobs = Object.freeze([
93+
if (ignoreGlobs === undefined) {
94+
ignoreGlobs = Object.freeze([
9595
// oxlint-disable-next-line socket/sort-set-args -- spread + template strings, non-sortable
9696
...new Set([
9797
// Most of these ignored files can be included specifically if included in the
@@ -108,7 +108,7 @@ export function getIgnoreGlobs(): readonly string[] {
108108
]),
109109
])
110110
}
111-
return _ignoreGlobs!
111+
return ignoreGlobs!
112112
}
113113

114114
/**

scripts/util/packages.mts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@ import { hasOwn } from '@socketsecurity/lib-stable/objects'
1010

1111
const __dirname = path.dirname(fileURLToPath(import.meta.url))
1212

13-
let _cachedTestNpmPackageJson
13+
let cachedTestNpmPackageJson
1414

1515
/**
1616
* Get cached test npm package.json.
1717
*/
1818
export function getTestNpmPackageJson() {
19-
if (_cachedTestNpmPackageJson === undefined) {
19+
if (cachedTestNpmPackageJson === undefined) {
2020
const testNpmPackageJsonPath = path.resolve(
2121
__dirname,
2222
'../../test/npm/package.json',
2323
)
24-
_cachedTestNpmPackageJson = JSON.parse(
24+
cachedTestNpmPackageJson = JSON.parse(
2525
readFileSync(testNpmPackageJsonPath, 'utf8'),
2626
)
2727
}
28-
return _cachedTestNpmPackageJson
28+
return cachedTestNpmPackageJson
2929
}
3030

3131
/**

scripts/util/templates.mts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ export async function getEta() {
7474
return eta
7575
}
7676

77-
let _templates
77+
let templates
7878
export function getTemplates() {
79-
if (_templates === undefined) {
80-
_templates = Object.freeze({
79+
if (templates === undefined) {
80+
templates = Object.freeze({
8181
__proto__: null,
8282
...Object.fromEntries(
8383
[
@@ -91,7 +91,7 @@ export function getTemplates() {
9191
),
9292
})
9393
}
94-
return _templates
94+
return templates
9595
}
9696

9797
/**

scripts/util/tests.mts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import process from 'node:process'
77

88
import { parseArgs } from '@socketsecurity/lib-stable/argv/parse'
99

10-
let _cliArgs: Record<string, unknown> | undefined
10+
let cliArgs: Record<string, unknown> | undefined
1111

1212
/**
1313
* Parse and cache command line arguments.
1414
*/
1515
function getCliArgs() {
16-
if (_cliArgs === undefined) {
16+
if (cliArgs === undefined) {
1717
const { values } = parseArgs({
1818
options: {
1919
force: {
@@ -26,9 +26,9 @@ function getCliArgs() {
2626
},
2727
strict: false,
2828
})
29-
_cliArgs = values
29+
cliArgs = values
3030
}
31-
return _cliArgs
31+
return cliArgs
3232
}
3333

3434
/**

scripts/validation/file-size.mts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ const rootPath = path.join(__dirname, '..', '..')
2323
// Maximum file size: 2MB (2,097,152 bytes)
2424
const MAX_FILE_SIZE = 2 * 1024 * 1024
2525

26+
// Allowlisted large files: fleet-canonical assets whose size is bounded by
27+
// the upstream they ship, not by repo authoring. acorn.wasm is the AST
28+
// parser shared by AST-based oxlint plugin rules + hooks; ~3MB is the
29+
// upstream build artifact.
30+
const ALLOWED_LARGE_FILES = new Set<string>([
31+
'.claude/hooks/_shared/acorn/acorn.wasm',
32+
'vendor/acorn-wasm/acorn.wasm',
33+
])
34+
2635
// Directories to skip
2736
const SKIP_DIRS = new Set([
2837
'.cache',
@@ -81,6 +90,9 @@ export async function scanDirectory(dir, violations = []) {
8190
const stats = await fs.stat(fullPath)
8291
if (stats.size > MAX_FILE_SIZE) {
8392
const relativePath = path.relative(rootPath, fullPath)
93+
if (ALLOWED_LARGE_FILES.has(relativePath)) {
94+
continue
95+
}
8496
violations.push({
8597
file: relativePath,
8698
size: stats.size,

test/npm/has-symbols.test.mts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ describe(`${eco} > ${sockRegPkgName}`, { skip }, () => {
4646
const sym = Symbol('test')
4747
obj[sym] = 42
4848

49-
for (const _key in obj) {
50-
expect.fail('symbol property key was found in for..in of object')
49+
for (const key in obj) {
50+
expect.fail(
51+
`symbol property key ${String(key)} was found in for..in of object`,
52+
)
5153
}
5254

5355
expect(Object.keys(obj)).toEqual([])

test/npm/json-stable-stringify.test.mts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe(
1818
},
1919
() => {
2020
const pkgRequireIndexJsPath = `${pkgPath}/index.js`
21-
const _jsonStableStringifyModule =
21+
const jsonStableStringifyModule =
2222
skip || ENV.CI ? undefined : require(pkgRequireIndexJsPath)
2323

2424
const rawJSON: ((_str: string) => { rawJSON: string }) | undefined = (
@@ -33,7 +33,7 @@ describe(
3333
]) {
3434
it(`${methodName}: space parameter (nested objects)`, () => {
3535
const obj = { one: 1, two: { b: 4, a: [2, 3] } }
36-
expect(_jsonStableStringifyModule(obj, { space: ' ' })).toBe(
36+
expect(jsonStableStringifyModule(obj, { space: ' ' })).toBe(
3737
'' +
3838
'{\n' +
3939
' "one": 1,\n' +
@@ -51,36 +51,36 @@ describe(
5151
it(`${methodName}: space parameter (same as native)`, () => {
5252
// For this test, properties need to be in alphabetical order.
5353
const obj = { one: 1, two: { a: [2, 3], b: 4 } }
54-
expect(_jsonStableStringifyModule(obj, { space: ' ' })).toBe(
54+
expect(jsonStableStringifyModule(obj, { space: ' ' })).toBe(
5555
JSON.stringify(obj, null, ' '),
5656
)
5757
})
5858

5959
it(`${methodName}: space parameter base empty behavior: empty arrays and objects have added newline and space`, () => {
6060
const obj = { emptyArr: [], emptyObj: {} }
61-
expect(_jsonStableStringifyModule(obj, { space: ' ' })).toBe(
61+
expect(jsonStableStringifyModule(obj, { space: ' ' })).toBe(
6262
'{\n "emptyArr": [\n ],\n "emptyObj": {\n }\n}',
6363
)
6464
})
6565

6666
it(`${methodName}: space parameter, with collapseEmpty: true`, () => {
6767
const obj = { emptyArr: [], emptyObj: {} }
6868
expect(() => {
69-
_jsonStableStringifyModule(obj, { collapseEmpty: 'not a boolean' })
69+
jsonStableStringifyModule(obj, { collapseEmpty: 'not a boolean' })
7070
}).toThrow(TypeError)
7171
expect(
72-
_jsonStableStringifyModule(obj, { collapseEmpty: true, space: ' ' }),
72+
jsonStableStringifyModule(obj, { collapseEmpty: true, space: ' ' }),
7373
).toBe('{\n "emptyArr": [],\n "emptyObj": {}\n}')
7474
})
7575

7676
it(
7777
`${methodName}: supports JSON.rawJSON`,
78-
{ skip: !SUPPORTS_JSON_RAW_JSON || !_jsonStableStringifyModule },
78+
{ skip: !SUPPORTS_JSON_RAW_JSON || !jsonStableStringifyModule },
7979
() => {
8080
// Test case from MDN example:
8181
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/isRawJSON#examples
8282
expect(
83-
_jsonStableStringifyModule({
83+
jsonStableStringifyModule({
8484
name: 'Josh',
8585
userId: rawJSON?.('12345678901234567890'),
8686
friends: [
@@ -114,7 +114,7 @@ describe(
114114
return result
115115
}
116116
expect(() =>
117-
_jsonStableStringifyModule(createCallStackBusterObject()),
117+
jsonStableStringifyModule(createCallStackBusterObject()),
118118
).not.toThrow()
119119
})
120120
}

0 commit comments

Comments
 (0)