From a67c11d2101973f5ea6008439fae82eaca081200 Mon Sep 17 00:00:00 2001 From: James Smith Date: Fri, 19 Mar 2021 11:44:10 +0000 Subject: [PATCH] basic ts-standard linting --- .../controllers/application_controller.ts | 14 ++++++------- .../controllers/example_controller.ts | 2 +- .../controllers/hello_controller.ts | 2 +- app/javascript/src/preview.ts | 20 +++++++++---------- tsconfig.json | 1 + 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/app/javascript/controllers/application_controller.ts b/app/javascript/controllers/application_controller.ts index 38c19a4e0..b8510af93 100644 --- a/app/javascript/controllers/application_controller.ts +++ b/app/javascript/controllers/application_controller.ts @@ -13,7 +13,7 @@ import StimulusReflex from 'stimulus_reflex' * Learn more at: https://docs.stimulusreflex.com */ export default class extends Controller { - connect () { + connect (): void { StimulusReflex.register(this) } @@ -34,27 +34,27 @@ export default class extends Controller { * reflexId - a UUID4 or developer-provided unique identifier for each Reflex */ - beforeReflex (element, reflex, noop, reflexId) { + beforeReflex (element, reflex, noop, reflexId): void { // document.body.classList.add('wait') } - reflexSuccess (element, reflex, noop, reflexId) { + reflexSuccess (element, reflex, noop, reflexId): void { // show success message } - reflexError (element, reflex, error, reflexId) { + reflexError (element, reflex, error, reflexId): void { // show error message } - reflexHalted (element, reflex, error, reflexId) { + reflexHalted (element, reflex, error, reflexId): void { // handle aborted Reflex action } - afterReflex (element, reflex, noop, reflexId) { + afterReflex (element, reflex, noop, reflexId): void { // document.body.classList.remove('wait') } - finalizeReflex (element, reflex, noop, reflexId) { + finalizeReflex (element, reflex, noop, reflexId): void { // all operations have completed, animation etc is now safe } } diff --git a/app/javascript/controllers/example_controller.ts b/app/javascript/controllers/example_controller.ts index f5e826f40..269db6603 100644 --- a/app/javascript/controllers/example_controller.ts +++ b/app/javascript/controllers/example_controller.ts @@ -16,7 +16,7 @@ export default class extends ApplicationController { * call super if you intend to do anything else when this controller connects. */ - connect () { + connect (): void { super.connect() // add your code here, if applicable } diff --git a/app/javascript/controllers/hello_controller.ts b/app/javascript/controllers/hello_controller.ts index d1bc4fc92..f77d311c9 100644 --- a/app/javascript/controllers/hello_controller.ts +++ b/app/javascript/controllers/hello_controller.ts @@ -12,7 +12,7 @@ import { Controller } from 'stimulus' export default class extends Controller { static targets = ['output'] - connect () { + connect (): void { this.outputTarget.textContent = 'Hello, Stimulus!' } } diff --git a/app/javascript/src/preview.ts b/app/javascript/src/preview.ts index bc4e5fbff..e12e966ca 100644 --- a/app/javascript/src/preview.ts +++ b/app/javascript/src/preview.ts @@ -12,15 +12,15 @@ class PartPreview { observer.observe(canvas) } - setup () { + setup (): void { this.scene = new THREE.Scene() this.renderer = new THREE.WebGLRenderer({ canvas: this.canvas }) this.camera = new THREE.PerspectiveCamera(45, this.canvas.width / this.canvas.height, 0.1, 1000) this.camera.position.z = 50 } - onIntersectionChanged (entries, observer) { - if (entries[0].isIntersecting) { + onIntersectionChanged (entries, observer): void { + if (entries[0].isIntersecting === true) { this.setup() this.load(this.url, this.format) } else { @@ -28,7 +28,7 @@ class PartPreview { } } - load (url, format) { + load (url, format): void { let loader = null if (format === 'obj') { loader = new OBJLoader() } else if (format === 'stl') { loader = new STLLoader() } @@ -39,7 +39,7 @@ class PartPreview { ) } - onLoad (model) { + onLoad (model): void { const material = new THREE.MeshNormalMaterial({ flatShading: true }) @@ -85,19 +85,19 @@ class PartPreview { this.animate() } - onLoadError (error) { + onLoadError (error): void { console.error(error) } - animate () { + animate (): void { this.scene.rotation.y = Date.now() / 1800 this.renderer.render(this.scene, this.camera) this.frame = window.requestAnimationFrame(this.animate.bind(this)) } - cleanup () { + cleanup (): void { window.cancelAnimationFrame(this.frame) - if (this.scene) { + if (this.scene !== null) { this.scene.traverse(function (node) { if (node instanceof THREE.Mesh) { node.geometry.dispose() @@ -105,7 +105,7 @@ class PartPreview { } }) } - if (this.renderer) { + if (this.renderer !== null) { this.renderer.dispose() } } diff --git a/tsconfig.json b/tsconfig.json index 4746f32a0..3b4f37b8d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,6 +11,7 @@ "*": ["node_modules/*", "app/javascript/*"] }, "sourceMap": true, + "strictNullChecks": true, "target": "es5", "noEmit": true },