Skip to content

Commit afd8044

Browse files
authored
fix(ignore): Migrate to eslint 9 (#23800)
* Eslint 9 * Automatic changes * Manual changes * Process feedback * u
1 parent d989061 commit afd8044

36 files changed

+581
-626
lines changed

.eslintignore

-2
This file was deleted.

.eslintrc.js

-63
This file was deleted.

.github/workflows/update_deps.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ jobs:
2323
node-version: 20
2424
cache: npm
2525
# [email protected] requires Node 20 >=
26-
# eslint: https://github.com/typescript-eslint/typescript-eslint/issues/8211
27-
- run: npx npm-check-updates -u -x connect-gzip-static -x eslint
26+
- run: npx npm-check-updates -u -x connect-gzip-static
2827
- run: rm -f package-lock.json
2928
- run: npm install
3029
- uses: peter-evans/create-pull-request@v7

.prettierrc

+19-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,23 @@
55
"printWidth": 150,
66
"bracketSpacing": false,
77
"endOfLine": "lf",
8-
"tabWidth": 4
8+
"tabWidth": 4,
9+
"importOrder": [
10+
"",
11+
"<TYPES>^(node:)",
12+
"",
13+
"<TYPES>",
14+
"",
15+
"<TYPES>^[.]",
16+
"",
17+
"<BUILTIN_MODULES>",
18+
"",
19+
"<THIRD_PARTY_MODULES>",
20+
"",
21+
"^zigbee",
22+
"",
23+
"^[.]"
24+
],
25+
"importOrderParserPlugins": ["typescript", "decorators"],
26+
"plugins": ["@ianvs/prettier-plugin-sort-imports"]
927
}

eslint.config.mjs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// @ts-check
2+
3+
import eslint from '@eslint/js';
4+
import eslintConfigPrettier from 'eslint-config-prettier';
5+
import tseslint from 'typescript-eslint';
6+
7+
export default tseslint.config(
8+
eslint.configs.recommended,
9+
...tseslint.configs.recommended,
10+
{
11+
languageOptions: {
12+
parserOptions: {
13+
project: true,
14+
},
15+
},
16+
rules: {
17+
'@typescript-eslint/await-thenable': 'error',
18+
'@typescript-eslint/ban-ts-comment': 'error',
19+
'@typescript-eslint/explicit-function-return-type': 'error',
20+
'@typescript-eslint/no-explicit-any': 'error',
21+
'@typescript-eslint/no-unused-vars': 'error',
22+
'array-bracket-spacing': ['error', 'never'],
23+
'no-return-await': 'error',
24+
'object-curly-spacing': ['error', 'never'],
25+
'@typescript-eslint/no-floating-promises': 'error',
26+
},
27+
},
28+
{
29+
ignores: ['dist/', '**/*.js', '**/*.mjs'],
30+
},
31+
eslintConfigPrettier,
32+
);

lib/controller.ts

+20-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
import type * as SdNotify from 'sd-notify';
2+
13
import assert from 'assert';
4+
25
import bind from 'bind-decorator';
36
import stringify from 'json-stable-stringify-without-jsonify';
7+
48
import {setLogger as zhSetLogger} from 'zigbee-herdsman';
59
import {setLogger as zhcSetLogger} from 'zigbee-herdsman-converters';
610

@@ -31,6 +35,8 @@ import * as settings from './util/settings';
3135
import utils from './util/utils';
3236
import Zigbee from './zigbee';
3337

38+
type SdNotifyType = typeof SdNotify;
39+
3440
const AllExtensions = [
3541
ExtensionPublish,
3642
ExtensionReceive,
@@ -63,15 +69,6 @@ type ExtensionArgs = [
6369
addExtension: (extension: Extension) => Promise<void>,
6470
];
6571

66-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
67-
let sdNotify: any = null;
68-
try {
69-
// eslint-disable-next-line @typescript-eslint/no-require-imports
70-
sdNotify = process.env.NOTIFY_SOCKET ? require('sd-notify') : null;
71-
} catch {
72-
// sd-notify is optional
73-
}
74-
7572
export class Controller {
7673
private eventBus: EventBus;
7774
private zigbee: Zigbee;
@@ -81,6 +78,7 @@ export class Controller {
8178
private exitCallback: (code: number, restart: boolean) => Promise<void>;
8279
private extensions: Extension[];
8380
private extensionArgs: ExtensionArgs;
81+
private sdNotify: SdNotifyType | undefined;
8482

8583
constructor(restartCallback: () => Promise<void>, exitCallback: (code: number, restart: boolean) => Promise<void>) {
8684
logger.init();
@@ -149,6 +147,14 @@ export class Controller {
149147
const info = await utils.getZigbee2MQTTVersion();
150148
logger.info(`Starting Zigbee2MQTT version ${info.version} (commit #${info.commitHash})`);
151149

150+
try {
151+
this.sdNotify = process.env.NOTIFY_SOCKET ? await import('sd-notify') : undefined;
152+
logger.debug('sd-notify loaded');
153+
} catch {
154+
// istanbul ignore next
155+
logger.debug('sd-notify is not installed');
156+
}
157+
152158
// Start zigbee
153159
let startResult;
154160
try {
@@ -224,11 +230,11 @@ export class Controller {
224230

225231
logger.info(`Zigbee2MQTT started!`);
226232

227-
const watchdogInterval = sdNotify?.watchdogInterval() || 0;
233+
const watchdogInterval = this.sdNotify?.watchdogInterval() || 0;
228234
if (watchdogInterval > 0) {
229-
sdNotify.startWatchdogMode(Math.floor(watchdogInterval / 2));
235+
this.sdNotify?.startWatchdogMode(Math.floor(watchdogInterval / 2));
230236
}
231-
sdNotify?.ready();
237+
this.sdNotify?.ready();
232238
}
233239

234240
@bind async enableDisableExtension(enable: boolean, name: string): Promise<void> {
@@ -253,7 +259,7 @@ export class Controller {
253259
}
254260

255261
async stop(restart = false): Promise<void> {
256-
sdNotify?.stopping();
262+
this.sdNotify?.stopping(process.pid);
257263

258264
// Call extensions
259265
await this.callExtensions('stop', this.extensions);
@@ -272,7 +278,7 @@ export class Controller {
272278
code = 1;
273279
}
274280

275-
sdNotify?.stopWatchdogMode();
281+
this.sdNotify?.stopWatchdogMode();
276282
return this.exit(code, restart);
277283
}
278284

lib/eventBus.ts

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import events from 'events';
22

33
import logger from './util/logger';
44

5-
// eslint-disable-next-line
65
type ListenerKey = object;
76

87
interface EventBusMap {

lib/extension/availability.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import assert from 'assert';
2+
23
import bind from 'bind-decorator';
34
import debounce from 'debounce';
5+
46
import * as zhc from 'zigbee-herdsman-converters';
57

68
import logger from '../util/logger';

lib/extension/bind.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import assert from 'assert';
2+
23
import bind from 'bind-decorator';
34
import debounce from 'debounce';
45
import stringify from 'json-stable-stringify-without-jsonify';
6+
57
import {Zcl} from 'zigbee-herdsman';
68
import {ClusterName} from 'zigbee-herdsman/dist/zspec/zcl/definition/tstype';
79

0 commit comments

Comments
 (0)