Skip to content

Commit

Permalink
Enable unicorn no-new-array
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettjstevens committed Aug 21, 2023
1 parent 408c59f commit 54adfb5
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 82 deletions.
3 changes: 1 addition & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ module.exports = {
'unicorn/consistent-destructuring': 'off',
'unicorn/filename-case': 'off',
'unicorn/no-array-for-each': 'off',
'unicorn/no-empty-file': 'off',
'unicorn/no-new-array': 'off',
'unicorn/no-empty-file': 'off', // False positives
'unicorn/no-null': 'off',
'unicorn/prefer-array-some': 'off',
'unicorn/prefer-module': 'off',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,50 +97,52 @@ export class CanonicalGeneGlyph extends Glyph {
const cdsCount = [...(mrna.children ?? [])].filter(
([, exonOrCDS]) => exonOrCDS.type === 'CDS',
).length
// eslint-disable-next-line unicorn/no-useless-undefined
new Array(cdsCount).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,
)
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,
)
}
}
})
currentCDS += 1
})
currentCDS += 1
})
})
currentCDS = 0
feature.children?.forEach((mrna: AnnotationFeatureI) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,52 +90,64 @@ export class ImplicitExonGeneGlyph extends Glyph {
const cdsCount = [...(mrna.children ?? [])].filter(
([, exonOrCDS]) => exonOrCDS.type === 'CDS',
).length
// eslint-disable-next-line unicorn/no-useless-undefined
new Array(cdsCount).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(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(
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(
startPx + 1,
cdsOrUTRTop + 1,
widthPx - 2,
(height - 2) / 2,
height - 2,
)
ctx.fillStyle = bottomFill
ctx.fillStyle = isCDS ? 'rgb(255,165,0)' : 'rgb(211,211,211)'
ctx.fillRect(
startPx + 1,
cdsOrUTRTop + 1 + (height - 2) / 2,
cdsOrUTRTop + 1,
widthPx - 2,
(height - 2) / 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) / 2,
)
ctx.fillStyle = bottomFill
ctx.fillRect(
startPx + 1,
cdsOrUTRTop + 1 + (height - 2) / 2,
widthPx - 2,
(height - 2) / 2,
)
}
}
}
})
})
})
currentMRNA += 1
})
const { apolloSelectedFeature } = session
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export function layoutsModelFactory(
if (rowsForFeature.length < rowCount) {
for (let i = 0; i < rowCount - rowsForFeature.length; i++) {
const newRowNumber = rows.length
rows[newRowNumber] = new Array(max - min)
rows[newRowNumber] = Array.from({ length: max - min })
featureLayout.set(newRowNumber, [])
}
rowsForFeature = rows.slice(startingRow, startingRow + rowCount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export function stateModelFactory(
const rowCount = 6
for (let i = 0; i < rowCount; i++) {
const newRowNumber = rows.length
rows[newRowNumber] = new Array(max - min)
rows[newRowNumber] = Array.from({ length: max - min })
featureLayout.set(newRowNumber, [])
}
for (const feature of [...featuresForRefSeq.values()].sort(
Expand Down

0 comments on commit 54adfb5

Please sign in to comment.