mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-14 15:24:52 +09:00
Replace ESLint, typescript-eslint, eslint-plugin-node and the flat config helpers with vite-plus, which runs Oxlint for vp lint. The rules are carried over from eslint.config.mjs by @oxlint/migrate into the lint section of the root vite.config.ts. The formatting rules ESLint deprecated run as @stylistic rules through Oxlint's JS plugin support, and disable comments naming them are updated to the @stylistic names. @stylistic understands TypeScript syntax that the core rules skipped, so the autofix adds missing semicolons and spaces in type literals and aliases. Leading | and & in multiline types stay where they were. Oxlint's node/no-sync also reports identifiers ending in Sync that are not calls. The test helper techSync is renamed and the two other names are ignored. Refs #1127 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
56 lines
1.9 KiB
TypeScript
56 lines
1.9 KiB
TypeScript
import * as lib from "@clusterio/lib";
|
|
|
|
export async function getEditor(argsEditor: string) {
|
|
// eslint-disable-next-line
|
|
return argsEditor || process.env.EDITOR || process.env.VISUAL || undefined;
|
|
// needed for the process.env statements to not be flagged by eslint
|
|
// priority for editors is CLI argument > env.EDITOR > env.VISUAL
|
|
}
|
|
|
|
export async function configToKeyVal(data: string) {
|
|
let final: Record<string, string> = {};
|
|
let splitData = data.split(/\r?\n/);
|
|
// split on newlines
|
|
let filtered = splitData.filter((value) => value[0] !== "#").filter((a) => a);
|
|
// the last filter removes empty elements left by the first. Not done on one line due to readability.
|
|
for (let index in filtered) {
|
|
if (index in filtered) {
|
|
// split on the first = only, values may contain = themselves
|
|
let split = filtered[index].indexOf("=");
|
|
if (split === -1) {
|
|
// no value given, it's a empty field and therefor null
|
|
final[filtered[index].trim()] = "";
|
|
continue;
|
|
}
|
|
final[filtered[index].slice(0, split).trim()] = filtered[index].slice(split + 1).trim();
|
|
}
|
|
}
|
|
return final;
|
|
}
|
|
|
|
export function serializedConfigToString(
|
|
serializedConfig: lib.ConfigSchema,
|
|
configClass: typeof lib.ControllerConfig | typeof lib.HostConfig | typeof lib.InstanceConfig,
|
|
) {
|
|
const config = configClass.fromJSON({}, "control");
|
|
let allConfigElements = "";
|
|
for (let [name, value] of Object.entries(serializedConfig)) {
|
|
const def = (configClass.fieldDefinitions as lib.ConfigDefs<any>)[name];
|
|
try {
|
|
if (!config.canAccess(name, lib.ConfigAccess.readWrite) || def.hidden) {
|
|
continue;
|
|
}
|
|
} catch (err) {
|
|
// Field does not exist in the config class
|
|
continue;
|
|
}
|
|
if (value === null) {
|
|
value = "";
|
|
} else if (typeof value === "object") {
|
|
value = JSON.stringify(value);
|
|
}
|
|
allConfigElements += `# ${def.description ?? "No description found"}\n${name} = ${value}\n\n`;
|
|
}
|
|
return allConfigElements;
|
|
}
|