Skip to content

Commit

Permalink
More lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Aug 29, 2023
1 parent d496de9 commit d0ae041
Show file tree
Hide file tree
Showing 52 changed files with 209 additions and 177 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/camelcase": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/prefer-nullish-coalescing": "off",
"@typescript-eslint/no-base-to-string": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-empty-function": "off",
Expand Down
6 changes: 3 additions & 3 deletions docs/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ export function extractWithComment(
'action',
'method',
]
for (let i = 0; i < list.length; i++) {
const type = '#' + list[i]
for (const entry of list) {
const type = '#' + entry
if (fulltext.includes(type) && r.comment.includes(type)) {
cb({ type: list[i], ...r })
cb({ type: entry, ...r })
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"@storybook/react": "^7.0.0",
"@storybook/react-webpack5": "^7.0.0",
"@svgr/webpack": "^8.1.0",
"@testing-library/dom": "^8.0.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^12.0.0",
"@testing-library/user-event": "^14.4.3",
Expand Down Expand Up @@ -174,6 +175,7 @@
"typescript": "^5.1.3",
"web-encoding": "^1.1.5",
"webpack": "^5.64.4",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.6.0",
"webpack-manifest-plugin": "^4.0.2"
},
Expand Down
7 changes: 5 additions & 2 deletions packages/core/data_adapters/dataAdapterCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ export async function getAdapter(
// cache the adapter object
const cacheKey = adapterConfigCacheKey(adapterConfigSnapshot)
if (!adapterCache[cacheKey]) {
const adapterType = (adapterConfigSnapshot || {}).type
const adapterType = adapterConfigSnapshot?.type

if (!adapterType) {
throw new Error(
'could not determine adapter type from adapter config snapshot',
`could not determine adapter type from adapter config snapshot ${JSON.stringify(
adapterConfigSnapshot,
)}`,
)
}
const dataAdapterType = pluginManager.getAdapterType(adapterType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ export default class SerializableFilterChain {

// eslint-disable-next-line @typescript-eslint/no-explicit-any
passes(...args: any[]) {
for (let i = 0; i < this.filterChain.length; i += 1) {
for (const entry of this.filterChain) {
if (
// @ts-expect-error
!this.filterChain[i].expr.evalSync({ feature: args[0] })
!entry.expr.evalSync({ feature: args[0] })
) {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/ui/FileSelector/LocalFileChooser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function LocalFileChooser(props: {
type="file"
hidden
onChange={({ target }) => {
const file = target && target.files && target.files[0]
const file = target?.files?.[0]
if (file) {
if (isElectron) {
setLocation({
Expand Down
3 changes: 1 addition & 2 deletions packages/core/util/dedupe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ export function dedupe<T>(list: T[], hasher: Hasher<T> = JSON.stringify) {
const clone: T[] = []
const lookup = new Set<string>()

for (let i = 0; i < list.length; i++) {
const entry = list[i]
for (const entry of list) {
const hashed = hasher(entry)

if (!lookup.has(hashed)) {
Expand Down
12 changes: 6 additions & 6 deletions packages/core/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1260,24 +1260,24 @@ export function localStorageSetItem(str: string, item: string) {

export function max(arr: number[], init = -Infinity) {
let max = init
for (let i = 0; i < arr.length; i++) {
max = arr[i] > max ? arr[i] : max
for (const entry of arr) {
max = entry > max ? entry : max
}
return max
}

export function min(arr: number[], init = Infinity) {
let min = init
for (let i = 0; i < arr.length; i++) {
min = arr[i] < min ? arr[i] : min
for (const entry of arr) {
min = entry < min ? entry : min
}
return min
}

export function sum(arr: number[]) {
let sum = 0
for (let i = 0; i < arr.length; i++) {
sum += arr[i]
for (const entry of arr) {
sum += entry
}
return sum
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/util/layouts/GranularRectLayout.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ describe('GranularRectLayout', () => {
['1,32', 239691, 245015, 16],
]

for (let i = 0; i < testRects.length; i += 1) {
const top = l.addRect(...testRects[i])
for (const rect of testRects) {
const top = l.addRect(...rect)
expect(top).toEqual(0)
}
})
Expand Down
3 changes: 1 addition & 2 deletions packages/core/util/layouts/GranularRectLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,7 @@ export default class GranularRectLayout<T> implements BaseLayout<T> {
const pLeft = Math.floor(left / this.pitchX)
const pRight = Math.floor(right / this.pitchX)
const { bitmap } = this
for (let y = 0; y < bitmap.length; y += 1) {
const row = bitmap[y]
for (const row of bitmap) {
if (row) {
row.discardRange(pLeft, pRight)
}
Expand Down
3 changes: 1 addition & 2 deletions packages/text-indexing/src/types/vcfAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ export async function* indexVcf(
.filter((f): f is string => !!f)

const ids = id.split(',')
for (let i = 0; i < ids.length; i++) {
const id = ids[i]
for (const id of ids) {
const attrs = [id]
const record = JSON.stringify([
encodeURIComponent(locStr),
Expand Down
2 changes: 2 additions & 0 deletions packages/text-indexing/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ export interface VcfAdapter {
type: 'VcfAdapter'
vcfLocation: UriLocation | LocalPathLocation
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type Track = Record<string, any>

export interface TextSearching {
indexingFeatureTypesToExclude?: string[]
indexingAttributes?: string[]
Expand Down
9 changes: 3 additions & 6 deletions plugins/alignments/src/CramAdapter/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ export function readFeaturesToMismatches(
let sublen = 0
let lastPos = start

for (let i = 0; i < readFeatures.length; i++) {
const f = readFeatures[i]
const { code, pos, data, sub, ref } = f
for (const { refPos: p, code, pos, data, sub, ref } of readFeatures) {
sublen = refPos - lastPos
lastPos = refPos

Expand All @@ -43,7 +41,7 @@ export function readFeaturesToMismatches(
}
insLen = 0
}
refPos = f.refPos - 1 - start
refPos = p - 1 - start

if (code === 'X') {
// substitution
Expand Down Expand Up @@ -150,8 +148,7 @@ export function readFeaturesToCIGAR(
let sublen = 0
let insLen = 0
if (readFeatures !== undefined) {
for (let i = 0; i < readFeatures.length; i++) {
const { code, refPos, sub, data } = readFeatures[i]
for (const { code, refPos, sub, data } of readFeatures) {
sublen = refPos - lastPos
seq += ref.slice(lastPos - refStart, refPos - refStart)
lastPos = refPos
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ export function drawPairChains({
const maxD = Math.log(max(coords.map(c => c.distance)))
const minD = Math.max(Math.log(min(coords.map(c => c.distance))) - 1, 0)
const scaler = (self.height - 20) / (maxD - minD)
for (let i = 0; i < coords.length; i++) {
const { r1e, r1s, r2e, r2s, distance, v0, v1 } = coords[i]
for (const { r1e, r1s, r2e, r2s, distance, v0, v1 } of coords) {
const w1 = Math.max(r1e - r1s, 2)
const w2 = Math.max(r2e - r2s, 2)
const [fill, stroke] = getPairedColor({ type, v0, v1, stats }) || []
Expand Down
14 changes: 6 additions & 8 deletions plugins/alignments/src/MismatchParser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,15 @@ export function mdToMismatches(

// now actually parse the MD string
const md = mdstring.match(mdRegex) || []
for (let i = 0; i < md.length; i++) {
const token = md[i]
for (const token of md) {
const num = +token
if (!Number.isNaN(num)) {
curr.start += num
} else if (token.startsWith('^')) {
curr.start += token.length - 1
} else {
// mismatch
// eslint-disable-next-line @typescript-eslint/prefer-for-of
for (let j = 0; j < token.length; j += 1) {
curr.length = 1

Expand Down Expand Up @@ -315,8 +315,7 @@ export function getModificationPositions(
const seq = fstrand === -1 ? revcom(fseq) : fseq
const mods = mm.split(';').filter(mod => !!mod)
const result = []
for (let i = 0; i < mods.length; i++) {
const mod = mods[i]
for (const mod of mods) {
const [basemod, ...skips] = mod.split(',')

// regexes based on parse_mm.pl from hts-specs
Expand All @@ -340,12 +339,11 @@ export function getModificationPositions(
// sequence of the read, if we have a modification type e.g. C+m;2 and a
// sequence ACGTACGTAC we skip the two instances of C and go to the last
// C
for (let j = 0; j < types.length; j++) {
const type = types[j]
for (const type of types) {
let i = 0
const positions = []
for (let k = 0; k < skips.length; k++) {
let delta = +skips[k]
for (const d of skips) {
let delta = +d
do {
if (base === 'N' || base === seq[i]) {
delta--
Expand Down
3 changes: 1 addition & 2 deletions plugins/alignments/src/PileupRenderer/layoutFeature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ export function layoutFeature({
const mismatches = feature.get('mismatches') as Mismatch[]
const seq = feature.get('seq') as string
if (seq) {
for (let i = 0; i < mismatches.length; i += 1) {
const { type, start, cliplen = 0 } = mismatches[i]
for (const { type, start, cliplen = 0 } of mismatches) {
if (type === 'softclip') {
start === 0 ? (expansionBefore = cliplen) : (expansionAfter = cliplen)
}
Expand Down
6 changes: 2 additions & 4 deletions plugins/alignments/src/PileupRenderer/renderMismatches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ export function renderMismatches({

// two pass rendering: first pass, draw all the mismatches except wide
// insertion markers
for (let i = 0; i < mismatches.length; i += 1) {
const mismatch = mismatches[i]
for (const mismatch of mismatches) {
const mstart = start + mismatch.start
const mlen = mismatch.length
const mbase = mismatch.base
Expand Down Expand Up @@ -164,8 +163,7 @@ export function renderMismatches({

// second pass, draw wide insertion markers on top
if (drawIndels) {
for (let i = 0; i < mismatches.length; i += 1) {
const mismatch = mismatches[i]
for (const mismatch of mismatches) {
const mstart = start + mismatch.start
const mlen = mismatch.length
const [leftPx] = bpSpanPx(mstart, mstart + mlen, region, bpPerPx)
Expand Down
18 changes: 6 additions & 12 deletions plugins/alignments/src/SNPCoverageRenderer/SNPCoverageRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ export default class SNPCoverageRenderer extends WiggleBaseRenderer {
// Use two pass rendering, which helps in visualizing the SNPs at higher
// bpPerPx First pass: draw the gray background
ctx.fillStyle = colorForBase.total
for (let i = 0; i < coverage.length; i++) {
const feature = coverage[i]
for (const feature of coverage) {
const [leftPx, rightPx] = featureSpanPx(feature, region, bpPerPx)
const w = rightPx - leftPx + fudgeFactor
const score = feature.get('score') as number
Expand All @@ -136,8 +135,7 @@ export default class SNPCoverageRenderer extends WiggleBaseRenderer {
// which can be wider than the actual bpPerPx This reduces overdrawing of
// the grey background over the SNPs

for (let i = 0; i < coverage.length; i++) {
const feature = coverage[i]
for (const feature of coverage) {
const [leftPx, rightPx] = featureSpanPx(feature, region, bpPerPx)

const score = feature.get('score') as number
Expand All @@ -147,8 +145,7 @@ export default class SNPCoverageRenderer extends WiggleBaseRenderer {
const keys = Object.keys(snpinfo.cov).sort()

let curr = 0
for (let i = 0; i < keys.length; i++) {
const base = keys[i]
for (const base of keys) {
const { total } = snpinfo.cov[base]
ctx.fillStyle =
colorForBase[base] ||
Expand All @@ -170,8 +167,7 @@ export default class SNPCoverageRenderer extends WiggleBaseRenderer {
const indicatorHeight = 4.5
if (drawInterbaseCounts) {
let curr = 0
for (let i = 0; i < interbaseEvents.length; i++) {
const base = interbaseEvents[i]
for (const base of interbaseEvents) {
const { total } = snpinfo.noncov[base]
const r = 0.6
ctx.fillStyle = colorForBase[base]
Expand All @@ -189,8 +185,7 @@ export default class SNPCoverageRenderer extends WiggleBaseRenderer {
let accum = 0
let max = 0
let maxBase = ''
for (let i = 0; i < interbaseEvents.length; i++) {
const base = interbaseEvents[i]
for (const base of interbaseEvents) {
const { total } = snpinfo.noncov[base]
accum += total
if (total > max) {
Expand Down Expand Up @@ -219,8 +214,7 @@ export default class SNPCoverageRenderer extends WiggleBaseRenderer {
}

if (drawArcs) {
for (let i = 0; i < skips.length; i++) {
const f = skips[i]
for (const f of skips) {
const [left, right] = bpSpanPx(
f.get('start'),
f.get('end'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ const Translocations = observer(function ({
// we follow a path in the list of chunks, not from top to bottom,
// just in series following x1,y1 -> x2,y2
const ret = []
for (let i = 0; i < chunk.length; i += 1) {
const { layout: c1, feature: f1, level: level1 } = chunk[i]
for (const { layout: c1, feature: f1, level: level1 } of chunk) {
const level2 = level1 === 0 ? 1 : 0
const id = f1.id()
if (!c1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ function getTrackOffsets(
) {
const offsets = {} as Record<string, number>
let curr = textOffset
for (let i = 0; i < view.tracks.length; i++) {
const track = view.tracks[i]
for (const track of view.tracks) {
offsets[track.configuration.trackId] = curr + extra
curr += track.displays[0].height + textOffset
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function heightFromSpecificLevel(
}

export function getPxFromCoordinate(view: LGV, refName: string, coord: number) {
return ((view.bpToPx({ refName, coord }) || {}).offsetPx || 0) - view.offsetPx
return (view.bpToPx({ refName, coord })?.offsetPx || 0) - view.offsetPx
}

// get's the yposition of a layout record in a track
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ export function viewportVisibleSection(
[viewR, viewB],
]
let maxRho = -Infinity
for (let i = 0; i < vertices.length; i += 1) {
const [x, y] = vertices[i]
for (const [x, y] of vertices) {
const rho = Math.sqrt(x * x + y * y)
if (rho > maxRho) {
maxRho = rho
Expand Down Expand Up @@ -231,9 +230,8 @@ export function viewportVisibleSection(
let rhoMax = -Infinity
let thetaMin = Infinity
let thetaMax = -Infinity
for (let i = 0; i < vertices.length; i += 1) {
for (const [vx, vy] of vertices) {
// ignore vertex if outside the viewport
const [vx, vy] = vertices[i]
if (vx >= viewL && vx <= viewR && vy >= viewT && vy <= viewB) {
const [rho, theta] = cartesianToPolar(vx * reflect, vy * reflect)
// ignore vertex if outside the circle
Expand Down
4 changes: 2 additions & 2 deletions plugins/comparative-adapters/src/DeltaAdapter/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ export function paf_delta2paf(buffer: Buffer) {
throw new Error(`inconsistent alignment on line ${i}`)
}
cigar.push((re - rs - x) << 4)
for (let i = 0; i < cigar.length; ++i) {
const rlen = cigar[i] >> 4
for (const entry of cigar) {
const rlen = entry >> 4
blen += rlen
cigar_str.push(rlen + 'MID'.charAt(cigar[i] & 0xf))
}
Expand Down
Loading

0 comments on commit d0ae041

Please sign in to comment.