Skip to content

Commit

Permalink
make debugging connect
Browse files Browse the repository at this point in the history
  • Loading branch information
mcnuttandrew committed Jan 18, 2025
1 parent f696bb6 commit ec1da3f
Show file tree
Hide file tree
Showing 12 changed files with 476 additions and 129 deletions.
206 changes: 206 additions & 0 deletions apps/color-buddy/src/linting/Eval.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
<script lang="ts">
import type { LintResult } from "color-buddy-palette-lint";
import IgnoreIcon from "virtual:icons/fa6-solid/eye-slash";
import ShowIcon from "virtual:icons/fa6-solid/eye";
import colorStore from "../stores/color-store";
import configStore from "../stores/config-store";
import lintStore from "../stores/lint-store";
import { lint } from "../lib/api-calls";
import { buttonStyle } from "../lib/styles";
import LintDisplay from "./LintDisplay.svelte";
import LintCustomizationModal from "./LintCustomizationTab.svelte";
import GlobalLintConfig from "./GlobalLintConfigModal.svelte";
import { lintGroupNames, typeToImg } from "../constants";
import Tooltip from "../components/Tooltip.svelte";
import QuestionIcon from "virtual:icons/fa6-solid/circle-question";
import { loadLints } from "../lib/api-calls";
$: currentPal = $colorStore.palettes[$colorStore.currentPal];
$: evalConfig = currentPal.evalConfig;
$: lintResults = $lintStore.currentChecks;
$: lintGroups = lintResults.reduce(
(acc, lintResult) => {
if (
$colorStore.globallyIgnoredLints.includes(lintResult.lintProgram.id)
) {
return acc;
}
const lint = lintResult.lintProgram;
if (!acc[lint.group]) {
acc[lint.group] = [];
}
// extremely dumb hack to move WCAGs to the top
if (lint.name.startsWith("WCAG")) {
acc[lint.group].push(lintResult);
} else {
acc[lint.group].push(lintResult);
}
return acc;
},
{} as Record<string, LintResult[]>
);
function setGroupTo(checks: LintResult[], ignore: boolean) {
const newEvalConfig = { ...evalConfig };
checks.forEach((check) => {
newEvalConfig[check.lintProgram.name] = { ignore };
});
colorStore.setCurrentPalEvalConfig(newEvalConfig);
}
$: displayMode = $configStore.evalDisplayMode;
function refreshLints() {
const outPal = {
...currentPal,
evalConfig: {
...currentPal.evalConfig,
globallyIgnoredLints: $colorStore.globallyIgnoredLints,
},
};
loadLints()
.then(() => lint(outPal, false))
.then((res) => {
lintResults = res;
});
}
$: numIgnored = Object.values(evalConfig).filter((x) => x.ignore).length;
$: groupNames = [
"usability",
"contrast-accessibility",
"color-accessibility",
"design",
"custom",
].filter((x) => (lintGroups[x] || []).length);
</script>

{#if displayMode === "check-customization"}
<LintCustomizationModal onClose={() => refreshLints()} />
{/if}
<div class=" w-full flex py-1 px-2 items-end bg-stone-100">
<div class="flex">
<GlobalLintConfig />
<div class="ml-1">
<button
class={buttonStyle
.split(" ")
.filter((x) => !x.startsWith("py"))
.join(" ")}
on:click={() => {
configStore.setEvalDisplayMode("check-customization");
lintStore.setFocusedLint(false);
}}
>
Customize tests
</button>
</div>
</div>
{#if numIgnored > 0}
<button
class={buttonStyle
.split(" ")
.filter((x) => !x.startsWith("py"))
.join(" ")}
on:click={() => {
const newEvalConfig = { ...evalConfig };
Object.keys(newEvalConfig).forEach((key) => {
newEvalConfig[key] = { ignore: false };
});
colorStore.setCurrentPalEvalConfig(newEvalConfig);
}}
>
Unhide all
</button>
{/if}
<Tooltip>
<div class="text-sm max-w-md" slot="content">
This collection of checks validates whether or not your palette matches a
number of commonly held beliefs about best practices. They wont fit every
situation! So feel free to turn some off.
</div>
<button slot="target" let:toggle on:click={toggle} class="mx-2">
<QuestionIcon />
</button>
</Tooltip>
</div>
<div class="flex h-full">
<div class="flex flex-col ml-2">
<div class="overflow-auto h-full mb-28 px-2">
<!-- lint group -->
<div class="flex flex-wrap">
{#each groupNames as lintGroup}
<div class="border border-stone-200 bg-white max-w-md w-full m-2">
<div
class="flex justify-between items-center mb-2 bg-stone-100 pl-2 pr-1 py-1"
>
<!-- logo -->
<div class="flex">
<div class="h-8 w-8 flex items-center justify-center">
<img
src={typeToImg[lintGroup]}
class="h-6 w-6"
alt="Logo for {lintGroup}"
title="Logo for {lintGroup} tests"
/>
</div>
<div class="text-xl">{lintGroupNames[lintGroup]}</div>
</div>
<!-- show hide stuff -->
<div>
{#if (lintGroups[lintGroup] || []).every((x) => !evalConfig[x.lintProgram.name]?.ignore)}
<button
class={`${buttonStyle} `}
on:click={() =>
setGroupTo(
lintGroups[lintGroup].filter(
(x) => x.kind !== "invalid"
) || [],
true
)}
>
<IgnoreIcon class="h-4 w-4" />
</button>
{/if}
{#if (lintGroups[lintGroup] || []).some((x) => evalConfig[x.lintProgram.name]?.ignore)}
<button
class={`${buttonStyle} `}
on:click={() =>
setGroupTo(lintGroups[lintGroup] || [], false)}
>
<ShowIcon class="h-4 w-4" />
</button>
{/if}
</div>
</div>
<div class="px-4">
<!-- lints in the lint group -->
{#if !lintGroups[lintGroup].every((x) => x.kind === "ignored" || x.kind === "invalid")}
<div class="">
{#each (lintGroups[lintGroup] || []).sort((a, b) => {
return a.kind === "ignored" ? 1 : -1;
}) as lintResult}
<LintDisplay {lintResult} />
{/each}
</div>
{:else}
<div class="text-sm italic">
All checks in this group are ignored
</div>
{/if}
{#if (lintGroups[lintGroup] || []).length === 0 && $lintStore.loadState === "loading"}
<div class="text-sm animate-pulse italic font-bold">
Loading
</div>
{/if}
</div>
</div>
{/each}
</div>
</div>
</div>
</div>
17 changes: 16 additions & 1 deletion apps/lil-buddy/netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,20 @@
command = "yarn workspace lil-buddy build"
publish = "apps/lil-buddy/dist"


[dev]
command = "yarn workspace lil-buddy dev"
command = "yarn workspace lil-buddy dev"
targetPort = 5173
functionsPort = 8081
envFiles=[".env.development"]
framework = "vite"

[[redirects]]
from = "/*"
to = "/index.html"
status = 200

[[headers]]
for = "/*.json"
[headers.values]
Access-Control-Allow-Origin = "*"
3 changes: 3 additions & 0 deletions apps/lil-buddy/src/components/MonacoEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
let monaco: typeof Monaco;
let editorContainer: HTMLElement;
let isTyping = false;
onMount(async () => {
// Import our 'monaco.ts' file here
// (onMount() will only be executed in the browser, which is what we want)
Expand All @@ -24,6 +26,7 @@
const model = monaco.editor.createModel(value, language);
editor.setModel(model);
editor.onDidChangeModelContent(() => {
// redo this such that there is a debounce
onChange(editor.getValue());
});
});
Expand Down
27 changes: 13 additions & 14 deletions apps/lil-buddy/src/lib/SmallStepEvaluator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { makePalFromString } from "color-buddy-palette";
import { GenerateAST } from "color-buddy-palette-lint";
import { generateEvaluations } from "./small-step-evaluator";

const defaultPal = makePalFromString(["red", "green"]);
test("SmallStepEvaluator works", () => {
const exampleNode = {
">": {
Expand All @@ -11,11 +12,10 @@ test("SmallStepEvaluator works", () => {
},
};
const ast = (GenerateAST(exampleNode as any).value as any).children[0] as any;
const pal = makePalFromString(["red", "green"]);
const result = generateEvaluations(
ast,
{ a: pal.colors[0], b: pal.colors[1] },
pal
{ a: defaultPal.colors[0], b: defaultPal.colors[1] },
defaultPal
);
expect(result).toMatchSnapshot();
});
Expand All @@ -24,22 +24,21 @@ test("SmallStepEvaluator works with smaller example", () => {
const smallExampleNode = { ">": { left: 11, right: 10 } };
const ast = (GenerateAST(smallExampleNode as any).value as any)
.children[0] as any;
const result = generateEvaluations(
ast,
{},
makePalFromString(["red", "green"])
);
const result = generateEvaluations(ast, {}, defaultPal);
expect(result).toMatchSnapshot();
});

test.only("SmallStepEvaluator works with small not example", () => {
test("SmallStepEvaluator works with small not example", () => {
const smallExampleNode = { not: { ">": { left: 11, right: 10 } } };
const ast = (GenerateAST(smallExampleNode as any).value as any)
.children[0] as any;
const result = generateEvaluations(
ast,
{},
makePalFromString(["red", "green"])
);
const result = generateEvaluations(ast, {}, defaultPal);
expect(result).toMatchSnapshot();
});

test("Agg Test", () => {
const example = { "<": { left: { count: "colors" }, right: 11 } };
const ast = (GenerateAST(example as any).value as any).children[0] as any;
const result = generateEvaluations(ast, {}, defaultPal);
expect(result).toMatchSnapshot();
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,47 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`Agg Test 1`] = `
[
LLExpression {
"nodeType": "expression",
"value": LLPredicate {
"left": LLAggregate {
"children": LLVariable {
"nodeType": "variable",
"value": "colors",
},
"nodeType": "aggregate",
"type": "count",
},
"nodeType": "predicate",
"right": LLNumber {
"nodeType": "number",
"value": 11,
},
"threshold": undefined,
"type": "<",
},
},
LLPredicate {
"left": LLNumber {
"nodeType": "number",
"value": 2,
},
"nodeType": "predicate",
"right": LLNumber {
"nodeType": "number",
"value": 11,
},
"threshold": undefined,
"type": "<",
},
LLBool {
"nodeType": "bool",
"value": true,
},
]
`;

exports[`SmallStepEvaluator works 1`] = `
[
LLExpression {
Expand Down Expand Up @@ -29,7 +71,7 @@ exports[`SmallStepEvaluator works 1`] = `
"type": ">",
},
},
{
LLPredicate {
"left": LLNumber {
"nodeType": "number",
"value": 70.2365636120491,
Expand All @@ -55,9 +97,21 @@ exports[`SmallStepEvaluator works with small not example 1`] = `
"nodeType": "expression",
"value": LLConjunction {
"children": [
LLBool {
"nodeType": "bool",
"value": true,
LLExpression {
"nodeType": "expression",
"value": LLPredicate {
"left": LLNumber {
"nodeType": "number",
"value": 11,
},
"nodeType": "predicate",
"right": LLNumber {
"nodeType": "number",
"value": 10,
},
"threshold": undefined,
"type": ">",
},
},
],
"nodeType": "conjunction",
Expand Down
Loading

0 comments on commit ec1da3f

Please sign in to comment.