From 60c5d5c7024c5fb8fac4b6a8a0e7b5625f7b13ce Mon Sep 17 00:00:00 2001 From: Colin Date: Fri, 30 Aug 2024 14:27:51 -0400 Subject: [PATCH] Updates --- eslint.config.mjs | 60 ++++++++++++++++++++--------------------------- src/bai.ts | 9 +++++-- src/bamFile.ts | 4 +++- src/csi.ts | 8 ++++--- src/record.ts | 2 +- 5 files changed, 42 insertions(+), 41 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index db0c4a5..bcb3c45 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -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', @@ -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', }, }, -] +) diff --git a/src/bai.ts b/src/bai.ts index f369b03..3394183 100644 --- a/src/bai.ts +++ b/src/bai.ts @@ -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 { @@ -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 [] } @@ -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 [] } @@ -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) { @@ -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 } @@ -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 }) diff --git a/src/bamFile.ts b/src/bamFile.ts index 368db39..0c61ba0 100644 --- a/src/bamFile.ts +++ b/src/bamFile.ts @@ -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 }) @@ -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-- @@ -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)), }) diff --git a/src/csi.ts b/src/csi.ts index f0e4ffb..072114c 100644 --- a/src/csi.ts +++ b/src/csi.ts @@ -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 [] } @@ -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) { @@ -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 }) diff --git a/src/record.ts b/src/record.ts index 2703bf0..4ca8cd9 100644 --- a/src/record.ts +++ b/src/record.ts @@ -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') {