Skip to content

Commit

Permalink
Convert to vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Dec 5, 2024
1 parent 4d942bc commit 90ff63c
Show file tree
Hide file tree
Showing 11 changed files with 1,027 additions and 2,961 deletions.
111 changes: 29 additions & 82 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,43 +1,30 @@
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 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,

{
rules: {
'@typescript-eslint/no-unused-vars': [
'warn',
Expand All @@ -47,62 +34,22 @@ export default [
},
],

'no-underscore-dangle': 0,
curly: 'error',
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/explicit-module-boundary-types': 0,
'@typescript-eslint/ban-ts-comment': 0,
semi: ['error', 'never'],
'unicorn/no-new-array': 'off',
'unicorn/no-empty-file': 'off',
'unicorn/prefer-type-error': 'off',
'unicorn/prefer-modern-math-apis': 'off',
'unicorn/prefer-node-protocol': 'off',
'unicorn/no-unreadable-array-destructuring': 'off',
'unicorn/no-abusive-eslint-disable': 'off',
'unicorn/no-array-callback-reference': 'off',
'unicorn/number-literal-case': 'off',
'unicorn/prefer-add-event-listener': 'off',
'unicorn/prefer-top-level-await': 'off',
'unicorn/consistent-function-scoping': 'off',
'unicorn/no-await-expression-member': 'off',
'unicorn/no-lonely-if': 'off',
'unicorn/consistent-destructuring': 'off',
'unicorn/prefer-module': 'off',
'unicorn/prefer-optional-catch-binding': 'off',
'unicorn/no-useless-undefined': 'off',
'unicorn/no-null': 'off',
'unicorn/no-nested-ternary': 'off',
'unicorn/filename-case': 'off',
'unicorn/catch-error-name': 'off',
'unicorn/prevent-abbreviations': 'off',
'unicorn/prefer-code-point': 'off',
'unicorn/numeric-separators-style': 'off',
'unicorn/no-array-for-each': 'off',
'unicorn/prefer-spread': 'off',
'unicorn/explicit-length-check': 'off',
'unicorn/prefer-regexp-test': 'off',
'unicorn/relative-url-style': 'off',
'unicorn/prefer-math-trunc': 'off',
'unicorn/prefer-query-selector': 'off',
'unicorn/no-negated-condition': 'off',
'unicorn/switch-case-braces': 'off',
'unicorn/prefer-switch': 'off',
'unicorn/better-regex': 'off',
'unicorn/no-for-loop': 'off',
'unicorn/prefer-string-replace-all': 'off',
'unicorn/escape-case': 'off',
'unicorn/prefer-structured-clone': 'off',
'unicorn/prefer-number-properties': 'off',
'unicorn/no-process-exit': 'off',
'unicorn/prefer-at': 'off',
'no-underscore-dangle': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@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',
},
},
]
)
29 changes: 12 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
"src"
],
"scripts": {
"test": "jest",
"coverage": "npm test -- --coverage",
"test": "vitest",
"coverage": "yarn test -- --coverage",
"lint": "eslint --report-unused-disable-directives --max-warnings 0 src test",
"docs": "documentation readme src --section=API",
"clean": "rimraf dist esm",
"prebuild": "npm run clean",
"prebuild": "yarn clean",
"build:esm": "tsc --target es2018 --outDir esm",
"build:es5": "tsc --target es2015 --module commonjs --outDir dist",
"build": "npm run build:esm && npm run build:es5",
"build": "yarn build:esm && yarn run build:es5",
"version": "standard-changelog && git add CHANGELOG.md",
"prepublishOnly": "npm test && npm run build",
"prepublishOnly": "yarn test --run && yarn build",
"postversion": "git push --follow-tags"
},
"keywords": [
Expand All @@ -41,26 +41,21 @@
],
"dependencies": {
"@gmod/bgzf-filehandle": "^1.4.0",
"buffer": "^6.0.3",
"generic-filehandle": "^3.0.0"
},
"devDependencies": {
"@types/jest": "^29.5.0",
"@types/object.fromentries": "^2.0.1",
"@typescript-eslint/eslint-plugin": "^7.13.1",
"@typescript-eslint/parser": "^7.13.1",
"@typescript-eslint/eslint-plugin": "^8.17.0",
"@typescript-eslint/parser": "^8.17.0",
"cross-fetch": "^4.0.0",
"documentation": "^14.0.1",
"eslint": "^9.5.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-unicorn": "^54.0.0",
"jest": "^29.5.0",
"eslint-plugin-unicorn": "^56.0.1",
"prettier": "^3.0.3",
"rimraf": "^6.0.1",
"standard-changelog": "^6.0.0",
"ts-jest": "^29.0.5",
"typescript": "^5.0.2"
"typescript": "^5.0.2",
"typescript-eslint": "^8.17.0",
"vitest": "^2.1.8"
},
"publishConfig": {
"access": "public"
Expand Down
5 changes: 4 additions & 1 deletion src/bgzipIndexedFasta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ export default class BgzipIndexedFasta extends IndexedFasta {
})
} else if (path && gziPath) {
// @ts-expect-error
this.fasta = new BgzfFilehandle({ path, gziPath })
this.fasta = new BgzfFilehandle({
path,
gziPath,
})
}
}
}
Empty file removed src/declare.d.ts
Empty file.
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ function parseSmallFasta(text: string) {
.filter(t => /\S/.test(t))
.map(entryText => {
const [defLine, ...seqLines] = entryText.split('\n')
const [id, ...description] = defLine.split(' ')
const [id, ...description] = defLine!.split(' ')
const sequence = seqLines.join('').replace(/\s/g, '')
return {
id,
id: id!,
description: description.join(' '),
sequence,
}
Expand All @@ -22,7 +22,7 @@ class FetchableSmallFasta {

data: Promise<{ id: string; description: string; sequence: string }[]>

constructor({ fasta, path }: { fasta: GenericFilehandle; path: string }) {
constructor({ fasta, path }: { fasta?: GenericFilehandle; path?: string }) {
if (fasta) {
this.fasta = fasta
} else if (path) {
Expand Down
23 changes: 13 additions & 10 deletions src/indexedFasta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,36 @@ function _faiOffset(idx: IndexEntry, pos: number) {

async function readFAI(fai: GenericFilehandle, opts?: BaseOpts) {
const text = await fai.readFile(opts)
if (!text?.length) {
if (!text.length) {
throw new Error('No data read from FASTA index (FAI) file')
}

let idCounter = 0
let currSeq: { name: string; id: number } | undefined
const data = text
.toString('utf8')
.toString()
.split(/\r?\n/)
.filter(line => /\S/.test(line))
.map(line => line.split('\t'))
.filter(row => row[0] !== '')
.map(row => {
if (!currSeq || currSeq.name !== row[0]) {
currSeq = { name: row[0], id: idCounter }
currSeq = {
name: row[0]!,
id: idCounter,
}
idCounter += 1
}

return {
id: currSeq.id,
name: row[0],
length: +row[1],
name: row[0]!,
length: +row[1]!,
start: 0,
end: +row[1],
offset: +row[2],
lineLength: +row[3],
lineBytes: +row[4],
end: +row[1]!,
offset: +row[2]!,
lineLength: +row[3]!,
lineBytes: +row[4]!,
}
})

Expand Down Expand Up @@ -203,7 +206,7 @@ export default class IndexedFasta {
if (min < 0) {
throw new TypeError('regionStart cannot be less than 0')
}
if (end === undefined || end > indexEntry.length) {
if (end > indexEntry.length) {
end = indexEntry.length
}
if (min >= end) {
Expand Down
2 changes: 1 addition & 1 deletion test/lib/io/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { RemoteFile, LocalFile } from 'generic-filehandle'
function fromUrl(source) {
const { protocol, pathname } = url.parse(source)
if (protocol === 'file:') {
return new LocalFile(unescape(pathname))
return new LocalFile(pathname)
}
return new RemoteFile(source)
}
Expand Down
1 change: 1 addition & 0 deletions test/parse.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@ts-nocheck
import { describe, expect, it } from 'vitest'
import { FetchableSmallFasta, IndexedFasta, BgzipIndexedFasta } from '../src'

import { testDataFile } from './lib/util'
Expand Down
1 change: 1 addition & 0 deletions test/twobit_parity.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@ts-nocheck
import { describe, expect, it } from 'vitest'
import { IndexedFasta } from '../src'

describe('.fa data store', () => {
Expand Down
4 changes: 3 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"compilerOptions": {
"moduleResolution": "node",
"lib": ["es2017", "es7", "es6", "dom"],
"skipLibCheck": true,
"target": "es2020",
"declaration": true,
"outDir": "dist",
"noUncheckedIndexedAccess": true,
"strict": true,
"sourceMap": true,
"esModuleInterop": true
Expand Down
Loading

0 comments on commit 90ff63c

Please sign in to comment.