Skip to content

Commit

Permalink
Fixup lint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Apr 28, 2021
1 parent 22118ff commit d351318
Show file tree
Hide file tree
Showing 171 changed files with 1,139 additions and 484 deletions.
7 changes: 5 additions & 2 deletions .eslintrc.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"browser": true
},
"extends": [
"airbnb-typescript",
"plugin:@typescript-eslint/recommended",
"plugin:monorepo/recommended",
"plugin:prettier/recommended",
Expand Down Expand Up @@ -37,9 +36,13 @@
"@typescript-eslint/require-await": "off",
"@typescript-eslint/unbound-method": "off",
"class-methods-use-this": "off",
"@typescript-eslint/no-redeclare": "off",
"global-require": "off",
"import/no-cycle": "off",
"curly": "error",
"no-global-assign": "warn",
"react/no-danger": "warn",
"import/no-cycle": "off",
"import/no-anonymous-default-export": "off",
"import/prefer-default-export": "off",
"jsx-a11y/mouse-events-have-key-events": "off",
"max-classes-per-file": "off",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/BaseFeatureWidget/BaseFeatureDetail.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any,react/prop-types,no-nested-ternary */
/* eslint-disable @typescript-eslint/no-explicit-any,react/prop-types */
import React from 'react'
import ErrorBoundary from 'react-error-boundary'
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/BaseFeatureWidget/SequenceFeatureDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable no-nested-ternary,react/prop-types */
/* eslint-disable react/prop-types */
import React, { useRef, useState, useEffect } from 'react'
import { Button, Select, MenuItem, Typography } from '@material-ui/core'
import { useInView } from 'react-intersection-observer'
Expand Down
12 changes: 9 additions & 3 deletions packages/core/PluginManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ export default class PluginManager {
}

configure() {
if (this.configured) throw new Error('already configured')
if (this.configured) {
throw new Error('already configured')
}

this.plugins.forEach(plugin => plugin.configure(this))

Expand Down Expand Up @@ -364,7 +366,9 @@ export default class PluginManager {
lib = ReExports

load = <FTYPE extends AnyFunction>(lib: FTYPE): ReturnType<FTYPE> => {
if (!this.jbrequireCache.has(lib)) this.jbrequireCache.set(lib, lib(this))
if (!this.jbrequireCache.has(lib)) {
this.jbrequireCache.set(lib, lib(this))
}
return this.jbrequireCache.get(lib)
}

Expand Down Expand Up @@ -392,7 +396,9 @@ export default class PluginManager {
return this.load(lib)
}

if (lib.default) return this.jbrequire(lib.default)
if (lib.default) {
return this.jbrequire(lib.default)
}

throw new TypeError(
'lib passed to jbrequire must be either a string or a function',
Expand Down
1 change: 0 additions & 1 deletion packages/core/assemblyManager/assembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ async function loadAssemblyReaction(
adapterRegionsWithAssembly.forEach(region => {
refNameAliases[region.refName] = region.refName
})
// eslint-disable-next-line consistent-return
return { adapterRegionsWithAssembly, refNameAliases }
}
export type Assembly = Instance<ReturnType<typeof assemblyFactory>>
8 changes: 6 additions & 2 deletions packages/core/assemblyManager/assemblyConfigSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ export default (pluginManager: PluginManager) => {
| SnapshotIn<typeof BaseAssemblyConfigSchema>
| SnapshotIn<typeof AssemblyConfigSchema>,
) {
if (!snapshot) return BaseAssemblyConfigSchema
if (!snapshot) {
return BaseAssemblyConfigSchema
}
const { refNameAliases } = snapshot
if (refNameAliases) return AssemblyConfigSchema
if (refNameAliases) {
return AssemblyConfigSchema
}
return BaseAssemblyConfigSchema
}

Expand Down
36 changes: 27 additions & 9 deletions packages/core/configuration/configurationSlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,23 @@ const typeModelExtensions: { [typeName: string]: (self: any) => any } = {
},
addToKey(key: string, val: string) {
const ar = self.value.get(key)
if (!ar) throw new Error(`${key} not found`)
if (!ar) {
throw new Error(`${key} not found`)
}
ar.push(val)
},
removeAtKeyIndex(key: string, idx: number) {
const ar = self.value.get(key)
if (!ar) throw new Error(`${key} not found`)
if (!ar) {
throw new Error(`${key} not found`)
}
ar.splice(idx, 1)
},
setAtKeyIndex(key: string, idx: number, val: string) {
const ar = self.value.get(key)
if (!ar) throw new Error(`${key} not found`)
if (!ar) {
throw new Error(`${key} not found`)
}
ar[idx] = val
},
},
Expand Down Expand Up @@ -163,15 +169,21 @@ export default function ConfigSlot(
contextVariable = [],
}: ConfigSlotDefinition,
) {
if (!type) throw new Error('type name required')
if (!model) model = typeModels[type]
if (!type) {
throw new Error('type name required')
}
if (!model) {
model = typeModels[type]
}
if (!model) {
throw new Error(
`no builtin config slot type "${type}", and no 'model' param provided`,
)
}

if (defaultValue === undefined) throw new Error("no 'defaultValue' provided")
if (defaultValue === undefined) {
throw new Error("no 'defaultValue' provided")
}

// if the `type` is something like `color`, then the model name
// here will be `ColorConfigSlot`
Expand Down Expand Up @@ -209,7 +221,9 @@ export default function ConfigSlot(
// for embedding in either JSON or a JS function string.
// many of the data types override this in typeModelExtensions
get valueJSON(): any[] | Record<string, any> | string | undefined {
if (self.isCallback) return undefined
if (self.isCallback) {
return undefined
}
function json(value: { toJSON: Function } | any) {
if (value && value.toJSON) {
return value.toJSON()
Expand Down Expand Up @@ -252,11 +266,15 @@ export default function ConfigSlot(
self.value = defaultValue
},
convertToCallback() {
if (self.isCallback) return
if (self.isCallback) {
return
}
self.value = `jexl:${self.valueJSON || "''"}`
},
convertToValue() {
if (!self.isCallback) return
if (!self.isCallback) {
return
}
// try calling it with no arguments
try {
const funcResult = self.expr.evalSync()
Expand Down
32 changes: 24 additions & 8 deletions packages/core/configuration/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ export function readConfObject(
args: Record<string, any> = {},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
): any {
if (!confObject) throw new TypeError('must provide conf object to read')
if (!slotPath) return getSnapshot(confObject)
if (!confObject) {
throw new TypeError('must provide conf object to read')
}
if (!slotPath) {
return getSnapshot(confObject)
}
if (typeof slotPath === 'string') {
let slot = confObject[slotPath]
// check for the subconf being a map if we don't find it immediately
Expand All @@ -66,10 +70,14 @@ export function readConfObject(

if (slot.expr) {
const appliedFunc = slot.expr.evalSync(args)
if (isStateTreeNode(appliedFunc)) return getSnapshot(appliedFunc)
if (isStateTreeNode(appliedFunc)) {
return getSnapshot(appliedFunc)
}
return appliedFunc
}
if (isStateTreeNode(slot)) return getSnapshot(slot)
if (isStateTreeNode(slot)) {
return getSnapshot(slot)
}
return slot
}

Expand Down Expand Up @@ -107,7 +115,9 @@ export function getConf(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
args: Record<string, any> = {},
) {
if (!model) throw new TypeError('must provide a model object')
if (!model) {
throw new TypeError('must provide a model object')
}
const { configuration } = model as { configuration: unknown }
if (isConfigurationModel(configuration)) {
return readConfObject(configuration, slotPath, args)
Expand Down Expand Up @@ -159,21 +169,27 @@ export function isBareConfigurationSchemaType(
return true
}
// if it's a late type, assume its a config schema
if (isLateType(thing)) return true
if (isLateType(thing)) {
return true
}
}
return false
}

export function isConfigurationSchemaType(thing: unknown): boolean {
if (!isType(thing)) return false
if (!isType(thing)) {
return false
}

// written as a series of if-statements instead of a big logical OR
// because this construction gives much better debugging backtraces.

// also, note that the order of these statements matters, because
// for example some union types are also optional types

if (isBareConfigurationSchemaType(thing)) return true
if (isBareConfigurationSchemaType(thing)) {
return true
}

if (isUnionType(thing)) {
return getUnionSubTypes(thing).every(
Expand Down
4 changes: 2 additions & 2 deletions packages/core/data_adapters/BaseAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ function idMaker(args: any, id = '') {
let chr
for (i = 0; i < id.length; i++) {
chr = id.charCodeAt(i)
hash = (hash << 5) - hash + chr // eslint-disable-line no-bitwise
hash |= 0 // eslint-disable-line no-bitwise
hash = (hash << 5) - hash + chr
hash |= 0
}
return hash
}
Expand Down
1 change: 0 additions & 1 deletion packages/core/pluggableElementTypes/ConnectionType.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable react/static-property-placement */
import { IAnyModelType } from 'mobx-state-tree'
import PluggableElementBase from './PluggableElementBase'
import { AnyConfigurationSchemaType } from '../configuration/configurationSchema'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ export function createBaseTrackConfig(pluginManager: PluginManager) {
actions: (self: any) => ({
addDisplayConf(displayConf: { type: string; displayId: string }) {
const { type } = displayConf
if (!type) throw new Error(`unknown display type ${type}`)
if (!type) {
throw new Error(`unknown display type ${type}`)
}
const display = self.displays.find(
(d: any) => d && d.displayId === displayConf.displayId,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,17 @@ export default class BoxRendererType extends FeatureRendererType {

// expands region for glyphs to use
getExpandedRegion(region: Region, renderArgs: RenderArgsDeserialized) {
if (!region) return region
if (!region) {
return region
}
const { bpPerPx, config } = renderArgs
const maxFeatureGlyphExpansion =
config === undefined
? 0
: readConfObject(config, 'maxFeatureGlyphExpansion')
if (!maxFeatureGlyphExpansion) return region
if (!maxFeatureGlyphExpansion) {
return region
}
const bpExpansion = Math.round(maxFeatureGlyphExpansion * bpPerPx)
return {
...region,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ export default class ComparativeServerSideRenderer extends ServerSideRenderer {
* @returns true if this feature passes all configured filters
*/
featurePassesFilters(renderArgs: RenderArgsDeserialized, feature: Feature) {
if (!renderArgs.filters) return true
if (!renderArgs.filters) {
return true
}
return renderArgs.filters.passes(feature, renderArgs)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ export default class FeatureRendererType extends ServerSideRendererType {
filter(feature => this.featurePassesFilters(renderArgs, feature)),
tap(feature => {
const id = feature.id()
if (!id) throw new Error(`invalid feature id "${id}"`)
if (!id) {
throw new Error(`invalid feature id "${id}"`)
}
features.set(id, feature)
}),
ignoreElements(),
Expand All @@ -190,7 +192,9 @@ export default class FeatureRendererType extends ServerSideRendererType {
* @returns true if this feature passes all configured filters
*/
featurePassesFilters(renderArgs: RenderArgsDeserialized, feature: Feature) {
if (!renderArgs.filters) return true
if (!renderArgs.filters) {
return true
}
return renderArgs.filters.passes(feature, renderArgs)
}

Expand Down
1 change: 0 additions & 1 deletion packages/core/rpc/BaseRpcDriver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class MockWorkerHandle implements WorkerHandle {
throw new Error('timeout')
}

// eslint-disable-next-line no-await-in-loop
await timeout(50)
}
} else if (name === 'doWorkShortPingTime') {
Expand Down
1 change: 0 additions & 1 deletion packages/core/rpc/ElectronRpcDriver.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-await-in-loop */
import shortid from 'shortid'
import BaseRpcDriver, { RpcDriverConstructorArgs } from './BaseRpcDriver'
import PluginManager from '../PluginManager'
Expand Down
4 changes: 3 additions & 1 deletion packages/core/rpc/RpcManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ export default class RpcManager {

getDriver(backendName: keyof typeof DriverClasses): DriverClass {
const driver = this.driverObjects.get(backendName)
if (driver) return driver
if (driver) {
return driver
}

const backendConfiguration = this.backendConfigurations[backendName]
const DriverClassImpl = DriverClasses[backendName]
Expand Down
4 changes: 3 additions & 1 deletion packages/core/rpc/coreRpcMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ export class CoreFreeResources extends RpcMethodType {
// pass the freeResources hint along to all the renderers as well
this.pluginManager.getRendererTypes().forEach(renderer => {
const count = renderer.freeResources(/* specification */)
if (count) deleteCount += count
if (count) {
deleteCount += count
}
})

return deleteCount
Expand Down
1 change: 0 additions & 1 deletion packages/core/ui/AboutDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-nested-ternary */
import React, { useState, useEffect } from 'react'
import {
Dialog,
Expand Down
12 changes: 9 additions & 3 deletions packages/core/ui/PrerenderedCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@ function PrerenderedCanvas(props: {
const featureCanvas = useRef<HTMLCanvasElement>(null)

useEffect(() => {
if (!imageData) return
if (!imageData) {
return
}
const canvas = featureCanvas.current
if (!canvas) return
if (!canvas) {
return
}
const context = canvas.getContext('2d')
if (!context) return
if (!context) {
return
}
if (imageData.commands) {
imageData.commands.forEach((command: any) => {
if (command.type === 'strokeStyle') {
Expand Down
Loading

0 comments on commit d351318

Please sign in to comment.