style: lint

This commit is contained in:
Slinetrac
2025-11-06 12:14:30 +08:00
Unverified
parent c76d33a103
commit 1ce192dfeb
17 changed files with 285 additions and 257 deletions

View File

@@ -928,9 +928,7 @@ function loadLocales() {
try {
data[file.namespace] = JSON.parse(raw);
} catch (error) {
console.warn(
`Warning: failed to parse ${file.path}: ${error.message}`,
);
console.warn(`Warning: failed to parse ${file.path}: ${error.message}`);
data[file.namespace] = {};
}
}
@@ -983,9 +981,8 @@ function toModuleIdentifier(namespace, seen) {
]);
const base =
namespace
.replace(/[^a-zA-Z0-9_$]/g, "_")
.replace(/^[^a-zA-Z_$]+/, "") || "ns";
namespace.replace(/[^a-zA-Z0-9_$]/g, "_").replace(/^[^a-zA-Z_$]+/, "") ||
"ns";
let candidate = base;
let counter = 1;
@@ -1142,10 +1139,7 @@ function processLocale(
return {
locale: locale.name,
file:
locale.format === "single-file"
? locale.files[0].path
: locale.dir,
file: locale.format === "single-file" ? locale.files[0].path : locale.dir,
totalKeys: flattened.size,
expectedKeys: expectedTotal,
unusedKeys: unused,

View File

@@ -16,7 +16,14 @@ async function ensureDir(dirPath) {
await fs.mkdir(dirPath, { recursive: true });
}
const RESERVED = new Set(["default", "function", "var", "let", "const", "import"]);
const RESERVED = new Set([
"default",
"function",
"var",
"let",
"const",
"import",
]);
function toIdentifier(namespace, taken) {
let base = namespace
@@ -61,11 +68,7 @@ async function splitLocaleFile(filePath, lang) {
const taken = new Set();
for (const [namespace, value] of namespaces) {
if (
typeof value !== "object" ||
value === null ||
Array.isArray(value)
) {
if (typeof value !== "object" || value === null || Array.isArray(value)) {
throw new Error(
`Locale ${lang} namespace "${namespace}" must be an object`,
);