Skip to content

Commit 0a342c8

Browse files
committed
fix: add curly braces for oxlint, update moduleResolution to bundler
- Add braces to all single-line if/for-of statements (eslint/curly: all) - Change moduleResolution from node to bundler in tsconfig.json and tsconfig.dts.json (node10 removed in tsgo)
1 parent 22d639d commit 0a342c8

4 files changed

Lines changed: 80 additions & 28 deletions

File tree

.config/esbuild.config.mjs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ function buildPathMap(modulePaths) {
5151

5252
for (const longPath of modulePaths) {
5353
const info = extractPackageInfo(longPath)
54-
if (!info) continue
54+
if (!info) {
55+
continue
56+
}
5557

5658
const shortPath = `${info.packageName}/${info.subpath}`
5759
if (!shortPathGroups.has(shortPath)) {
@@ -123,7 +125,9 @@ function createPathShorteningPlugin() {
123125
}
124126

125127
function collectPaths(node) {
126-
if (!node || typeof node !== 'object') return
128+
if (!node || typeof node !== 'object') {
129+
return
130+
}
127131

128132
if (
129133
node.type === 'StringLiteral' &&
@@ -133,11 +137,14 @@ function createPathShorteningPlugin() {
133137
}
134138

135139
for (const key of Object.keys(node)) {
136-
if (key === 'start' || key === 'end' || key === 'loc')
140+
if (key === 'start' || key === 'end' || key === 'loc') {
137141
continue
142+
}
138143
const value = node[key]
139144
if (Array.isArray(value)) {
140-
for (const item of value) collectPaths(item)
145+
for (const item of value) {
146+
collectPaths(item)
147+
}
141148
} else {
142149
collectPaths(value)
143150
}
@@ -169,7 +176,9 @@ function createPathShorteningPlugin() {
169176
}
170177

171178
function applyReplacements(node) {
172-
if (!node || typeof node !== 'object') return
179+
if (!node || typeof node !== 'object') {
180+
return
181+
}
173182

174183
if (
175184
node.type === 'StringLiteral' &&
@@ -187,11 +196,14 @@ function createPathShorteningPlugin() {
187196
}
188197

189198
for (const key of Object.keys(node)) {
190-
if (key === 'start' || key === 'end' || key === 'loc')
199+
if (key === 'start' || key === 'end' || key === 'loc') {
191200
continue
201+
}
192202
const value = node[key]
193203
if (Array.isArray(value)) {
194-
for (const item of value) applyReplacements(item)
204+
for (const item of value) {
205+
applyReplacements(item)
206+
}
195207
} else {
196208
applyReplacements(value)
197209
}

.config/tsconfig.dts.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
"declarationMap": false,
66
"emitDeclarationOnly": true,
77
"module": "commonjs",
8-
"moduleResolution": "node",
8+
"moduleResolution": "bundler",
99
"outDir": "../dist",
1010
"rootDir": "../src",
11+
"types": ["node"],
1112
"verbatimModuleSyntax": false
1213
},
1314
"include": ["../src/**/*.ts"]

src/vers.ts

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -123,29 +123,43 @@ function parseSemver(version: string): SemverParts {
123123
*/
124124
function comparePrereleases(a: string[], b: string[]): number {
125125
// No prerelease has higher precedence than any prerelease
126-
if (a.length === 0 && b.length === 0) return 0
127-
if (a.length === 0) return 1
128-
if (b.length === 0) return -1
126+
if (a.length === 0 && b.length === 0) {
127+
return 0
128+
}
129+
if (a.length === 0) {
130+
return 1
131+
}
132+
if (b.length === 0) {
133+
return -1
134+
}
129135

130136
const len = Math.min(a.length, b.length)
131137
for (let i = 0; i < len; i += 1) {
132138
const ai = a[i]!
133139
const bi = b[i]!
134-
if (ai === bi) continue
140+
if (ai === bi) {
141+
continue
142+
}
135143
const aNum = RegExpPrototypeTest(DIGITS_ONLY, ai)
136144
const bNum = RegExpPrototypeTest(DIGITS_ONLY, bi)
137145
// Numeric identifiers always have lower precedence than alphanumeric
138146
if (aNum && bNum) {
139147
const diff = Number(ai) - Number(bi)
140-
if (diff !== 0) return diff < 0 ? -1 : 1
148+
if (diff !== 0) {
149+
return diff < 0 ? -1 : 1
150+
}
141151
} else if (aNum) {
142152
return -1
143153
} else if (bNum) {
144154
return 1
145155
} else {
146156
// Alphanumeric: lexicographic comparison
147-
if (ai < bi) return -1
148-
if (ai > bi) return 1
157+
if (ai < bi) {
158+
return -1
159+
}
160+
if (ai > bi) {
161+
return 1
162+
}
149163
}
150164
}
151165
// Larger set of pre-release fields has higher precedence
@@ -164,12 +178,20 @@ function compareSemver(a: string, b: string): -1 | 0 | 1 {
164178
const pa = parseSemver(a)
165179
const pb = parseSemver(b)
166180
// Compare major.minor.patch
167-
if (pa.major !== pb.major) return pa.major < pb.major ? -1 : 1
168-
if (pa.minor !== pb.minor) return pa.minor < pb.minor ? -1 : 1
169-
if (pa.patch !== pb.patch) return pa.patch < pb.patch ? -1 : 1
181+
if (pa.major !== pb.major) {
182+
return pa.major < pb.major ? -1 : 1
183+
}
184+
if (pa.minor !== pb.minor) {
185+
return pa.minor < pb.minor ? -1 : 1
186+
}
187+
if (pa.patch !== pb.patch) {
188+
return pa.patch < pb.patch ? -1 : 1
189+
}
170190
// Compare prerelease
171191
const pre = comparePrereleases(pa.prerelease, pb.prerelease)
172-
if (pre !== 0) return pre < 0 ? -1 : 1
192+
if (pre !== 0) {
193+
return pre < 0 ? -1 : 1
194+
}
173195
return 0
174196
}
175197

@@ -396,10 +418,16 @@ class Vers {
396418
}
397419
// Version >= lower bound — check upper bound
398420
const next = ranges[i + 1]
399-
if (!next) return true
421+
if (!next) {
422+
return true
423+
}
400424
const cmpNext = compareSemver(version, next.version)
401-
if (next.comparator === '<' && cmpNext < 0) return true
402-
if (next.comparator === '<=' && cmpNext <= 0) return true
425+
if (next.comparator === '<' && cmpNext < 0) {
426+
return true
427+
}
428+
if (next.comparator === '<=' && cmpNext <= 0) {
429+
return true
430+
}
403431
// Outside this range's upper bound — advance past it and try next range
404432
i += 1
405433
} else if (c.comparator === '>') {
@@ -413,17 +441,27 @@ class Vers {
413441
}
414442
// Version > lower bound — check upper bound
415443
const next = ranges[i + 1]
416-
if (!next) return true
444+
if (!next) {
445+
return true
446+
}
417447
const cmpNext = compareSemver(version, next.version)
418-
if (next.comparator === '<' && cmpNext < 0) return true
419-
if (next.comparator === '<=' && cmpNext <= 0) return true
448+
if (next.comparator === '<' && cmpNext < 0) {
449+
return true
450+
}
451+
if (next.comparator === '<=' && cmpNext <= 0) {
452+
return true
453+
}
420454
// Outside this range's upper bound — advance past it and try next range
421455
i += 1
422456
} else if (c.comparator === '<' || c.comparator === '<=') {
423457
// Leading less-than without a preceding lower bound
424458
const cmpVal = compareSemver(version, c.version)
425-
if (c.comparator === '<' && cmpVal < 0) return true
426-
if (c.comparator === '<=' && cmpVal <= 0) return true
459+
if (c.comparator === '<' && cmpVal < 0) {
460+
return true
461+
}
462+
if (c.comparator === '<=' && cmpVal <= 0) {
463+
return true
464+
}
427465
// Not in this range — continue to next
428466
}
429467
}

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
"extends": "./.config/tsconfig.base.json",
33
"compilerOptions": {
44
"module": "commonjs",
5-
"moduleResolution": "node",
5+
"moduleResolution": "bundler",
66
"outDir": "dist",
77
"rootDir": "src",
8+
"types": ["node"],
89
"verbatimModuleSyntax": false,
910
"noEmit": false,
1011
"noEmitOnError": false,

0 commit comments

Comments
 (0)