ci(lint): add checks for variables (#522)
This commit is contained in:
1 parent
9577a38711
commit
b6001b26b9
2 files changed
+70
-18
No files matched your search
@@ -56,7 +56,12 @@ const prettyPrint = (
|
|||||||
color.dim(String(startLine + 1)),
|
color.dim(String(startLine + 1)),
|
||||||
color.dim(lines[startLine]),
|
color.dim(lines[startLine]),
|
||||||
),
|
),
|
||||||
sprintf("%*s╰─► %s", pad, "", error),
|
sprintf(
|
||||||
|
"%*s╰─► %s",
|
||||||
|
pad,
|
||||||
|
"",
|
||||||
|
error,
|
||||||
|
),
|
||||||
undefined,
|
undefined,
|
||||||
].join("\n"),
|
].join("\n"),
|
||||||
);
|
);
|
||||||
|
|||||||
+64
-17
@@ -3,7 +3,7 @@ import usercssMeta from "usercss-meta";
|
|||||||
import * as color from "std/fmt/colors.ts";
|
import * as color from "std/fmt/colors.ts";
|
||||||
import { sprintf } from "std/fmt/printf.ts";
|
import { sprintf } from "std/fmt/printf.ts";
|
||||||
import type { WalkEntry } from "std/fs/walk.ts";
|
import type { WalkEntry } from "std/fs/walk.ts";
|
||||||
import { relative } from "std/path/mod.ts";
|
import { join, relative } from "std/path/mod.ts";
|
||||||
|
|
||||||
import { REPO_ROOT } from "@/deps.ts";
|
import { REPO_ROOT } from "@/deps.ts";
|
||||||
import { log } from "@/lint/logger.ts";
|
import { log } from "@/lint/logger.ts";
|
||||||
@@ -20,11 +20,12 @@ export const verifyMetadata = async (
|
|||||||
const { metadata, errors: parsingErrors } = usercssMeta.parse(content, {
|
const { metadata, errors: parsingErrors } = usercssMeta.parse(content, {
|
||||||
allowErrors: true,
|
allowErrors: true,
|
||||||
});
|
});
|
||||||
|
const lines = content.split("\n");
|
||||||
|
|
||||||
// Pretty print / annotate the parsing errors.
|
// Pretty print / annotate the parsing errors.
|
||||||
parsingErrors.map((e) => {
|
parsingErrors.map((e) => {
|
||||||
let startLine = 0;
|
let startLine = 0;
|
||||||
for (const line of content.split("\n")) {
|
for (const line of lines) {
|
||||||
startLine++;
|
startLine++;
|
||||||
e.index -= line.length + 1;
|
e.index -= line.length + 1;
|
||||||
if (e.index < 0) break;
|
if (e.index < 0) break;
|
||||||
@@ -32,19 +33,21 @@ export const verifyMetadata = async (
|
|||||||
log(e.message, { file, startLine, content });
|
log(e.message, { file, startLine, content });
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const [key, value] of Object.entries(assert)) {
|
for (const [key, expected] of Object.entries(assert)) {
|
||||||
const defacto = metadata[key];
|
const current = metadata[key];
|
||||||
if (defacto !== value) {
|
|
||||||
const line = content
|
if (current !== expected) {
|
||||||
.split("\n")
|
const line = lines
|
||||||
.findIndex((line) => line.includes(key)) + 1;
|
.findIndex((line) => line.includes(key)) + 1;
|
||||||
|
|
||||||
const message = sprintf(
|
const message = current === undefined
|
||||||
'Metadata `%s` should be "%s" but is "%s"',
|
? sprintf("Metadata `%s` should not be undefined", color.bold(key))
|
||||||
color.bold(key),
|
: sprintf(
|
||||||
color.green(value),
|
'Metadata `%s` should be "%s" but is "%s"',
|
||||||
color.red(String(defacto)),
|
color.bold(key),
|
||||||
);
|
color.green(expected),
|
||||||
|
color.red(String(current)),
|
||||||
|
);
|
||||||
|
|
||||||
log(message, {
|
log(message, {
|
||||||
file,
|
file,
|
||||||
@@ -54,6 +57,50 @@ export const verifyMetadata = async (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const template =
|
||||||
|
(await Deno.readTextFile(join(REPO_ROOT, "template/catppuccin.user.css")))
|
||||||
|
.split("\n");
|
||||||
|
|
||||||
|
for (const variable of ["darkFlavor", "lightFlavor", "accentColor"]) {
|
||||||
|
const declaration = `@var select ${variable}`;
|
||||||
|
|
||||||
|
const expected = template.find((line) => line.includes(declaration));
|
||||||
|
const current = lines.findIndex((line) => line.includes(declaration)) +
|
||||||
|
1;
|
||||||
|
|
||||||
|
if (current === 0) {
|
||||||
|
// This variable is undefined so there isn't a line for it, so we just put it at the bottom of the variables section.
|
||||||
|
const line = lines
|
||||||
|
.findLastIndex((line: string) => line.includes("==/UserStyle== */")) +
|
||||||
|
1;
|
||||||
|
|
||||||
|
log(
|
||||||
|
sprintf(
|
||||||
|
"Metadata variable `%s` should exist",
|
||||||
|
color.bold(variable),
|
||||||
|
),
|
||||||
|
{
|
||||||
|
file,
|
||||||
|
startLine: line !== 0 ? line : undefined,
|
||||||
|
content,
|
||||||
|
},
|
||||||
|
"warning",
|
||||||
|
);
|
||||||
|
} else if (expected.trim() !== lines[current].trim()) {
|
||||||
|
const message = sprintf(
|
||||||
|
"Options for metadata variable `%s` should be `%s`",
|
||||||
|
color.bold(variable),
|
||||||
|
(/\[[^\]]+\]/.exec(expected) as RegExpExecArray)[0],
|
||||||
|
);
|
||||||
|
|
||||||
|
log(message, {
|
||||||
|
file,
|
||||||
|
startLine: current,
|
||||||
|
content,
|
||||||
|
}, "warning");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Parse the UserCSS variables to LESS global variables, e.g.
|
// Parse the UserCSS variables to LESS global variables, e.g.
|
||||||
// `@var select lightFlavor "Light Flavor" ["latte:Latte*", "frappe:Frappé", "macchiato:Macchiato", "mocha:Mocha"]`
|
// `@var select lightFlavor "Light Flavor" ["latte:Latte*", "frappe:Frappé", "macchiato:Macchiato", "mocha:Mocha"]`
|
||||||
// gets parsed as
|
// gets parsed as
|
||||||
@@ -91,16 +138,16 @@ const assertions = async (userstyle: string) => {
|
|||||||
: userstyles[userstyle].name
|
: userstyles[userstyle].name
|
||||||
} Catppuccin`,
|
} Catppuccin`,
|
||||||
namespace: `github.com/catppuccin/userstyles/styles/${userstyle}`,
|
namespace: `github.com/catppuccin/userstyles/styles/${userstyle}`,
|
||||||
author: "Catppuccin",
|
homepageURL: `${prefix}/tree/main/styles/${userstyle}`,
|
||||||
description: `Soothing pastel theme for ${
|
description: `Soothing pastel theme for ${
|
||||||
Array.isArray(userstyles[userstyle].name)
|
Array.isArray(userstyles[userstyle].name)
|
||||||
? formatListOfItems(userstyles[userstyle].name as string[])
|
? formatListOfItems(userstyles[userstyle].name as string[])
|
||||||
: userstyles[userstyle].name
|
: userstyles[userstyle].name
|
||||||
}`,
|
}`,
|
||||||
license: "MIT",
|
author: "Catppuccin",
|
||||||
preprocessor: "less",
|
|
||||||
homepageURL: `${prefix}/tree/main/styles/${userstyle}`,
|
|
||||||
updateURL: `${prefix}/raw/main/styles/${userstyle}/catppuccin.user.css`,
|
updateURL: `${prefix}/raw/main/styles/${userstyle}/catppuccin.user.css`,
|
||||||
supportURL: `${prefix}/issues?q=is%3Aopen+is%3Aissue+label%3A${userstyle}`,
|
supportURL: `${prefix}/issues?q=is%3Aopen+is%3Aissue+label%3A${userstyle}`,
|
||||||
|
license: "MIT",
|
||||||
|
preprocessor: "less",
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user