Introduce biome as linter with lint fixes

This commit is contained in:
Zef Hemel
2026-03-06 08:05:13 +01:00
parent de32dfb0f5
commit dbf275d75b
101 changed files with 521 additions and 393 deletions
+19 -19
View File
@@ -128,8 +128,8 @@ function pad(s: string, width: number, flags: number, numPad: boolean): string {
}
function addSign(s: string, flags: number): string {
if (flags & FLAG_PLUS) return "+" + s;
if (flags & FLAG_SPACE) return " " + s;
if (flags & FLAG_PLUS) return `+${s}`;
if (flags & FLAG_SPACE) return ` ${s}`;
return s;
}
@@ -200,7 +200,7 @@ function formatInt(n: number, spec: FormatSpec): string {
let result: string;
if (neg) {
result = "-" + prefix + digits;
result = `-${prefix}${digits}`;
} else {
result = addSign(prefix + digits, spec.flags);
}
@@ -216,7 +216,7 @@ function formatFloat(n: number, spec: FormatSpec): string {
const lower = code | 32; // to lowercase
// Lua convention
if (!isFinite(n)) {
if (!Number.isFinite(n)) {
let s: string;
if (n !== n) {
s = upper ? "-NAN" : "-nan";
@@ -275,9 +275,9 @@ function formatFloat(n: number, spec: FormatSpec): string {
const EIdx = body.indexOf("E");
const expIdx = eIdx !== -1 ? eIdx : EIdx;
if (expIdx !== -1) {
body = body.slice(0, expIdx) + "." + body.slice(expIdx);
body = `${body.slice(0, expIdx)}.${body.slice(expIdx)}`;
} else {
body = body + ".";
body = `${body}.`;
}
}
}
@@ -287,16 +287,16 @@ function formatFloat(n: number, spec: FormatSpec): string {
if (body.indexOf(".") === -1) {
const expIdx = findExpIndex(body);
if (expIdx !== -1) {
body = body.slice(0, expIdx) + "." + body.slice(expIdx);
body = `${body.slice(0, expIdx)}.${body.slice(expIdx)}`;
} else {
body = body + ".";
body = `${body}.`;
}
}
}
let result: string;
if (neg) {
result = "-" + body;
result = `-${body}`;
} else {
result = addSign(body, spec.flags);
}
@@ -322,7 +322,7 @@ function ensureExpTwoDigits(s: string): string {
const digitStart = signIdx + 1;
const expLen = s.length - digitStart;
if (expLen < 2) {
return s.slice(0, digitStart) + "0" + s.slice(digitStart);
return `${s.slice(0, digitStart)}0${s.slice(digitStart)}`;
}
return s;
}
@@ -353,7 +353,7 @@ function formatHexFloat(n: number, spec: FormatSpec): string {
const code = spec.spec;
const upper = code === 65; // 'A'
if (!isFinite(n)) {
if (!Number.isFinite(n)) {
let s: string;
if (n !== n) {
s = upper ? "-NAN" : "-nan";
@@ -373,7 +373,7 @@ function formatHexFloat(n: number, spec: FormatSpec): string {
if (abs === 0) {
const prec = spec.hasPrec ? spec.prec : 0;
if (prec > 0) {
body = "0x0." + "0".repeat(prec) + "p+0";
body = `0x0.${"0".repeat(prec)}p+0`;
} else {
body = "0x0p+0";
}
@@ -395,14 +395,14 @@ function formatHexFloat(n: number, spec: FormatSpec): string {
}
}
if (!hasDot) {
body = body.slice(0, pIdx) + "." + body.slice(pIdx);
body = `${body.slice(0, pIdx)}.${body.slice(pIdx)}`;
}
}
}
let result: string;
if (neg) {
result = "-" + body;
result = `-${body}`;
} else {
result = addSign(body, spec.flags);
}
@@ -474,9 +474,9 @@ function hexFloatBody(abs: number, spec: FormatSpec): string {
const expSign = exponent >= 0 ? "+" : "";
if (fracHex.length > 0) {
return "0x" + firstDigit + "." + fracHex + "p" + expSign + exponent;
return `0x${firstDigit}.${fracHex}p${expSign}${exponent}`;
}
return "0x" + firstDigit + "p" + expSign + exponent;
return `0x${firstDigit}p${expSign}${exponent}`;
}
// Convert 52-bit value to 13 hex digits, zero-padded
@@ -581,7 +581,7 @@ function quoteString(s: string): string {
if (ds.length < 3) out += "0".repeat(3 - ds.length);
out += ds;
} else {
out += "\\" + c.toString();
out += `\\${c.toString()}`;
}
} else {
out += String.fromCharCode(c);
@@ -643,7 +643,7 @@ function toPointer(v: unknown): string {
id = nextId++;
stringIds.set(key, id);
}
return "0x" + id.toString(16).padStart(14, "0");
return `0x${id.toString(16).padStart(14, "0")}`;
}
const obj = v as object;
@@ -652,7 +652,7 @@ function toPointer(v: unknown): string {
id = nextId++;
objectIds.set(obj, id);
}
return "0x" + id.toString(16).padStart(14, "0");
return `0x${id.toString(16).padStart(14, "0")}`;
}
function formatPointer(v: unknown, spec: FormatSpec): string {
+7 -7
View File
@@ -52,15 +52,15 @@ export const mathApi = new LuaTable({
*/
tointeger: new LuaBuiltinFunction((_sf, x?: any) => {
if (typeof x === "number") {
return Number.isInteger(x) && isFinite(x) ? x : null;
return Number.isInteger(x) && Number.isFinite(x) ? x : null;
}
if (isTaggedFloat(x)) {
const n = x.value;
return Number.isInteger(n) && isFinite(n) ? n : null;
return Number.isInteger(n) && Number.isFinite(n) ? n : null;
}
if (typeof x === "string") {
const n = untagNumber(x); // Number(x) coerces the string
if (isNaN(n) || !isFinite(n) || !Number.isInteger(n)) return null;
if (Number.isNaN(n) || !Number.isFinite(n) || !Number.isInteger(n)) return null;
return n;
}
return null;
@@ -123,12 +123,12 @@ export const mathApi = new LuaTable({
// Special cases: frexp(0) = (0, 0); frexp(+-inf/nan) = (x, 0).
frexp: new LuaBuiltinFunction((_sf, x: number) => {
const xn = untagNumber(x);
if (xn === 0 || !isFinite(xn) || isNaN(xn)) {
if (xn === 0 || !Number.isFinite(xn) || Number.isNaN(xn)) {
return new LuaMultiRes([xn, 0]);
}
const abs = Math.abs(xn);
let e = Math.floor(Math.log2(abs)) + 1;
let m = xn / Math.pow(2, e);
let m = xn / 2 ** e;
if (Math.abs(m) >= 1.0) {
e += 1;
m /= 2;
@@ -142,7 +142,7 @@ export const mathApi = new LuaTable({
// Returns m * 2^e (the inverse of frexp). Mirrors C99/Lua.
ldexp: new LuaBuiltinFunction((_sf, m: number, e: number) =>
untagNumber(m) * Math.pow(2, untagNumber(e))
untagNumber(m) * 2 ** untagNumber(e)
),
// Power and logarithms
@@ -155,7 +155,7 @@ export const mathApi = new LuaTable({
}),
// Power function (deprecated in Lua 5.4 but retained for compatibility)
pow: new LuaBuiltinFunction((_sf, x: number, y: number) =>
Math.pow(untagNumber(x), untagNumber(y))
untagNumber(x) ** untagNumber(y)
),
sqrt: new LuaBuiltinFunction((_sf, x: number) => Math.sqrt(untagNumber(x))),
+2 -2
View File
@@ -66,7 +66,7 @@ export const netApi = new LuaTable({
(uri: string, options: { uri?: string; encoding?: string } = {}) => {
options.uri = uri;
return client.clientSystem.serviceRegistry.invokeBestMatch(
"net.readURI:" + uri,
`net.readURI:${uri}`,
options,
);
},
@@ -74,7 +74,7 @@ export const netApi = new LuaTable({
writeURI: new LuaNativeJSFunction(
(uri: string, content: string | Uint8Array) => {
return client.clientSystem.serviceRegistry.invokeBestMatch(
"net.writeURI:" + uri,
`net.writeURI:${uri}`,
{ uri, content },
);
},
-1
View File
@@ -409,7 +409,6 @@ function match(ms: MatchState, si: number, pi: number): number {
}
si++;
pi = ep;
continue;
}
}
+4 -4
View File
@@ -92,7 +92,7 @@ export class LuaPRNG {
return Number(rv >> 11n) * (1.0 / 9007199254740992.0);
}
if (!isFinite(arg1) || !Number.isInteger(arg1)) {
if (!Number.isFinite(arg1) || !Number.isInteger(arg1)) {
throw new Error(
"bad argument #1 to 'random' (number has no integer representation)",
);
@@ -112,7 +112,7 @@ export class LuaPRNG {
return Number(this.project(rv, BigInt(arg1) - 1n) + 1n);
}
if (!isFinite(arg2) || !Number.isInteger(arg2)) {
if (!Number.isFinite(arg2) || !Number.isInteger(arg2)) {
throw new Error(
"bad argument #2 to 'random' (number has no integer representation)",
);
@@ -128,12 +128,12 @@ export class LuaPRNG {
if (arg1 === undefined) {
return this.autoSeed();
}
if (!isFinite(arg1) || !Number.isInteger(arg1)) {
if (!Number.isFinite(arg1) || !Number.isInteger(arg1)) {
throw new Error(
"bad argument #1 to 'randomseed' (number has no integer representation)",
);
}
if (arg2 !== undefined && (!isFinite(arg2) || !Number.isInteger(arg2))) {
if (arg2 !== undefined && (!Number.isFinite(arg2) || !Number.isInteger(arg2))) {
throw new Error(
"bad argument #2 to 'randomseed' (number has no integer representation)",
);