@contractspec/eslint-plugin-design-system 1.44.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Chaman Ventures, SASU
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # @contractspec/eslint-plugin-design-system
2
+
3
+ Design-system enforcement rules for LSSM apps. Ships:
4
+
5
+ - `prefer-design-system`: auto-rewrites known `@contractspec/lib.ui-kit-web` form/control imports to `@contractspec/lib.design-system` and flags intrinsic layout/form elements
6
+ - `no-intrinsic-typography`: flag raw headings/paragraph/spans; use DS typography primitives
7
+ - `design-import-boundary`: block forbidden design imports (default: native ui-kit in web)
8
+ - `localAllowPatterns` option (prefer-design-system): allow local/relative imports (shadcn-style) to bypass DS replacement so teams can copy/paste components.
9
+
10
+ `configs.recommended` enables all of the above.
11
+
12
+ Usage:
13
+
14
+ ```js
15
+ import dsPlugin from '@contractspec/eslint-plugin-design-system';
16
+
17
+ export default [
18
+ dsPlugin.configs.recommended,
19
+ // or customize
20
+ // {
21
+ // plugins: { 'design-system': dsPlugin },
22
+ // rules: {
23
+ // 'design-system/prefer-design-system': [
24
+ // 'error',
25
+ // {
26
+ // intrinsicDisallowList: ['div', 'button'],
27
+ // localAllowPatterns: ['^\\./components', '^@/components'],
28
+ // },
29
+ // ],
30
+ // 'design-system/no-intrinsic-typography': 'error',
31
+ // 'design-system/design-import-boundary': 'error',
32
+ // },
33
+ // },
34
+ ];
35
+ ```
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@contractspec/eslint-plugin-design-system",
3
+ "version": "1.44.0",
4
+ "private": false,
5
+ "type": "module",
6
+ "main": "src/index.js",
7
+ "exports": {
8
+ ".": "./src/index.js"
9
+ },
10
+ "files": [
11
+ "src"
12
+ ],
13
+ "scripts": {
14
+ "publish:pkg": "bun publish --tolerate-republish --ignore-scripts --verbose",
15
+ "publish:pkg:canary": "bun publish:pkg --tag canary",
16
+ "test": "node ./tests/prefer-design-system.test.js"
17
+ },
18
+ "peerDependencies": {
19
+ "eslint": "^9.39.2"
20
+ },
21
+ "devDependencies": {
22
+ "eslint": "^9.39.2"
23
+ },
24
+ "license": "MIT",
25
+ "description": "Design-system ESLint rules (prefer-design-system) for LSSM apps",
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "https://github.com/lssm-tech/contractspec.git",
29
+ "directory": "packages/tools/eslint-plugin-design-system"
30
+ },
31
+ "publishConfig": {
32
+ "registry": "https://registry.npmjs.org/",
33
+ "access": "public"
34
+ },
35
+ "homepage": "https://contractspec.io"
36
+ }
package/src/index.js ADDED
@@ -0,0 +1,40 @@
1
+ import preferDesignSystem from './rules/prefer-design-system.js';
2
+ import noIntrinsicTypography from './rules/no-intrinsic-typography.js';
3
+ import designImportBoundary from './rules/design-import-boundary.js';
4
+
5
+ export const rules = {
6
+ 'prefer-design-system': preferDesignSystem.rules['prefer-design-system'],
7
+ 'no-intrinsic-typography': noIntrinsicTypography,
8
+ 'design-import-boundary': designImportBoundary,
9
+ };
10
+
11
+ export const configs = {
12
+ recommended: {
13
+ plugins: {
14
+ 'design-system': {
15
+ rules,
16
+ },
17
+ },
18
+ rules: {
19
+ 'design-system/prefer-design-system': 'error',
20
+ 'design-system/no-intrinsic-typography': 'error',
21
+ 'design-system/design-import-boundary': 'error',
22
+ },
23
+ },
24
+ };
25
+
26
+ export default {
27
+ rules,
28
+ configs,
29
+ };
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
@@ -0,0 +1,73 @@
1
+ // Prevent forbidden cross-surface imports (e.g., native ui-kit in web code).
2
+ const DEFAULT_FORBIDDEN = [
3
+ {
4
+ path: '@contractspec/lib.ui-kit',
5
+ message:
6
+ 'Do not import native ui-kit in web code. Use @contractspec/lib.design-system or @contractspec/lib.ui-kit-web.',
7
+ },
8
+ ];
9
+
10
+ const rule = {
11
+ meta: {
12
+ type: 'problem',
13
+ docs: {
14
+ description:
15
+ 'Enforce design import boundaries (no native ui-kit in web; prefer design-system).',
16
+ },
17
+ schema: [
18
+ {
19
+ type: 'object',
20
+ properties: {
21
+ forbidden: {
22
+ type: 'array',
23
+ items: {
24
+ type: 'object',
25
+ properties: {
26
+ path: { type: 'string' },
27
+ message: { type: 'string' },
28
+ },
29
+ required: ['path'],
30
+ additionalProperties: false,
31
+ },
32
+ },
33
+ },
34
+ additionalProperties: false,
35
+ },
36
+ ],
37
+ messages: {
38
+ forbiddenImport: '{{message}}',
39
+ },
40
+ },
41
+ create(context) {
42
+ const forbidden = context.options[0]?.forbidden || DEFAULT_FORBIDDEN;
43
+ const pathToMessage = new Map(
44
+ forbidden.map((f) => [f.path, f.message || `Import "${f.path}" is forbidden here.`])
45
+ );
46
+
47
+ return {
48
+ ImportDeclaration(node) {
49
+ const source = node.source.value;
50
+ if (pathToMessage.has(source)) {
51
+ context.report({
52
+ node: node.source,
53
+ messageId: 'forbiddenImport',
54
+ data: { message: pathToMessage.get(source) },
55
+ });
56
+ }
57
+ },
58
+ };
59
+ },
60
+ };
61
+
62
+ export default rule;
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
@@ -0,0 +1,67 @@
1
+ // Flags intrinsic typography tags (headings, paragraph, spans, emphasis) in app/bundle code.
2
+ const DEFAULT_BLOCKLIST = new Set([
3
+ 'h1',
4
+ 'h2',
5
+ 'h3',
6
+ 'h4',
7
+ 'h5',
8
+ 'h6',
9
+ 'p',
10
+ 'span',
11
+ 'strong',
12
+ 'em',
13
+ ]);
14
+
15
+ const rule = {
16
+ meta: {
17
+ type: 'suggestion',
18
+ docs: {
19
+ description:
20
+ 'Use design-system typography primitives instead of intrinsic heading/paragraph/span tags.',
21
+ },
22
+ schema: [
23
+ {
24
+ type: 'object',
25
+ properties: {
26
+ allow: { type: 'array', items: { type: 'string' } },
27
+ },
28
+ additionalProperties: false,
29
+ },
30
+ ],
31
+ messages: {
32
+ avoidIntrinsicTypography:
33
+ 'Use design-system typography primitives instead of intrinsic <{{name}}>.',
34
+ },
35
+ },
36
+ create(context) {
37
+ const allow = new Set(context.options[0]?.allow || []);
38
+ return {
39
+ JSXOpeningElement(node) {
40
+ if (node.name.type !== 'JSXIdentifier') return;
41
+ const name = node.name.name;
42
+ if (!name || name[0] !== name[0]?.toLowerCase?.()) return;
43
+ if (allow.has(name)) return;
44
+ if (!DEFAULT_BLOCKLIST.has(name)) return;
45
+
46
+ context.report({
47
+ node: node.name,
48
+ messageId: 'avoidIntrinsicTypography',
49
+ data: { name },
50
+ });
51
+ },
52
+ };
53
+ },
54
+ };
55
+
56
+ export default rule;
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
@@ -0,0 +1,137 @@
1
+ // Custom ESLint rule to enforce design-system-first imports and discourage
2
+ // intrinsic layout/form elements in app/bundle code.
3
+ const DEFAULT_REPLACEMENTS = {
4
+ '@contractspec/lib.ui-kit-web/ui/button': '@contractspec/lib.design-system',
5
+ '@contractspec/lib.ui-kit-web/ui/input': '@contractspec/lib.design-system',
6
+ '@contractspec/lib.ui-kit-web/ui/textarea': '@contractspec/lib.design-system',
7
+ '@contractspec/lib.ui-kit-web/ui/cta': '@contractspec/lib.design-system',
8
+ '@contractspec/lib.ui-kit-web/ui/link': '@contractspec/lib.design-system',
9
+ '@contractspec/lib.ui-kit-web/ui/empty-state': '@contractspec/lib.design-system',
10
+ '@contractspec/lib.ui-kit-web/ui/loader': '@contractspec/lib.design-system',
11
+ '@contractspec/lib.ui-kit-web/ui/label': '@contractspec/lib.design-system',
12
+ '@contractspec/lib.ui-kit-web/ui/select': '@contractspec/lib.design-system',
13
+ '@contractspec/lib.ui-kit-web/ui/checkbox': '@contractspec/lib.design-system',
14
+ '@contractspec/lib.ui-kit-web/ui/radio-group': '@contractspec/lib.design-system',
15
+ '@contractspec/lib.ui-kit-web/ui/form': '@contractspec/lib.design-system',
16
+ '@contractspec/lib.ui-kit-web/ui/card': '@contractspec/lib.design-system',
17
+ '@contractspec/lib.ui-kit-web/ui/stack': '@contractspec/lib.design-system',
18
+ '@contractspec/lib.ui-kit-web/ui/typography': '@contractspec/lib.ui-kit-web/ui/typography', // allow typography to pass through
19
+ };
20
+
21
+ const DEFAULT_INTRINSIC = new Set([
22
+ 'div',
23
+ 'section',
24
+ 'main',
25
+ 'header',
26
+ 'footer',
27
+ 'nav',
28
+ 'span',
29
+ 'p',
30
+ 'h1',
31
+ 'h2',
32
+ 'h3',
33
+ 'h4',
34
+ 'h5',
35
+ 'h6',
36
+ 'button',
37
+ 'input',
38
+ 'textarea',
39
+ 'select',
40
+ 'option',
41
+ 'form',
42
+ 'label',
43
+ ]);
44
+
45
+ const preferDesignSystemRule = {
46
+ meta: {
47
+ type: 'suggestion',
48
+ docs: {
49
+ description:
50
+ 'Prefer design-system imports and avoid intrinsic layout/form elements in app/bundle code.',
51
+ },
52
+ schema: [
53
+ {
54
+ type: 'object',
55
+ properties: {
56
+ replacementMap: { type: 'object' },
57
+ intrinsicDisallowList: { type: 'array', items: { type: 'string' } },
58
+ allowIntrinsic: { type: 'array', items: { type: 'string' } },
59
+ localAllowPatterns: { type: 'array', items: { type: 'string' } },
60
+ },
61
+ additionalProperties: false,
62
+ },
63
+ ],
64
+ fixable: 'code',
65
+ messages: {
66
+ preferDSImport:
67
+ 'Use design-system import instead of "{{from}}". Prefer "{{to}}".',
68
+ avoidIntrinsic:
69
+ 'Use design-system layout/typography primitives instead of intrinsic <{{name}}> in app/bundle code.',
70
+ },
71
+ },
72
+ create(context) {
73
+ const options = context.options[0] || {};
74
+ const replacementMap = {
75
+ ...DEFAULT_REPLACEMENTS,
76
+ ...(options.replacementMap || {}),
77
+ };
78
+ const intrinsicDisallowList = new Set(
79
+ options.intrinsicDisallowList || DEFAULT_INTRINSIC
80
+ );
81
+ const allowIntrinsic = new Set(options.allowIntrinsic || []);
82
+ const localAllowPatterns = (options.localAllowPatterns || []).map(
83
+ (p) => new RegExp(p)
84
+ );
85
+
86
+ return {
87
+ ImportDeclaration(node) {
88
+ const sourceValue = node.source.value;
89
+ const replacement = replacementMap[sourceValue];
90
+ if (!replacement) return;
91
+ if (!node.specifiers || node.specifiers.length === 0) return;
92
+ if (localAllowPatterns.some((re) => re.test(sourceValue))) return;
93
+
94
+ context.report({
95
+ node: node.source,
96
+ messageId: 'preferDSImport',
97
+ data: { from: sourceValue, to: replacement },
98
+ fix(fixer) {
99
+ return fixer.replaceText(node.source, `'${replacement}'`);
100
+ },
101
+ });
102
+ },
103
+ JSXOpeningElement(node) {
104
+ if (node.name.type !== 'JSXIdentifier') return;
105
+ const name = node.name.name;
106
+ if (!name || name[0] !== name[0]?.toLowerCase?.()) return;
107
+ if (allowIntrinsic.has(name)) return;
108
+ if (!intrinsicDisallowList.has(name)) return;
109
+
110
+ context.report({
111
+ node: node.name,
112
+ messageId: 'avoidIntrinsic',
113
+ data: { name },
114
+ });
115
+ },
116
+ };
117
+ },
118
+ };
119
+
120
+ export const rules = {
121
+ 'prefer-design-system': preferDesignSystemRule,
122
+ };
123
+
124
+ export default {
125
+ rules,
126
+ };
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+