From 37e6e446122723e77320aa81bc7663a5796b5495 Mon Sep 17 00:00:00 2001 From: Gitea OpenCode Agent Date: Thu, 15 Oct 2026 16:44:08 +0000 Subject: [PATCH] Fix issue #71: Nuxt error with colors --- frontend/app/assets/css/colors.scss | 16 ++++--- tests/theme-color-vars.test.js | 72 +++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 tests/theme-color-vars.test.js diff --git a/frontend/app/assets/css/colors.scss b/frontend/app/assets/css/colors.scss index 50d0a19d..b2df6627 100644 --- a/frontend/app/assets/css/colors.scss +++ b/frontend/app/assets/css/colors.scss @@ -30,9 +30,12 @@ $themes: ( container-shadow: #151d28, sticky-header-bg: #20202077, - red: #e06c75, - green: #98c379, - gray: #cccccc, + // Quoted: red/green/gray are also Sass colour keywords, so unquoted they are parsed as + // colour values, and interpolating one into `--color-#{$name}` warns + // (Syndria98/dragonroll#71). + "red": #e06c75, + "green": #98c379, + "gray": #cccccc, // The rarity of an item colours its row in the sidebar (Syndria98/dragonroll#63). rarity-common: #ffffff, @@ -75,9 +78,10 @@ $themes: ( container-shadow: #5f6774, sticky-header-bg: #fff, - red: #e06c75, - green: #98c379, - gray: #cccccc, + // Quoted for the same reason as in the dark map. + "red": #e06c75, + "green": #98c379, + "gray": #cccccc, // Same rarities as the dark map, darkened to stay readable on a light background. rarity-common: #1e1e1e, diff --git a/tests/theme-color-vars.test.js b/tests/theme-color-vars.test.js new file mode 100644 index 00000000..61c318ff --- /dev/null +++ b/tests/theme-color-vars.test.js @@ -0,0 +1,72 @@ +// Tests for Syndria98/dragonroll#71: `pnpm dev` warned, on every frontend build, +// "You probably don't mean to use the color value red in interpolation here" from `theme-vars()` +// in colors.scss. `red`, `green` and `gray` are also Sass colour keywords, so as unquoted map keys +// they were parsed as colour *values* and interpolating one into `--color-#{$name}` warned (and can +// emit an invalid name). Quoting those keys keeps them strings; the emitted CSS is unchanged, so +// `var(--color-red)` and friends still resolve. +// +// `sass` is not installed for `npm test`, so this reads colors.scss the way the other tests read +// sources: the check is that no map key is left bare when it spells a CSS colour keyword. +// +// Run with `npm test` from the repository root, or `node --test tests/`. + +const { test } = require("node:test"); +const assert = require("node:assert/strict"); +const fs = require("node:fs"); +const path = require("node:path"); + +const read = (...parts) => fs.readFileSync(path.join(__dirname, "..", ...parts), "utf8"); + +const colorsSource = read("frontend", "app", "assets", "css", "colors.scss"); + +// The CSS named colours. Sass parses any of these (in any case) as a colour value, so a theme or +// accent map key spelled like one of them has to be quoted to stay a string. +const colorKeywords = new Set( + [ + "aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige", "bisque", "black", + "blanchedalmond", "blue", "blueviolet", "brown", "burlywood", "cadetblue", "chartreuse", + "chocolate", "coral", "cornflowerblue", "cornsilk", "crimson", "cyan", "darkblue", "darkcyan", + "darkgoldenrod", "darkgray", "darkgreen", "darkkhaki", "darkmagenta", "darkolivegreen", + "darkorange", "darkorchid", "darkred", "darksalmon", "darkseagreen", "darkslateblue", + "darkslategray", "darkturquoise", "darkviolet", "deeppink", "deepskyblue", "dimgray", + "dodgerblue", "firebrick", "floralwhite", "forestgreen", "fuchsia", "gainsboro", "ghostwhite", + "gold", "goldenrod", "gray", "green", "greenyellow", "honeydew", "hotpink", "indianred", + "indigo", "ivory", "khaki", "lavender", "lavenderblush", "lawngreen", "lemonchiffon", + "lightblue", "lightcoral", "lightcyan", "lightgoldenrodyellow", "lightgray", "lightgreen", + "lightpink", "lightsalmon", "lightseagreen", "lightskyblue", "lightslategray", + "lightsteelblue", "lightyellow", "lime", "limegreen", "linen", "magenta", "maroon", + "mediumaquamarine", "mediumblue", "mediumorchid", "mediumpurple", "mediumseagreen", + "mediumslateblue", "mediumspringgreen", "mediumturquoise", "mediumvioletred", "midnightblue", + "mintcream", "mistyrose", "moccasin", "navajowhite", "navy", "oldlace", "olive", "olivedrab", + "orange", "orangered", "orchid", "palegoldenrod", "palegreen", "paleturquoise", + "palevioletred", "papayawhip", "peachpuff", "peru", "pink", "plum", "powderblue", "purple", + "rebeccapurple", "red", "rosybrown", "royalblue", "saddlebrown", "salmon", "sandybrown", + "seagreen", "seashell", "sienna", "silver", "skyblue", "slateblue", "slategray", "snow", + "springgreen", "steelblue", "tan", "teal", "thistle", "tomato", "transparent", "turquoise", + "violet", "wheat", "white", "whitesmoke", "yellow", "yellowgreen", + ] +); + +// The keys of the `$themes` and `$accents` maps and of each theme inside them: a line starting with +// `key:` or `"key":`. The custom properties of the mixins (`--color-#{$name}: #{$value};`) do not +// match, `#` is not part of a key. +const mapKeys = [...colorsSource.matchAll(/^\s*("[^"]+"|[A-Za-z][A-Za-z0-9_-]*)\s*:/gm)].map((m) => m[1]); + +test("the theme and accent maps are read as maps of keys", () => { + // sanity check on the extraction above before it is trusted to find a bare colour keyword + for (const key of ["dark", "light", "katlum", "solus", "silang", "background", "text"]) { + assert.ok(mapKeys.includes(key), `expected to find the map key '${key}'`); + } +}); + +test("no map key is a bare CSS colour keyword", () => { + const bare = mapKeys.filter((key) => !key.startsWith('"') && colorKeywords.has(key.toLowerCase())); + assert.deepEqual(bare, [], `quote these colors.scss map keys so Sass keeps them strings: ${bare.join(", ")}`); +}); + +test("the colour-named theme keys are quoted in both maps", () => { + for (const [key, value] of [["red", "#e06c75"], ["green", "#98c379"], ["gray", "#cccccc"]]) { + const declarations = colorsSource.match(new RegExp(`"${key}":\\s*${value}\\b`, "g")) || []; + assert.equal(declarations.length, 2, `expected quoted "${key}": ${value} in both the dark and the light map`); + } +});