Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Aug 30, 2024
1 parent 79806bf commit 60c5d5c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 41 deletions.
60 changes: 26 additions & 34 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,43 +1,32 @@
import prettier from 'eslint-plugin-prettier'
import typescriptEslint from '@typescript-eslint/eslint-plugin'
import tsParser from '@typescript-eslint/parser'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import js from '@eslint/js'
import { FlatCompat } from '@eslint/eslintrc'
import eslint from '@eslint/js'
import eslintPluginUnicorn from 'eslint-plugin-unicorn'
import tseslint from 'typescript-eslint'

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
})

export default [
...compat.extends(
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:@typescript-eslint/stylistic-type-checked',
'plugin:prettier/recommended',
'plugin:unicorn/recommended',
),
export default tseslint.config(
{
ignores: [
'webpack.config.js',
'dist/*',
'esm/*',
'example/*',
'eslint.config.mjs',
],
},
{
plugins: {
prettier,
'@typescript-eslint': typescriptEslint,
},

languageOptions: {
parser: tsParser,
ecmaVersion: 5,
sourceType: 'script',

parserOptions: {
project: './tsconfig.lint.json',
project: ['./tsconfig.lint.json'],
tsconfigRootDir: import.meta.dirname,
},
},
},
eslint.configs.recommended,
...tseslint.configs.recommended,
...tseslint.configs.stylisticTypeChecked,
...tseslint.configs.strictTypeChecked,

eslintPluginUnicorn.configs['flat/recommended'],
{
rules: {
'@typescript-eslint/no-unused-vars': [
'warn',
Expand Down Expand Up @@ -101,6 +90,9 @@ export default [
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/prefer-nullish-coalescing': 'off',
'@typescript-eslint/require-await': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/restrict-plus-operands': 'off',
'no-empty': 'off',
},
},
]
)
9 changes: 7 additions & 2 deletions src/bai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function reg2bins(beg: number, end: number) {
[73 + (beg >> 20), 73 + (end >> 20)],
[585 + (beg >> 17), 585 + (end >> 17)],
[4681 + (beg >> 14), 4681 + (end >> 14)],
]
] as const
}

export default class BAI extends IndexFile {
Expand Down Expand Up @@ -125,6 +125,7 @@ export default class BAI extends IndexFile {
const range = start !== undefined
const indexData = await this.parse(opts)
const seqIdx = indexData.indices[seqId]
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!seqIdx) {
return []
}
Expand Down Expand Up @@ -167,10 +168,12 @@ export default class BAI extends IndexFile {
}

const indexData = await this.parse(opts)
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!indexData) {
return []
}
const ba = indexData.indices[refId]
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!ba) {
return []
}
Expand All @@ -182,6 +185,7 @@ export default class BAI extends IndexFile {
// Find chunks in overlapping bins. Leaf bins (< 4681) are not pruned
for (const [start, end] of overlappingBins) {
for (let bin = start; bin <= end; bin++) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (ba.binIndex[bin]) {
const binChunks = ba.binIndex[bin]
for (const binChunk of binChunks) {
Expand All @@ -199,6 +203,7 @@ export default class BAI extends IndexFile {
const maxLin = Math.min(max >> 14, nintv - 1)
for (let i = minLin; i <= maxLin; ++i) {
const vp = ba.linearIndex[i]
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (vp && (!lowest || vp.compareTo(lowest) < 0)) {
lowest = vp
}
Expand All @@ -209,7 +214,7 @@ export default class BAI extends IndexFile {

async parse(opts: BaseOpts = {}) {
if (!this.setupP) {
this.setupP = this._parse(opts).catch(e => {
this.setupP = this._parse(opts).catch((e: unknown) => {
this.setupP = undefined
throw e
})
Expand Down
4 changes: 3 additions & 1 deletion src/bamFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export default class BamFile {

getHeader(opts?: BaseOpts) {
if (!this.headerP) {
this.headerP = this.getHeaderPre(opts).catch(e => {
this.headerP = this.getHeaderPre(opts).catch((e: unknown) => {
this.headerP = undefined
throw e
})
Expand Down Expand Up @@ -430,6 +430,7 @@ export default class BamFile {
const blockEnd = blockStart + 4 + blockSize - 1

// increment position to the current decompressed status
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (dpositions) {
while (blockStart + chunk.minv.dataPosition >= dpositions[pos++]) {}
pos--
Expand Down Expand Up @@ -470,6 +471,7 @@ export default class BamFile {
chunk.minv.dataPosition +
1
: // must be slice, not subarray for buffer polyfill on web
// eslint-disable-next-line @typescript-eslint/no-deprecated
crc32.signed(ba.slice(blockStart, blockEnd)),
})

Expand Down
8 changes: 5 additions & 3 deletions src/csi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ export default class CSI extends IndexFile {
}

const indexData = await this.parse(opts)
const ba = indexData?.indices[refId]
const ba = indexData.indices[refId]
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!ba) {
return []
}
Expand All @@ -173,6 +174,7 @@ export default class CSI extends IndexFile {
// Find chunks in overlapping bins. Leaf bins (< 4681) are not pruned
for (const [start, end] of overlappingBins) {
for (let bin = start; bin <= end; bin++) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (ba.binIndex[bin]) {
const binChunks = ba.binIndex[bin]
for (const c of binChunks) {
Expand Down Expand Up @@ -210,14 +212,14 @@ export default class CSI extends IndexFile {
`query ${beg}-${end} is too large for current binning scheme (shift ${this.minShift}, depth ${this.depth}), try a smaller query or a coarser index binning scheme`,
)
}
bins.push([b, e])
bins.push([b, e] as const)
}
return bins
}

async parse(opts: BaseOpts = {}) {
if (!this.setupP) {
this.setupP = this._parse(opts).catch(e => {
this.setupP = this._parse(opts).catch((e: unknown) => {
this.setupP = undefined
throw e
})
Expand Down
2 changes: 1 addition & 1 deletion src/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default class BamRecord {
if (this.isPaired()) {
tags.push('next_segment_position', 'pair_orientation')
}
tags = tags.concat(this._tagList || [])
tags = tags.concat(this._tagList)

for (const k of Object.keys(this.data)) {
if (!k.startsWith('_') && k !== 'next_seq_id') {
Expand Down

0 comments on commit 60c5d5c

Please sign in to comment.