@lssm/eslint-plugin-design-system 0.0.0-canary-20251217073102

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 ADDED
@@ -0,0 +1,45 @@
1
+ # @lssm/eslint-plugin-design-system
2
+
3
+ Design-system enforcement rules for LSSM apps. Ships:
4
+
5
+ - `prefer-design-system`: auto-rewrites known `@lssm/lib.ui-kit-web` form/control imports to `@lssm/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 '@lssm/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,31 @@
1
+ {
2
+ "name": "@lssm/eslint-plugin-design-system",
3
+ "version": "0.0.0-canary-20251217073102",
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
+ "dev": "bun build:bundle --watch",
17
+ "clean": "rimraf dist .turbo",
18
+ "lint": "bun lint:fix",
19
+ "lint:fix": "eslint src --fix",
20
+ "lint:check": "eslint src",
21
+ "test": "node ./tests/prefer-design-system.test.js"
22
+ },
23
+ "peerDependencies": {
24
+ "eslint": "^9.39.2"
25
+ },
26
+ "devDependencies": {
27
+ "eslint": "^9.39.2"
28
+ },
29
+ "license": "MIT",
30
+ "description": "Design-system ESLint rules (prefer-design-system) for LSSM apps"
31
+ }
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: '@lssm/lib.ui-kit',
5
+ message:
6
+ 'Do not import native ui-kit in web code. Use @lssm/lib.design-system or @lssm/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
+ '@lssm/lib.ui-kit-web/ui/button': '@lssm/lib.design-system',
5
+ '@lssm/lib.ui-kit-web/ui/input': '@lssm/lib.design-system',
6
+ '@lssm/lib.ui-kit-web/ui/textarea': '@lssm/lib.design-system',
7
+ '@lssm/lib.ui-kit-web/ui/cta': '@lssm/lib.design-system',
8
+ '@lssm/lib.ui-kit-web/ui/link': '@lssm/lib.design-system',
9
+ '@lssm/lib.ui-kit-web/ui/empty-state': '@lssm/lib.design-system',
10
+ '@lssm/lib.ui-kit-web/ui/loader': '@lssm/lib.design-system',
11
+ '@lssm/lib.ui-kit-web/ui/label': '@lssm/lib.design-system',
12
+ '@lssm/lib.ui-kit-web/ui/select': '@lssm/lib.design-system',
13
+ '@lssm/lib.ui-kit-web/ui/checkbox': '@lssm/lib.design-system',
14
+ '@lssm/lib.ui-kit-web/ui/radio-group': '@lssm/lib.design-system',
15
+ '@lssm/lib.ui-kit-web/ui/form': '@lssm/lib.design-system',
16
+ '@lssm/lib.ui-kit-web/ui/card': '@lssm/lib.design-system',
17
+ '@lssm/lib.ui-kit-web/ui/stack': '@lssm/lib.design-system',
18
+ '@lssm/lib.ui-kit-web/ui/typography': '@lssm/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
+