Skip to content

Commit 6fbb8b5

Browse files
authored
fix: Migrate to Biome (#27150)
1 parent 130d041 commit 6fbb8b5

File tree

91 files changed

+9945
-10717
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+9945
-10717
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ jobs:
3030
cache: pnpm
3131

3232
- name: Install dependencies
33-
run: pnpm install --frozen-lockfile
34-
35-
- name: Build
36-
run: pnpm run build
33+
run: pnpm i --frozen-lockfile
3734

3835
- name: Check
3936
run: pnpm run check
4037

38+
- name: Build
39+
run: pnpm run build
40+
4141
- name: Test
4242
run: pnpm run test:coverage
4343

.prettierignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

.prettierrc

Lines changed: 0 additions & 28 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ Zigbee2MQTT is made up of three modules, each developed in its own Github projec
107107
Zigbee2MQTT uses TypeScript (partially for now). Therefore after making changes to files in the `lib/` directory you need to recompile Zigbee2MQTT. This can be done by executing `pnpm run build`. For faster development instead of running `pnpm run build` you can run `pnpm run build-watch` in another terminal session, this will recompile as you change files.
108108

109109
Before running any of the commands, you'll first need to run `pnpm install --include=dev`.
110-
Before submitting changes run `pnpm run test:coverage`, `pnpm run pretty:check` and `pnpm run eslint`
110+
Before submitting changes run `pnpm run check:w` then `pnpm run test:coverage`.
111111

112112
## Supported devices
113113

biome.json

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
3+
"vcs": {
4+
"enabled": true,
5+
"clientKind": "git",
6+
"useIgnoreFile": true
7+
},
8+
"formatter": {
9+
"indentStyle": "space",
10+
"indentWidth": 4,
11+
"lineWidth": 150,
12+
"bracketSpacing": false
13+
},
14+
"linter": {
15+
"ignore": [],
16+
"rules": {
17+
"correctness": {
18+
"noUnusedImports": "error",
19+
"noUnusedVariables": {
20+
"level": "warn",
21+
"fix": "none"
22+
}
23+
},
24+
"style": {
25+
"noParameterAssign": "off",
26+
"useThrowNewError": "error",
27+
"useThrowOnlyError": "error",
28+
"useNamingConvention": {
29+
"level": "error",
30+
"options": {
31+
"strictCase": false,
32+
"conventions": [
33+
{
34+
"selector": {
35+
"kind": "objectLiteralProperty"
36+
},
37+
"formats": ["snake_case", "camelCase", "CONSTANT_CASE", "PascalCase"]
38+
},
39+
{
40+
"selector": {
41+
"kind": "const"
42+
},
43+
"formats": ["snake_case", "camelCase", "CONSTANT_CASE", "PascalCase"]
44+
},
45+
{
46+
"selector": {
47+
"kind": "typeProperty"
48+
},
49+
"formats": ["snake_case", "camelCase", "CONSTANT_CASE", "PascalCase"]
50+
},
51+
{
52+
"selector": {
53+
"kind": "enumMember"
54+
},
55+
"formats": ["CONSTANT_CASE", "PascalCase"]
56+
}
57+
]
58+
}
59+
}
60+
},
61+
"performance": {
62+
"noDelete": "off"
63+
},
64+
"suspicious": {
65+
"noConstEnum": "off",
66+
"useAwait": "error"
67+
}
68+
}
69+
},
70+
"overrides": [
71+
{
72+
"include": ["test/**"],
73+
"linter": {
74+
"rules": {
75+
"style": {
76+
"noNonNullAssertion": "off",
77+
"useNamingConvention": "off"
78+
},
79+
"suspicious": {
80+
"noImplicitAnyLet": "off"
81+
}
82+
}
83+
}
84+
}
85+
]
86+
}

cli.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env node
2-
const path = require('path');
3-
process.env['ZIGBEE2MQTT_DATA'] = process.env['ZIGBEE2MQTT_DATA'] || path.join(process.env['HOME'], '.z2m');
4-
require('./index');
2+
const path = require("node:path");
3+
process.env.ZIGBEE2MQTT_DATA = process.env.ZIGBEE2MQTT_DATA || path.join(process.env.HOME, ".z2m");
4+
require("./index");

eslint.config.mjs

Lines changed: 0 additions & 32 deletions
This file was deleted.

index.js

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
const semver = require('semver');
2-
const engines = require('./package.json').engines;
3-
const fs = require('fs');
4-
const os = require('os');
5-
const path = require('path');
6-
const {exec} = require('child_process');
7-
require('source-map-support').install();
1+
const semver = require("semver");
2+
const engines = require("./package.json").engines;
3+
const fs = require("node:fs");
4+
const os = require("node:os");
5+
const path = require("node:path");
6+
const {exec} = require("node:child_process");
7+
require("source-map-support").install();
88

99
let controller;
1010
let stopping = false;
11-
let watchdog = process.env.Z2M_WATCHDOG != undefined;
11+
const watchdog = process.env.Z2M_WATCHDOG != null;
1212
let watchdogCount = 0;
1313
let unsolicitedStop = false;
1414
// csv in minutes, default: 1min, 5min, 15min, 30min, 60min
1515
let watchdogDelays = [2000, 60000, 300000, 900000, 1800000, 3600000];
1616

17-
if (watchdog && process.env.Z2M_WATCHDOG !== 'default') {
17+
if (watchdog && process.env.Z2M_WATCHDOG !== "default") {
1818
if (/^\d+(.\d+)?(,\d+(.\d+)?)*$/.test(process.env.Z2M_WATCHDOG)) {
19-
watchdogDelays = process.env.Z2M_WATCHDOG.split(',').map((v) => parseFloat(v) * 60000);
19+
watchdogDelays = process.env.Z2M_WATCHDOG.split(",").map((v) => Number.parseFloat(v) * 60000);
2020
} else {
2121
console.log(`Invalid watchdog delays (must use number-only CSV format representing minutes, example: 'Z2M_WATCHDOG=1,5,15,30,60'.`);
2222
process.exit(1);
2323
}
2424
}
2525

26-
const hashFile = path.join(__dirname, 'dist', '.hash');
26+
const hashFile = path.join(__dirname, "dist", ".hash");
2727

2828
async function triggerWatchdog(code) {
2929
const delay = watchdogDelays[watchdogCount];
@@ -58,11 +58,11 @@ async function exit(code, restart = false) {
5858

5959
async function currentHash() {
6060
return await new Promise((resolve) => {
61-
exec('git rev-parse --short=8 HEAD', (error, stdout) => {
61+
exec("git rev-parse --short=8 HEAD", (error, stdout) => {
6262
const commitHash = stdout.trim();
6363

64-
if (error || commitHash === '') {
65-
resolve('unknown');
64+
if (error || commitHash === "") {
65+
resolve("unknown");
6666
} else {
6767
resolve(commitHash);
6868
}
@@ -81,26 +81,26 @@ async function build(reason) {
8181

8282
return await new Promise((resolve, reject) => {
8383
const env = {...process.env};
84-
const _600mb = 629145600;
84+
const mb600 = 629145600;
8585

86-
if (_600mb > os.totalmem() && !env.NODE_OPTIONS) {
86+
if (mb600 > os.totalmem() && !env.NODE_OPTIONS) {
8787
// Prevent OOM on tsc compile for system with low memory
8888
// https://github.com/Koenkk/zigbee2mqtt/issues/12034
89-
env.NODE_OPTIONS = '--max_old_space_size=256';
89+
env.NODE_OPTIONS = "--max_old_space_size=256";
9090
}
9191

9292
// clean build, prevent failures due to tsc incremental building
93-
exec('pnpm run prepack', {env, cwd: __dirname}, async (err, stdout, stderr) => {
93+
exec("pnpm run prepack", {env, cwd: __dirname}, (err) => {
9494
if (err) {
95-
process.stdout.write(', failed\n');
95+
process.stdout.write(", failed\n");
9696

9797
if (err.code === 134) {
98-
process.stderr.write('\n\nBuild failed; ran out-of-memory, free some memory (RAM) and start again\n\n');
98+
process.stderr.write("\n\nBuild failed; ran out-of-memory, free some memory (RAM) and start again\n\n");
9999
}
100100

101101
reject(err);
102102
} else {
103-
process.stdout.write(', finished\n');
103+
process.stdout.write(", finished\n");
104104
resolve();
105105
}
106106
});
@@ -109,19 +109,19 @@ async function build(reason) {
109109

110110
async function checkDist() {
111111
if (!fs.existsSync(hashFile)) {
112-
await build('initial build');
112+
await build("initial build");
113113
}
114114

115-
const distHash = fs.readFileSync(hashFile, 'utf8');
115+
const distHash = fs.readFileSync(hashFile, "utf8");
116116
const hash = await currentHash();
117117

118-
if (hash !== 'unknown' && distHash !== hash) {
119-
await build('hash changed');
118+
if (hash !== "unknown" && distHash !== hash) {
119+
await build("hash changed");
120120
}
121121
}
122122

123123
async function start() {
124-
console.log(`Starting Zigbee2MQTT ${watchdog ? `with watchdog (${watchdogDelays})` : `without watchdog`}.`);
124+
console.log(`Starting Zigbee2MQTT ${watchdog ? `with watchdog (${watchdogDelays})` : "without watchdog"}.`);
125125
await checkDist();
126126

127127
// gc
@@ -132,7 +132,7 @@ async function start() {
132132
console.log(`\t\tZigbee2MQTT requires node version ${version}, you are running ${process.version}!\n`);
133133
}
134134

135-
const {onboard} = require('./dist/util/onboarding');
135+
const {onboard} = require("./dist/util/onboarding");
136136

137137
const success = await onboard();
138138

@@ -143,7 +143,7 @@ async function start() {
143143
}
144144
}
145145

146-
const {Controller} = require('./dist/controller');
146+
const {Controller} = require("./dist/controller");
147147
controller = new Controller(restart, exit);
148148

149149
await controller.start();
@@ -172,17 +172,17 @@ async function handleQuit() {
172172
}
173173
}
174174

175-
if (require.main === module || require.main.filename.endsWith(path.sep + 'cli.js')) {
176-
if (process.argv.length === 3 && process.argv[2] === 'writehash') {
175+
if (require.main === module || require.main.filename.endsWith(`${path.sep}cli.js`)) {
176+
if (process.argv.length === 3 && process.argv[2] === "writehash") {
177177
writeHash();
178178
} else {
179-
process.on('SIGINT', handleQuit);
180-
process.on('SIGTERM', handleQuit);
179+
process.on("SIGINT", handleQuit);
180+
process.on("SIGTERM", handleQuit);
181181
start();
182182
}
183183
} else {
184-
process.on('SIGINT', handleQuit);
185-
process.on('SIGTERM', handleQuit);
184+
process.on("SIGINT", handleQuit);
185+
process.on("SIGTERM", handleQuit);
186186

187187
module.exports = {start};
188188
}

0 commit comments

Comments
 (0)