Skip to content

Commit

Permalink
eslint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
NorthernMan54 committed Oct 28, 2024
1 parent a4f7a04 commit be7e750
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 69 deletions.
99 changes: 54 additions & 45 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -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
},
},
],
})
11 changes: 5 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -60,4 +60,4 @@
"ts-node": "^10.9.2",
"typescript": "^5.5.4"
}
}
}
32 changes: 16 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -73,8 +73,8 @@ export class HapClient extends EventEmitter {
this.instances = []

this.resetInstancePoolTimeout = setTimeout(() => {
this.refreshInstances();
}, 6000);
this.refreshInstances()
}, 6000)
}

public refreshInstances() {
Expand All @@ -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)
}
}

Expand All @@ -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) => {
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit be7e750

Please sign in to comment.