Skip to content

Commit

Permalink
Improved typescript-eslint setup
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Feb 21, 2024
1 parent 18f3e43 commit 24e2e16
Show file tree
Hide file tree
Showing 31 changed files with 954 additions and 848 deletions.
82 changes: 82 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/** @type {import("eslint").Linter.Config} */
module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['prettier', '@typescript-eslint'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:@typescript-eslint/stylistic-type-checked',
'plugin:prettier/recommended',
'plugin:unicorn/recommended',
],
parser: '@typescript-eslint/parser',
parserOptions: {
tsconfigRootDir: __dirname,
project: './tsconfig.lint.json',
},
rules: {
'@typescript-eslint/no-unused-vars': [
'warn',
{ argsIgnorePattern: '^_', ignoreRestSiblings: true },
],
'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/escape-case': 'off',
'unicorn/prefer-number-properties': 'off',
'unicorn/no-process-exit': 'off',
'unicorn/prefer-at': 'off',
'unicorn/prefer-string-replace-all': 'off',
'unicorn/no-array-reduce': 'off',

'@typescript-eslint/no-base-to-string': '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',
},
}
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,28 @@
"@babel/plugin-transform-modules-commonjs": "^7.18.2",
"@babel/preset-typescript": "^7.17.12",
"@gmod/indexedfasta": "^2.1.0",
"@types/jest": "^29.2.4",
"@types/jest": "^29.5.12",
"@types/long": "^4.0.2",
"@types/md5": "^2.3.2",
"@types/pako": "^1.0.3",
"@typescript-eslint/eslint-plugin": "^6.9.1",
"@typescript-eslint/parser": "^6.9.1",
"@typescript-eslint/eslint-plugin": "^7.0.2",
"@typescript-eslint/parser": "^7.0.2",
"buffer": "^6.0.3",
"documentation": "^14.0.1",
"documentation": "^14.0.3",
"eslint": "^8.30.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-unicorn": "^51.0.1",
"glob": "^10.3.1",
"jest": "^29.3.1",
"mock-fs": "^5.2.0",
"prettier": "^3.0.3",
"prettier": "^3.2.5",
"rimraf": "^5.0.1",
"ts-jest": "^29.0.3",
"ts-jest": "^29.1.2",
"typescript": "^5.0.3",
"url": "^0.11.0",
"webpack": "^5.89.0",
"webpack": "^5.90.3",
"webpack-cli": "^5.0.1"
},
"publishConfig": {
Expand Down
19 changes: 7 additions & 12 deletions src/craiIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Filehandle } from './cramFile/filehandle'

const BAI_MAGIC = 21578050 // BAI\1

export type Slice = {
export interface Slice {
start: number
span: number
containerStart: number
Expand All @@ -19,10 +19,6 @@ export type Slice = {
type ParsedIndex = Record<string, Slice[]>

function addRecordToIndex(index: ParsedIndex, record: number[]) {
if (record.some(el => el === undefined)) {
throw new CramMalformedError('invalid .crai index file')
}

const [seqId, start, span, containerStart, sliceStart, sliceBytes] = record

if (!index[seqId]) {
Expand Down Expand Up @@ -61,7 +57,7 @@ export default class CraiIndex {
this.filehandle = open(args.url, args.path, args.filehandle)
this._parseCache = new AbortablePromiseCache<unknown, ParsedIndex>({
cache: new QuickLRU({ maxSize: 1 }),
fill: (data, signal) => this.parseIndex(),
fill: (_data, _signal) => this.parseIndex(),
})
}

Expand Down Expand Up @@ -90,8 +86,7 @@ export default class CraiIndex {
// because some .crai files can be pretty large.
let currentRecord: number[] = []
let currentString = ''
for (let i = 0; i < uncompressedBuffer.length; i += 1) {
const charCode = uncompressedBuffer[i]
for (const charCode of uncompressedBuffer) {
if (
(charCode >= 48 && charCode <= 57) /* 0-9 */ ||
(!currentString && charCode === 45) /* leading - */
Expand Down Expand Up @@ -175,10 +170,10 @@ export default class CraiIndex {
} // entry is behind query
return 0 // entry overlaps query
}
const bins = []
for (let i = 0; i < seqEntries.length; i += 1) {
if (compare(seqEntries[i]) === 0) {
bins.push(seqEntries[i])
const bins = [] as Slice[]
for (const entry of seqEntries) {
if (compare(entry) === 0) {
bins.push(entry)
}
}
return bins
Expand Down
6 changes: 3 additions & 3 deletions src/cramFile/codecs/_base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import CramSlice from '../slice'
import { CramFileBlock } from '../file'
import { DataType } from './dataSeriesTypes'

export type DataTypeMapping = {
export interface DataTypeMapping {
byte: number
int: number
long: number
byteArray: Uint8Array
}

export type Cursor = {
export interface Cursor {
bitPosition: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
bytePosition: number
}

export type Cursors = {
export interface Cursors {
lastAlignmentStart: number
coreBlock: Cursor
externalBlocks: {
Expand Down
1 change: 1 addition & 0 deletions src/cramFile/codecs/external.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/unbound-method */
import { CramMalformedError, CramUnimplementedError } from '../../errors'
import CramCodec, { Cursor, Cursors } from './_base'
import { parseItf8 } from '../util'
Expand Down
15 changes: 7 additions & 8 deletions src/cramFile/codecs/huffman.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/unbound-method */
import { CramMalformedError } from '../../errors'
import CramCodec, { Cursor, Cursors } from './_base'
import { getBits } from './getBits'
Expand All @@ -12,15 +13,18 @@ function numberOfSetBits(ii: number) {
return (((i + (i >> 4)) & 0x0f0f0f0f) * 0x01010101) >> 24
}

type Code = { bitLength: number; value: number; bitCode: number }
interface Code {
bitLength: number
value: number
bitCode: number
}

export default class HuffmanIntCodec extends CramCodec<
'byte' | 'int',
HuffmanEncoding['parameters']
> {
private codes: Record<number, Code> = {}
private codeBook: Record<number, number[]> = {}
private sortedByValue: Code[] = []
private sortedCodes: Code[] = []
private sortedValuesByBitCode: number[] = []
private sortedBitCodes: number[] = []
Expand Down Expand Up @@ -50,7 +54,7 @@ export default class HuffmanIntCodec extends CramCodec<

buildCodeBook() {
// parse the parameters together into a `codes` data structure
let codes: Array<{ symbol: number; bitLength: number }> = new Array(
let codes = new Array<{ symbol: number; bitLength: number }>(
this.parameters.numCodes,
)
for (let i = 0; i < this.parameters.numCodes; i += 1) {
Expand Down Expand Up @@ -105,11 +109,6 @@ export default class HuffmanIntCodec extends CramCodec<
(a, b) => a.bitLength - b.bitLength || a.bitCode - b.bitCode,
)

// this.sortedValues = this.parameters.values.sort((a,b) => a-b)
this.sortedByValue = Object.values(this.codes).sort(
(a, b) => a.value - b.value,
)

this.sortedValuesByBitCode = this.sortedCodes.map(c => c.value)
this.sortedBitCodes = this.sortedCodes.map(c => c.bitCode)
this.sortedBitLengthsByBitCode = this.sortedCodes.map(c => c.bitLength)
Expand Down
2 changes: 1 addition & 1 deletion src/cramFile/container/compressionScheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export default class CramContainerCompressionScheme {
toJSON() {
const data: any = {}
Object.keys(this).forEach(k => {
if (/Cache$/.test(k)) {
if (k.endsWith('Cache')) {
return
}
data[k] = (this as any)[k]
Expand Down
20 changes: 10 additions & 10 deletions src/cramFile/encoding.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
export type NullEncoding = {
export interface NullEncoding {
codecId: 0
parametersBytes: number
parameters: Record<string, never>
}

export type ExternalCramEncoding = {
export interface ExternalCramEncoding {
codecId: 1
parametersBytes: number
parameters: {
blockContentId: number
}
}

export type GolombEncoding = {
export interface GolombEncoding {
codecId: 2
parametersBytes: number
parameters: {
Expand All @@ -21,7 +21,7 @@ export type GolombEncoding = {
}
}

export type HuffmanEncoding = {
export interface HuffmanEncoding {
codecId: 3
parametersBytes: number
parameters: {
Expand All @@ -32,7 +32,7 @@ export type HuffmanEncoding = {
}
}

export type ByteArrayLengthEncoding = {
export interface ByteArrayLengthEncoding {
codecId: 4
parametersBytes: number
parameters: {
Expand All @@ -41,7 +41,7 @@ export type ByteArrayLengthEncoding = {
}
}

export type ByteArrayStopCramEncoding = {
export interface ByteArrayStopCramEncoding {
codecId: 5
parametersBytes: number
parameters: {
Expand All @@ -50,7 +50,7 @@ export type ByteArrayStopCramEncoding = {
}
}

export type BetaEncoding = {
export interface BetaEncoding {
codecId: 6
parametersBytes: number
parameters: {
Expand All @@ -59,7 +59,7 @@ export type BetaEncoding = {
}
}

export type SubexpEncoding = {
export interface SubexpEncoding {
codecId: 7
parametersBytes: number
parameters: {
Expand All @@ -68,7 +68,7 @@ export type SubexpEncoding = {
}
}

export type GolombRiceEncoding = {
export interface GolombRiceEncoding {
codecId: 8
parametersBytes: number
parameters: {
Expand All @@ -77,7 +77,7 @@ export type GolombRiceEncoding = {
}
}

export type GammaEncoding = {
export interface GammaEncoding {
codecId: 9
parametersBytes: number
parameters: {
Expand Down
2 changes: 1 addition & 1 deletion src/cramFile/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function getEndianness() {
// | { path: string; url?: undefined; filehandle?: undefined }
// | { filehandle: Filehandle; url?: undefined; path?: undefined }

export type CramFileSource = {
export interface CramFileSource {
filehandle?: Filehandle
url?: string
path?: string
Expand Down
4 changes: 1 addition & 3 deletions src/cramFile/filehandle.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
import { GenericFilehandle } from 'generic-filehandle'

export { GenericFilehandle as Filehandle }
export { GenericFilehandle as Filehandle } from 'generic-filehandle'
3 changes: 1 addition & 2 deletions src/cramFile/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import CramFile from './file'
export { default as CramRecord } from './record'

export default CramFile
export { default } from './file'
Loading

0 comments on commit 24e2e16

Please sign in to comment.