kira-kit 0.3.0 → 0.4.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/dist/index.mjs +106 -34
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -17,7 +17,7 @@ import { detect } from "package-manager-detector";
17
17
  import { readFile, readdir, stat, writeFile } from "node:fs/promises";
18
18
  // src/version.ts
19
19
  function getVersion() {
20
- return "0.3.0";
20
+ return "0.4.0";
21
21
  }
22
22
  /**
23
23
  * Error carrying the kira-kit exit-code contract:
@@ -753,13 +753,13 @@ const TEXT_PAIRS = [
753
753
  ["sidebar-primary-foreground", "sidebar-primary"],
754
754
  ["sidebar-accent-foreground", "sidebar-accent"]
755
755
  ];
756
- /** UI-boundary pairs: WCAG 2.2 requires >= 3:1. Blocking. */
757
- const UI_PAIRS = [
758
- ["ring", "background"],
759
- ["border", "background"],
760
- ["sidebar-ring", "sidebar"],
761
- ["sidebar-border", "sidebar"]
762
- ];
756
+ /**
757
+ * UI-boundary pairs: WCAG 2.2 requires >= 3:1. Blocking.
758
+ * Only focus rings are checked here. Decorative borders (border, sidebar-border)
759
+ * are exempt from WCAG 1.4.11 — they aren't functional UI boundaries — so forcing
760
+ * them to 3:1 would crush the intentionally subtle hairlines the palette designs.
761
+ */
762
+ const UI_PAIRS = [["ring", "background"], ["sidebar-ring", "sidebar"]];
763
763
  function verifyScheme(scheme, tokens) {
764
764
  const failures = [];
765
765
  for (const [fg, bg] of TEXT_PAIRS) {
@@ -1104,27 +1104,31 @@ async function searchItems(options) {
1104
1104
  }
1105
1105
  // src/core/checks/suppressions.ts
1106
1106
  const LINE_SUPPRESSION = /\/\/\s*kira-kit-ignore\s+([a-z0-9-]+)\s*:\s*(.+)$/i;
1107
+ const JSX_LINE_SUPPRESSION = /^\{\s*\/\*\s*kira-kit-ignore\s+([a-z0-9-]+)\s*:\s*(.+?)\s*\*\/\s*\}$/i;
1107
1108
  const FILE_SUPPRESSION = /\/\*\s*kira-kit-ignore-file\s+([a-z0-9-]+)\s*:\s*([^*]+)\*\//i;
1108
1109
  /** Suppression comment without a reason is itself an error. */
1109
1110
  const LINE_SUPPRESSION_NO_REASON = /\/\/\s*kira-kit-ignore\s+([a-z0-9-]+)\s*$/i;
1111
+ const JSX_LINE_SUPPRESSION_NO_REASON = /^\{\s*\/\*\s*kira-kit-ignore\s+([a-z0-9-]+)\s*\*\/\s*\}$/i;
1110
1112
  const FILE_SUPPRESSION_NO_REASON = /\/\*\s*kira-kit-ignore-file\s+([a-z0-9-]+)\s*\*\//i;
1111
- function parseSuppressions(source, file) {
1112
- const suppressions = {
1113
- line: [],
1114
- file: []
1115
- };
1113
+ function isSuppressionLine(text) {
1114
+ const trimmed = text.trim();
1115
+ return LINE_SUPPRESSION.test(trimmed) || JSX_LINE_SUPPRESSION.test(trimmed) || LINE_SUPPRESSION_NO_REASON.test(trimmed) || JSX_LINE_SUPPRESSION_NO_REASON.test(trimmed);
1116
+ }
1117
+ function collectLineSuppressions(lines, file) {
1118
+ const raw = [];
1116
1119
  const errors = [];
1117
- source.split("\n").forEach((text, index) => {
1118
- const match = LINE_SUPPRESSION.exec(text.trim());
1120
+ lines.forEach((text, index) => {
1121
+ const trimmed = text.trim();
1122
+ const match = LINE_SUPPRESSION.exec(trimmed) ?? JSX_LINE_SUPPRESSION.exec(trimmed);
1119
1123
  if (match) {
1120
- suppressions.line.push({
1124
+ raw.push({
1121
1125
  checkId: match[1],
1122
1126
  line: index + 1,
1123
1127
  reason: match[2].trim()
1124
1128
  });
1125
1129
  return;
1126
1130
  }
1127
- if (LINE_SUPPRESSION_NO_REASON.exec(text.trim())) errors.push({
1131
+ if (LINE_SUPPRESSION_NO_REASON.test(trimmed) || JSX_LINE_SUPPRESSION_NO_REASON.test(trimmed)) errors.push({
1128
1132
  checkId: "suppression",
1129
1133
  severity: "error",
1130
1134
  file,
@@ -1132,27 +1136,66 @@ function parseSuppressions(source, file) {
1132
1136
  message: "kira-kit-ignore without a reason — add `: <why this is intentional>`."
1133
1137
  });
1134
1138
  });
1135
- const fileMatch = FILE_SUPPRESSION.exec(source);
1136
- if (fileMatch) suppressions.file.push({
1137
- checkId: fileMatch[1],
1138
- line: 0,
1139
- reason: fileMatch[2].trim()
1139
+ return {
1140
+ raw,
1141
+ errors
1142
+ };
1143
+ }
1144
+ /** A comment above a JSX opening tag covers the whole tag (≤40 lines). */
1145
+ function openingTagEnd(lines, target) {
1146
+ const targetText = (lines[target - 1] ?? "").trim();
1147
+ if (!/^<[A-Za-z]/.test(targetText) || /\/?>$/.test(targetText)) return target;
1148
+ for (let i = target; i < Math.min(target + 40, lines.length); i++) if (/\/?>$/.test(lines[i].trim())) return i + 1;
1149
+ return target;
1150
+ }
1151
+ function resolveRanges(raw, lines) {
1152
+ return raw.map((entry) => {
1153
+ let target = entry.line + 1;
1154
+ while (target <= lines.length && isSuppressionLine(lines[target - 1])) target++;
1155
+ return {
1156
+ ...entry,
1157
+ target,
1158
+ end: openingTagEnd(lines, target)
1159
+ };
1140
1160
  });
1141
- else if (FILE_SUPPRESSION_NO_REASON.exec(source)) errors.push({
1161
+ }
1162
+ function collectFileSuppressions(source, file) {
1163
+ const matches = [...source.matchAll(new RegExp(FILE_SUPPRESSION, "gi"))];
1164
+ const suppressions = matches.map((m) => ({
1165
+ checkId: m[1],
1166
+ line: 0,
1167
+ target: 0,
1168
+ end: Number.MAX_SAFE_INTEGER,
1169
+ reason: m[2].trim()
1170
+ }));
1171
+ const errors = [];
1172
+ if (matches.length === 0 && FILE_SUPPRESSION_NO_REASON.test(source)) errors.push({
1142
1173
  checkId: "suppression",
1143
1174
  severity: "error",
1144
1175
  file,
1145
1176
  message: "kira-kit-ignore-file without a reason — add `: <why this is intentional>`."
1146
1177
  });
1147
1178
  return {
1148
- errors,
1149
- suppressions
1179
+ suppressions,
1180
+ errors
1181
+ };
1182
+ }
1183
+ function parseSuppressions(source, file) {
1184
+ const lines = source.split("\n");
1185
+ const lineResult = collectLineSuppressions(lines, file);
1186
+ const fileResult = collectFileSuppressions(source, file);
1187
+ return {
1188
+ errors: [...lineResult.errors, ...fileResult.errors],
1189
+ suppressions: {
1190
+ line: resolveRanges(lineResult.raw, lines),
1191
+ file: fileResult.suppressions
1192
+ }
1150
1193
  };
1151
1194
  }
1152
1195
  function isSuppressed(finding, suppressions) {
1153
1196
  if (suppressions.file.some((s) => s.checkId === finding.checkId)) return true;
1154
1197
  if (finding.line === void 0) return false;
1155
- return suppressions.line.some((s) => s.checkId === finding.checkId && s.line + 1 === finding.line);
1198
+ return suppressions.line.some((s) => s.checkId === finding.checkId && finding.line >= s.target && finding.line <= s.end);
1156
1199
  }
1157
1200
  function unusedSuppressions(findings, suppressions, file) {
1158
1201
  const used = /* @__PURE__ */ new Set();
@@ -1162,7 +1205,7 @@ function unusedSuppressions(findings, suppressions, file) {
1162
1205
  }
1163
1206
  for (const suppression of suppressions.line) {
1164
1207
  const key = `line:${suppression.line}:${suppression.checkId}`;
1165
- if (findings.some((f) => f.checkId === suppression.checkId && f.line === suppression.line + 1)) used.add(key);
1208
+ if (findings.some((f) => f.checkId === suppression.checkId && f.line !== void 0 && f.line >= suppression.target && f.line <= suppression.end)) used.add(key);
1166
1209
  }
1167
1210
  const unused = [];
1168
1211
  for (const suppression of suppressions.file) if (!used.has(`file:${suppression.checkId}`)) unused.push({
@@ -1489,16 +1532,18 @@ const layoutTransitions = (file) => {
1489
1532
  };
1490
1533
  // src/core/checks/arbitrary-values.ts
1491
1534
  /**
1492
- * Check 9: one-off arbitrary z-/shadow-/rounded- values outside token scales.
1493
- * `inherit` and values derived from design tokens (`var(--…)`) stay inside
1494
- * the token system and are not findings.
1535
+ * Check 9: one-off arbitrary values outside token scales. Covers z/shadow/
1536
+ * rounded plus spacing, sizing, and font utilities. Values that stay relative
1537
+ * to a token or the environment are not findings: `inherit`, `var(--…)`,
1538
+ * `clamp(…)`, `env(…)`, percentages, and viewport/character/em units.
1495
1539
  */
1496
- const ARBITRARY = /\b(z|shadow|rounded)-\[([^\]]*)\]/g;
1540
+ const ARBITRARY = /\b(z|shadow|rounded|min-h|min-w|max-h|max-w|gap-x|gap-y|space-x|space-y|size|text|inset|top|right|bottom|left|gap|px|py|pt|pr|pb|pl|ps|pe|mx|my|mt|mr|mb|ml|ms|me|h|w|p|m)-\[([^\]]*)\]/g;
1541
+ const RELATIVE_UNIT = /\d(?:vh|vw|dvh|dvw|svh|svw|lvh|lvw|vmin|vmax|ch|em)\b/;
1497
1542
  const arbitraryValues = (file) => {
1498
1543
  const findings = [];
1499
1544
  for (const match of file.content.matchAll(ARBITRARY)) {
1500
1545
  const value = match[2];
1501
- if (value === "inherit" || value.includes("var(--")) continue;
1546
+ if (value === "inherit" || value.includes("var(--") || value.includes("clamp(") || value.includes("env(") || value.includes("%") || RELATIVE_UNIT.test(value)) continue;
1502
1547
  const line = file.content.slice(0, match.index).split("\n").length;
1503
1548
  findings.push({
1504
1549
  checkId: "arbitrary-values",
@@ -1510,6 +1555,27 @@ const arbitraryValues = (file) => {
1510
1555
  }
1511
1556
  return findings;
1512
1557
  };
1558
+ // src/core/checks/spacing-scale.ts
1559
+ /**
1560
+ * Half-step spacing (1.5 / 2.5 / …) on heights, widths, gaps, and horizontal
1561
+ * padding breaks the 4px design-system scale. Vertical text padding (`py-*`)
1562
+ * is the documented optical exception and is not flagged.
1563
+ */
1564
+ const HALF_STEP = /\b(h|w|size|min-h|min-w|gap-x|gap-y|gap|px|pl|pr|ps|pe)-(\d+\.5)(?![\d.])/g;
1565
+ const spacingScale = (file) => {
1566
+ const findings = [];
1567
+ for (const match of file.content.matchAll(HALF_STEP)) {
1568
+ const line = file.content.slice(0, match.index).split("\n").length;
1569
+ findings.push({
1570
+ checkId: "spacing-scale",
1571
+ severity: "warning",
1572
+ file: file.name,
1573
+ line,
1574
+ message: `${match[1]}-${match[2]} is a half-step; use the 4px scale (1, 2, 3, 4, 5, 6, 8, 10, 12, 16) or document the optical exception.`
1575
+ });
1576
+ }
1577
+ return findings;
1578
+ };
1513
1579
  // src/core/checks/registry-metadata.ts
1514
1580
  const BOILERPLATE_PATTERNS = [
1515
1581
  /^component from kira kit/i,
@@ -1598,6 +1664,7 @@ const CHECKS = [
1598
1664
  rawColors,
1599
1665
  layoutTransitions,
1600
1666
  arbitraryValues,
1667
+ spacingScale,
1601
1668
  registryMetadata,
1602
1669
  baseUiOnly,
1603
1670
  cnSource
@@ -1608,11 +1675,16 @@ const SKIP_FILES = /* @__PURE__ */ new Set([
1608
1675
  "index",
1609
1676
  "prop-guards"
1610
1677
  ]);
1678
+ function prefixForPath(abs) {
1679
+ if (abs.includes(join("src", "components", "ui"))) return "ui/";
1680
+ if (abs.includes(join("src", "pages"))) return "pages/";
1681
+ return "hooks/";
1682
+ }
1611
1683
  function sourceDirs(repoRoot, paths) {
1612
1684
  if (paths.length === 0) return [[join(repoRoot, "src/components/ui"), "ui/"], [join(repoRoot, "src/hooks"), "hooks/"]];
1613
1685
  return paths.map((path) => {
1614
1686
  const abs = join(repoRoot, path);
1615
- return [abs, abs.includes(join("src", "components", "ui")) ? "ui/" : "hooks/"];
1687
+ return [abs, prefixForPath(abs)];
1616
1688
  });
1617
1689
  }
1618
1690
  function collectSourceFiles$1(repoRoot, paths) {
@@ -1704,7 +1776,7 @@ function loadItemMeta(repoRoot) {
1704
1776
  function githubAnnotation(f) {
1705
1777
  const level = f.severity === "error" ? "error" : "warning";
1706
1778
  const lineProp = f.line ? `,line=${f.line}` : "";
1707
- return `::${level} ${[`file=${f.file.replace(/^ui\//, "src/components/ui/").replace(/^hooks\//, "src/hooks/")}${lineProp}`, `title=${f.checkId}`].join(",")}::${f.message}`;
1779
+ return `::${level} ${[`file=${f.file.replace(/^ui\//, "src/components/ui/").replace(/^hooks\//, "src/hooks/").replace(/^pages\//, "src/pages/components/")}${lineProp}`, `title=${f.checkId}`].join(",")}::${f.message}`;
1708
1780
  }
1709
1781
  function formatFindings(result, format) {
1710
1782
  if (format === "json") return JSON.stringify(result, null, 2);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kira-kit",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },