@appdirect/ds-enforce 0.0.0-stage → 0.0.1
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.
- package/README.md +19 -2
- package/dist/contracts/Alert.json +79 -0
- package/dist/contracts/Badge.json +77 -0
- package/dist/contracts/Box.json +51 -0
- package/dist/contracts/Button.json +110 -0
- package/dist/contracts/DataTable.json +67 -0
- package/dist/contracts/Grid.json +34 -0
- package/dist/contracts/Group.json +43 -0
- package/dist/contracts/Inline.json +72 -0
- package/dist/contracts/PageContentHeader.json +106 -0
- package/dist/contracts/Stack.json +61 -0
- package/dist/contracts/index.json +54 -0
- package/dist/eslint/contracts.json +843 -0
- package/dist/eslint/index.cjs +70 -0
- package/dist/eslint/rules/contract-props.cjs +276 -0
- package/dist/eslint/rules/no-tailwind-classnames.cjs +76 -0
- package/dist/eslint/rules/no-theme-override.cjs +55 -0
- package/dist/eslint/rules/no-unadopted-mantine.cjs +79 -0
- package/dist/mantine-theme-defaults.json +30 -0
- package/dist/mantine.d.ts +10 -0
- package/dist/stylelint/index.cjs +16 -0
- package/package.json +36 -4
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const contractProps = require('./rules/contract-props.cjs');
|
|
4
|
+
const noTailwind = require('./rules/no-tailwind-classnames.cjs');
|
|
5
|
+
const noThemeOverride = require('./rules/no-theme-override.cjs');
|
|
6
|
+
const noUnadoptedMantine = require('./rules/no-unadopted-mantine.cjs');
|
|
7
|
+
const path = require('node:path');
|
|
8
|
+
const fs = require('node:fs');
|
|
9
|
+
|
|
10
|
+
function loadContractsJson() {
|
|
11
|
+
const contractsPath = path.join(__dirname, 'contracts.json');
|
|
12
|
+
return JSON.parse(fs.readFileSync(contractsPath, 'utf8'));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const plugin = {
|
|
16
|
+
meta: {
|
|
17
|
+
name: '@appdirect/design-tokens-eslint',
|
|
18
|
+
version: '1.0.0',
|
|
19
|
+
},
|
|
20
|
+
rules: {
|
|
21
|
+
'contract-props': {
|
|
22
|
+
meta: { type: 'problem', schema: [{ type: 'object' }] },
|
|
23
|
+
create(context) {
|
|
24
|
+
const contracts = loadContractsJson();
|
|
25
|
+
return contractProps.createContractPropsRule(context, {
|
|
26
|
+
contracts,
|
|
27
|
+
adTokenNames: contracts.adTokenNames,
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
'no-tailwind-classnames': noTailwind,
|
|
32
|
+
'no-theme-override': noThemeOverride,
|
|
33
|
+
'no-unadopted-mantine': noUnadoptedMantine,
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
function buildConfig(contracts, severity) {
|
|
38
|
+
const mantineThemeNames = [
|
|
39
|
+
...new Set((contracts.components ?? []).map((entry) => entry.mantineName).filter(Boolean)),
|
|
40
|
+
];
|
|
41
|
+
return {
|
|
42
|
+
plugins: { ds: plugin },
|
|
43
|
+
rules: {
|
|
44
|
+
'ds/contract-props': [severity, { contracts, adTokenNames: contracts.adTokenNames }],
|
|
45
|
+
'ds/no-tailwind-classnames': severity,
|
|
46
|
+
'ds/no-theme-override': [
|
|
47
|
+
severity,
|
|
48
|
+
{
|
|
49
|
+
providerGlobs: ['**/src/providers/**', '**/__setup__/**'],
|
|
50
|
+
mantineNames: mantineThemeNames,
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
// Components the kit has not adopted yet are a warning, not a hard ban.
|
|
54
|
+
'ds/no-unadopted-mantine': ['warn', { disallowed: contracts.mantineDisallowed }],
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let cachedContracts;
|
|
60
|
+
function getContracts() {
|
|
61
|
+
if (!cachedContracts) cachedContracts = loadContractsJson();
|
|
62
|
+
return cachedContracts;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
plugin.configs = {
|
|
66
|
+
strict: [buildConfig(getContracts(), 'error')],
|
|
67
|
+
recommended: [buildConfig(getContracts(), 'warn')],
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
module.exports = plugin;
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
const fs = require('node:fs');
|
|
5
|
+
|
|
6
|
+
const BANNED_STYLE_PROPS = new Set([
|
|
7
|
+
'style',
|
|
8
|
+
'styles',
|
|
9
|
+
'vars',
|
|
10
|
+
'classNames',
|
|
11
|
+
'c',
|
|
12
|
+
'bg',
|
|
13
|
+
'bd',
|
|
14
|
+
'color',
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
const SPACING_PROPS = new Set([
|
|
18
|
+
'p',
|
|
19
|
+
'pt',
|
|
20
|
+
'pb',
|
|
21
|
+
'pl',
|
|
22
|
+
'pr',
|
|
23
|
+
'px',
|
|
24
|
+
'py',
|
|
25
|
+
'm',
|
|
26
|
+
'mt',
|
|
27
|
+
'mb',
|
|
28
|
+
'ml',
|
|
29
|
+
'mr',
|
|
30
|
+
'mx',
|
|
31
|
+
'my',
|
|
32
|
+
'gap',
|
|
33
|
+
'rowGap',
|
|
34
|
+
'columnGap',
|
|
35
|
+
]);
|
|
36
|
+
|
|
37
|
+
const DIMENSION_PROPS = new Set(['w', 'miw', 'maw', 'h', 'mih', 'mah']);
|
|
38
|
+
|
|
39
|
+
const IMPORT_SOURCES = new Set(['@mantine/core', '@mantine/dates']);
|
|
40
|
+
|
|
41
|
+
function isStringLiteral(node) {
|
|
42
|
+
return node && node.type === 'Literal' && typeof node.value === 'string';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function unwrapExpression(node) {
|
|
46
|
+
let current = node;
|
|
47
|
+
while (current && (current.type === 'TSAsExpression' || current.type === 'TSSatisfiesExpression')) {
|
|
48
|
+
current = current.expression;
|
|
49
|
+
}
|
|
50
|
+
return current;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function collectStringLiterals(node, out = []) {
|
|
54
|
+
if (!node) return out;
|
|
55
|
+
const unwrapped = unwrapExpression(node);
|
|
56
|
+
if (isStringLiteral(unwrapped)) {
|
|
57
|
+
out.push(unwrapped.value);
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
if (unwrapped.type === 'ConditionalExpression') {
|
|
61
|
+
collectStringLiterals(unwrapped.consequent, out);
|
|
62
|
+
collectStringLiterals(unwrapped.alternate, out);
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
if (unwrapped.type === 'LogicalExpression' && unwrapped.operator === '&&') {
|
|
66
|
+
collectStringLiterals(unwrapped.right, out);
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
if (unwrapped.type === 'Identifier') {
|
|
70
|
+
out.push({ identifier: unwrapped.name });
|
|
71
|
+
}
|
|
72
|
+
return out;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function resolveIdentifierValue(name, scopeConstants) {
|
|
76
|
+
return scopeConstants.get(name);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function buildImportMap(context) {
|
|
80
|
+
const sourceCode = context.sourceCode ?? context.getSourceCode();
|
|
81
|
+
const scopeConstants = new Map();
|
|
82
|
+
const localToContract = new Map();
|
|
83
|
+
|
|
84
|
+
for (const node of sourceCode.ast.body) {
|
|
85
|
+
if (node.type !== 'ImportDeclaration') continue;
|
|
86
|
+
if (!IMPORT_SOURCES.has(node.source.value)) continue;
|
|
87
|
+
|
|
88
|
+
for (const spec of node.specifiers) {
|
|
89
|
+
if (spec.type === 'ImportSpecifier') {
|
|
90
|
+
const imported = spec.imported.name;
|
|
91
|
+
const local = spec.local.name;
|
|
92
|
+
localToContract.set(local, { imported, source: node.source.value });
|
|
93
|
+
} else if (spec.type === 'ImportDefaultSpecifier') {
|
|
94
|
+
localToContract.set(spec.local.name, { imported: 'default', source: node.source.value });
|
|
95
|
+
} else if (spec.type === 'ImportNamespaceSpecifier') {
|
|
96
|
+
localToContract.set(spec.local.name, { imported: '*', source: node.source.value });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const scope = sourceCode.scope ?? null;
|
|
102
|
+
if (scope) {
|
|
103
|
+
for (const variable of scope.variables ?? []) {
|
|
104
|
+
if (variable.defs?.[0]?.type === 'Variable' && variable.defs[0].node.init) {
|
|
105
|
+
const init = variable.defs[0].node.init;
|
|
106
|
+
const unwrapped = unwrapExpression(init);
|
|
107
|
+
if (isStringLiteral(unwrapped)) {
|
|
108
|
+
scopeConstants.set(variable.name, unwrapped.value);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return { localToContract, scopeConstants };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function resolveJsxName(node, localToContract, contractsByImportName) {
|
|
118
|
+
if (node.type === 'JSXIdentifier') {
|
|
119
|
+
const mapping = localToContract.get(node.name);
|
|
120
|
+
const importName = mapping?.imported === '*' ? node.name : mapping?.imported ?? node.name;
|
|
121
|
+
return contractsByImportName.get(importName) ?? contractsByImportName.get(node.name) ?? null;
|
|
122
|
+
}
|
|
123
|
+
if (node.type === 'JSXMemberExpression') {
|
|
124
|
+
const objectName = node.object.name;
|
|
125
|
+
const prop = node.property.name;
|
|
126
|
+
const mapping = localToContract.get(objectName);
|
|
127
|
+
const base = mapping?.imported ?? objectName;
|
|
128
|
+
if (prop === 'Section' && base === 'Card') {
|
|
129
|
+
return contractsByImportName.get('Card') ?? null;
|
|
130
|
+
}
|
|
131
|
+
return contractsByImportName.get(`${base}.${prop}`) ?? contractsByImportName.get(base) ?? null;
|
|
132
|
+
}
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function isAdTokenValue(value, adTokens) {
|
|
137
|
+
if (typeof value !== 'string') return false;
|
|
138
|
+
if (['xxs', 'xs', 'sm', 'md', 'lg', 'xl', 'xxl', 'none', 'xshalf', 'xstwothirds'].includes(value)) return true;
|
|
139
|
+
if (/^calc\(var\(--col-/.test(value) || /^max\(calc\(var\(--col-/.test(value)) return true;
|
|
140
|
+
if (/^var\(--col-/.test(value)) return true;
|
|
141
|
+
if (/^var\(--col-.*\)\s+0\s+auto$/.test(value)) return true;
|
|
142
|
+
if (value.startsWith('var(--ad-')) {
|
|
143
|
+
const tokenName = value.slice(4, -1);
|
|
144
|
+
return adTokens.has(tokenName);
|
|
145
|
+
}
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function createContractPropsRule(context, contractData) {
|
|
150
|
+
const contracts = contractData?.contracts ?? context.options[0]?.contracts ?? {};
|
|
151
|
+
const adTokens = new Set(
|
|
152
|
+
contractData?.adTokenNames ?? context.options[0]?.adTokenNames ?? []
|
|
153
|
+
);
|
|
154
|
+
const contractsByImportName = new Map();
|
|
155
|
+
for (const entry of contracts.components ?? []) {
|
|
156
|
+
for (const name of entry.importNames ?? [entry.id]) {
|
|
157
|
+
contractsByImportName.set(name, entry);
|
|
158
|
+
}
|
|
159
|
+
contractsByImportName.set(entry.mantineName, entry);
|
|
160
|
+
contractsByImportName.set(entry.id, entry);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const { localToContract, scopeConstants } = buildImportMap(context);
|
|
164
|
+
|
|
165
|
+
function reportProp(node, message) {
|
|
166
|
+
context.report({ node, message });
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function checkPropValue(attrName, attrValue, contract, node) {
|
|
170
|
+
if (attrValue?.type === 'JSXExpressionContainer') {
|
|
171
|
+
checkPropValue(attrName, attrValue.expression, contract, node);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (BANNED_STYLE_PROPS.has(attrName)) {
|
|
176
|
+
if (
|
|
177
|
+
attrName === 'color' &&
|
|
178
|
+
contract.colorEnum?.length &&
|
|
179
|
+
!contract.colorDeprecated
|
|
180
|
+
) {
|
|
181
|
+
checkEnum(attrName, attrValue, contract.colorEnum, contract, node);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
if (attrName === 'color') {
|
|
185
|
+
reportProp(node, `Prop "color" is forbidden on ${contract.id}. Use CSS modules with --ad-* tokens.`);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
reportProp(node, `Prop "${attrName}" is forbidden on ${contract.id}. Use CSS modules with --ad-* tokens.`);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (SPACING_PROPS.has(attrName) || DIMENSION_PROPS.has(attrName)) {
|
|
193
|
+
const literals = collectStringLiterals(attrValue);
|
|
194
|
+
for (const lit of literals) {
|
|
195
|
+
if (typeof lit === 'object' && lit.identifier) {
|
|
196
|
+
const resolved = resolveIdentifierValue(lit.identifier, scopeConstants);
|
|
197
|
+
if (resolved && !isAdTokenValue(resolved, adTokens)) {
|
|
198
|
+
reportProp(
|
|
199
|
+
node,
|
|
200
|
+
`Prop "${attrName}" must use an --ad-* spacing token or scale name; got identifier "${lit.identifier}" = "${resolved}".`
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
if (!isAdTokenValue(lit, adTokens)) {
|
|
206
|
+
reportProp(
|
|
207
|
+
node,
|
|
208
|
+
`Prop "${attrName}" must use an --ad-* token or scale name (xxs–xl); got "${lit}".`
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (attrName === 'variant' && contract.variantEnum) {
|
|
216
|
+
checkEnum(attrName, attrValue, contract.variantEnum, contract, node);
|
|
217
|
+
}
|
|
218
|
+
if (attrName === 'size' && contract.sizeEnum) {
|
|
219
|
+
checkEnum(attrName, attrValue, contract.sizeEnum, contract, node);
|
|
220
|
+
}
|
|
221
|
+
if (contract.fixedProps?.[attrName] !== undefined) {
|
|
222
|
+
checkFixed(attrName, attrValue, contract.fixedProps[attrName], contract, node);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function checkEnum(attrName, attrValue, allowed, contract, node) {
|
|
227
|
+
const literals = collectStringLiterals(attrValue);
|
|
228
|
+
for (const lit of literals) {
|
|
229
|
+
if (typeof lit === 'object' && lit.identifier) {
|
|
230
|
+
const resolved = resolveIdentifierValue(lit.identifier, scopeConstants);
|
|
231
|
+
if (resolved && !allowed.includes(resolved)) {
|
|
232
|
+
reportProp(
|
|
233
|
+
node,
|
|
234
|
+
`${contract.id} ${attrName}="${resolved}" is not allowed. Allowed: ${allowed.join(', ')}.`
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
if (!allowed.includes(lit)) {
|
|
240
|
+
reportProp(node, `${contract.id} ${attrName}="${lit}" is not allowed. Allowed: ${allowed.join(', ')}.`);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function checkFixed(attrName, attrValue, expected, contract, node) {
|
|
246
|
+
const literals = collectStringLiterals(attrValue);
|
|
247
|
+
for (const lit of literals) {
|
|
248
|
+
if (typeof lit === 'object') continue;
|
|
249
|
+
if (String(lit) !== String(expected)) {
|
|
250
|
+
reportProp(node, `${contract.id} requires ${attrName}="${expected}".`);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return {
|
|
256
|
+
JSXOpeningElement(node) {
|
|
257
|
+
const contract = resolveJsxName(node.name, localToContract, contractsByImportName);
|
|
258
|
+
if (!contract || contract.kind === 'complex') return;
|
|
259
|
+
|
|
260
|
+
for (const attr of node.attributes) {
|
|
261
|
+
if (attr.type === 'JSXSpreadAttribute') {
|
|
262
|
+
reportProp(
|
|
263
|
+
attr,
|
|
264
|
+
`Spread props on <${contract.id}> hide contract values. List props explicitly.`
|
|
265
|
+
);
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
if (attr.type !== 'JSXAttribute' || !attr.name) continue;
|
|
269
|
+
const attrName = attr.name.name;
|
|
270
|
+
checkPropValue(attrName, attr.value, contract, attr);
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
module.exports = { createContractPropsRule, BANNED_STYLE_PROPS };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/** Hyphenated Tailwind utilities (token must start with one of these prefixes). */
|
|
4
|
+
const TAILWIND_TOKEN =
|
|
5
|
+
/^(?:grid|flex|gap|space-[xy]|p[trblxy]?|m[trblxy]?|w|min-w|max-w|h|min-h|max-h|text|bg|border|rounded|ring|shadow|opacity|z|top|bottom|left|right|font|leading|tracking|items|justify|content|self|place|divide|outline|decoration|translate|scale|rotate|skew|origin|fill|stroke|accent|caret|scroll|snap|aspect|columns|overflow|overscroll|whitespace|align|vertical|line-clamp|blur|brightness|contrast|grayscale|hue|invert|saturate|sepia|backdrop|from|via|to|underline|overline|antialiased|subpixel|italic|ordinal|tabular|proportional|lining)-[^\s'"]+/;
|
|
6
|
+
|
|
7
|
+
/** Whole-token utilities with no suffix (exact match after stripping hover:/md:/! ). */
|
|
8
|
+
const BARE_TAILWIND = new Set([
|
|
9
|
+
'sr-only',
|
|
10
|
+
'not-sr-only',
|
|
11
|
+
'hidden',
|
|
12
|
+
'invisible',
|
|
13
|
+
'block',
|
|
14
|
+
'inline-block',
|
|
15
|
+
'inline-flex',
|
|
16
|
+
'flex',
|
|
17
|
+
'inline-grid',
|
|
18
|
+
'grid',
|
|
19
|
+
'contents',
|
|
20
|
+
]);
|
|
21
|
+
|
|
22
|
+
function stripTailwindVariants(token) {
|
|
23
|
+
let base = token;
|
|
24
|
+
let changed = true;
|
|
25
|
+
while (changed) {
|
|
26
|
+
changed = false;
|
|
27
|
+
const withoutImportant = base.replace(/^!+/, '');
|
|
28
|
+
if (withoutImportant !== base) {
|
|
29
|
+
base = withoutImportant;
|
|
30
|
+
changed = true;
|
|
31
|
+
}
|
|
32
|
+
const withoutVariant = base.replace(/^[a-z]+:/, '');
|
|
33
|
+
if (withoutVariant !== base) {
|
|
34
|
+
base = withoutVariant;
|
|
35
|
+
changed = true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return base;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function tokenUsesTailwind(token) {
|
|
42
|
+
if (!token) return false;
|
|
43
|
+
const base = stripTailwindVariants(token);
|
|
44
|
+
if (BARE_TAILWIND.has(base)) return true;
|
|
45
|
+
return TAILWIND_TOKEN.test(base);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function classStringUsesTailwind(text) {
|
|
49
|
+
return text.split(/\s+/).some((token) => tokenUsesTailwind(token));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
module.exports = {
|
|
53
|
+
meta: {
|
|
54
|
+
type: 'problem',
|
|
55
|
+
schema: [],
|
|
56
|
+
messages: {
|
|
57
|
+
tailwind: 'Tailwind-style utility classes are forbidden. Use Mantine layout props with --ad-* tokens or a CSS module.',
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
create(context) {
|
|
61
|
+
return {
|
|
62
|
+
JSXAttribute(node) {
|
|
63
|
+
if (node.name.name !== 'className') return;
|
|
64
|
+
if (!node.value) return;
|
|
65
|
+
let text = '';
|
|
66
|
+
if (node.value.type === 'Literal') text = String(node.value.value);
|
|
67
|
+
if (node.value.type === 'JSXExpressionContainer' && node.value.expression.type === 'Literal') {
|
|
68
|
+
text = String(node.value.expression.value);
|
|
69
|
+
}
|
|
70
|
+
if (text && classStringUsesTailwind(text)) {
|
|
71
|
+
context.report({ node, messageId: 'tailwind' });
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
meta: {
|
|
5
|
+
type: 'problem',
|
|
6
|
+
schema: [
|
|
7
|
+
{
|
|
8
|
+
type: 'object',
|
|
9
|
+
properties: {
|
|
10
|
+
providerGlobs: { type: 'array', items: { type: 'string' } },
|
|
11
|
+
mantineNames: { type: 'array', items: { type: 'string' } },
|
|
12
|
+
},
|
|
13
|
+
additionalProperties: false,
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
messages: {
|
|
17
|
+
extend: 'Do not call {{name}}.extend outside MantineProvider setup. Theme defaults come from @appdirect/design-tokens/mantine-theme-defaults.json.',
|
|
18
|
+
createTheme: 'Do not call createTheme outside src/providers or __setup__.',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
create(context) {
|
|
22
|
+
const options = context.options[0] ?? {};
|
|
23
|
+
const providerGlobs = options.providerGlobs ?? ['**/src/providers/**', '**/__setup__/**'];
|
|
24
|
+
const mantineNames = new Set(options.mantineNames ?? []);
|
|
25
|
+
const filename = context.filename.replace(/\\/g, '/');
|
|
26
|
+
const inProvider = providerGlobs.some((glob) => globToRegExp(glob).test(filename));
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
CallExpression(node) {
|
|
30
|
+
if (
|
|
31
|
+
node.callee.type === 'MemberExpression' &&
|
|
32
|
+
node.callee.property.name === 'extend' &&
|
|
33
|
+
node.callee.object.type === 'Identifier'
|
|
34
|
+
) {
|
|
35
|
+
const name = node.callee.object.name;
|
|
36
|
+
if (!inProvider && (mantineNames.size === 0 || mantineNames.has(name))) {
|
|
37
|
+
context.report({ node, messageId: 'extend', data: { name } });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (node.callee.type === 'Identifier' && node.callee.name === 'createTheme' && !inProvider) {
|
|
41
|
+
context.report({ node, messageId: 'createTheme' });
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
function globToRegExp(pattern) {
|
|
49
|
+
const escaped = pattern
|
|
50
|
+
.replace(/\\/g, '\\\\')
|
|
51
|
+
.replace(/\*\*/g, '§§')
|
|
52
|
+
.replace(/\*/g, '[^/]*')
|
|
53
|
+
.replace(/§§/g, '.*');
|
|
54
|
+
return new RegExp(`^${escaped.replace(/\//g, '\\/')}$`);
|
|
55
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Flags imports of @mantine/core components the design system never adopted.
|
|
5
|
+
* The kit's own rule is "use Mantine core directly when there is no DS wrapper"
|
|
6
|
+
* (components/DesignSystem/LAYOUT_GUIDE.md), so anything the kit wraps, allows
|
|
7
|
+
* in rules/mantine-rules.ts, or builds on stays importable.
|
|
8
|
+
*/
|
|
9
|
+
module.exports = {
|
|
10
|
+
meta: {
|
|
11
|
+
type: 'suggestion',
|
|
12
|
+
schema: [
|
|
13
|
+
{
|
|
14
|
+
type: 'object',
|
|
15
|
+
properties: {
|
|
16
|
+
disallowed: {
|
|
17
|
+
type: 'array',
|
|
18
|
+
items: {
|
|
19
|
+
type: 'object',
|
|
20
|
+
properties: {
|
|
21
|
+
name: { type: 'string' },
|
|
22
|
+
replacement: { type: ['string', 'null'] },
|
|
23
|
+
},
|
|
24
|
+
required: ['name'],
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
additionalProperties: true,
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
messages: {
|
|
32
|
+
unadopted:
|
|
33
|
+
'{{name}} is not in the design system yet. Prefer {{replacement}} unless this component is required. Tell the user this component is outside the UX-approved list.',
|
|
34
|
+
unadoptedNoReplacement:
|
|
35
|
+
'{{name}} is not in the design system yet and has no approved equivalent. Tell the user this component is outside the UX-approved list and that they may want to talk to UX.',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
create(context) {
|
|
39
|
+
const disallowed = new Map(
|
|
40
|
+
(context.options[0]?.disallowed ?? []).map((entry) => [entry.name, entry.replacement])
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
ImportDeclaration(node) {
|
|
45
|
+
if (!String(node.source.value).startsWith('@mantine/core')) return;
|
|
46
|
+
for (const specifier of node.specifiers) {
|
|
47
|
+
if (specifier.type !== 'ImportSpecifier') continue;
|
|
48
|
+
reportIfDisallowed(specifier, specifier.imported.name);
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
ExportNamedDeclaration(node) {
|
|
52
|
+
if (!node.source || !String(node.source.value).startsWith('@mantine/core')) return;
|
|
53
|
+
for (const specifier of node.specifiers ?? []) {
|
|
54
|
+
if (specifier.type !== 'ExportSpecifier') continue;
|
|
55
|
+
const importedName = specifier.local?.name ?? specifier.exported.name;
|
|
56
|
+
reportIfDisallowed(specifier, importedName);
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
ExportAllDeclaration(node) {
|
|
60
|
+
if (!node.source || !String(node.source.value).startsWith('@mantine/core')) return;
|
|
61
|
+
context.report({
|
|
62
|
+
node,
|
|
63
|
+
message:
|
|
64
|
+
'Re-exporting all of @mantine/core bypasses the design-system import check. Export only adopted components by name.',
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
function reportIfDisallowed(node, name) {
|
|
70
|
+
if (!disallowed.has(name)) return;
|
|
71
|
+
const replacement = disallowed.get(name);
|
|
72
|
+
context.report({
|
|
73
|
+
node,
|
|
74
|
+
messageId: replacement ? 'unadopted' : 'unadoptedNoReplacement',
|
|
75
|
+
data: { name, replacement },
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Alert": {
|
|
3
|
+
"color": "default",
|
|
4
|
+
"variant": "light",
|
|
5
|
+
"radius": "sm",
|
|
6
|
+
"withCloseButton": false
|
|
7
|
+
},
|
|
8
|
+
"Badge": {
|
|
9
|
+
"variant": "filled",
|
|
10
|
+
"color": "default",
|
|
11
|
+
"size": "md",
|
|
12
|
+
"radius": "sm"
|
|
13
|
+
},
|
|
14
|
+
"Button": {
|
|
15
|
+
"variant": "default",
|
|
16
|
+
"size": "sm",
|
|
17
|
+
"radius": "sm"
|
|
18
|
+
},
|
|
19
|
+
"Group": {
|
|
20
|
+
"gap": "md",
|
|
21
|
+
"align": "center",
|
|
22
|
+
"justify": "flex-start",
|
|
23
|
+
"wrap": "wrap"
|
|
24
|
+
},
|
|
25
|
+
"Stack": {
|
|
26
|
+
"gap": "md",
|
|
27
|
+
"align": "stretch",
|
|
28
|
+
"justify": "flex-start"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import '@mantine/core';
|
|
2
|
+
|
|
3
|
+
declare module '@mantine/core' {
|
|
4
|
+
export interface BadgeProps {
|
|
5
|
+
variant?: 'filled'|'outline'|'info'|'success'|'danger'|'pending'|'default'|'warning';
|
|
6
|
+
}
|
|
7
|
+
export interface ButtonProps {
|
|
8
|
+
variant?: 'primary'|'secondary'|'default'|'disabled'|'link'|'secret'|'outline'|'danger';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
rules: {
|
|
5
|
+
'color-no-hex': true,
|
|
6
|
+
'color-named': 'never',
|
|
7
|
+
'selector-disallowed-list': [
|
|
8
|
+
/^\.mantine-.*-root\[data-variant/,
|
|
9
|
+
/^:global\(\.mantine-.*-root\[data-variant/,
|
|
10
|
+
],
|
|
11
|
+
'declaration-property-value-disallowed-list': {
|
|
12
|
+
'/.*/': [/--mantine-color-/],
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
ignoreFiles: ['**/MantineProviderWrapper/global.css'],
|
|
16
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appdirect/ds-enforce",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "ESLint, Stylelint, and Mantine types that keep apps on the AppDirect design system.",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
"./contracts": "./dist/contracts/index.json",
|
|
9
|
+
"./contracts/*": "./dist/contracts/*",
|
|
10
|
+
"./eslint": "./dist/eslint/index.cjs",
|
|
11
|
+
"./eslint/contracts.json": "./dist/eslint/contracts.json",
|
|
12
|
+
"./stylelint": "./dist/stylelint/index.cjs",
|
|
13
|
+
"./mantine": {
|
|
14
|
+
"types": "./dist/mantine.d.ts"
|
|
15
|
+
},
|
|
16
|
+
"./mantine-theme-defaults.json": "./dist/mantine-theme-defaults.json"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist/contracts/",
|
|
20
|
+
"dist/eslint/",
|
|
21
|
+
"dist/stylelint/",
|
|
22
|
+
"dist/mantine.d.ts",
|
|
23
|
+
"dist/mantine-theme-defaults.json",
|
|
24
|
+
"README.md"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"clean": "rm -rf dist",
|
|
28
|
+
"build": "npm run clean && node scripts/build-contract-enforcement.mjs",
|
|
29
|
+
"sync:contracts": "node scripts/sync-kit-contracts.mjs",
|
|
30
|
+
"verify:package": "npm pack --dry-run",
|
|
31
|
+
"prepack": "npm run build"
|
|
32
|
+
},
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/AppDirect/ad-design-system.git",
|
|
36
|
+
"directory": "packages/enforce"
|
|
37
|
+
}
|
|
38
|
+
}
|