Skip to content

Commit 20e18ec

Browse files
cmdcolinclaude
andcommitted
fix lint: replace any types with proper types in parseLine
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent d29412b commit 20e18ec

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

src/parser.ts

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,49 +50,50 @@ export default class BED {
5050
const { uniqueId } = options
5151
const fields = Array.isArray(line) ? line : line.split('\t')
5252

53-
let feature = {} as Record<string, any>
53+
const feature: Record<string, string | number | string[] | number[]> = {}
5454
if (
5555
!this.attemptDefaultBed ||
5656
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
5757
(this.attemptDefaultBed && isBed12Like(fields))
5858
) {
5959
for (let index = 0; index < autoSql.fields.length; index++) {
6060
const autoField = autoSql.fields[index]
61-
let columnValue: any = fields[index]
61+
const rawColumn = fields[index]
6262
const { isNumeric, isArray, arrayIsNumeric, name } = autoField
63-
if (columnValue === null || columnValue === undefined) {
63+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
64+
if (rawColumn === undefined) {
6465
break
6566
}
66-
if (columnValue !== '.') {
67+
if (rawColumn !== '.') {
6768
if (isNumeric) {
68-
const number_ = Number(columnValue)
69-
columnValue = Number.isNaN(number_) ? columnValue : number_
69+
const number_ = Number(rawColumn)
70+
feature[name] = Number.isNaN(number_) ? rawColumn : number_
7071
} else if (isArray) {
71-
columnValue = columnValue.split(',')
72-
if (columnValue.at(-1) === '') {
73-
columnValue.pop()
74-
}
75-
if (arrayIsNumeric) {
76-
columnValue = columnValue.map(Number)
72+
const parts = rawColumn.split(',')
73+
if (parts.at(-1) === '') {
74+
parts.pop()
7775
}
76+
feature[name] = arrayIsNumeric ? parts.map(Number) : parts
77+
} else {
78+
feature[name] = rawColumn
7879
}
79-
80-
feature[name] = columnValue
8180
}
8281
}
8382
} else {
8483
const fieldNames = ['chrom', 'chromStart', 'chromEnd', 'name']
85-
feature = Object.fromEntries(
86-
fields.map((f, index) => [fieldNames[index] || 'field' + index, f]),
87-
)
88-
feature.chromStart = +feature.chromStart
89-
feature.chromEnd = +feature.chromEnd
90-
if (!Number.isNaN(Number.parseFloat(feature.field4))) {
91-
feature.score = +feature.field4
84+
for (let i = 0; i < fields.length; i++) {
85+
feature[fieldNames[i] ?? 'field' + i] = fields[i]
86+
}
87+
feature.chromStart = Number(fields[1])
88+
feature.chromEnd = Number(fields[2])
89+
const field4 = fields[4]
90+
if (!Number.isNaN(Number.parseFloat(field4))) {
91+
feature.score = Number.parseFloat(field4)
9292
delete feature.field4
9393
}
94-
if (feature.field5 === '+' || feature.field5 === '-') {
95-
feature.strand = feature.field5
94+
const field5 = fields[5]
95+
if (field5 === '+' || field5 === '-') {
96+
feature.strand = field5
9697
delete feature.field5
9798
}
9899
}
@@ -101,7 +102,7 @@ export default class BED {
101102
}
102103
feature.strand = strandMap[feature.strand as keyof typeof strandMap] || 0
103104

104-
feature.chrom = decodeURIComponent(feature.chrom)
105+
feature.chrom = decodeURIComponent(String(feature.chrom))
105106
return feature
106107
}
107108
}

0 commit comments

Comments
 (0)