Skip to content

Commit 888d4c0

Browse files
committed
fix(types): restore null sentinel for ObjectCreate / ReflectSetPrototypeOf
prefer-undefined-over-null autofix converted 5 sites where the Node API contract requires `null` specifically: * helpers.ts: 2× ObjectCreate(null) for null-prototype proxy targets * normalize.ts: 1× ObjectCreate(null) for qualifiers map * package-url.ts: 1× ObjectCreate(null) for qualifiers copy, 1× ReflectSetPrototypeOf(PackageURL.prototype, null) for the null-prototype prototype-chain root All flipped back to `null` with inline `socket/prefer-undefined-over-null` disables explaining the Node API constraint. tsgo check now passes.
1 parent 1693541 commit 888d4c0

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

src/helpers.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ export function createHelpersNamespaceObject(
3737
],
3838
comparator,
3939
)
40-
const nsObject: Record<string, Record<string, unknown>> = ObjectCreate(undefined)
40+
// oxlint-disable-next-line socket/prefer-undefined-over-null -- Object.create(null) / Reflect.setPrototypeOf(_, null) require the null sentinel.
41+
const nsObject: Record<string, Record<string, unknown>> = ObjectCreate(null)
4142
// Build inverted structure: property -> {helper1: value1, helper2: value2}
4243
for (let i = 0, { length } = propNames; i < length; i += 1) {
4344
const propName = propNames[i]!
44-
const helpersForProp: Record<string, unknown> = ObjectCreate(undefined)
45+
// oxlint-disable-next-line socket/prefer-undefined-over-null -- Object.create(null) / Reflect.setPrototypeOf(_, null) require the null sentinel.
46+
const helpersForProp: Record<string, unknown> = ObjectCreate(null)
4547
for (
4648
let j = 0, { length: helperNamesLength } = helperNames;
4749
j < helperNamesLength;

src/normalize.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ export function normalizeQualifiers(
114114
continue
115115
}
116116
if (qualifiers === undefined) {
117-
qualifiers = ObjectCreate(undefined) as Record<string, string>
117+
// oxlint-disable-next-line socket/prefer-undefined-over-null -- Object.create(null) / Reflect.setPrototypeOf(_, null) require the null sentinel.
118+
qualifiers = ObjectCreate(null) as Record<string, string>
118119
}
119120
// A key is case insensitive. The canonical form is lowercase
120121
qualifiers[StringPrototypeToLowerCase(key)] = trimmed

src/package-url.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ class PackageURL {
251251
result.version = this.version
252252
}
253253
if (this.qualifiers !== undefined) {
254-
const qualifiersCopy = ObjectCreate(undefined) as QualifiersObject
254+
// oxlint-disable-next-line socket/prefer-undefined-over-null -- Object.create(null) / Reflect.setPrototypeOf(_, null) require the null sentinel.
255+
const qualifiersCopy = ObjectCreate(null) as QualifiersObject
255256
for (const key of ObjectKeys(this.qualifiers)) {
256257
qualifiersCopy[key] = this.qualifiers[key]!
257258
}
@@ -897,7 +898,8 @@ for (const staticProp of ['Component', 'KnownQualifierNames', 'Type']) {
897898
})
898899
}
899900

900-
ReflectSetPrototypeOf(PackageURL.prototype, undefined)
901+
// oxlint-disable-next-line socket/prefer-undefined-over-null -- Object.create(null) / Reflect.setPrototypeOf(_, null) require the null sentinel.
902+
ReflectSetPrototypeOf(PackageURL.prototype, null)
901903

902904
// Register PackageURL with compare module for string-based comparison support.
903905
_registerPackageURL(PackageURL)

0 commit comments

Comments
 (0)