Skip to content

Commit

Permalink
Add curly:error to eslint config (#1925)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Apr 28, 2021
1 parent 00f9a79 commit e2b1261
Show file tree
Hide file tree
Showing 68 changed files with 294 additions and 175 deletions.
1 change: 1 addition & 0 deletions .eslintrc.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"class-methods-use-this": "off",
"global-require": "off",
"import/no-cycle": "off",
"curly": "error",
"import/prefer-default-export": "off",
"jsx-a11y/mouse-events-have-key-events": "off",
"max-classes-per-file": "off",
Expand Down
3 changes: 2 additions & 1 deletion packages/core/PluginLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ export default class PluginLoader {
this
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const plugin = (scope as any)[umdName] as { default: PluginConstructor }
if (!plugin)
if (!plugin) {
throw new Error(
`plugin ${moduleName} failed to load, ${scope.constructor.name}.${umdName} is undefined`,
)
}

return plugin.default
}
Expand Down
9 changes: 6 additions & 3 deletions packages/core/PluginManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@ class TypeRecord<ElementClass extends PluggableElementBase> {
}

get(name: string) {
if (!this.has(name))
if (!this.has(name)) {
throw new Error(
`${this.typeName} '${name}' not found, perhaps its plugin is not loaded or its plugin has not added it.`,
)
}
return this.registeredTypes[name]
}

Expand Down Expand Up @@ -285,8 +286,9 @@ export default class PluginManager {

this.elementCreationSchedule.add(groupName, () => {
const newElement = creationCallback(this)
if (!newElement.name)
if (!newElement.name) {
throw new Error(`cannot add a ${groupName} with no name`)
}

if (typeRecord.has(newElement.name)) {
throw new Error(
Expand Down Expand Up @@ -351,8 +353,9 @@ export default class PluginManager {
pluggableTypes.push(thing)
}
})
if (pluggableTypes.length === 0)
if (pluggableTypes.length === 0) {
pluggableTypes.push(ConfigurationSchema('Null', {}))
}
return types.union(...pluggableTypes)
}

Expand Down
3 changes: 2 additions & 1 deletion packages/core/assemblyManager/assembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,11 @@ export default function assemblyFactory(
return self.refNameColors[idx % self.refNameColors.length]
},
isValidRefName(refName: string) {
if (!self.refNameAliases)
if (!self.refNameAliases) {
throw new Error(
'isValidRefName cannot be called yet, the assembly has not finished loading',
)
}
return !!this.getCanonicalRefName(refName)
},
}))
Expand Down
3 changes: 2 additions & 1 deletion packages/core/configuration/configurationSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ function makeConfigurationSchemaModel<
modelDefinition.type = types.optional(types.literal(modelName), modelName)
}

if (options.explicitIdentifier && options.implicitIdentifier)
if (options.explicitIdentifier && options.implicitIdentifier) {
throw new Error(
`Cannot have both explicit and implicit identifiers in ${modelName}`,
)
}
if (options.explicitIdentifier) {
if (typeof options.explicitIdentifier === 'string') {
modelDefinition[options.explicitIdentifier] = types.identifier
Expand Down
3 changes: 2 additions & 1 deletion packages/core/configuration/configurationSlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,11 @@ export default function ConfigSlot(
// }),
)
.postProcessSnapshot(snap => {
if (typeof snap.value === 'object')
if (typeof snap.value === 'object') {
return JSON.stringify(snap.value) !== JSON.stringify(defaultValue)
? snap.value
: undefined
}
return snap.value !== defaultValue ? snap.value : undefined
})
.actions(self => ({
Expand Down
6 changes: 4 additions & 2 deletions packages/core/data_adapters/dataAdapterCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ export function getAdapter(
const cacheKey = adapterConfigCacheKey(adapterConfigSnapshot)
if (!adapterCache[cacheKey]) {
const adapterType = (adapterConfigSnapshot || {}).type
if (!adapterType)
if (!adapterType) {
throw new Error(
'could not determine adapter type from adapter config snapshot',
)
}
const dataAdapterType = pluginManager.getAdapterType(adapterType)
if (!dataAdapterType) {
throw new Error(`unknown data adapter type ${adapterType}`)
Expand Down Expand Up @@ -113,8 +114,9 @@ export function freeAdapterResources(specification: Record<string, any>) {
specification.regions ||
(specification.region ? [specification.region] : [])
regions.forEach((region: Region) => {
if (region.refName !== undefined)
if (region.refName !== undefined) {
cacheEntry.dataAdapter.freeResources(region)
}
})
}
})
Expand Down
6 changes: 4 additions & 2 deletions packages/core/pluggableElementTypes/ConnectionType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ export default class ConnectionType extends PluggableElementBase {
this.description = stuff.description
this.url = stuff.url
this.configEditorComponent = stuff.configEditorComponent
if (!this.stateModel)
if (!this.stateModel) {
throw new Error(`no stateModel defined for connection ${this.name}`)
if (!this.configSchema)
}
if (!this.configSchema) {
throw new Error(`no configSchema defined for connection ${this.name}`)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,14 @@ export const BaseDisplay = types
get rendererType() {
const { pluginManager } = getEnv(self)
const RendererType = pluginManager.getRendererType(self.rendererTypeName)
if (!RendererType)
if (!RendererType) {
throw new Error(`renderer "${self.rendererTypeName}" not found`)
if (!RendererType.ReactComponent)
}
if (!RendererType.ReactComponent) {
throw new Error(
`renderer ${self.rendererTypeName} has no ReactComponent, it may not be completely implemented yet`,
)
}
return RendererType
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ export default class BoxRendererType extends FeatureRendererType {

getWorkerSession(props: LayoutSessionProps & { sessionId: string }) {
const { sessionId } = props
if (!this.sessions[sessionId])
if (!this.sessions[sessionId]) {
this.sessions[sessionId] = this.createSession(props)
}
const session = this.sessions[sessionId]
session.update(props)
return session
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ export default class SerializableFilterChain {
if (
// @ts-ignore
!this.filterChain[i].expr.evalSync({ feature: args[0] })
)
) {
return false
}
}
return true
}
Expand Down
3 changes: 2 additions & 1 deletion packages/core/rpc/coreRpcMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,11 @@ export class CoreRender extends RpcMethodType {
sessionId,
adapterConfig,
)
if (!(dataAdapter instanceof BaseFeatureDataAdapter))
if (!(dataAdapter instanceof BaseFeatureDataAdapter)) {
throw new Error(
`CoreRender cannot handle this type of data adapter ${dataAdapter}`,
)
}

const RendererType = validateRendererType(
rendererType,
Expand Down
7 changes: 6 additions & 1 deletion packages/core/ui/ViewContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,13 @@ export default withContentRect('bounds')(
// note that this effect will run only once, because of
// the empty array second param
useEffect(() => {
if (scrollRef && scrollRef.current && scrollRef.current.scrollIntoView)
if (
scrollRef &&
scrollRef.current &&
scrollRef.current.scrollIntoView
) {
scrollRef.current.scrollIntoView({ block: 'center' })
}
}, [])

const aboutTrack = session.showAboutConfig
Expand Down
3 changes: 2 additions & 1 deletion packages/core/util/calculateStaticBlocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ export default function calculateStaticBlocks(

let windowRightBlockNum =
Math.floor((windowRightBp - regionBpOffset) / blockSizeBp) + extra
if (windowRightBlockNum >= regionBlockCount)
if (windowRightBlockNum >= regionBlockCount) {
windowRightBlockNum = regionBlockCount - 1
}

let windowLeftBlockNum =
Math.floor((windowLeftBp - regionBpOffset) / blockSizeBp) - extra
Expand Down
3 changes: 2 additions & 1 deletion packages/core/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,9 @@ export function makeAbortableReaction<T, U, V>(
successFunction(result)
}
} catch (error) {
if (thisInProgress && !thisInProgress.signal.aborted)
if (thisInProgress && !thisInProgress.signal.aborted) {
thisInProgress.abort()
}
handleError(error)
}
},
Expand Down
6 changes: 4 additions & 2 deletions packages/core/util/io/ElectronLocalFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,22 @@ export default class ElectronLocalFile implements GenericFilehandle {
constructor(source: PathLike) {
let ipcRenderer
if (electron) ipcRenderer = electron.ipcRenderer
if (!ipcRenderer)
if (!ipcRenderer) {
throw new Error(
'Cannot use ElectronLocalFile without ipcRenderer from electron',
)
}
this.ipcRenderer = ipcRenderer
this.filename = source
}

private async getFd(): Promise<number> {
if (!this.filename) throw new Error('no file path specified')
if (!this.fd)
if (!this.fd) {
this.fd = this.ipcRenderer.invoke('open', this.filename, 'r') as Promise<
number
>
}
return this.fd
}

Expand Down
12 changes: 8 additions & 4 deletions packages/core/util/io/ElectronRemoteFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ export default class ElectronRemoteFile implements GenericFilehandle {
public constructor(source: string, opts: FilehandleOptions = {}) {
let ipcRenderer
if (electron) ipcRenderer = electron.ipcRenderer
if (!ipcRenderer)
if (!ipcRenderer) {
throw new Error(
'Cannot use ElectronLocalFile without ipcRenderer from electron',
)
}
this.ipcRenderer = ipcRenderer

this.url = source
Expand Down Expand Up @@ -113,10 +114,11 @@ export default class ElectronRemoteFile implements GenericFilehandle {
protected async getFetch(
opts: FilehandleOptions,
): Promise<PolyfilledResponse> {
if (!this.fetch)
if (!this.fetch) {
throw new Error(
'a fetch function must be available unless using a file:// url',
)
}
if (!this.url) {
throw new Error('no URL specified')
}
Expand Down Expand Up @@ -152,8 +154,9 @@ export default class ElectronRemoteFile implements GenericFilehandle {
if (requestOptions.headers && requestOptions.headers.range) {
const contentRange = response.headers.get('content-range')
const sizeMatch = /\/(\d+)$/.exec(contentRange || '')
if (sizeMatch && sizeMatch[1])
if (sizeMatch && sizeMatch[1]) {
this._stat = { size: parseInt(sizeMatch[1], 10) }
}
} else {
const contentLength = response.headers.get('content-length')
if (contentLength) this._stat = { size: parseInt(contentLength, 10) }
Expand Down Expand Up @@ -233,8 +236,9 @@ export default class ElectronRemoteFile implements GenericFilehandle {
public async stat(): Promise<Stats> {
if (!this._stat) await this.headFetch()
if (!this._stat) await this.read(Buffer.allocUnsafe(10), 0, 10, 0)
if (!this._stat)
if (!this._stat) {
throw new Error(`unable to determine size of file at ${this.url}`)
}
return this._stat
}
}
6 changes: 3 additions & 3 deletions packages/core/util/io/rangeFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ async function globalCacheFetch(
let range
if (requestHeaders) {
if (requestHeaders instanceof Headers) range = requestHeaders.get('range')
else if (Array.isArray(requestHeaders))
[, range] = requestHeaders.find(([key]) => key === 'range') || [
else if (Array.isArray(requestHeaders)) {
;[, range] = requestHeaders.find(([key]) => key === 'range') || [
undefined,
undefined,
]
else range = requestHeaders.range
} else range = requestHeaders.range
}
if (range) {
const rangeParse = /bytes=(\d+)-(\d+)/.exec(range)
Expand Down
13 changes: 9 additions & 4 deletions packages/core/util/layouts/SceneGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,21 @@ export default class SceneGraph {
data?: Record<string, any>,
): SceneGraph {
let child: SceneGraph
if (nameOrSceneGraph instanceof SceneGraph) child = nameOrSceneGraph
else
if (nameOrSceneGraph instanceof SceneGraph) {
child = nameOrSceneGraph
} else {
child = new SceneGraph(nameOrSceneGraph, left, top, width, height, data)
}

if (!(child instanceof SceneGraph)) {
throw new TypeError(
'argument to addChild must be an array or a SceneGraph',
)
}

if (this.children.has(child.name))
if (this.children.has(child.name)) {
throw new Error(`child named "${child.name}" already exists`)
}

// update the bounds to match the child
child.parent = this
Expand Down Expand Up @@ -146,7 +149,9 @@ export default class SceneGraph {
if (bottom !== undefined && newBottom > bottom) {
this.height += newBottom - bottom
}
if (this.parent) this.parent.expand(newLeft, newRight, newTop, newBottom)
if (this.parent) {
this.parent.expand(newLeft, newRight, newTop, newBottom)
}
this.absoluteCache.dirty = true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,14 @@ export const BaseChordDisplayModel = types
const ThisRendererType = pluginManager.getRendererType(
self.rendererTypeName,
)
if (!ThisRendererType)
if (!ThisRendererType) {
throw new Error(`renderer "${display.rendererTypeName}" not found`)
if (!ThisRendererType.ReactComponent)
}
if (!ThisRendererType.ReactComponent) {
throw new Error(
`renderer ${display.rendererTypeName} has no ReactComponent, it may not be completely implemented yet`,
)
}
return ThisRendererType
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ export default ({ jbrequire }) => {
}

// check renderertype compatibility
if (!self.isCompatibleWithRenderer(rendererType))
if (!self.isCompatibleWithRenderer(rendererType)) {
throw new Error(
`renderer ${rendererType.name} is not compatible with this display type`,
)
}

const { html, ...data } = await rendererType.renderInClient(rpcManager, {
...renderArgs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,9 @@ export default function CircularView(pluginManager: PluginManager) {
get assemblyNames() {
const assemblyNames: string[] = []
self.displayedRegions.forEach(displayedRegion => {
if (!assemblyNames.includes(displayedRegion.assemblyName))
if (!assemblyNames.includes(displayedRegion.assemblyName)) {
assemblyNames.push(displayedRegion.assemblyName)
}
})
return assemblyNames
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ const Member = observer(props => {
slotName={slotName}
slot={slot}
onChange={evt => {
if (evt.target.value !== slot.type)
if (evt.target.value !== slot.type) {
schema.setSubschema(slotName, { type: evt.target.value })
}
}}
/>
)
Expand Down
Loading

0 comments on commit e2b1261

Please sign in to comment.