Parse Commands Properly For Lint

This commit is contained in:
thororen1234 2025-09-02 16:43:00 -04:00
parent e6c427edad
commit 145befc42b
No known key found for this signature in database
4 changed files with 83 additions and 68 deletions

View file

@ -167,27 +167,33 @@ async function parseFile(fileName: string) {
break;
case "commands":
data.hasCommands = true;
if (!isArrayLiteralExpression(value)) throw fail("commands is not an array literal");
data.commands = value.elements.map((e) => {
if (isObjectLiteralExpression(e)) {
const nameProperty = e.properties.find((p): p is PropertyAssignment => {
return isPropertyAssignment(p) && isIdentifier(p.name) && p.name.escapedText === 'name';
});
const descriptionProperty = e.properties.find((p): p is PropertyAssignment => {
return isPropertyAssignment(p) && isIdentifier(p.name) && p.name.escapedText === 'description';
});
if (!nameProperty || !descriptionProperty) throw fail("command missing required properties");
const name = isStringLiteral(nameProperty.initializer) ? nameProperty.initializer.text : '';
const description = isStringLiteral(descriptionProperty.initializer) ? descriptionProperty.initializer.text : '';
return { name, description };
} else if (isCallExpression(e) && isIdentifier(e.expression)) {
const [nameArg] = e.arguments;
if (!isStringLiteral(nameArg)) throw fail("first argument must be a string");
const name = nameArg.text;
return { name, description: "" };
}
throw fail("commands array contains invalid elements");
});
if (isArrayLiteralExpression(value)) {
data.commands = value.elements.map((e) => {
if (isObjectLiteralExpression(e)) {
const nameProperty = e.properties.find((p): p is PropertyAssignment =>
isPropertyAssignment(p) && isIdentifier(p.name) && p.name.escapedText === "name"
);
const descriptionProperty = e.properties.find((p): p is PropertyAssignment =>
isPropertyAssignment(p) && isIdentifier(p.name) && p.name.escapedText === "description"
);
if (!nameProperty || !descriptionProperty) throw fail("command missing required properties");
const name = isStringLiteral(nameProperty.initializer) ? nameProperty.initializer.text : "";
const description = isStringLiteral(descriptionProperty.initializer) ? descriptionProperty.initializer.text : "";
return { name, description };
} else if (isCallExpression(e) && isIdentifier(e.expression)) {
const [nameArg] = e.arguments;
if (!isStringLiteral(nameArg)) throw fail("first argument must be a string");
return { name: nameArg.text, description: "" };
} else if (e.kind === SyntaxKind.SpreadElement) {
return undefined;
}
throw fail("commands array contains invalid elements");
}).filter((c): c is { name: string; description: string; } => Boolean(c)) as Command[];
} else if (isIdentifier(value)) {
data.commands = [];
} else {
throw fail("commands is not an array literal or identifier");
}
break;
case "authors":
if (!isArrayLiteralExpression(value)) throw fail("authors is not an array literal");
@ -229,8 +235,7 @@ async function parseFile(fileName: string) {
data.filePath = posixNormalize(fileName)
.split(sep)
.join(posixSep)
.replace(/\/index\.([jt]sx?)$/, "")
.replace(/^src\/equicordplugins\//, "");
.replace(/\/index\.([jt]sx?)$/, "");
return [data] as const;
}

View file

@ -167,27 +167,33 @@ async function parseFile(fileName: string) {
break;
case "commands":
data.hasCommands = true;
if (!isArrayLiteralExpression(value)) throw fail("commands is not an array literal");
data.commands = value.elements.map((e) => {
if (isObjectLiteralExpression(e)) {
const nameProperty = e.properties.find((p): p is PropertyAssignment => {
return isPropertyAssignment(p) && isIdentifier(p.name) && p.name.escapedText === 'name';
});
const descriptionProperty = e.properties.find((p): p is PropertyAssignment => {
return isPropertyAssignment(p) && isIdentifier(p.name) && p.name.escapedText === 'description';
});
if (!nameProperty || !descriptionProperty) throw fail("command missing required properties");
const name = isStringLiteral(nameProperty.initializer) ? nameProperty.initializer.text : '';
const description = isStringLiteral(descriptionProperty.initializer) ? descriptionProperty.initializer.text : '';
return { name, description };
} else if (isCallExpression(e) && isIdentifier(e.expression)) {
const [nameArg] = e.arguments;
if (!isStringLiteral(nameArg)) throw fail("first argument must be a string");
const name = nameArg.text;
return { name, description: "" };
}
throw fail("commands array contains invalid elements");
});
if (isArrayLiteralExpression(value)) {
data.commands = value.elements.map((e) => {
if (isObjectLiteralExpression(e)) {
const nameProperty = e.properties.find((p): p is PropertyAssignment =>
isPropertyAssignment(p) && isIdentifier(p.name) && p.name.escapedText === "name"
);
const descriptionProperty = e.properties.find((p): p is PropertyAssignment =>
isPropertyAssignment(p) && isIdentifier(p.name) && p.name.escapedText === "description"
);
if (!nameProperty || !descriptionProperty) throw fail("command missing required properties");
const name = isStringLiteral(nameProperty.initializer) ? nameProperty.initializer.text : "";
const description = isStringLiteral(descriptionProperty.initializer) ? descriptionProperty.initializer.text : "";
return { name, description };
} else if (isCallExpression(e) && isIdentifier(e.expression)) {
const [nameArg] = e.arguments;
if (!isStringLiteral(nameArg)) throw fail("first argument must be a string");
return { name: nameArg.text, description: "" };
} else if (e.kind === SyntaxKind.SpreadElement) {
return undefined;
}
throw fail("commands array contains invalid elements");
}).filter((c): c is { name: string; description: string; } => Boolean(c)) as Command[];
} else if (isIdentifier(value)) {
data.commands = [];
} else {
throw fail("commands is not an array literal or identifier");
}
break;
case "authors":
if (!isArrayLiteralExpression(value)) throw fail("authors is not an array literal");

View file

@ -166,27 +166,33 @@ async function parseFile(fileName: string) {
break;
case "commands":
data.hasCommands = true;
if (!isArrayLiteralExpression(value)) throw fail("commands is not an array literal");
data.commands = value.elements.map((e) => {
if (isObjectLiteralExpression(e)) {
const nameProperty = e.properties.find((p): p is PropertyAssignment => {
return isPropertyAssignment(p) && isIdentifier(p.name) && p.name.escapedText === 'name';
});
const descriptionProperty = e.properties.find((p): p is PropertyAssignment => {
return isPropertyAssignment(p) && isIdentifier(p.name) && p.name.escapedText === 'description';
});
if (!nameProperty || !descriptionProperty) throw fail("command missing required properties");
const name = isStringLiteral(nameProperty.initializer) ? nameProperty.initializer.text : '';
const description = isStringLiteral(descriptionProperty.initializer) ? descriptionProperty.initializer.text : '';
return { name, description };
} else if (isCallExpression(e) && isIdentifier(e.expression)) {
const [nameArg] = e.arguments;
if (!isStringLiteral(nameArg)) throw fail("first argument must be a string");
const name = nameArg.text;
return { name, description: "" };
}
throw fail("commands array contains invalid elements");
});
if (isArrayLiteralExpression(value)) {
data.commands = value.elements.map((e) => {
if (isObjectLiteralExpression(e)) {
const nameProperty = e.properties.find((p): p is PropertyAssignment =>
isPropertyAssignment(p) && isIdentifier(p.name) && p.name.escapedText === "name"
);
const descriptionProperty = e.properties.find((p): p is PropertyAssignment =>
isPropertyAssignment(p) && isIdentifier(p.name) && p.name.escapedText === "description"
);
if (!nameProperty || !descriptionProperty) throw fail("command missing required properties");
const name = isStringLiteral(nameProperty.initializer) ? nameProperty.initializer.text : "";
const description = isStringLiteral(descriptionProperty.initializer) ? descriptionProperty.initializer.text : "";
return { name, description };
} else if (isCallExpression(e) && isIdentifier(e.expression)) {
const [nameArg] = e.arguments;
if (!isStringLiteral(nameArg)) throw fail("first argument must be a string");
return { name: nameArg.text, description: "" };
} else if (e.kind === SyntaxKind.SpreadElement) {
return undefined;
}
throw fail("commands array contains invalid elements");
}).filter((c): c is { name: string; description: string; } => Boolean(c)) as Command[];
} else if (isIdentifier(value)) {
data.commands = [];
} else {
throw fail("commands is not an array literal or identifier");
}
break;
case "authors":
if (!isArrayLiteralExpression(value)) throw fail("authors is not an array literal");
@ -228,8 +234,7 @@ async function parseFile(fileName: string) {
data.filePath = posixNormalize(fileName)
.split(sep)
.join(posixSep)
.replace(/\/index\.([jt]sx?)$/, "")
.replace(/^src\/plugins\//, "");
.replace(/\/index\.([jt]sx?)$/, "");
return [data] as const;
}

View file

@ -26,7 +26,6 @@ import system from "./commands/system";
import text from "./commands/text";
import time from "./commands/time";
migratePluginSettings("MoreCommands", "CuteAnimeBoys", "CuteNekos", "CutePats", "Slap");
export default definePlugin({
name: "MoreCommands",