Skip to content

Commit 7ca23fa

Browse files
cmdcolinclaude
andcommitted
fix non-null assertion lint errors
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent db0b6f1 commit 7ca23fa

6 files changed

Lines changed: 23 additions & 20 deletions

File tree

.github/workflows/push.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ jobs:
99
steps:
1010
- uses: actions/checkout@v4
1111
- uses: pnpm/action-setup@v4
12+
with:
13+
version: 10
1214
- uses: actions/setup-node@v4
1315
with:
1416
node-version: 22.x

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pnpm-lock.yaml

src/Variant.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class Variant {
4646
const fields = line.slice(0, splitPos).split('\t')
4747
const rest = line.slice(splitPos + 1)
4848
const [CHROM, POS, ID, REF, ALT, QUAL, FILTER] = fields
49-
const filter = FILTER === '.' ? undefined : FILTER!.split(';')
49+
const filter = FILTER === '.' ? undefined : FILTER?.split(';')
5050

5151
if (strict && !fields[7]) {
5252
throw new Error(
@@ -55,11 +55,11 @@ export class Variant {
5555
}
5656

5757
this.CHROM = CHROM
58-
this.POS = +POS!
59-
this.ID = ID === '.' ? undefined : ID!.split(';')
58+
this.POS = POS !== undefined ? +POS : 0
59+
this.ID = ID === '.' ? undefined : ID?.split(';')
6060
this.REF = REF
61-
this.ALT = ALT === '.' ? undefined : ALT!.split(',')
62-
this.QUAL = QUAL === '.' ? undefined : +QUAL!
61+
this.ALT = ALT === '.' ? undefined : ALT?.split(',')
62+
this.QUAL = QUAL === '.' ? undefined : QUAL !== undefined ? +QUAL : undefined
6363
this.FILTER = filter?.length === 1 && filter[0] === 'PASS' ? 'PASS' : filter
6464
this.INFO =
6565
fields[7] === undefined || fields[7] === '.'
@@ -82,7 +82,7 @@ export class Variant {
8282
const pairsLen = infoPairs.length
8383

8484
for (let i = 0; i < pairsLen; i++) {
85-
const pair = infoPairs[i]!
85+
const pair = infoPairs[i] ?? ''
8686
const eqIdx = pair.indexOf('=')
8787
const key = eqIdx === -1 ? pair : pair.slice(0, eqIdx)
8888
const val = eqIdx === -1 ? undefined : pair.slice(eqIdx + 1)
@@ -100,7 +100,7 @@ export class Variant {
100100
if (hasDecode) {
101101
const items: (string | number | undefined)[] = []
102102
for (let j = 0; j < itemsLen; j++) {
103-
const v = rawItems[j]!
103+
const v = rawItems[j] ?? ''
104104
if (v === '.') {
105105
items.push(undefined)
106106
} else {
@@ -112,7 +112,7 @@ export class Variant {
112112
} else {
113113
const items: (string | number | undefined)[] = []
114114
for (let j = 0; j < itemsLen; j++) {
115-
const v = rawItems[j]!
115+
const v = rawItems[j] ?? ''
116116
if (v === '.') {
117117
items.push(undefined)
118118
} else {
@@ -137,18 +137,18 @@ export class Variant {
137137
const formatKeys = format.split(':')
138138
const isNumberType: boolean[] = []
139139
for (let i = 0; i < formatKeys.length; i++) {
140-
const r = this.formatMeta[formatKeys[i]!]?.Type
140+
const r = this.formatMeta[formatKeys[i] ?? '']?.Type
141141
isNumberType.push(r === 'Integer' || r === 'Float')
142142
}
143143
const numKeys = formatKeys.length
144144
const samplesLen = this.sampleNames.length
145145
for (let i = 0; i < samplesLen; i++) {
146-
const sample = this.sampleNames[i]!
146+
const sample = this.sampleNames[i] ?? ''
147147
const sampleData: Record<
148148
string,
149149
(string | number | undefined)[] | undefined
150150
> = {}
151-
const sampleStr = rest[i]!
151+
const sampleStr = rest[i] ?? ''
152152
const sampleStrLen = sampleStr.length
153153
let colStart = 0
154154
let colIdx = 0
@@ -157,22 +157,22 @@ export class Variant {
157157
if (j === sampleStrLen || sampleStr[j] === ':') {
158158
const val = sampleStr.slice(colStart, j)
159159
if (val === '' || val === '.') {
160-
sampleData[formatKeys[colIdx]!] = undefined
160+
sampleData[formatKeys[colIdx] ?? ''] = undefined
161161
} else {
162162
const items = val.split(',')
163163
const result: (string | number | undefined)[] = []
164164
if (isNumberType[colIdx]) {
165165
for (let k = 0; k < items.length; k++) {
166-
const ent = items[k]!
166+
const ent = items[k] ?? ''
167167
result.push(ent === '.' ? undefined : +ent)
168168
}
169169
} else {
170170
for (let k = 0; k < items.length; k++) {
171-
const ent = items[k]!
171+
const ent = items[k] ?? ''
172172
result.push(ent === '.' ? undefined : ent)
173173
}
174174
}
175-
sampleData[formatKeys[colIdx]!] = result
175+
sampleData[formatKeys[colIdx] ?? ''] = result
176176
}
177177
colStart = j + 1
178178
colIdx += 1

src/parse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default class VCFParser {
3939

4040
let lastLine: string | undefined
4141
for (let i = 0; i < headerLines.length; i++) {
42-
const line = headerLines[i]!
42+
const line = headerLines[i] ?? ''
4343
if (!line.startsWith('#')) {
4444
throw new Error(`Bad line in header:\n${line}`)
4545
} else if (line.startsWith('##')) {

src/parseGenotypesOnly.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function parseGenotypesOnly(
2121
while (pos < prerestLen && prerest.charCodeAt(pos) !== TAB) {
2222
pos++
2323
}
24-
genotypes[samples[idx]!] = prerest.slice(start, pos)
24+
genotypes[samples[idx] ?? ''] = prerest.slice(start, pos)
2525
pos++
2626
}
2727
return genotypes
@@ -44,7 +44,7 @@ export function parseGenotypesOnly(
4444
) {
4545
pos++
4646
}
47-
genotypes[samples[idx]!] = prerest.slice(start, pos)
47+
genotypes[samples[idx] ?? ''] = prerest.slice(start, pos)
4848
while (pos < prerestLen && prerest.charCodeAt(pos) !== TAB) {
4949
pos++
5050
}
@@ -72,7 +72,7 @@ export function parseGenotypesOnly(
7272
for (let j = sampleStart; j <= tabIdx; j++) {
7373
if (j === tabIdx || prerest.charCodeAt(j) === COLON) {
7474
if (colons === colonCount) {
75-
genotypes[samples[idx]!] = prerest.slice(fieldStart, j)
75+
genotypes[samples[idx] ?? ''] = prerest.slice(fieldStart, j)
7676
break
7777
}
7878
colons++

src/parseMetaString.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function customSplit(str: string) {
66
const strLen = str.length
77

88
for (let i = 0; i < strLen; i++) {
9-
const char = str[i]!
9+
const char = str[i] ?? ''
1010
if (char === '"') {
1111
inQuotes = !inQuotes
1212
chars.push(char)

0 commit comments

Comments
 (0)