@appdirect/ds-enforce 0.0.9 → 0.0.11
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "PageContentHeader",
|
|
3
3
|
"kind": "complex",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.0",
|
|
5
5
|
"purpose": "Required page header for prototype pages. AppDirect composition; Mantine has no page-content-header.",
|
|
6
6
|
"importFrom": [
|
|
7
7
|
"@appdirect/design-system"
|
|
@@ -51,17 +51,23 @@
|
|
|
51
51
|
},
|
|
52
52
|
"notes": "Actions use DS Button variants, not a Mantine variant map."
|
|
53
53
|
},
|
|
54
|
+
"panelNotification": {
|
|
55
|
+
"type": "boolean"
|
|
56
|
+
},
|
|
57
|
+
"panelNotificationMessage": {
|
|
58
|
+
"type": "ReactNode",
|
|
59
|
+
"notes": "Ignored when panelNotification is false. Orthogonal to contentSection - can be shown alongside any section, or none."
|
|
60
|
+
},
|
|
54
61
|
"contentSection": {
|
|
55
62
|
"enum": [
|
|
56
63
|
"insights",
|
|
57
64
|
"description",
|
|
58
|
-
"descriptionBlock",
|
|
59
65
|
"nameValuePairs",
|
|
60
66
|
"drawer"
|
|
61
67
|
],
|
|
62
|
-
"required":
|
|
68
|
+
"required": false,
|
|
63
69
|
"exclusive": true,
|
|
64
|
-
"notes": "Mutually exclusive content slots. Do not pass more than one section's data as if they compose."
|
|
70
|
+
"notes": "Mutually exclusive content slots. Do not pass more than one section's data as if they compose. Omit entirely for a header-only layout (Figma's 'default' variant)."
|
|
65
71
|
}
|
|
66
72
|
}
|
|
67
73
|
},
|
|
@@ -80,7 +86,6 @@
|
|
|
80
86
|
"ThemeIcon",
|
|
81
87
|
"KeyInsight",
|
|
82
88
|
"NameValue",
|
|
83
|
-
"DescriptionBlock",
|
|
84
89
|
"Inline",
|
|
85
90
|
"Stack"
|
|
86
91
|
],
|
|
@@ -355,7 +355,7 @@
|
|
|
355
355
|
"colorDeprecated": false
|
|
356
356
|
}
|
|
357
357
|
],
|
|
358
|
-
"mantineVersion": "9.
|
|
358
|
+
"mantineVersion": "9.7.2",
|
|
359
359
|
"mantineDisallowed": [
|
|
360
360
|
{
|
|
361
361
|
"name": "Accordion",
|
|
@@ -461,6 +461,18 @@
|
|
|
461
461
|
"name": "TableOfContents",
|
|
462
462
|
"replacement": null
|
|
463
463
|
},
|
|
464
|
+
{
|
|
465
|
+
"name": "Toggle",
|
|
466
|
+
"replacement": null
|
|
467
|
+
},
|
|
468
|
+
{
|
|
469
|
+
"name": "Toolbar",
|
|
470
|
+
"replacement": null
|
|
471
|
+
},
|
|
472
|
+
{
|
|
473
|
+
"name": "Tour",
|
|
474
|
+
"replacement": null
|
|
475
|
+
},
|
|
464
476
|
{
|
|
465
477
|
"name": "TreeSelect",
|
|
466
478
|
"replacement": "Select"
|
package/dist/eslint/index.cjs
CHANGED
|
@@ -28,6 +28,17 @@ const plugin = {
|
|
|
28
28
|
});
|
|
29
29
|
},
|
|
30
30
|
},
|
|
31
|
+
'uncontracted-props': {
|
|
32
|
+
meta: { type: 'problem', schema: [{ type: 'object' }] },
|
|
33
|
+
create(context) {
|
|
34
|
+
const contracts = loadContractsJson();
|
|
35
|
+
return contractProps.createContractPropsRule(
|
|
36
|
+
context,
|
|
37
|
+
{ contracts, adTokenNames: contracts.adTokenNames },
|
|
38
|
+
{ uncontracted: true }
|
|
39
|
+
);
|
|
40
|
+
},
|
|
41
|
+
},
|
|
31
42
|
'no-tailwind-classnames': noTailwind,
|
|
32
43
|
'no-theme-override': noThemeOverride,
|
|
33
44
|
'no-unadopted-mantine': noUnadoptedMantine,
|
|
@@ -42,6 +53,9 @@ function buildConfig(contracts, severity) {
|
|
|
42
53
|
plugins: { ds: plugin },
|
|
43
54
|
rules: {
|
|
44
55
|
'ds/contract-props': [severity, { contracts, adTokenNames: contracts.adTokenNames }],
|
|
56
|
+
// Styling escape hatches on components without a contract. A warning until
|
|
57
|
+
// existing screens (the micro-ui-ts Table) are migrated.
|
|
58
|
+
'ds/uncontracted-props': 'warn',
|
|
45
59
|
'ds/no-tailwind-classnames': severity,
|
|
46
60
|
'ds/no-theme-override': [
|
|
47
61
|
severity,
|
|
@@ -38,6 +38,13 @@ const DIMENSION_PROPS = new Set(['w', 'miw', 'maw', 'h', 'mih', 'mah']);
|
|
|
38
38
|
|
|
39
39
|
const IMPORT_SOURCES = new Set(['@mantine/core', '@mantine/dates']);
|
|
40
40
|
|
|
41
|
+
// Components without a contract still get the design-system theme, so styling
|
|
42
|
+
// escape hatches and palette props are banned on them too. `color` is left to
|
|
43
|
+
// each component because the kit's own semantic color names differ per wrapper.
|
|
44
|
+
const UNCONTRACTED_BANNED_PROPS = new Set(['style', 'styles', 'vars', 'classNames']);
|
|
45
|
+
const UNCONTRACTED_TOKEN_PROPS = new Set(['c', 'bg', 'bd']);
|
|
46
|
+
const NON_PALETTE_VALUES = new Set(['inherit', 'currentColor']);
|
|
47
|
+
|
|
41
48
|
function isStringLiteral(node) {
|
|
42
49
|
return node && node.type === 'Literal' && typeof node.value === 'string';
|
|
43
50
|
}
|
|
@@ -146,7 +153,7 @@ function isAdTokenValue(value, adTokens) {
|
|
|
146
153
|
return false;
|
|
147
154
|
}
|
|
148
155
|
|
|
149
|
-
function createContractPropsRule(context, contractData) {
|
|
156
|
+
function createContractPropsRule(context, contractData, { uncontracted = false } = {}) {
|
|
150
157
|
const contracts = contractData?.contracts ?? context.options[0]?.contracts ?? {};
|
|
151
158
|
const adTokens = new Set(
|
|
152
159
|
contractData?.adTokenNames ?? context.options[0]?.adTokenNames ?? []
|
|
@@ -252,9 +259,66 @@ function createContractPropsRule(context, contractData) {
|
|
|
252
259
|
}
|
|
253
260
|
}
|
|
254
261
|
|
|
262
|
+
function mantineImportName(nameNode) {
|
|
263
|
+
if (nameNode.type === 'JSXIdentifier') {
|
|
264
|
+
return localToContract.has(nameNode.name) ? localToContract.get(nameNode.name).imported : null;
|
|
265
|
+
}
|
|
266
|
+
if (nameNode.type === 'JSXMemberExpression' && nameNode.object.type === 'JSXIdentifier') {
|
|
267
|
+
const mapping = localToContract.get(nameNode.object.name);
|
|
268
|
+
return mapping ? `${mapping.imported}.${nameNode.property.name}` : null;
|
|
269
|
+
}
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const moduleConstants = new Map();
|
|
274
|
+
for (const statement of (context.sourceCode ?? context.getSourceCode()).ast.body) {
|
|
275
|
+
const declaration = statement.type === 'ExportNamedDeclaration' ? statement.declaration : statement;
|
|
276
|
+
if (declaration?.type !== 'VariableDeclaration' || declaration.kind !== 'const') continue;
|
|
277
|
+
for (const declarator of declaration.declarations) {
|
|
278
|
+
const init = unwrapExpression(declarator.init);
|
|
279
|
+
if (declarator.id.type === 'Identifier' && isStringLiteral(init)) {
|
|
280
|
+
moduleConstants.set(declarator.id.name, init.value);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function isTokenValue(attrValue) {
|
|
286
|
+
const value = attrValue?.type === 'JSXExpressionContainer' ? attrValue.expression : attrValue;
|
|
287
|
+
const literals = collectStringLiterals(value).map((lit) =>
|
|
288
|
+
typeof lit === 'object'
|
|
289
|
+
? resolveIdentifierValue(lit.identifier, scopeConstants) ?? moduleConstants.get(lit.identifier)
|
|
290
|
+
: lit
|
|
291
|
+
);
|
|
292
|
+
return (
|
|
293
|
+
literals.length > 0 &&
|
|
294
|
+
literals.every(
|
|
295
|
+
(lit) =>
|
|
296
|
+
typeof lit === 'string' &&
|
|
297
|
+
(NON_PALETTE_VALUES.has(lit) || (lit.startsWith('var(--ad-') && isAdTokenValue(lit, adTokens)))
|
|
298
|
+
)
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function checkUncontracted(node, name) {
|
|
303
|
+
for (const attr of node.attributes) {
|
|
304
|
+
if (attr.type !== 'JSXAttribute' || !attr.name) continue;
|
|
305
|
+
const attrName = attr.name.name;
|
|
306
|
+
if (UNCONTRACTED_BANNED_PROPS.has(attrName)) {
|
|
307
|
+
reportProp(attr, `Prop "${attrName}" is forbidden on ${name}. Use component props or a CSS module with --ad-* tokens.`);
|
|
308
|
+
} else if (UNCONTRACTED_TOKEN_PROPS.has(attrName) && !isTokenValue(attr.value)) {
|
|
309
|
+
reportProp(attr, `Prop "${attrName}" on ${name} must be a var(--ad-*) token. Use a CSS module with --ad-* tokens.`);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
255
314
|
return {
|
|
256
315
|
JSXOpeningElement(node) {
|
|
257
316
|
const contract = resolveJsxName(node.name, localToContract, contractsByImportName);
|
|
317
|
+
if (uncontracted) {
|
|
318
|
+
const name = contract ? null : mantineImportName(node.name);
|
|
319
|
+
if (name) checkUncontracted(node, name);
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
258
322
|
if (!contract || contract.kind === 'complex') return;
|
|
259
323
|
|
|
260
324
|
for (const attr of node.attributes) {
|