Skip to content

Isometric line figures that answer the pointer. For React and for anything with a DOM.

Skill: the validator accepts a handle returned in shorthand, { set, destroy }, as SKILL.md writes it

Lucas Marques4bd5196d8816
diff --git a/packages/hairline/test/skill/validate.test.ts b/packages/hairline/test/skill/validate.test.ts
index e61c863..5a16be7 100644
--- a/packages/hairline/test/skill/validate.test.ts
+++ b/packages/hairline/test/skill/validate.test.ts
@@ -55,20 +55,27 @@ describe("pages that pass", () => {
});
});
-/** Honest code that only looks like a broken rule: a good figure with any of these added still passes. */
-const HONEST: [why: string, code: string][] = [
- ["an identifier named gradient, for a slope", "const gradient = 0.5;"],
- ["a read-out with a number sign", 'const label = "pillar #101";'],
- ["the word import in a string", 'const note = "import";'],
- ["the word import inside a longer name", "const important = true;"],
- ["a name that starts with import, before a comma", "const [important, b] = [1, 2];"],
- ["a name that starts with import, as an argument", "f(imported, 1);"],
+/** Honest code that only looks like a broken rule: a good figure with any of these changes still passes. */
+const HONEST: [why: string, figure: string][] = [
+ ["an identifier named gradient, for a slope", plus("const gradient = 0.5;")],
+ ["a read-out with a number sign", plus('const label = "pillar #101";')],
+ ["the word import in a string", plus('const note = "import";')],
+ ["the word import inside a longer name", plus("const important = true;")],
+ ["a name that starts with import, before a comma", plus("const [important, b] = [1, 2];")],
+ ["a name that starts with import, as an argument", plus("f(imported, 1);")],
+ ["a handle returned in shorthand, { set, destroy }", terrain.replace(
+ /return \{\n {4}set: (\(v\) => \{[^\n]*\}),\n {4}destroy: bag\.dispose,\n {2}\};/,
+ (_, set) => `const set = ${set};\n const destroy = bag.dispose;\n return { set, destroy };`,
+ )],
];
-describe("honest additions that pass", () => {
- for (const [why, code] of HONEST) {
+describe("honest changes that pass", () => {
+ it("each change is made", () => {
+ for (const [why, figure] of HONEST) expect(figure, why).not.toBe(terrain);
+ });
+ for (const [why, figure] of HONEST) {
it(why, () => {
- const run = check(plus(code));
+ const run = check(figure);
expect(run.err).toBe("");
expect(run.status).toBe(0);
});
diff --git a/skills/hairline-create/validate.mjs b/skills/hairline-create/validate.mjs
index 5f06d90..bd44cdb 100644
--- a/skills/hairline-create/validate.mjs
+++ b/skills/hairline-create/validate.mjs
@@ -92,13 +92,17 @@ const BAD = [
"rule 01. The figure listens to the pointer itself or measures what is on screen. Take the pointer from HL.pointer(stage, { move, leave }) and test it against the rest or target pose, in world units."],
];
-/** What a figure must contain. A call on something else, such as `map.set(k, v)`, is not the handle's `set`. */
+/**
+ * What a figure must contain. The handle's keys may be written `set(v)`, `set: f`
+ * or, shorthand, `{ set, destroy }`. A call on something else, such as
+ * `map.set(k, v)`, is not the handle's `set`.
+ */
const NEED = [
["clock", /\bregister\s*\(/, "rule 07. The figure never joins the kernel's loop. Draw inside HL.register(stage, tick), and give its unregister to destroy."],
["hit", /\bpointer\s*\(/, "the figure never listens to the pointer. Call HL.pointer(stage, { move, leave }) and answer it."],
["readout", /\bread\.textContent\s*=/, 'the figure never writes the read-out. Set read.textContent to what is under the pointer, and to "rest" when nothing is.'],
- ["handle", /(?<![.\w$])set\s*[:(]/, "mount must return { set(value), destroy() }, and set is missing. It takes the slider's number."],
- ["handle", /(?<![.\w$])destroy\s*[:(]/, "mount must return { set(value), destroy() }, and destroy is missing. It undoes everything mount did: bag.dispose."],
+ ["handle", /(?<![.\w$])set\s*[:(,}]/, "mount must return { set(value), destroy() }, and set is missing. It takes the slider's number."],
+ ["handle", /(?<![.\w$])destroy\s*[:(,}]/, "mount must return { set(value), destroy() }, and destroy is missing. It undoes everything mount did: bag.dispose."],
];
/** The declaration at the end of the file, read as text. */