@ksmv/ui-checks 0.1.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.
@@ -0,0 +1,9 @@
1
+ import type { ExitCode, Suppression, Violation } from "./result.js";
2
+ export interface SuppressionValidation {
3
+ errors: string[];
4
+ exitCode: ExitCode;
5
+ issues: Violation[];
6
+ remaining: Violation[];
7
+ used: Suppression[];
8
+ }
9
+ export declare function validateSuppressions(value: unknown, violations: Violation[], now?: Date): SuppressionValidation;
@@ -0,0 +1,126 @@
1
+ import { fingerprintViolation, normalizeRelativePath } from "./baseline.js";
2
+ const sha256Pattern = /^[a-f0-9]{64}$/;
3
+ const datePattern = /^\d{4}-\d{2}-\d{2}$/;
4
+ const suppressionKeys = [
5
+ "expires",
6
+ "fingerprint",
7
+ "ownerRole",
8
+ "path",
9
+ "reason",
10
+ "rule",
11
+ ];
12
+ function isValidDate(value) {
13
+ if (!datePattern.test(value)) {
14
+ return false;
15
+ }
16
+ const parsed = new Date(`${value}T00:00:00.000Z`);
17
+ return !Number.isNaN(parsed.valueOf()) && parsed.toISOString().startsWith(value);
18
+ }
19
+ function isValidSuppression(value) {
20
+ if (!value || typeof value !== "object") {
21
+ return false;
22
+ }
23
+ const candidate = value;
24
+ const normalizedPath = typeof candidate.path === "string"
25
+ ? normalizeRelativePath(candidate.path)
26
+ : "";
27
+ return (Object.keys(candidate).sort().join(",") === suppressionKeys.join(",") &&
28
+ typeof candidate.expires === "string" &&
29
+ isValidDate(candidate.expires) &&
30
+ typeof candidate.fingerprint === "string" &&
31
+ sha256Pattern.test(candidate.fingerprint) &&
32
+ typeof candidate.ownerRole === "string" &&
33
+ candidate.ownerRole.trim().length > 0 &&
34
+ !candidate.ownerRole.includes("@") &&
35
+ !/[\r\n]/.test(candidate.ownerRole) &&
36
+ normalizedPath.trim().length > 0 &&
37
+ !normalizedPath.startsWith("/") &&
38
+ !/^[a-z]:\//i.test(normalizedPath) &&
39
+ !/[?*{}[\]]/.test(normalizedPath) &&
40
+ !normalizedPath.split("/").includes("..") &&
41
+ typeof candidate.reason === "string" &&
42
+ candidate.reason.trim().length > 0 &&
43
+ typeof candidate.rule === "string" &&
44
+ candidate.rule.trim().length > 0);
45
+ }
46
+ function issue(suppression, kind) {
47
+ return {
48
+ column: 1,
49
+ line: 1,
50
+ message: kind === "expired"
51
+ ? "A configured suppression has expired."
52
+ : "A configured suppression is unused.",
53
+ nodeKind: "suppression",
54
+ path: normalizeRelativePath(suppression.path),
55
+ rule: `suppressions/${kind}`,
56
+ };
57
+ }
58
+ export function validateSuppressions(value, violations, now = new Date()) {
59
+ if (!Array.isArray(value)) {
60
+ return {
61
+ errors: ["Suppressions must be an array."],
62
+ exitCode: 2,
63
+ issues: [],
64
+ remaining: violations,
65
+ used: [],
66
+ };
67
+ }
68
+ const suppressions = [];
69
+ const fingerprints = new Set();
70
+ for (const candidate of value) {
71
+ if (!isValidSuppression(candidate)) {
72
+ return {
73
+ errors: ["A suppression is malformed or repository-wide."],
74
+ exitCode: 2,
75
+ issues: [],
76
+ remaining: violations,
77
+ used: [],
78
+ };
79
+ }
80
+ if (fingerprints.has(candidate.fingerprint)) {
81
+ return {
82
+ errors: ["Suppression fingerprints must be unique."],
83
+ exitCode: 2,
84
+ issues: [],
85
+ remaining: violations,
86
+ used: [],
87
+ };
88
+ }
89
+ fingerprints.add(candidate.fingerprint);
90
+ suppressions.push({
91
+ expires: candidate.expires,
92
+ fingerprint: candidate.fingerprint,
93
+ ownerRole: candidate.ownerRole,
94
+ path: normalizeRelativePath(candidate.path),
95
+ reason: candidate.reason,
96
+ rule: candidate.rule,
97
+ });
98
+ }
99
+ const currentDate = now.toISOString().slice(0, 10);
100
+ const suppressedFingerprints = new Set();
101
+ const issues = [];
102
+ const used = [];
103
+ for (const suppression of suppressions) {
104
+ if (suppression.expires < currentDate) {
105
+ issues.push(issue(suppression, "expired"));
106
+ continue;
107
+ }
108
+ const matched = violations.some((violation) => fingerprintViolation(violation) === suppression.fingerprint &&
109
+ violation.rule === suppression.rule &&
110
+ normalizeRelativePath(violation.path) === suppression.path);
111
+ if (!matched) {
112
+ issues.push(issue(suppression, "unused"));
113
+ continue;
114
+ }
115
+ suppressedFingerprints.add(suppression.fingerprint);
116
+ used.push(suppression);
117
+ }
118
+ const remaining = violations.filter((violation) => !suppressedFingerprints.has(fingerprintViolation(violation)));
119
+ return {
120
+ errors: [],
121
+ exitCode: issues.length > 0 ? 1 : 0,
122
+ issues,
123
+ remaining,
124
+ used,
125
+ };
126
+ }
@@ -0,0 +1,82 @@
1
+ {
2
+ "contractVersion": "1.0.0",
3
+ "schemaVersion": 1,
4
+ "prefix": "--ui-",
5
+ "required": [
6
+ "--ui-surface-page",
7
+ "--ui-surface",
8
+ "--ui-surface-subtle",
9
+ "--ui-surface-raised",
10
+ "--ui-surface-inverse",
11
+ "--ui-text-primary",
12
+ "--ui-text-secondary",
13
+ "--ui-text-muted",
14
+ "--ui-text-inverse",
15
+ "--ui-text-disabled",
16
+ "--ui-text-placeholder",
17
+ "--ui-border",
18
+ "--ui-border-strong",
19
+ "--ui-border-control",
20
+ "--ui-border-disabled",
21
+ "--ui-focus-ring",
22
+ "--ui-focus-ring-offset",
23
+ "--ui-overlay",
24
+ "--ui-action-primary-bg",
25
+ "--ui-action-primary-bg-hover",
26
+ "--ui-action-primary-bg-active",
27
+ "--ui-action-primary-text",
28
+ "--ui-action-secondary-bg",
29
+ "--ui-action-secondary-bg-hover",
30
+ "--ui-action-secondary-bg-active",
31
+ "--ui-action-secondary-text",
32
+ "--ui-action-danger-bg",
33
+ "--ui-action-danger-bg-hover",
34
+ "--ui-action-danger-bg-active",
35
+ "--ui-action-danger-text",
36
+ "--ui-action-ghost-text",
37
+ "--ui-action-ghost-bg-hover",
38
+ "--ui-action-ghost-bg-active",
39
+ "--ui-status-success",
40
+ "--ui-status-success-bg",
41
+ "--ui-status-success-text",
42
+ "--ui-status-warning",
43
+ "--ui-status-warning-bg",
44
+ "--ui-status-warning-text",
45
+ "--ui-status-danger",
46
+ "--ui-status-danger-bg",
47
+ "--ui-status-danger-text",
48
+ "--ui-status-info",
49
+ "--ui-status-info-bg",
50
+ "--ui-status-info-text",
51
+ "--ui-disabled-bg",
52
+ "--ui-disabled-text",
53
+ "--ui-disabled-border",
54
+ "--ui-font-body",
55
+ "--ui-font-emphasis",
56
+ "--ui-font-mono",
57
+ "--ui-dialog-title-font",
58
+ "--ui-dialog-title-weight",
59
+ "--ui-radius-sm",
60
+ "--ui-radius-md",
61
+ "--ui-radius-lg",
62
+ "--ui-radius-pill",
63
+ "--ui-shadow-sm",
64
+ "--ui-shadow-md",
65
+ "--ui-shadow-lg"
66
+ ],
67
+ "derived": {
68
+ "--ui-action-primary-border": "--ui-action-primary-bg",
69
+ "--ui-action-secondary-border": "--ui-border-control",
70
+ "--ui-action-danger-border": "--ui-action-danger-bg",
71
+ "--ui-status-success-border": "--ui-status-success",
72
+ "--ui-status-warning-border": "--ui-status-warning",
73
+ "--ui-status-danger-border": "--ui-status-danger",
74
+ "--ui-status-info-border": "--ui-status-info"
75
+ },
76
+ "brandComposition": [
77
+ "--ui-brand-primary",
78
+ "--ui-brand-on-primary",
79
+ "--ui-brand-secondary",
80
+ "--ui-brand-on-secondary"
81
+ ]
82
+ }
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@ksmv/ui-checks",
3
+ "version": "0.1.0",
4
+ "description": "Static and computed quality checks for semantic UI token contracts.",
5
+ "keywords": ["accessibility", "design-tokens", "quality", "static-analysis"],
6
+ "license": "Apache-2.0",
7
+ "type": "module",
8
+ "bin": { "ksmv-ui-checks": "./dist/cli.js" },
9
+ "exports": {
10
+ ".": { "types": "./dist/index.d.ts", "default": "./dist/index.js" },
11
+ "./config": { "types": "./dist/config.d.ts", "default": "./dist/config.js" },
12
+ "./theme-contract.json": "./dist/theme-contract.json",
13
+ "./contrast-contract.json": "./dist/contrast-contract.json"
14
+ },
15
+ "files": ["CHANGELOG.md", "dist/**/*.d.ts", "dist/**/*.js", "dist/*.json"],
16
+ "scripts": {
17
+ "build": "node scripts/clean-dist.mjs && tsc -p tsconfig.json && node scripts/copy-contracts.mjs",
18
+ "test": "vitest run",
19
+ "typecheck": "tsc -p tsconfig.json --noEmit"
20
+ },
21
+ "dependencies": {
22
+ "culori": "4.0.2",
23
+ "postcss": "8.5.28",
24
+ "postcss-value-parser": "4.2.0",
25
+ "typescript": "7.0.2"
26
+ },
27
+ "devDependencies": { "@types/node": "26.6.2", "vitest": "5.0.1" },
28
+ "engines": { "node": ">=22.14" },
29
+ "repository": { "type": "git", "url": "https://github.com/AxisGov/ui.git", "directory": "packages/checks" },
30
+ "homepage": "https://github.com/AxisGov/ui#readme",
31
+ "bugs": { "url": "https://github.com/AxisGov/ui/issues" },
32
+ "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org/" }
33
+ }