Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
design_adherence.hpp
Go to the documentation of this file.
1#pragma once
2
3// pulp::design — adherence lint.
4//
5// The mechanical backstop for the design contract (design_manifest.hpp): given
6// UI JS and a compiled DesignManifest, flag the places where the code breaks out
7// of the design system instead of binding to it. Three checks, all high-signal:
8//
9// - raw_color: a hex color literal (#rrggbb / #rgb / #rrggbbaa) where a
10// bound theme should be referenced by token. When the value
11// is one the system defines, the finding names the token.
12// - unknown_token: a `var(--name)` reference whose token is not in the
13// manifest — a hallucinated or renamed token that would
14// silently fall back at runtime (the exact failure the
15// binding prompt exists to prevent).
16// - raw_dimension: an `<n>px` literal whose value matches a dimension token
17// (info-level: prefer the token).
18//
19// The scan is purely lexical — no JS parse. Line and block comments are ignored
20// (a color mentioned in a comment is not a binding); string literals are scanned
21// (that is where style values live). Known limitation: raw_color matches any
22// `#` + 3/6/8 hex-digit run outside a comment, so an all-hex CSS id selector such
23// as `querySelector('#fff')` is reported as a raw color. Such ids are vanishingly
24// rare in generated UI and `#fff` is almost always a color, so the check favors
25// catching real drift over that edge.
26
28
29#include <string>
30#include <vector>
31
32namespace pulp::design {
33
35
36enum class AdherenceKind {
37 raw_color, // hex color literal where a token is expected
38 unknown_token, // var(--x) reference to a token not in the manifest
39 raw_dimension, // <n>px literal matching a dimension token's value
40};
41
45 int line = 0; // 1-based
46 int column = 0; // 1-based byte column of the snippet start
47 std::string snippet; // the offending literal / reference
48 std::string message; // human-readable, names a suggested token when known
49};
50
53
57std::vector<AdherenceFinding> lint_adherence(const std::string& js_source,
58 const DesignManifest& manifest);
59
60} // namespace pulp::design
Definition design_adherence.hpp:32
AdherenceSeverity
Definition design_adherence.hpp:34
@ warning
Definition design_adherence.hpp:34
@ info
Definition design_adherence.hpp:34
@ error
Definition design_adherence.hpp:34
AdherenceKind
Definition design_adherence.hpp:36
@ raw_dimension
Definition design_adherence.hpp:39
@ unknown_token
Definition design_adherence.hpp:38
@ raw_color
Definition design_adherence.hpp:37
const char * adherence_kind_name(AdherenceKind kind)
Human-readable kind slug ("raw-color", "unknown-token", "raw-dimension").
std::vector< AdherenceFinding > lint_adherence(const std::string &js_source, const DesignManifest &manifest)
Lint UI JS against a compiled design contract.
Definition design_adherence.hpp:42
AdherenceKind kind
Definition design_adherence.hpp:43
AdherenceSeverity severity
Definition design_adherence.hpp:44
int line
Definition design_adherence.hpp:45
int column
Definition design_adherence.hpp:46
std::string snippet
Definition design_adherence.hpp:47
std::string message
Definition design_adherence.hpp:48
The compiled design contract.
Definition design_manifest.hpp:56