diff --git a/Makefile b/Makefile index 163c540..a355ab0 100644 --- a/Makefile +++ b/Makefile @@ -33,3 +33,7 @@ dev-server: build-server: @echo "Build server" ./node_modules/.bin/esbuild $(FLAGS) --define:LIVE_RELOAD=false + +lint: + @echo "Lint" + ./node_modules/.bin/eslint --fix . diff --git a/dev/main.ts b/dev/main.ts index 85745fc..39712e1 100644 --- a/dev/main.ts +++ b/dev/main.ts @@ -1,3 +1,7 @@ +/* eslint-disable @typescript-eslint/no-unsafe-assignment */ +/* eslint-disable @typescript-eslint/no-unsafe-member-access */ +/* eslint-disable @typescript-eslint/no-unsafe-return */ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { c2m, createTreemap, presetDecorator, sortChildrenByKey } from '../src' import './live-reload' @@ -24,7 +28,7 @@ async function main() { treemap.init(root) -main() +main().catch(console.error) treemap.on('click', function(metadata) { this.zoom(metadata.module) diff --git a/eslint.config.js b/eslint.config.js index af99e52..1c035b5 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,19 +1,13 @@ const { nonzzz } = require('eslint-config-kagura') module.exports = nonzzz( - { ts: true, jsx: true, react: true, unusedImports: true }, + { typescript: true }, { ignores: [ - 'dist', - 'node_modules', - 'examples/vue/dist/**', - 'examples/vue/node_modules', - '__tests__/dist', - '**/*.d.ts' - ], - rules: { - 'stylistic/indent': 'off', - 'stylistic/space-before-function-paren': 'off' - } + '**/node_modules', + '**/dist', + '**/display', + '**/analysis' + ] } ) diff --git a/src/etoile/graph/box.ts b/src/etoile/graph/box.ts index cdc8030..e7e58d9 100644 --- a/src/etoile/graph/box.ts +++ b/src/etoile/graph/box.ts @@ -7,7 +7,7 @@ export abstract class C extends Display { super() this.elements = [] } - abstract get __instanceOf__(): string + abstract get __instanceOf__(): DisplayType add(...elements: Display[]) { const cap = elements.length diff --git a/src/etoile/schedule/render.ts b/src/etoile/schedule/render.ts index 2eaae1d..b2aa620 100644 --- a/src/etoile/schedule/render.ts +++ b/src/etoile/schedule/render.ts @@ -34,7 +34,9 @@ export class Render { this.c = new Canvas(options) this.options = options this.initOptions(options) - !options.shaow && to.appendChild(this.canvas) + if (!options.shaow) { + to.appendChild(this.canvas) + } } clear(width: number, height: number) { diff --git a/src/primitives/event.ts b/src/primitives/event.ts index 918c966..74b2074 100644 --- a/src/primitives/event.ts +++ b/src/primitives/event.ts @@ -173,7 +173,7 @@ function bindPrimitiveEvent( native: e, module: findRelativeNode({ x, y }, treemap.layoutNodes) } - // @ts-expect-error + // @ts-expect-error safe bus.emit(evt, event) } c.addEventListener(evt, handler) @@ -234,8 +234,7 @@ export class SelfEvent extends RegisterModule { // If highlighting is triggered, it needs to be destroyed first this.self.highlight.reset() this.self.highlight.setDisplayLayerForHighlight() - // @ts-expect-error - this.self.event.off('mousemove', this.self.onmousemove) + this.self.event.off('mousemove', this.self.onmousemove.bind(this)) this.treemap.event.off(internalEventMappings.ON_ZOOM) this.self.forceDestroy = true const { native } = metadata @@ -263,7 +262,7 @@ export class SelfEvent extends RegisterModule { this.self.draggingState = { x: 0, y: 0 } this.self.highlight.reset() this.self.highlight.setDisplayLayerForHighlight() - this.self.event.bindWithContext(this)('mousemove', this.self.onmousemove) + this.self.event.bindWithContext(this)('mousemove', this.self.onmousemove.bind(this)) } onmousemove(this: SelfEventContenxt, metadata: PrimitiveEventMetadata<'mousemove'>) { @@ -285,8 +284,9 @@ export class SelfEvent extends RegisterModule { onwheel(this: SelfEventContenxt, metadata: PrimitiveEventMetadata<'wheel'>) { const { self, treemap } = this - // @ts-expect-error - const wheelDelta = metadata.native.wheelDelta + + // @ts-expect-error safe + const wheelDelta = metadata.native.wheelDelta as number const absWheelDelta = Math.abs(wheelDelta) const offsetX = metadata.native.offsetX const offsetY = metadata.native.offsetY @@ -332,17 +332,18 @@ export class SelfEvent extends RegisterModule { } ] mixin(app, methods) + const selfCtx = { treemap, self: this } const selfEvents = [...primitiveEvents, 'wheel'] as const selfEvents.forEach((evt) => { - nativeEvents.push(bindPrimitiveEvent(treemap.render.canvas, { treemap, self: this }, evt, event)) + nativeEvents.push(bindPrimitiveEvent(treemap.render.canvas, selfCtx, evt, event)) }) - const selfEvt = event.bindWithContext({ treemap, self: this }) - selfEvt('mousedown', this.ondragstart) - selfEvt('mousemove', this.ondragmove) - selfEvt('mouseup', this.ondragend) + const selfEvt = event.bindWithContext(selfCtx) + selfEvt('mousedown', this.ondragstart.bind(selfCtx)) + selfEvt('mousemove', this.ondragmove.bind(selfCtx)) + selfEvt('mouseup', this.ondragend.bind(selfCtx)) // wheel - selfEvt('wheel', this.onwheel) + selfEvt('wheel', this.onwheel.bind(selfCtx)) applyZoomEvent({ treemap, self: this }) @@ -352,11 +353,9 @@ export class SelfEvent extends RegisterModule { this.highlight.init(width, height, root) if (!installHightlightEvent) { - bindPrimitiveEvent(this.highlight.highlight.render.canvas, { treemap, self: this }, 'mousemove', event) - bindPrimitiveEvent(this.highlight.highlight.render.canvas, { treemap, self: this }, 'mouseout', event) // highlight - selfEvt('mousemove', this.onmousemove) - selfEvt('mouseout', this.onmouseout) + selfEvt('mousemove', this.onmousemove.bind(selfCtx)) + selfEvt('mouseout', this.onmouseout.bind(selfCtx)) installHightlightEvent = true this.highlight.setDisplayLayerForHighlight() } @@ -394,6 +393,7 @@ function estimateZoomingArea(node: LayoutModule, root: LayoutModule | null, w: n let siblingWeightSum = 0 for (const sibling of siblings) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access siblingWeightSum += sibling.weight }