@widlarzgroup/docusaurus-ui 0.0.2 → 0.0.3

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,142 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ // Extract CSS variables from a file
5
+ function extractVariablesFromFile(filePath) {
6
+ if (!fs.existsSync(filePath)) {
7
+ return new Set();
8
+ }
9
+
10
+ const content = fs.readFileSync(filePath, 'utf-8');
11
+ const variableRegex = /^\s*(--[\w-]+)\s*:/gm;
12
+ const variables = new Set();
13
+
14
+ let match;
15
+ while ((match = variableRegex.exec(content)) !== null) {
16
+ variables.add(match[1]);
17
+ }
18
+
19
+ return variables;
20
+ }
21
+
22
+ // Extract CSS variables from the library's custom.css
23
+ function extractLibraryVariables() {
24
+ const customCssPath = path.resolve(__dirname, '../src/css/custom.css');
25
+ return extractVariablesFromFile(customCssPath);
26
+ }
27
+
28
+ // Extract variable name from a node
29
+ function extractVariableName(node) {
30
+ // Try to find the variable name in different places
31
+ if (node.name && node.name.startsWith('--')) {
32
+ return node.name;
33
+ }
34
+
35
+ // Check children
36
+ if (node.children) {
37
+ for (const child of node.children) {
38
+ if (child.name && child.name.startsWith('--')) {
39
+ return child.name;
40
+ }
41
+ if (child.type === 'Identifier' && child.name && child.name.startsWith('--')) {
42
+ return child.name;
43
+ }
44
+ }
45
+ }
46
+
47
+ // Check value
48
+ if (node.value) {
49
+ if (typeof node.value === 'string') {
50
+ const match = node.value.match(/--([\w-]+)/);
51
+ if (match) return '--' + match[1];
52
+ }
53
+ if (node.value.children) {
54
+ for (const child of node.value.children) {
55
+ if (child.name && child.name.startsWith('--')) {
56
+ return child.name;
57
+ }
58
+ }
59
+ }
60
+ }
61
+
62
+ return null;
63
+ }
64
+
65
+ const plugin = {
66
+ meta: {
67
+ name: '@widlarzgroup/eslint-plugin-css-variables',
68
+ version: '1.0.0',
69
+ },
70
+
71
+ rules: {
72
+ 'allowed-css-variables': {
73
+ meta: {
74
+ type: 'problem',
75
+ docs: {
76
+ description: 'Enforce using only allowed CSS variables',
77
+ },
78
+ schema: [
79
+ {
80
+ type: 'object',
81
+ properties: {
82
+ extend: {
83
+ oneOf: [
84
+ { type: 'string' },
85
+ { type: 'array', items: { type: 'string' } },
86
+ ],
87
+ },
88
+ },
89
+ additionalProperties: false,
90
+ },
91
+ ],
92
+ },
93
+
94
+ create(context) {
95
+ const options = context.options[0] || {};
96
+
97
+ // Get allowed variables from library
98
+ const allowedVariables = extractLibraryVariables();
99
+
100
+ // Get extended variables from user-specified files
101
+ if (options.extend) {
102
+ const extendFiles = Array.isArray(options.extend)
103
+ ? options.extend
104
+ : [options.extend];
105
+
106
+ for (const file of extendFiles) {
107
+ const resolvedPath = path.resolve(process.cwd(), file);
108
+ const extendedVars = extractVariablesFromFile(resolvedPath);
109
+ extendedVars.forEach((v) => allowedVariables.add(v));
110
+ }
111
+ }
112
+
113
+ return {
114
+ // Match any node and look for var() function calls
115
+ '*'(node) {
116
+ // Log node types to understand the AST
117
+ // console.log('Node type:', node.type, node.name || '');
118
+
119
+ // Look for Function nodes with name 'var'
120
+ if (node.type === 'Function' && node.name === 'var') {
121
+ const variableName = extractVariableName(node);
122
+
123
+ if (!variableName) return;
124
+
125
+ // Skip if allowed (defined in library or extended files)
126
+ if (allowedVariables.has(variableName)) {
127
+ return;
128
+ }
129
+
130
+ context.report({
131
+ node,
132
+ message: `Unexpected CSS variable "${variableName}". Only variables defined in custom.css (or extended files) are allowed.`,
133
+ });
134
+ }
135
+ },
136
+ };
137
+ },
138
+ },
139
+ },
140
+ };
141
+
142
+ module.exports = plugin;
@@ -1 +1 @@
1
- {"version":3,"file":"PlusBadge.d.ts","sourceRoot":"","sources":["../../../src/components/PlusBadge/PlusBadge.tsx"],"names":[],"mappings":"AAEA,UAAU,cAAc;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,QAAA,MAAM,SAAS,GAAI,aAA6B,cAAc,4CAc7D,CAAC;AAEF,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"PlusBadge.d.ts","sourceRoot":"","sources":["../../../src/components/PlusBadge/PlusBadge.tsx"],"names":[],"mappings":"AAEA,UAAU,cAAc;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,QAAA,MAAM,SAAS,gBAAiC,cAAc,4CAc7D,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"ProFeature.d.ts","sourceRoot":"","sources":["../../../src/components/ProFeature/ProFeature.tsx"],"names":[],"mappings":"AAEA,UAAU,eAAe;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,QAAA,MAAM,UAAU,GAAI,yBAGjB,eAAe,4CAsCjB,CAAC;AAEF,eAAe,UAAU,CAAC"}
1
+ {"version":3,"file":"ProFeature.d.ts","sourceRoot":"","sources":["../../../src/components/ProFeature/ProFeature.tsx"],"names":[],"mappings":"AAEA,UAAU,eAAe;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,QAAA,MAAM,UAAU,4BAGb,eAAe,4CAsCjB,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"TWGBadge.d.ts","sourceRoot":"","sources":["../../../src/components/TWGBadge/TWGBadge.tsx"],"names":[],"mappings":"AAEA,UAAU,aAAa;IACrB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,QAAA,MAAM,QAAQ,GAAI,oBAAoB,aAAa,4CAkBlD,CAAC;AAEF,eAAe,QAAQ,CAAC"}
1
+ {"version":3,"file":"TWGBadge.d.ts","sourceRoot":"","sources":["../../../src/components/TWGBadge/TWGBadge.tsx"],"names":[],"mappings":"AAEA,UAAU,aAAa;IACrB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,QAAA,MAAM,QAAQ,uBAAwB,aAAa,4CAkBlD,CAAC;AAEF,eAAe,QAAQ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widlarzgroup/docusaurus-ui",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -12,11 +12,13 @@
12
12
  "require": "./lib/index.js",
13
13
  "import": "./lib/index.js"
14
14
  },
15
- "./css/custom.css": "./lib/css/custom.css"
15
+ "./css/custom.css": "./lib/css/custom.css",
16
+ "./eslint-plugin": "./eslint-plugins/allowed-css-variables.js"
16
17
  },
17
18
  "files": [
18
19
  "lib",
19
- "src"
20
+ "src",
21
+ "eslint-plugins"
20
22
  ],
21
23
  "scripts": {
22
24
  "swizzle": "docusaurus swizzle",