From 388060e91713a3db3e859133925ad30d950fa551 Mon Sep 17 00:00:00 2001 From: Philipp Arndt <2f.mail@gmx.de> Date: Wed, 19 Jan 2022 18:59:12 +0100 Subject: [PATCH] linter --- app/lib/logger.test.ts | 5 ++--- app/lib/logger.ts | 1 - app/lib/put/put-handler.test.ts | 1 - app/lib/put/put-handler.ts | 27 ++++++++++++++------------- app/package.json | 2 +- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/app/lib/logger.test.ts b/app/lib/logger.test.ts index eff6d608..e8202fb2 100755 --- a/app/lib/logger.test.ts +++ b/app/lib/logger.test.ts @@ -1,9 +1,8 @@ -import { createLogger, log } from "./logger" +import { log } from "./logger" import { Writable } from "stream" import * as winston from "winston" import * as Transport from "winston-transport" - export class TestLogger { output = "" transports: Transport[] @@ -21,7 +20,7 @@ export class TestLogger { close = () => { log.clear() - for (let transport of this.transports) { + for (const transport of this.transports) { log.add(transport) } } diff --git a/app/lib/logger.ts b/app/lib/logger.ts index 4ff0c50e..6ae05b98 100755 --- a/app/lib/logger.ts +++ b/app/lib/logger.ts @@ -12,4 +12,3 @@ export const createLogger = (transport: Transport = new winston.transports.Conso } export const log = createLogger() - diff --git a/app/lib/put/put-handler.test.ts b/app/lib/put/put-handler.test.ts index 6cb644cc..6dbad8f6 100644 --- a/app/lib/put/put-handler.test.ts +++ b/app/lib/put/put-handler.test.ts @@ -79,7 +79,6 @@ describe("PUT handler", () => { expect(messages.length).toBe(0) expect(logger.output).toMatch(/\d+\d+\d+\d+-\d+\d+-\d+\d+T.* ERROR invalid message Unexpected token i in JSON at position 0.*/) - }) test("Turn on", async () => { diff --git a/app/lib/put/put-handler.ts b/app/lib/put/put-handler.ts index 982d324d..609c1d1e 100644 --- a/app/lib/put/put-handler.ts +++ b/app/lib/put/put-handler.ts @@ -9,22 +9,23 @@ export const putMessage = async (resource: HueIdentifiable, message: Buffer) => if (isLight(resource)) { // only supported for light messages at the moment try { - const lightMsg = JSON.parse(message.toString()) as LightMessage | LightEffectMessage - if (isEffectMessage(lightMsg)) { - await applyEffect(resource, lightMsg) - } - else { - const newResource = toLight(resource, lightMsg) - - // resource will be updated by the Hue SSE API - try { - await putResource(newResource) + const lightMsg = JSON.parse(message.toString()) as LightMessage | LightEffectMessage + if (isEffectMessage(lightMsg)) { + await applyEffect(resource, lightMsg) } - catch (e) { - log.error(e) + else { + const newResource = toLight(resource, lightMsg) + + // resource will be updated by the Hue SSE API + try { + await putResource(newResource) + } + catch (e) { + log.error(e) + } } } - } catch (e) { + catch (e) { log.error("invalid message", e) } } diff --git a/app/package.json b/app/package.json index 68c43fc1..c589dc04 100755 --- a/app/package.json +++ b/app/package.json @@ -8,7 +8,7 @@ "coverage": "jest --coverage", "start": "tsc && node dist/index.js", "build": "tsc", - "lint": "eslint lib/** --ext .ts", + "lint": "eslint lib/** --ext .ts --fix", "generate-test-stubs": "node dist/lib/test-stub-generator.js" }, "keywords": [],