From be7e750e39301aa346986cd9482ef4e48196529e Mon Sep 17 00:00:00 2001 From: Northern Man <19808920+NorthernMan54@users.noreply.github.com> Date: Mon, 28 Oct 2024 18:30:11 -0400 Subject: [PATCH] eslint fixes --- eslint.config.js | 99 ++++++++++++++++++++++++++--------------------- package-lock.json | 11 +++--- package.json | 4 +- src/index.ts | 32 +++++++-------- 4 files changed, 77 insertions(+), 69 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index 6a1295d..67d2be7 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,48 +1,57 @@ import antfu from '@antfu/eslint-config' -export default antfu( - { - ignores: ['dist', 'docs'], - jsx: false, - typescript: true, - formatters: { - markdown: true, - }, - rules: { - 'curly': ['error', 'multi-line'], - 'import/extensions': ['error', 'ignorePackages'], - 'import/order': 0, - 'jsdoc/check-alignment': 'error', - 'jsdoc/check-line-alignment': 'error', - 'no-undef': 'error', - 'perfectionist/sort-exports': 'error', - 'perfectionist/sort-imports': [ - 'error', - { - groups: [ - 'builtin-type', - 'external-type', - 'internal-type', - ['parent-type', 'sibling-type', 'index-type'], - 'builtin', - 'external', - 'internal', - ['parent', 'sibling', 'index'], - 'object', - 'unknown', - ], - order: 'asc', - type: 'natural', - }, - ], - 'perfectionist/sort-named-exports': 'error', - 'perfectionist/sort-named-imports': 'error', - 'sort-imports': 0, - 'style/brace-style': ['error', '1tbs', { allowSingleLine: true }], - 'style/quote-props': ['error', 'consistent-as-needed'], - 'test/no-only-tests': 'error', - 'unicorn/no-useless-spread': 'error', - 'unused-imports/no-unused-vars': ['error', { caughtErrors: 'none' }], - }, +export default antfu({ + ignores: ['dist', 'docs'], + jsx: false, + typescript: true, + formatters: { + markdown: true, }, -) + rules: { + 'curly': ['error', 'multi-line'], + 'import/extensions': ['error', 'ignorePackages'], + 'import/order': 0, + 'jsdoc/check-alignment': 'error', + 'jsdoc/check-line-alignment': 'error', + 'no-undef': 'off', // Turn off no-undef for TypeScript, handled by TS itself + 'perfectionist/sort-exports': 'error', + 'perfectionist/sort-imports': [ + 'error', + { + groups: [ + 'builtin-type', + 'external-type', + 'internal-type', + ['parent-type', 'sibling-type', 'index-type'], + 'builtin', + 'external', + 'internal', + ['parent', 'sibling', 'index'], + 'object', + 'unknown', + ], + order: 'asc', + type: 'natural', + }, + ], + 'perfectionist/sort-named-exports': 'error', + 'perfectionist/sort-named-imports': 'error', + 'sort-imports': 0, + 'style/brace-style': ['error', '1tbs', { allowSingleLine: true }], + 'style/quote-props': ['error', 'consistent-as-needed'], + 'test/no-only-tests': 'error', + 'unicorn/no-useless-spread': 'error', + 'unused-imports/no-unused-vars': ['error', { caughtErrors: 'none' }], + }, + overrides: [ + { + files: ['*.ts', '*.tsx'], // Apply to TypeScript files only + env: { + node: true, // Enables Node.js global variables and type definitions + }, + parserOptions: { + project: './tsconfig.json', // Directs ESLint to use your TypeScript config + }, + }, + ], +}) diff --git a/package-lock.json b/package-lock.json index ed937c6..a98d67b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,7 @@ }, "devDependencies": { "@antfu/eslint-config": "^3.0.0", - "@types/node": "^22.5.2", + "@types/node": "^22.8.2", "@types/source-map-support": "^0.5.10", "eslint": "^9.9.1", "eslint-plugin-format": "^0.1.2", @@ -939,13 +939,12 @@ } }, "node_modules/@types/node": { - "version": "22.5.2", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.5.2.tgz", - "integrity": "sha512-acJsPTEqYqulZS/Yp/S3GgeE6GZ0qYODUR8aVr/DkhHQ8l9nd4j5x1/ZJy9/gHrRlFMqkO6i0I3E27Alu4jjPg==", + "version": "22.8.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.8.2.tgz", + "integrity": "sha512-NzaRNFV+FZkvK/KLCsNdTvID0SThyrs5SHB6tsD/lajr22FGC73N2QeDPM2wHtVde8mgcXuSsHQkH5cX1pbPLw==", "dev": true, - "license": "MIT", "dependencies": { - "undici-types": "~6.19.2" + "undici-types": "~6.19.8" } }, "node_modules/@types/normalize-package-data": { diff --git a/package.json b/package.json index 0111728..4d7f6dc 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ }, "devDependencies": { "@antfu/eslint-config": "^3.0.0", - "@types/node": "^22.5.2", + "@types/node": "^22.8.2", "@types/source-map-support": "^0.5.10", "eslint": "^9.9.1", "eslint-plugin-format": "^0.1.2", @@ -60,4 +60,4 @@ "ts-node": "^10.9.2", "typescript": "^5.5.4" } -} \ No newline at end of file +} diff --git a/src/index.ts b/src/index.ts index 976416b..f57846d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -38,10 +38,10 @@ export class HapClient extends EventEmitter { private hiddenCharacteristics = [ Characteristics.Name, - ]; + ] - private resetInstancePoolTimeout: NodeJS.Timeout | undefined = undefined; - private startDiscoveryTimeout: NodeJS.Timeout | undefined = undefined; + private resetInstancePoolTimeout: NodeJS.Timeout | undefined = undefined + private startDiscoveryTimeout: NodeJS.Timeout | undefined = undefined constructor(opts: { pin: string @@ -73,8 +73,8 @@ export class HapClient extends EventEmitter { this.instances = [] this.resetInstancePoolTimeout = setTimeout(() => { - this.refreshInstances(); - }, 6000); + this.refreshInstances() + }, 6000) } public refreshInstances() { @@ -92,14 +92,14 @@ export class HapClient extends EventEmitter { * Destroy the HapClient instance, used for testing */ public destroy() { - this.browser?.stop(); + this.browser?.stop() - this.discoveryInProgress = false; + this.discoveryInProgress = false if (this.resetInstancePoolTimeout) { - clearTimeout(this.resetInstancePoolTimeout); + clearTimeout(this.resetInstancePoolTimeout) } if (this.startDiscoveryTimeout) { - clearTimeout(this.startDiscoveryTimeout); + clearTimeout(this.startDiscoveryTimeout) } } @@ -116,10 +116,10 @@ export class HapClient extends EventEmitter { // stop discovery after 20 seconds this.startDiscoveryTimeout = setTimeout(() => { - this.browser?.stop(); - this.debug(`[HapClient] Discovery :: Ended`); - this.discoveryInProgress = false; - }, 60000); + this.browser?.stop() + this.debug(`[HapClient] Discovery :: Ended`) + this.discoveryInProgress = false + }, 60000) // service found this.browser.on('up', async (device: Service) => { @@ -149,7 +149,7 @@ export class HapClient extends EventEmitter { this.instances[existingInstanceIndex].port = instance.port this.instances[existingInstanceIndex].name = instance.name this.debug(`[HapClient] Discovery :: [${this.instances[existingInstanceIndex].ipAddress}:${instance.port} ` - + `(${instance.username})] Instance Updated`) + + `(${instance.username})] Instance Updated`) this.emit('instance-discovered', instance) } @@ -451,10 +451,10 @@ export class HapClient extends EventEmitter { } catch (e: any) { if (this.logger) { this.logger.error(`[HapClient] [${service.instance.ipAddress}:${service.instance.port} (${service.instance.username})] ` - + `Failed to set value for ${service.serviceName}.`) + + `Failed to set value for ${service.serviceName}.`) if ([401, 470].includes(e.response?.status)) { this.logger.warn(`[HapClient] [${service.instance.ipAddress}:${service.instance.port} (${service.instance.username})] ` - + `Make sure Homebridge pin for this instance is set to ${this.pin}.`) + + `Make sure Homebridge pin for this instance is set to ${this.pin}.`) throw new Error(`Failed to control accessory. Make sure the Homebridge pin for ${service.instance.ipAddress}:${service.instance.port} ` + `is set to ${this.pin}.`) } else {