Skip to content

Commit

Permalink
Enable unicorn no-array-for-each
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettjstevens committed Aug 21, 2023
1 parent 00d4201 commit 54eedc3
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 143 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ module.exports = {
// eslint-plugin-unicorn rules (override recommended)
'unicorn/consistent-destructuring': 'off',
'unicorn/filename-case': 'off',
'unicorn/no-array-for-each': 'off',
'unicorn/no-empty-file': 'off', // False positives
'unicorn/no-null': 'off',
'unicorn/prefer-module': 'off', // Cypress and apollo-collaboration-server need this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,11 @@ export class FeaturesService {

const headerStream = new Readable({ objectMode: true })
headerStream.push('##gff-version 3\n')
refSeqs.forEach((refSeqDoc: RefSeqDocument) => {
for (const refSeqDoc of refSeqs) {
headerStream.push(
`##sequence-region ${refSeqDoc.name} 1 ${refSeqDoc.length}\n`,
)
})
}
headerStream.push(null)

const refSeqIds = refSeqs.map((refSeq) => refSeq._id)
Expand Down
8 changes: 4 additions & 4 deletions packages/apollo-mst/src/AnnotationFeature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ export const AnnotationFeature = types
*/
get min() {
let min = self.start
self.children?.forEach((child: AnnotationFeatureI) => {
for (const [, child] of self.children ?? []) {
min = Math.min(min, child.min)
})
}
return min
},
/**
Expand All @@ -83,9 +83,9 @@ export const AnnotationFeature = types
*/
get max() {
let max = self.end
self.children?.forEach((child: AnnotationFeatureI) => {
for (const [, child] of self.children ?? []) {
max = Math.max(max, child.max)
})
}
return max
},
}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
isAbstractMenuManager,
} from '@jbrowse/core/util'
import type AuthenticationPlugin from '@jbrowse/plugin-authentication'
import { Change, SerializedChange } from 'apollo-common'
import { Change } from 'apollo-common'
import { getDecodedToken, makeUserSessionId } from 'apollo-shared'
import { autorun } from 'mobx'
import { Instance, flow, getRoot, types } from 'mobx-state-tree'
Expand Down Expand Up @@ -254,10 +254,10 @@ const stateModelFactory = (
return
}
const serializedChanges = yield response.json()
serializedChanges.forEach((serializedChange: SerializedChange) => {
for (const serializedChange of serializedChanges) {
const change = Change.fromJSON(serializedChange)
changeManager?.submit(change, { submitToBackend: false })
})
}
}),
}))
.actions((self) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ if ('document' in window) {
export class CanonicalGeneGlyph extends Glyph {
getRowCount(feature: AnnotationFeatureI, _bpPerPx: number): number {
let cdsCount = 0
feature.children?.forEach((child: AnnotationFeatureI) => {
child.children?.forEach((grandchild: AnnotationFeatureI) => {
for (const [, child] of feature.children ?? new Map()) {
for (const [, grandchild] of child.children ?? new Map()) {
if (grandchild.type === 'CDS') {
cdsCount += 1
}
})
})
}
}
return cdsCount
}

Expand All @@ -66,11 +66,11 @@ export class CanonicalGeneGlyph extends Glyph {
const cdsHeight = Math.round(0.9 * rowHeight)
const { strand } = feature
let currentCDS = 0
feature.children?.forEach((mrna: AnnotationFeatureI) => {
for (const [, mrna] of feature.children ?? new Map()) {
if (mrna.type !== 'mRNA') {
return
}
mrna.children?.forEach((cds: AnnotationFeatureI) => {
for (const [, cds] of mrna.children ?? new Map()) {
if (cds.type !== 'CDS') {
return
}
Expand All @@ -87,69 +87,66 @@ export class CanonicalGeneGlyph extends Glyph {
ctx.lineTo(startPx + widthPx, height)
ctx.stroke()
currentCDS += 1
})
})
}
}
currentCDS = 0
feature.children?.forEach((mrna: AnnotationFeatureI) => {
for (const [, mrna] of feature.children ?? new Map()) {
if (mrna.type !== 'mRNA') {
return
}
const cdsCount = [...(mrna.children ?? [])].filter(
([, exonOrCDS]) => exonOrCDS.type === 'CDS',
).length
Array.from({ length: cdsCount })
// eslint-disable-next-line unicorn/no-useless-undefined
.fill(undefined)
.forEach(() => {
mrna.children?.forEach((exon: AnnotationFeatureI) => {
if (exon.type !== 'exon') {
return
}
const offsetPx = (exon.start - feature.min) / bpPerPx
const widthPx = exon.length / bpPerPx
const startPx = reversed
? xOffset - offsetPx - widthPx
: xOffset + offsetPx
const top = (row + currentCDS) * rowHeight
const utrTop = top + (rowHeight - utrHeight) / 2
ctx.fillStyle = theme?.palette.text.primary ?? 'black'
ctx.fillRect(startPx, utrTop, widthPx, utrHeight)
if (widthPx > 2) {
ctx.clearRect(startPx + 1, utrTop + 1, widthPx - 2, utrHeight - 2)
ctx.fillStyle = 'rgb(211,211,211)'
ctx.fillRect(startPx + 1, utrTop + 1, widthPx - 2, utrHeight - 2)
if (forwardFill && backwardFill && strand) {
const reversal = reversed ? -1 : 1
const [topFill, bottomFill] =
strand * reversal === 1
? [forwardFill, backwardFill]
: [backwardFill, forwardFill]
ctx.fillStyle = topFill
ctx.fillRect(
startPx + 1,
utrTop + 1,
widthPx - 2,
(utrHeight - 2) / 2,
)
ctx.fillStyle = bottomFill
ctx.fillRect(
startPx + 1,
utrTop + 1 + (utrHeight - 2) / 2,
widthPx - 2,
(utrHeight - 2) / 2,
)
}
for (let count = 0; count < cdsCount; count++) {
for (const [, exon] of mrna.children ?? new Map()) {
if (exon.type !== 'exon') {
return
}
const offsetPx = (exon.start - feature.min) / bpPerPx
const widthPx = exon.length / bpPerPx
const startPx = reversed
? xOffset - offsetPx - widthPx
: xOffset + offsetPx
const top = (row + currentCDS) * rowHeight
const utrTop = top + (rowHeight - utrHeight) / 2
ctx.fillStyle = theme?.palette.text.primary ?? 'black'
ctx.fillRect(startPx, utrTop, widthPx, utrHeight)
if (widthPx > 2) {
ctx.clearRect(startPx + 1, utrTop + 1, widthPx - 2, utrHeight - 2)
ctx.fillStyle = 'rgb(211,211,211)'
ctx.fillRect(startPx + 1, utrTop + 1, widthPx - 2, utrHeight - 2)
if (forwardFill && backwardFill && strand) {
const reversal = reversed ? -1 : 1
const [topFill, bottomFill] =
strand * reversal === 1
? [forwardFill, backwardFill]
: [backwardFill, forwardFill]
ctx.fillStyle = topFill
ctx.fillRect(
startPx + 1,
utrTop + 1,
widthPx - 2,
(utrHeight - 2) / 2,
)
ctx.fillStyle = bottomFill
ctx.fillRect(
startPx + 1,
utrTop + 1 + (utrHeight - 2) / 2,
widthPx - 2,
(utrHeight - 2) / 2,
)
}
})
currentCDS += 1
})
})
}
}
currentCDS += 1
}
}
currentCDS = 0
feature.children?.forEach((mrna: AnnotationFeatureI) => {
for (const [, mrna] of feature.children ?? new Map()) {
if (mrna.type !== 'mRNA') {
return
}
mrna.children?.forEach((cds: AnnotationFeatureI) => {
for (const [, cds] of mrna.children ?? new Map()) {
if (cds.type !== 'CDS') {
return
}
Expand Down Expand Up @@ -193,8 +190,8 @@ export class CanonicalGeneGlyph extends Glyph {
}
}
currentCDS += 1
})
})
}
}
const { apolloSelectedFeature } = session
if (apolloSelectedFeature && feature._id === apolloSelectedFeature._id) {
const widthPx = feature.max - feature.min
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ export class GenericChildGlyph extends Glyph {
featuresForRow(feature: AnnotationFeatureI): AnnotationFeatureI[][] {
const features = [[feature]]
if (feature.children) {
feature.children?.forEach((child: AnnotationFeatureI) => {
for (const [, child] of feature.children ?? new Map()) {
features.push(...this.featuresForRow(child))
})
}
}
return features
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ if ('document' in window) {
export class ImplicitExonGeneGlyph extends Glyph {
getRowCount(feature: AnnotationFeatureI): number {
let mrnaCount = 0
feature.children?.forEach((child: AnnotationFeatureI) => {
for (const [, child] of feature.children ?? new Map()) {
if (child.type === 'mRNA') {
mrnaCount += 1
}
})
}
return mrnaCount
}

Expand All @@ -64,7 +64,7 @@ export class ImplicitExonGeneGlyph extends Glyph {
const cdsHeight = Math.round(0.9 * rowHeight)
const { strand } = feature
let currentMRNA = 0
feature.children?.forEach((mrna: AnnotationFeatureI) => {
for (const [, mrna] of feature.children ?? new Map()) {
if (mrna.type !== 'mRNA') {
return
}
Expand All @@ -81,75 +81,62 @@ export class ImplicitExonGeneGlyph extends Glyph {
ctx.lineTo(startPx + widthPx, height)
ctx.stroke()
currentMRNA += 1
})
}
currentMRNA = 0
feature.children?.forEach((mrna: AnnotationFeatureI) => {
for (const [, mrna] of feature.children ?? new Map()) {
if (mrna.type !== 'mRNA') {
return
}
const cdsCount = [...(mrna.children ?? [])].filter(
([, exonOrCDS]) => exonOrCDS.type === 'CDS',
).length
Array.from({ length: cdsCount })
// eslint-disable-next-line unicorn/no-useless-undefined
.fill(undefined)
.forEach(() => {
mrna.children?.forEach((cdsOrUTR: AnnotationFeatureI) => {
const isCDS = cdsOrUTR.type === 'CDS'
const isUTR = cdsOrUTR.type.endsWith('UTR')
if (!(isCDS || isUTR)) {
return
}
const offsetPx = (cdsOrUTR.start - feature.min) / bpPerPx
const widthPx = cdsOrUTR.length / bpPerPx
const startPx = reversed
? xOffset - offsetPx - widthPx
: xOffset + offsetPx
ctx.fillStyle = theme?.palette.text.primary ?? 'black'
const top = (row + currentMRNA) * rowHeight
const height = isCDS ? cdsHeight : utrHeight
const cdsOrUTRTop = top + (rowHeight - height) / 2
ctx.fillRect(startPx, cdsOrUTRTop, widthPx, height)
if (widthPx > 2) {
ctx.clearRect(
for (let count = 0; count < cdsCount; count++) {
for (const [, cdsOrUTR] of mrna.children ?? new Map()) {
const isCDS = cdsOrUTR.type === 'CDS'
const isUTR = cdsOrUTR.type.endsWith('UTR')
if (!(isCDS || isUTR)) {
return
}
const offsetPx = (cdsOrUTR.start - feature.min) / bpPerPx
const widthPx = cdsOrUTR.length / bpPerPx
const startPx = reversed
? xOffset - offsetPx - widthPx
: xOffset + offsetPx
ctx.fillStyle = theme?.palette.text.primary ?? 'black'
const top = (row + currentMRNA) * rowHeight
const height = isCDS ? cdsHeight : utrHeight
const cdsOrUTRTop = top + (rowHeight - height) / 2
ctx.fillRect(startPx, cdsOrUTRTop, widthPx, height)
if (widthPx > 2) {
ctx.clearRect(startPx + 1, cdsOrUTRTop + 1, widthPx - 2, height - 2)
ctx.fillStyle = isCDS ? 'rgb(255,165,0)' : 'rgb(211,211,211)'
ctx.fillRect(startPx + 1, cdsOrUTRTop + 1, widthPx - 2, height - 2)
if (forwardFill && backwardFill && strand) {
const reversal = reversed ? -1 : 1
const [topFill, bottomFill] =
strand * reversal === 1
? [forwardFill, backwardFill]
: [backwardFill, forwardFill]
ctx.fillStyle = topFill
ctx.fillRect(
startPx + 1,
cdsOrUTRTop + 1,
widthPx - 2,
height - 2,
(height - 2) / 2,
)
ctx.fillStyle = isCDS ? 'rgb(255,165,0)' : 'rgb(211,211,211)'
ctx.fillStyle = bottomFill
ctx.fillRect(
startPx + 1,
cdsOrUTRTop + 1,
cdsOrUTRTop + 1 + (height - 2) / 2,
widthPx - 2,
height - 2,
(height - 2) / 2,
)
if (forwardFill && backwardFill && strand) {
const reversal = reversed ? -1 : 1
const [topFill, bottomFill] =
strand * reversal === 1
? [forwardFill, backwardFill]
: [backwardFill, forwardFill]
ctx.fillStyle = topFill
ctx.fillRect(
startPx + 1,
cdsOrUTRTop + 1,
widthPx - 2,
(height - 2) / 2,
)
ctx.fillStyle = bottomFill
ctx.fillRect(
startPx + 1,
cdsOrUTRTop + 1 + (height - 2) / 2,
widthPx - 2,
(height - 2) / 2,
)
}
}
})
})
}
}
}
currentMRNA += 1
})
}
const { apolloSelectedFeature } = session
if (apolloSelectedFeature && feature._id === apolloSelectedFeature._id) {
const widthPx = feature.max - feature.min
Expand Down
Loading

0 comments on commit 54eedc3

Please sign in to comment.