guard-my-design-system 1.6.0 → 1.7.0

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/judge.mjs +17 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "guard-my-design-system",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "description": "Your design system dies one pull request at a time. This makes sure it doesn't. A guard that judges only the lines a change adds, against the system the repo already has, and names the on-system value the author probably meant.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -11,7 +11,7 @@
11
11
  "src/"
12
12
  ],
13
13
  "dependencies": {
14
- "roast-my-design-system": "7.8.0"
14
+ "roast-my-design-system": "8.4.5"
15
15
  },
16
16
  "keywords": [
17
17
  "design-system",
package/src/judge.mjs CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  isCodeFile, isStyleFile, typefaceOf, GENERIC_FONTS,
13
13
  definedComponents, exemptReason,
14
14
  EXTRA_KINDS, extraValue, fontDeclarations,
15
- WIDGET_CSS_RE, isLibraryClass, PALETTE_CLASS_RE,
15
+ WIDGET_CSS_RE, isLibraryClass, PALETTE_CLASS_RE, blankComments,
16
16
  } from 'roast-my-design-system/engine';
17
17
 
18
18
  // Folder membership, the way the engine's own splits do it.
@@ -106,6 +106,20 @@ export function judge(added, system, { readFile } = {}) {
106
106
  };
107
107
  const isWidgetFile = (file) => underAny(file, prof.widgetDirs) || WIDGET_CSS_RE.test(wholeText(file) ?? '');
108
108
  const paletteRe = new RegExp(PALETTE_CLASS_RE.source, 'g');
109
+ // The added line with its comments blanked, the way the report and the
110
+ // live checks read a file before matching (roast 8.4.4): a class named in
111
+ // a comment paints nothing. Blanked from the whole file when it is at hand,
112
+ // so a block comment opened on an earlier line still counts as a comment.
113
+ const blanked = new Map();
114
+ const codeText = (file, lineNo, text) => {
115
+ const w = wholeText(file);
116
+ if (w == null) return blankComments(text);
117
+ if (!blanked.has(file)) blanked.set(file, blankComments(w).split('\n'));
118
+ // blanking keeps every character's place, so the file's line is the
119
+ // diff's line only if the lengths match; otherwise the file has moved on
120
+ const l = blanked.get(file)[lineNo - 1];
121
+ return l != null && l.length === text.length ? l : blankComments(text);
122
+ };
109
123
 
110
124
  // The system was learned from the tree that already CONTAINS these added
111
125
  // lines, so a new value would vouch for itself. A value is only "known"
@@ -282,10 +296,10 @@ export function judge(added, system, { readFile } = {}) {
282
296
  // CSS-variable mode): paint from a tin. The same pattern the report
283
297
  // counts per 100 files; here, per added line.
284
298
  if (!css && prof.paletteReady) {
285
- for (const m of text.matchAll(paletteRe)) {
299
+ for (const m of codeText(file, line, text).matchAll(paletteRe)) {
286
300
  findings.push({
287
301
  file, line, kind: 'palette', value: m[0],
288
- advice: `a theme variable covers this; use a semantic class such as bg-primary or text-muted-foreground, or add a variable${prof.sheetFile ? ` to ${prof.sheetFile}` : ''}`,
302
+ advice: `a theme token covers this; use it as the class (bg-primary, text-muted-foreground), or add one${prof.sheetFile ? ` to ${prof.sheetFile}` : ' to the theme'} once`,
289
303
  });
290
304
  }
291
305
  }