Skip to content

Commit fd4f3b0

Browse files
committed
Lint
1 parent ee8c901 commit fd4f3b0

File tree

9 files changed

+785
-675
lines changed

9 files changed

+785
-675
lines changed

eslint.config.mjs

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@ export default tseslint.config(
2929
eslintPluginUnicorn.configs.recommended,
3030
{
3131
rules: {
32-
'@typescript-eslint/no-unused-vars': [
33-
'warn',
34-
{
35-
argsIgnorePattern: '^_',
36-
ignoreRestSiblings: true,
37-
},
38-
],
39-
4032
'no-console': [
4133
'warn',
4234
{
@@ -45,50 +37,58 @@ export default tseslint.config(
4537
],
4638
'no-underscore-dangle': 'off',
4739
curly: 'error',
48-
'@typescript-eslint/no-explicit-any': 'off',
49-
'@typescript-eslint/explicit-module-boundary-types': 'off',
50-
'@typescript-eslint/ban-ts-comment': 'off',
40+
5141
semi: ['error', 'never'],
5242
'unicorn/no-new-array': 'off',
53-
'unicorn/no-empty-file': 'off',
54-
'unicorn/prefer-type-error': 'off',
55-
'unicorn/prefer-modern-math-apis': 'off',
56-
'unicorn/prefer-node-protocol': 'off',
57-
'unicorn/no-unreadable-array-destructuring': 'off',
58-
'unicorn/no-abusive-eslint-disable': 'off',
59-
'unicorn/no-array-callback-reference': 'off',
60-
'unicorn/number-literal-case': 'off',
61-
'unicorn/prefer-add-event-listener': 'off',
62-
'unicorn/prefer-top-level-await': 'off',
63-
'unicorn/consistent-function-scoping': 'off',
64-
'unicorn/no-await-expression-member': 'off',
65-
'unicorn/no-lonely-if': 'off',
66-
'unicorn/consistent-destructuring': 'off',
43+
// 'unicorn/no-empty-file': 'off',
44+
// 'unicorn/prefer-type-error': 'off',
45+
// 'unicorn/prefer-modern-math-apis': 'off',
46+
// 'unicorn/prefer-node-protocol': 'off',
47+
// 'unicorn/no-unreadable-array-destructuring': 'off',
48+
// 'unicorn/no-abusive-eslint-disable': 'off',
49+
// 'unicorn/no-array-callback-reference': 'off',
50+
// 'unicorn/number-literal-case': 'off',
51+
// 'unicorn/prefer-add-event-listener': 'off',
52+
// 'unicorn/prefer-top-level-await': 'off',
53+
// 'unicorn/consistent-function-scoping': 'off',
54+
// 'unicorn/no-await-expression-member': 'off',
55+
// 'unicorn/no-lonely-if': 'off',
56+
// 'unicorn/consistent-destructuring': 'off',
6757
'unicorn/prefer-module': 'off',
68-
'unicorn/prefer-optional-catch-binding': 'off',
69-
'unicorn/no-useless-undefined': 'off',
70-
'unicorn/no-null': 'off',
71-
'unicorn/no-nested-ternary': 'off',
58+
// 'unicorn/prefer-optional-catch-binding': 'off',
59+
// 'unicorn/no-useless-undefined': 'off',
60+
// 'unicorn/no-null': 'off',
61+
// 'unicorn/no-nested-ternary': 'off',
7262
'unicorn/filename-case': 'off',
73-
'unicorn/catch-error-name': 'off',
63+
// 'unicorn/catch-error-name': 'off',
7464
'unicorn/prevent-abbreviations': 'off',
7565
'unicorn/prefer-code-point': 'off',
7666
'unicorn/numeric-separators-style': 'off',
77-
'unicorn/no-array-for-each': 'off',
78-
'unicorn/prefer-spread': 'off',
79-
'unicorn/explicit-length-check': 'off',
80-
'unicorn/prefer-regexp-test': 'off',
81-
'unicorn/relative-url-style': 'off',
82-
'unicorn/prefer-math-trunc': 'off',
83-
'unicorn/prefer-query-selector': 'off',
84-
'unicorn/no-negated-condition': 'off',
85-
'unicorn/switch-case-braces': 'off',
86-
'unicorn/prefer-switch': 'off',
87-
'unicorn/better-regex': 'off',
88-
'unicorn/no-for-loop': 'off',
89-
'unicorn/escape-case': 'off',
90-
'unicorn/prefer-number-properties': 'off',
91-
'unicorn/no-process-exit': 'off',
67+
// 'unicorn/no-array-for-each': 'off',
68+
// 'unicorn/prefer-spread': 'off',
69+
// 'unicorn/explicit-length-check': 'off',
70+
// 'unicorn/prefer-regexp-test': 'off',
71+
// 'unicorn/relative-url-style': 'off',
72+
// 'unicorn/prefer-math-trunc': 'off',
73+
// 'unicorn/prefer-query-selector': 'off',
74+
// 'unicorn/no-negated-condition': 'off',
75+
// 'unicorn/switch-case-braces': 'off',
76+
// 'unicorn/prefer-switch': 'off',
77+
// 'unicorn/better-regex': 'off',
78+
// 'unicorn/no-for-loop': 'off',
79+
// 'unicorn/escape-case': 'off',
80+
// 'unicorn/prefer-number-properties': 'off',
81+
82+
'@typescript-eslint/no-unused-vars': [
83+
'warn',
84+
{
85+
argsIgnorePattern: '^_',
86+
ignoreRestSiblings: true,
87+
},
88+
],
89+
'@typescript-eslint/no-explicit-any': 'off',
90+
'@typescript-eslint/explicit-module-boundary-types': 'off',
91+
'@typescript-eslint/ban-ts-comment': 'off',
9292
'@typescript-eslint/no-non-null-assertion': 'off',
9393
'@typescript-eslint/restrict-template-expressions': 'off',
9494
'@typescript-eslint/no-unsafe-member-access': 'off',

src/chunk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default class Chunk {
1111
minv: VirtualOffset,
1212
maxv: VirtualOffset,
1313
bin: number,
14-
fetchedSize = undefined,
14+
fetchedSize?: number,
1515
) {
1616
this.minv = minv
1717
this.maxv = maxv

src/csi.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export default class CSI extends IndexFile {
5858
const formatFlags = dataView.getInt32(offset, true)
5959
const coordinateType =
6060
formatFlags & 0x10000 ? 'zero-based-half-open' : '1-based-closed'
61-
const format = formats[(formatFlags & 0xf) as 0 | 1 | 2]
61+
const format = formats[(formatFlags & 0xF) as 0 | 1 | 2]
6262
if (!format) {
6363
throw new Error(`invalid Tabix preset format flags ${formatFlags}`)
6464
}
@@ -68,7 +68,7 @@ export default class CSI extends IndexFile {
6868
end: dataView.getInt32(offset + 12, true),
6969
}
7070
const metaValue = dataView.getInt32(offset + 16, true)
71-
const metaChar = metaValue ? String.fromCharCode(metaValue) : null
71+
const metaChar = metaValue ? String.fromCharCode(metaValue) : undefined
7272
const skipLines = dataView.getInt32(offset + 20, true)
7373
const nameSectionLength = dataView.getInt32(offset + 24, true)
7474

@@ -112,8 +112,6 @@ export default class CSI extends IndexFile {
112112
}
113113
}
114114

115-
// fetch and parse the index
116-
117115
async _parse(opts: Options = {}) {
118116
const bytes = await unzip(await this.filehandle.readFile(opts))
119117
const dataView = new DataView(bytes.buffer)
@@ -139,7 +137,7 @@ export default class CSI extends IndexFile {
139137
: {
140138
refIdToName: [],
141139
refNameToId: {},
142-
metaChar: null,
140+
metaChar: undefined,
143141
columnNumbers: { ref: 0, start: 1, end: 2 },
144142
coordinateType: 'zero-based-half-open',
145143
format: 'generic',

src/indexFile.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface Options {
1010
export interface IndexData {
1111
refNameToId: Record<string, number>
1212
refIdToName: string[]
13-
metaChar: string | null
13+
metaChar: string | undefined
1414
columnNumbers: { ref: number; start: number; end: number }
1515
coordinateType: string
1616
format: string
@@ -64,9 +64,9 @@ export default abstract class IndexFile {
6464

6565
async parse(opts: Options = {}) {
6666
if (!this.parseP) {
67-
this.parseP = this._parse(opts).catch((e: unknown) => {
67+
this.parseP = this._parse(opts).catch((error: unknown) => {
6868
this.parseP = undefined
69-
throw e
69+
throw error
7070
})
7171
}
7272
return this.parseP

src/tabixIndexedFile.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,13 @@ export default class TabixIndexedFile {
303303
let lastNewline = -1
304304
const newlineByte = '\n'.charCodeAt(0)
305305
const metaByte = metaChar.charCodeAt(0)
306-
for (let i = 0; i < bytes.length; i += 1) {
307-
if (i === lastNewline + 1 && bytes[i] !== metaByte) {
306+
307+
for (let i = 0, l = bytes.length; i < l; i++) {
308+
const byte = bytes[i]
309+
if (i === lastNewline + 1 && byte !== metaByte) {
308310
break
309311
}
310-
if (bytes[i] === newlineByte) {
312+
if (byte === newlineByte) {
311313
lastNewline = i
312314
}
313315
}
@@ -402,7 +404,10 @@ export default class TabixIndexedFile {
402404
}
403405
}
404406
} else if (currentColumnNumber === start) {
405-
startCoordinate = parseInt(line.slice(currentColumnStart, i), 10)
407+
startCoordinate = Number.parseInt(
408+
line.slice(currentColumnStart, i),
409+
10,
410+
)
406411
// we convert to 0-based-half-open
407412
if (coordinateType === '1-based-closed') {
408413
startCoordinate -= 1
@@ -413,13 +418,13 @@ export default class TabixIndexedFile {
413418
overlaps: false,
414419
}
415420
}
416-
if (end === 0 || end === start) {
417-
// if we have no end, we assume the feature is 1 bp long
418-
if (startCoordinate + 1 <= regionStart) {
419-
return {
420-
startCoordinate,
421-
overlaps: false,
422-
}
421+
if (
422+
(end === 0 || end === start) && // if we have no end, we assume the feature is 1 bp long
423+
startCoordinate + 1 <= regionStart
424+
) {
425+
return {
426+
startCoordinate,
427+
overlaps: false,
423428
}
424429
}
425430
} else if (format === 'VCF' && currentColumnNumber === 4) {
@@ -469,7 +474,7 @@ export default class TabixIndexedFile {
469474
if (valueEnd === -1) {
470475
valueEnd = info.length
471476
}
472-
endCoordinate = parseInt(info.slice(j + 4, valueEnd), 10)
477+
endCoordinate = Number.parseInt(info.slice(j + 4, valueEnd), 10)
473478
break
474479
}
475480
prevChar = info[j]

src/tbi.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export default class TabixIndex extends IndexFile {
6262
1: 'SAM',
6363
2: 'VCF',
6464
}
65-
const format = formatOpts[formatFlags & 0xf]
65+
const format = formatOpts[formatFlags & 0xF]
6666
if (!format) {
6767
throw new Error(`invalid Tabix preset format flags ${formatFlags}`)
6868
}
@@ -75,7 +75,7 @@ export default class TabixIndex extends IndexFile {
7575
const depth = 5
7676
const maxBinNumber = ((1 << ((depth + 1) * 3)) - 1) / 7
7777
const maxRefLength = 2 ** (14 + depth * 3)
78-
const metaChar = metaValue ? String.fromCharCode(metaValue) : null
78+
const metaChar = metaValue ? String.fromCharCode(metaValue) : undefined
7979
const skipLines = dataView.getInt32(28, true)
8080

8181
// read sequence dictionary
@@ -205,13 +205,14 @@ export default class TabixIndex extends IndexFile {
205205
return []
206206
}
207207

208-
const minOffset = ba.linearIndex.length
209-
? ba.linearIndex[
210-
min >> TAD_LIDX_SHIFT >= ba.linearIndex.length
211-
? ba.linearIndex.length - 1
212-
: min >> TAD_LIDX_SHIFT
213-
]
214-
: new VirtualOffset(0, 0)
208+
const minOffset =
209+
ba.linearIndex.length > 0
210+
? ba.linearIndex[
211+
min >> TAD_LIDX_SHIFT >= ba.linearIndex.length
212+
? ba.linearIndex.length - 1
213+
: min >> TAD_LIDX_SHIFT
214+
]
215+
: new VirtualOffset(0, 0)
215216
if (!minOffset) {
216217
console.warn('querying outside of possible tabix range')
217218
}
@@ -235,15 +236,13 @@ export default class TabixIndex extends IndexFile {
235236
// Use the linear index to find minimum file position of chunks that could
236237
// contain alignments in the region
237238
const nintv = ba.linearIndex.length
238-
let lowest = null
239+
let lowest: VirtualOffset | undefined
239240
const minLin = Math.min(min >> 14, nintv - 1)
240241
const maxLin = Math.min(max >> 14, nintv - 1)
241242
for (let i = minLin; i <= maxLin; ++i) {
242243
const vp = ba.linearIndex[i]
243-
if (vp) {
244-
if (!lowest || vp.compareTo(lowest) < 0) {
245-
lowest = vp
246-
}
244+
if (vp && (!lowest || vp.compareTo(lowest) < 0)) {
245+
lowest = vp
247246
}
248247
}
249248

src/util.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ export function checkAbortSignal(signal?: AbortSignal) {
2222
}
2323

2424
if (signal.aborted) {
25-
if (typeof DOMException !== 'undefined') {
26-
throw new DOMException('aborted', 'AbortError')
27-
} else {
25+
if (typeof DOMException === 'undefined') {
2826
const e = new AbortError('aborted')
2927
e.code = 'ERR_ABORTED'
3028
throw e
29+
} else {
30+
throw new DOMException('aborted', 'AbortError')
3131
}
3232
}
3333
}
@@ -52,20 +52,20 @@ export function canMergeBlocks(chunk1: Chunk, chunk2: Chunk) {
5252

5353
export function optimizeChunks(chunks: Chunk[], lowest?: VirtualOffset) {
5454
const mergedChunks: Chunk[] = []
55-
let lastChunk: Chunk | null = null
55+
let lastChunk: Chunk | undefined
5656

5757
if (chunks.length === 0) {
5858
return chunks
5959
}
6060

6161
chunks.sort(function (c0, c1) {
6262
const dif = c0.minv.blockPosition - c1.minv.blockPosition
63-
return dif !== 0 ? dif : c0.minv.dataPosition - c1.minv.dataPosition
63+
return dif === 0 ? c0.minv.dataPosition - c1.minv.dataPosition : dif
6464
})
6565

66-
chunks.forEach(chunk => {
66+
for (const chunk of chunks) {
6767
if (!lowest || chunk.maxv.compareTo(lowest) > 0) {
68-
if (lastChunk === null) {
68+
if (lastChunk === undefined) {
6969
mergedChunks.push(chunk)
7070
lastChunk = chunk
7171
} else {
@@ -79,7 +79,7 @@ export function optimizeChunks(chunks: Chunk[], lowest?: VirtualOffset) {
7979
}
8080
}
8181
}
82-
})
82+
}
8383

8484
return mergedChunks
8585
}

0 commit comments

Comments
 (0)