dslinter 0.0.33 → 0.0.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,149 @@
1
+ import type { TokenCatalog } from "../types/tokenCatalog";
2
+ import type { CssTokenSummary, WorkspaceReport } from "../types/report";
3
+
4
+ export type TokenUsageFilter = "all" | "used" | "unused";
5
+
6
+ export type ScannedTokenRow = {
7
+ cssName: string;
8
+ value: string;
9
+ category: "color" | "spacing" | "radius" | "typography" | "other";
10
+ scope: string;
11
+ path: string;
12
+ line: number;
13
+ referenceCount: number;
14
+ fileCount: number;
15
+ isUnused: boolean;
16
+ /** From manual catalog when names align */
17
+ tw?: string;
18
+ /** Display swatch / resolved color for the wall */
19
+ displayValue?: string;
20
+ usageFiles: string[];
21
+ };
22
+
23
+ export type MergedTokenView = {
24
+ source: "scan" | "manual" | "hybrid";
25
+ rows: ScannedTokenRow[];
26
+ usedCount: number;
27
+ totalCount: number;
28
+ };
29
+
30
+ function catalogTwByCssName(catalog: TokenCatalog): Map<string, string> {
31
+ const map = new Map<string, string>();
32
+ for (const c of catalog.colors) {
33
+ const cssVar = `--color-${c.token}${c.shade === "DEFAULT" ? "" : `-${c.shade}`}`;
34
+ map.set(cssVar, c.tw);
35
+ }
36
+ for (const s of catalog.spacing) {
37
+ map.set(`--spacing-${s.token}`, s.tw);
38
+ }
39
+ for (const r of catalog.radius) {
40
+ map.set(`--radius-${r.token}`, r.tw);
41
+ }
42
+ const typo = catalog.typography;
43
+ if (typo) {
44
+ for (const f of typo.families) {
45
+ map.set(`--font-${f.key}`, f.tw);
46
+ }
47
+ for (const s of typo.sizes) {
48
+ map.set(`--font-size-${s.token}`, s.tw);
49
+ }
50
+ }
51
+ return map;
52
+ }
53
+
54
+ function catalogDisplayByCssName(catalog: TokenCatalog): Map<string, string> {
55
+ const map = new Map<string, string>();
56
+ for (const c of catalog.colors) {
57
+ const cssVar = `--color-${c.token}${c.shade === "DEFAULT" ? "" : `-${c.shade}`}`;
58
+ map.set(cssVar, c.value);
59
+ }
60
+ for (const s of catalog.spacing) {
61
+ map.set(`--spacing-${s.token}`, s.value);
62
+ }
63
+ for (const r of catalog.radius) {
64
+ map.set(`--radius-${r.token}`, r.value);
65
+ }
66
+ return map;
67
+ }
68
+
69
+ function isParseableColor(value: string): boolean {
70
+ const v = value.trim();
71
+ return (
72
+ /^#[0-9a-fA-F]{3,8}$/.test(v) ||
73
+ v.startsWith("rgb(") ||
74
+ v.startsWith("oklch(") ||
75
+ v.startsWith("hsl(")
76
+ );
77
+ }
78
+
79
+ export function buildMergedTokenView(
80
+ report: WorkspaceReport | null | undefined,
81
+ catalog?: TokenCatalog,
82
+ ): MergedTokenView | null {
83
+ const summary = report?.css_tokens;
84
+ if (!summary?.definitions?.length) {
85
+ if (!catalog) return null;
86
+ return { source: "manual", rows: [], totalCount: 0, usedCount: 0 };
87
+ }
88
+
89
+ const unusedSet = new Set(summary.unused_tokens ?? []);
90
+ const usageByName = new Map(
91
+ (summary.usage_by_token ?? []).map((u) => [u.name, u]),
92
+ );
93
+ const twMap = catalog ? catalogTwByCssName(catalog) : new Map<string, string>();
94
+ const displayMap = catalog
95
+ ? catalogDisplayByCssName(catalog)
96
+ : new Map<string, string>();
97
+
98
+ const rows: ScannedTokenRow[] = summary.definitions.map((def) => {
99
+ const usage = usageByName.get(def.name);
100
+ const referenceCount = usage?.reference_count ?? 0;
101
+ const isUnused = unusedSet.has(def.name);
102
+ const manualDisplay = displayMap.get(def.name);
103
+ const displayValue =
104
+ manualDisplay ??
105
+ (def.category === "color" && isParseableColor(def.value)
106
+ ? def.value
107
+ : def.value.startsWith("var(")
108
+ ? manualDisplay
109
+ : def.value);
110
+
111
+ return {
112
+ cssName: def.name,
113
+ value: def.value,
114
+ category: def.category,
115
+ scope: def.scope,
116
+ path: def.path,
117
+ line: def.line,
118
+ referenceCount,
119
+ fileCount: usage?.file_count ?? 0,
120
+ isUnused,
121
+ tw: twMap.get(def.name),
122
+ displayValue: displayValue ?? def.value,
123
+ usageFiles: usage?.files ?? [],
124
+ };
125
+ });
126
+
127
+ rows.sort((a, b) => a.cssName.localeCompare(b.cssName));
128
+
129
+ const themeRoot = rows.filter(
130
+ (r) => r.scope === "theme" || r.scope === "root",
131
+ );
132
+ const usedCount = themeRoot.filter((r) => !r.isUnused).length;
133
+
134
+ return {
135
+ source: catalog ? "hybrid" : "scan",
136
+ rows,
137
+ usedCount,
138
+ totalCount: themeRoot.length,
139
+ };
140
+ }
141
+
142
+ export function filterTokenRows(
143
+ rows: ScannedTokenRow[],
144
+ filter: TokenUsageFilter,
145
+ ): ScannedTokenRow[] {
146
+ if (filter === "all") return rows;
147
+ if (filter === "used") return rows.filter((r) => !r.isUnused);
148
+ return rows.filter((r) => r.isUnused);
149
+ }
package/src/index.ts CHANGED
@@ -25,7 +25,18 @@ export type {
25
25
  FileScan,
26
26
  PlaygroundSpec,
27
27
  DeclaredPropKind,
28
+ CssTokenSummary,
29
+ CssTokenDefinition,
30
+ CssTokenUsage,
31
+ CssTokenCategory,
32
+ CssTokenScope,
28
33
  } from "./types/report";
34
+ export { buildMergedTokenView } from "./dashboard/mergeTokenCatalog";
35
+ export type {
36
+ MergedTokenView,
37
+ ScannedTokenRow,
38
+ TokenUsageFilter,
39
+ } from "./dashboard/mergeTokenCatalog";
29
40
  export type {
30
41
  TokenCatalog,
31
42
  TokenCatalogColor,
@@ -10,10 +10,13 @@ export function resolveModuleSourcePath(reportRoot: string, modulePath: string):
10
10
  return `${root}/${withSrc}`;
11
11
  }
12
12
 
13
+ const SRC_COMPONENTS = "src/components/";
14
+
13
15
  /** Match finding path to source file even when `report.root` differs from machine that generated JSON. */
14
16
  function tailSrcComponents(p: string): string | null {
15
- const m = norm(p).match(/(src\/components\/.+)$/);
16
- return m ? m[1] : null;
17
+ const normalized = norm(p);
18
+ const idx = normalized.indexOf(SRC_COMPONENTS);
19
+ return idx === -1 ? null : normalized.slice(idx);
17
20
  }
18
21
 
19
22
  export function pathsMatch(reportPath: string, candidate: string): boolean {
@@ -119,7 +119,7 @@ export function useDashboardTheme(): DashboardThemeContextValue {
119
119
 
120
120
  export type DashboardLayoutProps = {
121
121
  playgroundEntries: PlaygroundEntry[];
122
- tokenCatalog: TokenCatalog;
122
+ tokenCatalog?: TokenCatalog;
123
123
  /** Custom intro shown above the governance inventory on `#!/governance`; defaults to package copy. */
124
124
  overview?: ReactNode;
125
125
  /** Fetch URL for `dslint --json` output. */
@@ -169,7 +169,12 @@ function DashboardLayoutInner({
169
169
 
170
170
  let main: ReactNode;
171
171
  if (route.view === "tokens") {
172
- main = <TokensPane tokenCatalog={tokenCatalog} />;
172
+ main = (
173
+ <TokensPane
174
+ tokenCatalog={tokenCatalog}
175
+ dslinterReport={dslinterReport.report}
176
+ />
177
+ );
173
178
  } else if (route.view === "governance") {
174
179
  main = (
175
180
  <GovernancePane
@@ -104,6 +104,38 @@ export interface PlaygroundSpec {
104
104
  declared_prop_kinds?: Partial<Record<string, DeclaredPropKind>>;
105
105
  }
106
106
 
107
+ export type CssTokenCategory =
108
+ | "color"
109
+ | "spacing"
110
+ | "radius"
111
+ | "typography"
112
+ | "other";
113
+
114
+ export type CssTokenScope = "theme" | "root" | "selector";
115
+
116
+ export interface CssTokenDefinition {
117
+ name: string;
118
+ value: string;
119
+ category: CssTokenCategory;
120
+ scope: CssTokenScope;
121
+ path: string;
122
+ line: number;
123
+ }
124
+
125
+ export interface CssTokenUsage {
126
+ name: string;
127
+ reference_count: number;
128
+ file_count: number;
129
+ files: string[];
130
+ usage_locations?: UsageLocation[];
131
+ }
132
+
133
+ export interface CssTokenSummary {
134
+ definitions: CssTokenDefinition[];
135
+ usage_by_token: CssTokenUsage[];
136
+ unused_tokens?: string[];
137
+ }
138
+
107
139
  export interface WorkspaceReport {
108
140
  root: string;
109
141
  files: FileScan[];
@@ -113,4 +145,5 @@ export interface WorkspaceReport {
113
145
  ownership: OwnershipSummary[];
114
146
  scores: GovernanceScores;
115
147
  playgrounds?: PlaygroundSpec[];
148
+ css_tokens?: CssTokenSummary;
116
149
  }