fix: Migrate to Biome (#27150)

This commit is contained in:
Nerivec
2025-04-18 20:34:47 +02:00
committed by GitHub
parent 130d041f75
commit 6fbb8b5ca2
91 changed files with 9944 additions and 10716 deletions
+55 -49
View File
@@ -1,8 +1,8 @@
const path = require('path');
const fs = require('fs');
const process = require('process');
const {execSync} = require('child_process');
const zhc = require('zigbee-herdsman-converters');
const path = require("node:path");
const fs = require("node:fs");
const process = require("node:process");
const {execSync} = require("node:child_process");
const zhc = require("zigbee-herdsman-converters");
const z2mTillVersion = process.argv[2];
const zhcTillVersion = process.argv[3];
@@ -12,24 +12,24 @@ const frontendTillVersion = process.argv[5];
const changelogs = [
{
tillVersion: z2mTillVersion,
project: 'koenkk/zigbee2mqtt',
contents: fs.readFileSync(path.join(__dirname, '..', 'CHANGELOG.md'), 'utf-8').split('\n'),
project: "koenkk/zigbee2mqtt",
contents: fs.readFileSync(path.join(__dirname, "..", "CHANGELOG.md"), "utf-8").split("\n"),
},
{
tillVersion: zhcTillVersion,
project: 'koenkk/zigbee-herdsman-converters',
contents: fs.readFileSync(path.join(__dirname, '..', 'node_modules', 'zigbee-herdsman-converters', 'CHANGELOG.md'), 'utf-8').split('\n'),
project: "koenkk/zigbee-herdsman-converters",
contents: fs.readFileSync(path.join(__dirname, "..", "node_modules", "zigbee-herdsman-converters", "CHANGELOG.md"), "utf-8").split("\n"),
},
{
tillVersion: zhTillVersion,
project: 'koenkk/zigbee-herdsman',
contents: fs.readFileSync(path.join(__dirname, '..', 'node_modules', 'zigbee-herdsman', 'CHANGELOG.md'), 'utf-8').split('\n'),
project: "koenkk/zigbee-herdsman",
contents: fs.readFileSync(path.join(__dirname, "..", "node_modules", "zigbee-herdsman", "CHANGELOG.md"), "utf-8").split("\n"),
},
{
tillVersion: frontendTillVersion,
project: 'nurikk/zigbee2mqtt-frontend',
project: "nurikk/zigbee2mqtt-frontend",
isFrontend: true,
contents: fs.readFileSync(path.join(__dirname, '..', 'node_modules', 'zigbee2mqtt-frontend', 'CHANGELOG.md'), 'utf-8').split('\n'),
contents: fs.readFileSync(path.join(__dirname, "..", "node_modules", "zigbee2mqtt-frontend", "CHANGELOG.md"), "utf-8").split("\n"),
},
];
@@ -44,12 +44,12 @@ const changeRe = [
const frontendChangeRe = /^\* (\*\*.+:\*\* )()?(.+) \(\[.+\]\(https:.+\/()(.+)\)\)(.+)?$/;
let commitUserLookup = {};
const commitUserFile = path.join(__dirname, 'commit-user-lookup.json');
const commitUserFile = path.join(__dirname, "commit-user-lookup.json");
if (fs.existsSync(commitUserFile)) {
commitUserLookup = JSON.parse(fs.readFileSync(commitUserFile, 'utf8'));
commitUserLookup = JSON.parse(fs.readFileSync(commitUserFile, "utf8"));
}
const definitions = require('zigbee-herdsman-converters/devices/index').default.map((d) => zhc.prepareDefinition(d));
const definitions = require("zigbee-herdsman-converters/devices/index").default.map((d) => zhc.prepareDefinition(d));
const whiteLabels = definitions.filter((d) => d.whiteLabel).flatMap((d) => d.whiteLabel);
const capitalizeFirstChar = (str) => str.charAt(0).toUpperCase() + str.slice(1);
@@ -61,15 +61,15 @@ for (const changelog of changelogs) {
if (releaseMatch[1] === changelog.tillVersion) {
break;
}
} else if (line === '### Features') {
context = 'features';
} else if (line === '### Bug Fixes') {
context = 'fixes';
} else if (line.startsWith('* **ignore:**')) {
continue;
} else if (line === "### Features") {
context = "features";
} else if (line === "### Bug Fixes") {
context = "fixes";
} else if (line.startsWith("* **ignore:**")) {
// continue;
} else if (changeMatch) {
let localContext = changelog.isFrontend ? 'frontend' : changeMatch[2] ? changeMatch[2] : context;
if (!changes[localContext]) localContext = 'error';
let localContext = changelog.isFrontend ? "frontend" : changeMatch[2] ? changeMatch[2] : context;
if (!changes[localContext]) localContext = "error";
const commit = changeMatch[5];
const commitUserKey = `${changelog.project}-${commit} `;
@@ -79,10 +79,10 @@ for (const changelog of changelogs) {
: execSync(`curl -s https://api.github.com/repos/${changelog.project}/commits/${commit} | jq -r '.author.login'`)
.toString()
.trim();
if (user !== 'null') commitUserLookup[commitUserKey] = user;
if (user !== "null") commitUserLookup[commitUserKey] = user;
const messages = [];
let message = changeMatch[3].trim();
if (message.endsWith('.')) message = message.substring(0, message.length - 1);
if (message.endsWith(".")) message = message.substring(0, message.length - 1);
if (changelog.isFrontend) {
changes[localContext].push(
@@ -93,18 +93,18 @@ for (const changelog of changelogs) {
const otherUser = message.match(/\[@(.+)\]\(https:\/\/github.com\/.+\)/) || message.match(/@(.+)/);
if (otherUser) {
user = otherUser[1];
message = message.replace(otherUser[0], '');
message = message.replace(otherUser[0], "");
}
if (localContext === 'add') {
for (const model of message.split(',')) {
if (localContext === "add") {
for (const model of message.split(",")) {
const definition = definitions.find((d) => d.model === model.trim());
const whiteLabel = whiteLabels.find((d) => d.model === model.trim());
const match = definition || whiteLabel;
if (match) {
messages.push(`\`${match.model}\` ${match.vendor} ${match.description}`);
} else {
changes['error'].push(`${line} (model '${model}' does not exist)`);
changes.error.push(`${line} (model '${model}' does not exist)`);
}
}
} else {
@@ -112,40 +112,46 @@ for (const changelog of changelogs) {
}
let issue = changeMatch[4].trim();
if (issue && !issue.startsWith('[#')) issue = `[#${issue.split('/').pop()}](${issue})`;
if (issue && !issue.startsWith("[#")) issue = `[#${issue.split("/").pop()}](${issue})`;
if (!issue) {
issue = '_NO_ISSUE_';
localContext = 'error';
issue = "_NO_ISSUE_";
localContext = "error";
}
messages.forEach((m) => changes[localContext].push(`- ${issue} ${m} (@${user})`));
for (const message of messages) {
changes[localContext].push(`- ${issue} ${message} (@${user})`);
}
}
} else if (line === '# Changelog' || line === '### ⚠ BREAKING CHANGES' || !line) {
continue;
} else if (line === "# Changelog" || line === "### ⚠ BREAKING CHANGES" || !line) {
// continue;
} else {
changes['error'].push(`- Unmatched line: ${line}`);
changes.error.push(`- Unmatched line: ${line}`);
}
}
}
let result = '';
let result = "";
const names = [
['features', 'Improvements'],
['fixes', 'Fixes'],
['frontend', 'Frontend'],
['add', 'New supported devices'],
['detect', 'Fixed device detections'],
['error', 'Changelog generator error'],
["features", "Improvements"],
["fixes", "Fixes"],
["frontend", "Frontend"],
["add", "New supported devices"],
["detect", "Fixed device detections"],
["error", "Changelog generator error"],
];
for (const name of names) {
result += `# ${name[1]}\n`;
if (name[0] === 'add') {
result += `This release adds support for ${changes['add'].length} devices: \n`;
if (name[0] === "add") {
result += `This release adds support for ${changes.add.length} devices: \n`;
}
changes[name[0]].forEach((e) => (result += `${e}\n`));
result += '\n';
for (const change of changes[name[0]]) {
result += `${change}\n`;
}
result += "\n";
}
fs.writeFileSync(commitUserFile, JSON.stringify(commitUserLookup), 'utf-8');
fs.writeFileSync(commitUserFile, JSON.stringify(commitUserLookup), "utf-8");
console.log(result.trim());
+5 -5
View File
@@ -1,10 +1,10 @@
const assert = require('assert');
const vm = require('vm');
const fs = require('fs');
const path = require('path');
const assert = require("node:assert");
const vm = require("node:vm");
const fs = require("node:fs");
const path = require("node:path");
const filename = process.argv[2];
const moduleCode = fs.readFileSync(filename);
const moduleFakePath = path.join(__dirname, 'externally-loaded.js');
const moduleFakePath = path.join(__dirname, "externally-loaded.js");
const sandbox = {
require: require,
module: {},
+21 -21
View File
@@ -1,7 +1,7 @@
const {ZnpCommandStatus, NvSystemIds} = require('zigbee-herdsman/dist/adapter/z-stack/constants/common');
const {ZnpVersion} = require('zigbee-herdsman/dist/adapter/z-stack/adapter/tstype');
const {Subsystem} = require('zigbee-herdsman/dist/adapter/z-stack/unpi/constants');
const {Znp} = require('zigbee-herdsman/dist/adapter/z-stack/znp');
const {ZnpCommandStatus, NvSystemIds} = require("zigbee-herdsman/dist/adapter/z-stack/constants/common");
const {ZnpVersion} = require("zigbee-herdsman/dist/adapter/z-stack/adapter/tstype");
const {Subsystem} = require("zigbee-herdsman/dist/adapter/z-stack/unpi/constants");
const {Znp} = require("zigbee-herdsman/dist/adapter/z-stack/znp");
class ZStackNvMemEraser {
constructor(device) {
@@ -13,7 +13,7 @@ class ZStackNvMemEraser {
const attempts = 3;
for (let i = 0; i < attempts; i++) {
try {
await this.znp.request(Subsystem.SYS, 'ping', {capabilities: 1});
await this.znp.request(Subsystem.SYS, "ping", {capabilities: 1});
break;
} catch (e) {
if (attempts - 1 === i) {
@@ -23,10 +23,10 @@ class ZStackNvMemEraser {
}
// Old firmware did not support version, assume it's Z-Stack 1.2 for now.
try {
this.version = (await this.znp.request(Subsystem.SYS, 'version', {})).payload;
} catch (e) {
console.log(`Failed to get zStack version, assuming 1.2`);
this.version = {transportrev: 2, product: 0, majorrel: 2, minorrel: 0, maintrel: 0, revision: ''};
this.version = (await this.znp.request(Subsystem.SYS, "version", {})).payload;
} catch {
console.log("Failed to get zStack version, assuming 1.2");
this.version = {transportrev: 2, product: 0, majorrel: 2, minorrel: 0, maintrel: 0, revision: ""};
}
console.log(`Detected znp version '${ZnpVersion[this.version.product]}' (${JSON.stringify(this.version)})`);
@@ -54,23 +54,23 @@ class ZStackNvMemEraser {
console.log(`Clearing all NVMEM items, from 0 to ${maxNvMemId}`);
for (let id = 0; id <= maxNvMemId; id++) {
let len;
const needOsal = !(this.version.product == ZnpVersion.zStack3x0 && id <= 7);
const needOsal = !(this.version.product === ZnpVersion.zStack3x0 && id <= 7);
if (needOsal) {
const lengthRes = await this.znp.request(Subsystem.SYS, 'osalNvLength', {id: id});
len = lengthRes.payload['length'];
const lengthRes = await this.znp.request(Subsystem.SYS, "osalNvLength", {id: id});
len = lengthRes.payload.length;
} else {
const lengthRes = await this.znp.request(Subsystem.SYS, 'nvLength', {sysid: NvSystemIds.ZSTACK, itemid: id, subid: 0});
len = lengthRes.payload['len'];
const lengthRes = await this.znp.request(Subsystem.SYS, "nvLength", {sysid: NvSystemIds.ZSTACK, itemid: id, subid: 0});
len = lengthRes.payload.len;
}
if (len != 0) {
if (len !== 0) {
console.log(`NVMEM item #${id} - deleting, size: ${len}`);
if (needOsal) {
await this.znp.request(Subsystem.SYS, 'osalNvDelete', {id: id, len: len}, undefined, undefined, [
await this.znp.request(Subsystem.SYS, "osalNvDelete", {id: id, len: len}, undefined, undefined, [
ZnpCommandStatus.SUCCESS,
ZnpCommandStatus.NV_ITEM_INITIALIZED,
]);
} else {
await this.znp.request(Subsystem.SYS, 'nvDelete', {sysid: NvSystemIds.ZSTACK, itemid: id, subid: 0}, undefined, undefined, [
await this.znp.request(Subsystem.SYS, "nvDelete", {sysid: NvSystemIds.ZSTACK, itemid: id, subid: 0}, undefined, undefined, [
ZnpCommandStatus.SUCCESS,
ZnpCommandStatus.NV_ITEM_INITIALIZED,
]);
@@ -82,10 +82,10 @@ class ZStackNvMemEraser {
}
}
const processArgs = process.argv.slice(2);
if (processArgs.length != 1) {
console.log('ZStack NVMEM eraser.');
console.log('Usage:');
console.log(' node zStackEraseAllNvMem.js <SERIAL_PORT>');
if (processArgs.length !== 1) {
console.log("ZStack NVMEM eraser.");
console.log("Usage:");
console.log(" node zStackEraseAllNvMem.js <SERIAL_PORT>");
process.exit(1);
}