boss-css 0.0.1 → 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.
Files changed (268) hide show
  1. package/README.md +1 -0
  2. package/dist/_virtual/rolldown_runtime.cjs +43 -0
  3. package/dist/_virtual/rolldown_runtime.mjs +20 -0
  4. package/dist/api/browser.cjs +54 -0
  5. package/dist/api/browser.mjs +48 -0
  6. package/dist/api/config.cjs +94 -0
  7. package/dist/api/config.mjs +91 -0
  8. package/dist/api/css.cjs +304 -0
  9. package/dist/api/css.mjs +303 -0
  10. package/dist/api/dictionary.cjs +218 -0
  11. package/dist/api/dictionary.mjs +215 -0
  12. package/dist/api/file/dts.cjs +21 -0
  13. package/dist/api/file/dts.mjs +21 -0
  14. package/dist/api/file/file.cjs +123 -0
  15. package/dist/api/file/file.mjs +120 -0
  16. package/dist/api/file/js.cjs +118 -0
  17. package/dist/api/file/js.mjs +116 -0
  18. package/dist/api/names.cjs +52 -0
  19. package/dist/api/names.mjs +46 -0
  20. package/dist/api/noopCss.cjs +37 -0
  21. package/dist/api/noopCss.mjs +36 -0
  22. package/dist/api/propTree.cjs +54 -0
  23. package/dist/api/propTree.mjs +48 -0
  24. package/dist/api/server.cjs +112 -0
  25. package/dist/api/server.mjs +106 -0
  26. package/dist/cli/build.cjs +1 -0
  27. package/dist/cli/build.mjs +3 -0
  28. package/dist/cli/index.cjs +30 -0
  29. package/dist/cli/index.mjs +29 -0
  30. package/dist/cli/tasks/build.cjs +24 -0
  31. package/dist/cli/tasks/build.mjs +23 -0
  32. package/dist/cli/tasks/choose.cjs +47 -0
  33. package/dist/cli/tasks/choose.mjs +46 -0
  34. package/dist/cli/tasks/compile.cjs +68 -0
  35. package/dist/cli/tasks/compile.mjs +67 -0
  36. package/dist/cli/tasks/dev.cjs +51 -0
  37. package/dist/cli/tasks/dev.mjs +48 -0
  38. package/dist/cli/tasks/init.cjs +1835 -0
  39. package/dist/cli/tasks/init.mjs +1831 -0
  40. package/dist/cli/tasks/watch.cjs +38 -0
  41. package/dist/cli/tasks/watch.mjs +37 -0
  42. package/dist/cli/templates/init.cjs +82 -0
  43. package/dist/cli/templates/init.mjs +78 -0
  44. package/dist/cli/types.cjs +13 -0
  45. package/dist/cli/types.mjs +13 -0
  46. package/dist/cli/utils.cjs +43 -0
  47. package/dist/cli/utils.mjs +41 -0
  48. package/dist/compile/classname-strategy.cjs +79 -0
  49. package/dist/compile/classname-strategy.mjs +77 -0
  50. package/dist/compile/classname.cjs +366 -0
  51. package/dist/compile/classname.mjs +360 -0
  52. package/dist/compile/index.cjs +238 -0
  53. package/dist/compile/index.mjs +235 -0
  54. package/dist/compile/jsx.cjs +803 -0
  55. package/dist/compile/jsx.mjs +800 -0
  56. package/dist/compile/prepared.cjs +88 -0
  57. package/dist/compile/prepared.mjs +87 -0
  58. package/dist/compile/runtime.cjs +33 -0
  59. package/dist/compile/runtime.mjs +32 -0
  60. package/dist/compile/transform.cjs +371 -0
  61. package/dist/compile/transform.mjs +369 -0
  62. package/dist/cx/index.cjs +93 -0
  63. package/dist/cx/index.mjs +85 -0
  64. package/dist/detect-fw/index.cjs +384 -0
  65. package/dist/detect-fw/index.mjs +379 -0
  66. package/dist/dev/client.cjs +39 -0
  67. package/dist/dev/client.mjs +38 -0
  68. package/dist/dev/plugin/browser.cjs +11 -0
  69. package/dist/dev/plugin/browser.mjs +9 -0
  70. package/dist/dev/plugin/server.cjs +86 -0
  71. package/dist/dev/plugin/server.mjs +78 -0
  72. package/dist/dev/port.cjs +46 -0
  73. package/dist/dev/port.mjs +43 -0
  74. package/dist/dev/runtime.cjs +28 -0
  75. package/dist/dev/runtime.mjs +29 -0
  76. package/dist/dev/server.cjs +808 -0
  77. package/dist/dev/server.mjs +805 -0
  78. package/dist/dev/shared.cjs +6 -0
  79. package/dist/dev/shared.mjs +5 -0
  80. package/dist/eslint-plugin/index.cjs +66 -0
  81. package/dist/eslint-plugin/index.mjs +66 -0
  82. package/dist/eslint-plugin/rules/classnames-only.cjs +68 -0
  83. package/dist/eslint-plugin/rules/classnames-only.mjs +68 -0
  84. package/dist/eslint-plugin/rules/format-classnames.cjs +137 -0
  85. package/dist/eslint-plugin/rules/format-classnames.mjs +136 -0
  86. package/dist/eslint-plugin/rules/no-unknown-classes.cjs +119 -0
  87. package/dist/eslint-plugin/rules/no-unknown-classes.mjs +119 -0
  88. package/dist/eslint-plugin/rules/prefer-classnames.cjs +69 -0
  89. package/dist/eslint-plugin/rules/prefer-classnames.mjs +69 -0
  90. package/dist/eslint-plugin/rules/prefer-token-values.cjs +197 -0
  91. package/dist/eslint-plugin/rules/prefer-token-values.mjs +197 -0
  92. package/dist/eslint-plugin/rules/props-only.cjs +115 -0
  93. package/dist/eslint-plugin/rules/props-only.mjs +115 -0
  94. package/dist/eslint-plugin/rules/redundant-cx.cjs +66 -0
  95. package/dist/eslint-plugin/rules/redundant-cx.mjs +66 -0
  96. package/dist/eslint-plugin/rules/require-prop-functions.cjs +130 -0
  97. package/dist/eslint-plugin/rules/require-prop-functions.mjs +130 -0
  98. package/dist/eslint-plugin/utils/api.cjs +30 -0
  99. package/dist/eslint-plugin/utils/api.mjs +29 -0
  100. package/dist/eslint-plugin/utils/ast.cjs +119 -0
  101. package/dist/eslint-plugin/utils/ast.mjs +112 -0
  102. package/dist/eslint-plugin/utils/boss-classes.cjs +185 -0
  103. package/dist/eslint-plugin/utils/boss-classes.mjs +175 -0
  104. package/dist/eslint-plugin/utils/defaults.cjs +99 -0
  105. package/dist/eslint-plugin/utils/defaults.mjs +93 -0
  106. package/dist/eslint-plugin/utils/format.cjs +20 -0
  107. package/dist/eslint-plugin/utils/format.mjs +19 -0
  108. package/dist/eslint-plugin/utils/order.cjs +76 -0
  109. package/dist/eslint-plugin/utils/order.mjs +76 -0
  110. package/dist/eslint-plugin/utils/property-order.cjs +449 -0
  111. package/dist/eslint-plugin/utils/property-order.mjs +448 -0
  112. package/dist/eslint-plugin/utils/static.cjs +36 -0
  113. package/dist/eslint-plugin/utils/static.mjs +35 -0
  114. package/dist/fontsource/directory.cjs +39588 -0
  115. package/dist/fontsource/directory.mjs +39587 -0
  116. package/dist/fontsource/server.cjs +291 -0
  117. package/dist/fontsource/server.mjs +282 -0
  118. package/dist/index.cjs +10 -0
  119. package/dist/index.mjs +6 -0
  120. package/dist/log/browser.cjs +28 -0
  121. package/dist/log/browser.mjs +28 -0
  122. package/dist/log/server.cjs +32 -0
  123. package/dist/log/server.mjs +30 -0
  124. package/dist/merge/index.cjs +590 -0
  125. package/dist/merge/index.mjs +586 -0
  126. package/dist/native/browser.cjs +78 -0
  127. package/dist/native/browser.mjs +77 -0
  128. package/dist/native/server.cjs +180 -0
  129. package/dist/native/server.mjs +176 -0
  130. package/dist/native/styleTypes.cjs +168 -0
  131. package/dist/native/styleTypes.mjs +164 -0
  132. package/dist/parser/classname/server.cjs +239 -0
  133. package/dist/parser/classname/server.mjs +232 -0
  134. package/dist/parser/jsx/browser.cjs +66 -0
  135. package/dist/parser/jsx/browser.mjs +63 -0
  136. package/dist/parser/jsx/extractCode.cjs +99 -0
  137. package/dist/parser/jsx/extractCode.mjs +98 -0
  138. package/dist/parser/jsx/extractPrepared.cjs +123 -0
  139. package/dist/parser/jsx/extractPrepared.mjs +122 -0
  140. package/dist/parser/jsx/extractProps.cjs +234 -0
  141. package/dist/parser/jsx/extractProps.mjs +232 -0
  142. package/dist/parser/jsx/isDOMProp.cjs +17 -0
  143. package/dist/parser/jsx/isDOMProp.mjs +15 -0
  144. package/dist/parser/jsx/native.cjs +110 -0
  145. package/dist/parser/jsx/native.mjs +108 -0
  146. package/dist/parser/jsx/runtime.cjs +4 -0
  147. package/dist/parser/jsx/runtime.mjs +3 -0
  148. package/dist/parser/jsx/server.cjs +278 -0
  149. package/dist/parser/jsx/server.mjs +268 -0
  150. package/dist/postcss/index.cjs +16 -0
  151. package/dist/postcss/index.mjs +16 -0
  152. package/dist/prop/at/runtime-only.cjs +90 -0
  153. package/dist/prop/at/runtime-only.mjs +88 -0
  154. package/dist/prop/at/server.cjs +282 -0
  155. package/dist/prop/at/server.mjs +268 -0
  156. package/dist/prop/at/shared.cjs +153 -0
  157. package/dist/prop/at/shared.mjs +144 -0
  158. package/dist/prop/bosswind/browser.cjs +18 -0
  159. package/dist/prop/bosswind/browser.mjs +16 -0
  160. package/dist/prop/bosswind/runtime-only.cjs +18 -0
  161. package/dist/prop/bosswind/runtime-only.mjs +16 -0
  162. package/dist/prop/bosswind/server.cjs +81 -0
  163. package/dist/prop/bosswind/server.mjs +72 -0
  164. package/dist/prop/bosswind/shared.cjs +861 -0
  165. package/dist/prop/bosswind/shared.mjs +855 -0
  166. package/dist/prop/bosswind/tailwind-theme.cjs +703 -0
  167. package/dist/prop/bosswind/tailwind-theme.mjs +702 -0
  168. package/dist/prop/child/runtime-only.cjs +18 -0
  169. package/dist/prop/child/runtime-only.mjs +15 -0
  170. package/dist/prop/child/server.cjs +81 -0
  171. package/dist/prop/child/server.mjs +72 -0
  172. package/dist/prop/css/getDtsTemplate.cjs +65 -0
  173. package/dist/prop/css/getDtsTemplate.mjs +63 -0
  174. package/dist/prop/css/runtime-only.cjs +14 -0
  175. package/dist/prop/css/runtime-only.mjs +13 -0
  176. package/dist/prop/css/server.cjs +99 -0
  177. package/dist/prop/css/server.mjs +90 -0
  178. package/dist/prop/pseudo/runtime-only.cjs +23 -0
  179. package/dist/prop/pseudo/runtime-only.mjs +21 -0
  180. package/dist/prop/pseudo/server.cjs +91 -0
  181. package/dist/prop/pseudo/server.mjs +82 -0
  182. package/dist/prop/pseudo/shared.cjs +61 -0
  183. package/dist/prop/pseudo/shared.mjs +60 -0
  184. package/dist/reset/server.cjs +34 -0
  185. package/dist/reset/server.mjs +26 -0
  186. package/dist/runtime/index.cjs +119 -0
  187. package/dist/runtime/index.mjs +118 -0
  188. package/dist/runtime/preact.cjs +4 -0
  189. package/dist/runtime/preact.mjs +3 -0
  190. package/dist/runtime/qwik.cjs +21 -0
  191. package/dist/runtime/qwik.mjs +18 -0
  192. package/dist/runtime/react.cjs +4 -0
  193. package/dist/runtime/react.mjs +3 -0
  194. package/dist/runtime/solid.cjs +15 -0
  195. package/dist/runtime/solid.mjs +14 -0
  196. package/dist/runtime/stencil.cjs +25 -0
  197. package/dist/runtime/stencil.mjs +21 -0
  198. package/dist/runtime/style.cjs +14 -0
  199. package/dist/runtime/style.mjs +13 -0
  200. package/dist/shared/boundaries.cjs +288 -0
  201. package/dist/shared/boundaries.mjs +285 -0
  202. package/dist/shared/customCss.cjs +212 -0
  203. package/dist/shared/customCss.mjs +211 -0
  204. package/dist/shared/debug.cjs +76 -0
  205. package/dist/shared/debug.mjs +74 -0
  206. package/dist/shared/file.cjs +21 -0
  207. package/dist/shared/file.mjs +19 -0
  208. package/dist/shared/framework.cjs +10 -0
  209. package/dist/shared/framework.mjs +9 -0
  210. package/dist/shared/json.cjs +58 -0
  211. package/dist/shared/json.mjs +57 -0
  212. package/dist/shared/types.cjs +11 -0
  213. package/dist/shared/types.mjs +10 -0
  214. package/dist/strategy/classic/runtime-only.cjs +190 -0
  215. package/dist/strategy/classic/runtime-only.mjs +186 -0
  216. package/dist/strategy/classname-first/runtime-only.cjs +138 -0
  217. package/dist/strategy/classname-first/runtime-only.mjs +134 -0
  218. package/dist/strategy/classname-first/server.cjs +139 -0
  219. package/dist/strategy/classname-first/server.mjs +133 -0
  220. package/dist/strategy/classname-only/server.cjs +43 -0
  221. package/dist/strategy/classname-only/server.mjs +35 -0
  222. package/dist/strategy/inline-first/browser.cjs +61 -0
  223. package/dist/strategy/inline-first/browser.mjs +58 -0
  224. package/dist/strategy/inline-first/runtime-only.cjs +159 -0
  225. package/dist/strategy/inline-first/runtime-only.mjs +155 -0
  226. package/dist/strategy/inline-first/server.cjs +92 -0
  227. package/dist/strategy/inline-first/server.mjs +83 -0
  228. package/dist/strategy/runtime/runtime-only.cjs +24 -0
  229. package/dist/strategy/runtime/runtime-only.mjs +22 -0
  230. package/dist/strategy/runtime/server.cjs +72 -0
  231. package/dist/strategy/runtime/server.mjs +63 -0
  232. package/dist/strategy/runtime-only/css.cjs +183 -0
  233. package/dist/strategy/runtime-only/css.mjs +181 -0
  234. package/dist/tasks/build.cjs +88 -0
  235. package/dist/tasks/build.mjs +84 -0
  236. package/dist/tasks/compile.cjs +12 -0
  237. package/dist/tasks/compile.mjs +12 -0
  238. package/dist/tasks/postcss.cjs +116 -0
  239. package/dist/tasks/postcss.mjs +113 -0
  240. package/dist/tasks/session.cjs +46 -0
  241. package/dist/tasks/session.mjs +42 -0
  242. package/dist/tasks/watch.cjs +102 -0
  243. package/dist/tasks/watch.mjs +99 -0
  244. package/dist/transform/cache.cjs +24 -0
  245. package/dist/transform/cache.mjs +21 -0
  246. package/dist/transform/processFile.cjs +26 -0
  247. package/dist/transform/processFile.mjs +24 -0
  248. package/dist/use/token/browser.cjs +65 -0
  249. package/dist/use/token/browser.mjs +61 -0
  250. package/dist/use/token/runtime-only.cjs +245 -0
  251. package/dist/use/token/runtime-only.mjs +239 -0
  252. package/dist/use/token/server.cjs +325 -0
  253. package/dist/use/token/server.mjs +313 -0
  254. package/dist/use/token/vars.cjs +47 -0
  255. package/dist/use/token/vars.mjs +46 -0
  256. package/package.json +300 -4
  257. package/src/api/config.d.ts +1 -0
  258. package/src/fontsource/types.d.ts +50 -0
  259. package/src/packages/document-create-element/createElement.browser.js +3 -0
  260. package/src/packages/document-create-element/createElement.js +7 -0
  261. package/src/packages/document-create-element/package.json +17 -0
  262. package/src/packages/is-css-prop/browser.js +13 -0
  263. package/src/packages/is-css-prop/index.js +13 -0
  264. package/src/packages/is-css-prop/package-lock.json +52 -0
  265. package/src/packages/is-css-prop/package.json +17 -0
  266. package/src/prop/css/csstype.json +4387 -0
  267. package/src/prop/css/package.json +3 -0
  268. package/src/reset/reset.css +259 -0
@@ -0,0 +1,119 @@
1
+ import { collectClassLiteralsFromExpression, compilePatterns, getCalleeName, getJSXAttributeName, getLiteralInfo, matchesPattern } from "../utils/ast.mjs";
2
+ import { DEFAULT_ATTRIBUTE_PATTERNS, DEFAULT_CALLEE_PATTERNS, DEFAULT_TAG_PATTERNS, DEFAULT_VARIABLE_PATTERNS } from "../utils/defaults.mjs";
3
+ import { findInvalidTokens } from "../utils/boss-classes.mjs";
4
+
5
+ //#region src/eslint-plugin/rules/no-unknown-classes.js
6
+ const RULE_NAME = "no-unknown-classes";
7
+ const defaultOptions = {
8
+ attributes: DEFAULT_ATTRIBUTE_PATTERNS,
9
+ callees: DEFAULT_CALLEE_PATTERNS,
10
+ variables: DEFAULT_VARIABLE_PATTERNS,
11
+ tags: DEFAULT_TAG_PATTERNS,
12
+ allowCustomContexts: false,
13
+ additionalContexts: [],
14
+ additionalProps: [],
15
+ singleProps: []
16
+ };
17
+ const createPatterns = (options) => ({
18
+ attributes: compilePatterns(options.attributes),
19
+ callees: compilePatterns(options.callees),
20
+ variables: compilePatterns(options.variables),
21
+ tags: compilePatterns(options.tags)
22
+ });
23
+ const create = (context) => {
24
+ const sourceCode = context.getSourceCode();
25
+ const options = {
26
+ ...defaultOptions,
27
+ ...context.options[0] || {}
28
+ };
29
+ const patterns = createPatterns(options);
30
+ const reportInvalid = (literal) => {
31
+ if (!literal || !literal.value) return;
32
+ const invalid = findInvalidTokens(literal.value, options);
33
+ if (!invalid.length) return;
34
+ const preview = invalid.slice(0, 3).join(", ");
35
+ const remainder = invalid.length > 3 ? ` (+${invalid.length - 3} more)` : "";
36
+ context.report({
37
+ node: literal.node,
38
+ messageId: "invalid",
39
+ data: { classes: preview + remainder }
40
+ });
41
+ };
42
+ return {
43
+ JSXAttribute(node) {
44
+ const name = getJSXAttributeName(node);
45
+ if (!name || !matchesPattern(patterns.attributes, name)) return;
46
+ if (!node.value) return;
47
+ const literals = [];
48
+ collectClassLiteralsFromExpression(node.value, sourceCode, literals);
49
+ for (const literal of literals) reportInvalid(literal);
50
+ },
51
+ CallExpression(node) {
52
+ const calleeName = getCalleeName(node.callee);
53
+ if (!calleeName || !matchesPattern(patterns.callees, calleeName)) return;
54
+ const literals = [];
55
+ for (const argument of node.arguments) collectClassLiteralsFromExpression(argument, sourceCode, literals);
56
+ for (const literal of literals) reportInvalid(literal);
57
+ },
58
+ VariableDeclarator(node) {
59
+ if (!node.id || node.id.type !== "Identifier") return;
60
+ if (!matchesPattern(patterns.variables, node.id.name)) return;
61
+ const literals = [];
62
+ collectClassLiteralsFromExpression(node.init, sourceCode, literals);
63
+ for (const literal of literals) reportInvalid(literal);
64
+ },
65
+ TaggedTemplateExpression(node) {
66
+ const tagName = getCalleeName(node.tag);
67
+ if (!tagName || !matchesPattern(patterns.tags, tagName)) return;
68
+ const literal = getLiteralInfo(node.quasi, sourceCode);
69
+ if (literal) reportInvalid(literal);
70
+ }
71
+ };
72
+ };
73
+ var no_unknown_classes_default = {
74
+ name: RULE_NAME,
75
+ meta: {
76
+ type: "problem",
77
+ docs: { description: "Disallow unknown or non-Boss class names." },
78
+ schema: [{
79
+ type: "object",
80
+ additionalProperties: false,
81
+ properties: {
82
+ attributes: {
83
+ type: "array",
84
+ items: { type: "string" }
85
+ },
86
+ callees: {
87
+ type: "array",
88
+ items: { type: "string" }
89
+ },
90
+ variables: {
91
+ type: "array",
92
+ items: { type: "string" }
93
+ },
94
+ tags: {
95
+ type: "array",
96
+ items: { type: "string" }
97
+ },
98
+ allowCustomContexts: { type: "boolean" },
99
+ additionalContexts: {
100
+ type: "array",
101
+ items: { type: "string" }
102
+ },
103
+ additionalProps: {
104
+ type: "array",
105
+ items: { type: "string" }
106
+ },
107
+ singleProps: {
108
+ type: "array",
109
+ items: { type: "string" }
110
+ }
111
+ }
112
+ }],
113
+ messages: { invalid: "Invalid Boss class names: {{classes}}." }
114
+ },
115
+ create
116
+ };
117
+
118
+ //#endregion
119
+ export { no_unknown_classes_default as default };
@@ -0,0 +1,69 @@
1
+ const require_ast = require('../utils/ast.cjs');
2
+ const require_defaults = require('../utils/defaults.cjs');
3
+ const require_boss_classes = require('../utils/boss-classes.cjs');
4
+ const require_static = require('../utils/static.cjs');
5
+
6
+ //#region src/eslint-plugin/rules/prefer-classnames.js
7
+ const RULE_NAME = "prefer-classnames";
8
+ const defaultOptions = {
9
+ components: require_defaults.DEFAULT_COMPONENTS,
10
+ additionalContexts: [],
11
+ additionalProps: []
12
+ };
13
+ const isStyleProp = (name, options) => {
14
+ if (!name || name === "className" || name === "class") return false;
15
+ if (require_boss_classes.getContextSet(options).has(name)) return true;
16
+ return require_boss_classes.isCssPropName(name, options.additionalProps?.length ? new Set(options.additionalProps) : null);
17
+ };
18
+ const create = (context) => {
19
+ const options = {
20
+ ...defaultOptions,
21
+ ...context.options[0] || {}
22
+ };
23
+ const componentSet = new Set(options.components);
24
+ return { JSXOpeningElement(node) {
25
+ const rootName = require_ast.getJSXRootName(node.name);
26
+ if (!rootName || !componentSet.has(rootName)) return;
27
+ for (const attribute of node.attributes) {
28
+ if (!attribute || attribute.type !== "JSXAttribute") continue;
29
+ const name = require_ast.getJSXAttributeName(attribute);
30
+ if (!name || !isStyleProp(name, options)) continue;
31
+ if (!require_static.isStaticValue(attribute.value)) continue;
32
+ context.report({
33
+ node: attribute,
34
+ messageId: "preferClassnames",
35
+ data: { prop: name }
36
+ });
37
+ }
38
+ } };
39
+ };
40
+ var prefer_classnames_default = {
41
+ name: RULE_NAME,
42
+ meta: {
43
+ type: "suggestion",
44
+ docs: { description: "Prefer className for static Boss props; allow props for dynamic values only." },
45
+ schema: [{
46
+ type: "object",
47
+ additionalProperties: false,
48
+ properties: {
49
+ components: {
50
+ type: "array",
51
+ items: { type: "string" }
52
+ },
53
+ additionalContexts: {
54
+ type: "array",
55
+ items: { type: "string" }
56
+ },
57
+ additionalProps: {
58
+ type: "array",
59
+ items: { type: "string" }
60
+ }
61
+ }
62
+ }],
63
+ messages: { preferClassnames: "Use className instead of the static \"{{prop}}\" Boss prop." }
64
+ },
65
+ create
66
+ };
67
+
68
+ //#endregion
69
+ exports.default = prefer_classnames_default;
@@ -0,0 +1,69 @@
1
+ import { getJSXAttributeName, getJSXRootName } from "../utils/ast.mjs";
2
+ import { DEFAULT_COMPONENTS } from "../utils/defaults.mjs";
3
+ import { getContextSet, isCssPropName } from "../utils/boss-classes.mjs";
4
+ import { isStaticValue } from "../utils/static.mjs";
5
+
6
+ //#region src/eslint-plugin/rules/prefer-classnames.js
7
+ const RULE_NAME = "prefer-classnames";
8
+ const defaultOptions = {
9
+ components: DEFAULT_COMPONENTS,
10
+ additionalContexts: [],
11
+ additionalProps: []
12
+ };
13
+ const isStyleProp = (name, options) => {
14
+ if (!name || name === "className" || name === "class") return false;
15
+ if (getContextSet(options).has(name)) return true;
16
+ return isCssPropName(name, options.additionalProps?.length ? new Set(options.additionalProps) : null);
17
+ };
18
+ const create = (context) => {
19
+ const options = {
20
+ ...defaultOptions,
21
+ ...context.options[0] || {}
22
+ };
23
+ const componentSet = new Set(options.components);
24
+ return { JSXOpeningElement(node) {
25
+ const rootName = getJSXRootName(node.name);
26
+ if (!rootName || !componentSet.has(rootName)) return;
27
+ for (const attribute of node.attributes) {
28
+ if (!attribute || attribute.type !== "JSXAttribute") continue;
29
+ const name = getJSXAttributeName(attribute);
30
+ if (!name || !isStyleProp(name, options)) continue;
31
+ if (!isStaticValue(attribute.value)) continue;
32
+ context.report({
33
+ node: attribute,
34
+ messageId: "preferClassnames",
35
+ data: { prop: name }
36
+ });
37
+ }
38
+ } };
39
+ };
40
+ var prefer_classnames_default = {
41
+ name: RULE_NAME,
42
+ meta: {
43
+ type: "suggestion",
44
+ docs: { description: "Prefer className for static Boss props; allow props for dynamic values only." },
45
+ schema: [{
46
+ type: "object",
47
+ additionalProperties: false,
48
+ properties: {
49
+ components: {
50
+ type: "array",
51
+ items: { type: "string" }
52
+ },
53
+ additionalContexts: {
54
+ type: "array",
55
+ items: { type: "string" }
56
+ },
57
+ additionalProps: {
58
+ type: "array",
59
+ items: { type: "string" }
60
+ }
61
+ }
62
+ }],
63
+ messages: { preferClassnames: "Use className instead of the static \"{{prop}}\" Boss prop." }
64
+ },
65
+ create
66
+ };
67
+
68
+ //#endregion
69
+ export { prefer_classnames_default as default };
@@ -0,0 +1,197 @@
1
+ const require_ast = require('../utils/ast.cjs');
2
+ const require_defaults = require('../utils/defaults.cjs');
3
+ const require_api = require('../utils/api.cjs');
4
+ const require_boss_classes = require('../utils/boss-classes.cjs');
5
+
6
+ //#region src/eslint-plugin/rules/prefer-token-values.js
7
+ const RULE_NAME = "prefer-token-values";
8
+ const defaultOptions = {
9
+ components: require_defaults.DEFAULT_COMPONENTS,
10
+ additionalContexts: [],
11
+ additionalProps: []
12
+ };
13
+ const unwrapExpression = (node) => {
14
+ if (!node) return node;
15
+ switch (node.type) {
16
+ case "JSXExpressionContainer": return unwrapExpression(node.expression);
17
+ case "ChainExpression": return unwrapExpression(node.expression);
18
+ case "ParenthesizedExpression": return unwrapExpression(node.expression);
19
+ case "TSAsExpression":
20
+ case "TSTypeAssertion":
21
+ case "TSNonNullExpression": return unwrapExpression(node.expression);
22
+ default: return node;
23
+ }
24
+ };
25
+ const getPropertyName = (node) => {
26
+ if (!node) return null;
27
+ if (node.type === "Identifier") return node.name;
28
+ if (node.type === "Literal" && typeof node.value === "string") return node.value;
29
+ if (node.type === "StringLiteral") return node.value;
30
+ return null;
31
+ };
32
+ const getMemberPath = (node) => {
33
+ const resolved = unwrapExpression(node);
34
+ if (!resolved) return null;
35
+ if (resolved.type === "CallExpression") return getMemberPath(resolved.callee);
36
+ if (resolved.type !== "MemberExpression" && resolved.type !== "OptionalMemberExpression") return null;
37
+ const parts = [];
38
+ let current = resolved;
39
+ while (current) {
40
+ if (current.type === "MemberExpression" || current.type === "OptionalMemberExpression") {
41
+ const propName = getPropertyName(current.property);
42
+ if (!propName) return null;
43
+ parts.unshift(propName);
44
+ current = unwrapExpression(current.object);
45
+ continue;
46
+ }
47
+ if (current.type === "Identifier") {
48
+ parts.unshift(current.name);
49
+ break;
50
+ }
51
+ return null;
52
+ }
53
+ return parts;
54
+ };
55
+ const getTokenPathFromNode = (node, sourceCode) => {
56
+ const resolved = unwrapExpression(node);
57
+ if (!resolved) return null;
58
+ const literalInfo = require_ast.getLiteralInfo(resolved, sourceCode);
59
+ if (literalInfo?.value && typeof literalInfo.value === "string") {
60
+ if (literalInfo.value.startsWith("$$.token.")) return literalInfo.value.slice(9);
61
+ return null;
62
+ }
63
+ const parts = getMemberPath(resolved);
64
+ if (!parts || parts.length < 3) return null;
65
+ if (parts[0] !== "$$" || parts[1] !== "token") return null;
66
+ return parts.slice(2).join(".");
67
+ };
68
+ const isContainerContextKey = (name) => name === "container" || name.startsWith("container ") || name.startsWith("container_");
69
+ const isContextKey = (name, contextSet) => {
70
+ if (!name) return false;
71
+ if (name.startsWith("[") && name.endsWith("]")) return true;
72
+ if (isContainerContextKey(name)) return true;
73
+ return contextSet.has(name);
74
+ };
75
+ const dashToCamelCase = (str) => str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
76
+ const getPropAliases = (api, name) => {
77
+ if (!name) return [];
78
+ const aliases = new Set([name]);
79
+ const dictionary = api?.dictionary;
80
+ if (dictionary) {
81
+ const entry = typeof dictionary.resolve === "function" && (dictionary.resolve(name).descriptor || dictionary.resolve(dashToCamelCase(name)).descriptor) || dictionary.get(name) || dictionary.get(dashToCamelCase(name));
82
+ if (entry?.property) aliases.add(entry.property);
83
+ if (Array.isArray(entry?.aliases)) entry.aliases.forEach((alias) => aliases.add(alias));
84
+ }
85
+ return Array.from(aliases);
86
+ };
87
+ const resolveTokenValue = (groupValues, tokenPath) => {
88
+ let current = groupValues;
89
+ for (const key of tokenPath) {
90
+ if (!current || typeof current !== "object") return void 0;
91
+ const next = current[key];
92
+ current = next && typeof next === "object" && "value" in next ? next.value : next;
93
+ }
94
+ return current;
95
+ };
96
+ const create = (context) => {
97
+ const sourceCode = context.getSourceCode();
98
+ const options = {
99
+ ...defaultOptions,
100
+ ...context.options[0] || {}
101
+ };
102
+ const componentSet = new Set(options.components);
103
+ const contextSet = require_boss_classes.getContextSet(options);
104
+ const extraProps = options.additionalProps?.length ? new Set(options.additionalProps) : null;
105
+ const { api } = require_api.getApi();
106
+ const tokenGroups = api?.tokens && typeof api.tokens === "object" ? api.tokens : null;
107
+ if (!api || !tokenGroups) return {};
108
+ const reportTokenUsage = (node, propName, tokenKey) => {
109
+ context.report({
110
+ node,
111
+ messageId: "preferTokenValues",
112
+ data: {
113
+ prop: propName,
114
+ token: tokenKey
115
+ }
116
+ });
117
+ };
118
+ const checkValue = (valueNode, propName) => {
119
+ if (!valueNode) return;
120
+ const tokenPath = getTokenPathFromNode(valueNode, sourceCode);
121
+ if (!tokenPath) return;
122
+ const [groupName, ...rest] = tokenPath.split(".");
123
+ if (!groupName || rest.length === 0) return;
124
+ if (!getPropAliases(api, propName).includes(groupName)) return;
125
+ const groupValues = tokenGroups[groupName];
126
+ if (!groupValues) return;
127
+ if (resolveTokenValue(groupValues, rest) === void 0) return;
128
+ reportTokenUsage(valueNode, propName, rest.join("."));
129
+ };
130
+ const checkObjectExpression = (objectExpression) => {
131
+ for (const property of objectExpression.properties || []) {
132
+ if (!property || property.type !== "Property") continue;
133
+ if (property.kind && property.kind !== "init") continue;
134
+ if (property.computed) continue;
135
+ const key = getPropertyName(property.key);
136
+ if (!key) continue;
137
+ const value = property.value;
138
+ const resolved = unwrapExpression(value);
139
+ if (require_boss_classes.isCssPropName(key, extraProps)) {
140
+ checkValue(value, key);
141
+ continue;
142
+ }
143
+ if (resolved?.type === "ObjectExpression" && isContextKey(key, contextSet)) {
144
+ checkObjectExpression(resolved);
145
+ continue;
146
+ }
147
+ if (resolved?.type === "ObjectExpression") checkObjectExpression(resolved);
148
+ }
149
+ };
150
+ return { JSXOpeningElement(node) {
151
+ const rootName = require_ast.getJSXRootName(node.name);
152
+ if (!rootName || !componentSet.has(rootName)) return;
153
+ for (const attribute of node.attributes) {
154
+ if (!attribute || attribute.type !== "JSXAttribute") continue;
155
+ const name = require_ast.getJSXAttributeName(attribute);
156
+ if (!name) continue;
157
+ if (name === "className" || name === "class") continue;
158
+ if (require_boss_classes.isCssPropName(name, extraProps)) {
159
+ checkValue(attribute.value, name);
160
+ continue;
161
+ }
162
+ if (!isContextKey(name, contextSet)) continue;
163
+ const value = unwrapExpression(attribute.value);
164
+ if (value?.type === "ObjectExpression") checkObjectExpression(value);
165
+ }
166
+ } };
167
+ };
168
+ var prefer_token_values_default = {
169
+ name: RULE_NAME,
170
+ meta: {
171
+ type: "suggestion",
172
+ docs: { description: "Prefer token keys instead of $$.token proxies when the prop has tokens." },
173
+ schema: [{
174
+ type: "object",
175
+ additionalProperties: false,
176
+ properties: {
177
+ components: {
178
+ type: "array",
179
+ items: { type: "string" }
180
+ },
181
+ additionalContexts: {
182
+ type: "array",
183
+ items: { type: "string" }
184
+ },
185
+ additionalProps: {
186
+ type: "array",
187
+ items: { type: "string" }
188
+ }
189
+ }
190
+ }],
191
+ messages: { preferTokenValues: "Use {{prop}}=\"{{token}}\" instead of $$.token for this prop." }
192
+ },
193
+ create
194
+ };
195
+
196
+ //#endregion
197
+ exports.default = prefer_token_values_default;
@@ -0,0 +1,197 @@
1
+ import { getJSXAttributeName, getJSXRootName, getLiteralInfo } from "../utils/ast.mjs";
2
+ import { DEFAULT_COMPONENTS } from "../utils/defaults.mjs";
3
+ import { getApi } from "../utils/api.mjs";
4
+ import { getContextSet, isCssPropName } from "../utils/boss-classes.mjs";
5
+
6
+ //#region src/eslint-plugin/rules/prefer-token-values.js
7
+ const RULE_NAME = "prefer-token-values";
8
+ const defaultOptions = {
9
+ components: DEFAULT_COMPONENTS,
10
+ additionalContexts: [],
11
+ additionalProps: []
12
+ };
13
+ const unwrapExpression = (node) => {
14
+ if (!node) return node;
15
+ switch (node.type) {
16
+ case "JSXExpressionContainer": return unwrapExpression(node.expression);
17
+ case "ChainExpression": return unwrapExpression(node.expression);
18
+ case "ParenthesizedExpression": return unwrapExpression(node.expression);
19
+ case "TSAsExpression":
20
+ case "TSTypeAssertion":
21
+ case "TSNonNullExpression": return unwrapExpression(node.expression);
22
+ default: return node;
23
+ }
24
+ };
25
+ const getPropertyName = (node) => {
26
+ if (!node) return null;
27
+ if (node.type === "Identifier") return node.name;
28
+ if (node.type === "Literal" && typeof node.value === "string") return node.value;
29
+ if (node.type === "StringLiteral") return node.value;
30
+ return null;
31
+ };
32
+ const getMemberPath = (node) => {
33
+ const resolved = unwrapExpression(node);
34
+ if (!resolved) return null;
35
+ if (resolved.type === "CallExpression") return getMemberPath(resolved.callee);
36
+ if (resolved.type !== "MemberExpression" && resolved.type !== "OptionalMemberExpression") return null;
37
+ const parts = [];
38
+ let current = resolved;
39
+ while (current) {
40
+ if (current.type === "MemberExpression" || current.type === "OptionalMemberExpression") {
41
+ const propName = getPropertyName(current.property);
42
+ if (!propName) return null;
43
+ parts.unshift(propName);
44
+ current = unwrapExpression(current.object);
45
+ continue;
46
+ }
47
+ if (current.type === "Identifier") {
48
+ parts.unshift(current.name);
49
+ break;
50
+ }
51
+ return null;
52
+ }
53
+ return parts;
54
+ };
55
+ const getTokenPathFromNode = (node, sourceCode) => {
56
+ const resolved = unwrapExpression(node);
57
+ if (!resolved) return null;
58
+ const literalInfo = getLiteralInfo(resolved, sourceCode);
59
+ if (literalInfo?.value && typeof literalInfo.value === "string") {
60
+ if (literalInfo.value.startsWith("$$.token.")) return literalInfo.value.slice(9);
61
+ return null;
62
+ }
63
+ const parts = getMemberPath(resolved);
64
+ if (!parts || parts.length < 3) return null;
65
+ if (parts[0] !== "$$" || parts[1] !== "token") return null;
66
+ return parts.slice(2).join(".");
67
+ };
68
+ const isContainerContextKey = (name) => name === "container" || name.startsWith("container ") || name.startsWith("container_");
69
+ const isContextKey = (name, contextSet) => {
70
+ if (!name) return false;
71
+ if (name.startsWith("[") && name.endsWith("]")) return true;
72
+ if (isContainerContextKey(name)) return true;
73
+ return contextSet.has(name);
74
+ };
75
+ const dashToCamelCase = (str) => str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
76
+ const getPropAliases = (api, name) => {
77
+ if (!name) return [];
78
+ const aliases = new Set([name]);
79
+ const dictionary = api?.dictionary;
80
+ if (dictionary) {
81
+ const entry = typeof dictionary.resolve === "function" && (dictionary.resolve(name).descriptor || dictionary.resolve(dashToCamelCase(name)).descriptor) || dictionary.get(name) || dictionary.get(dashToCamelCase(name));
82
+ if (entry?.property) aliases.add(entry.property);
83
+ if (Array.isArray(entry?.aliases)) entry.aliases.forEach((alias) => aliases.add(alias));
84
+ }
85
+ return Array.from(aliases);
86
+ };
87
+ const resolveTokenValue = (groupValues, tokenPath) => {
88
+ let current = groupValues;
89
+ for (const key of tokenPath) {
90
+ if (!current || typeof current !== "object") return void 0;
91
+ const next = current[key];
92
+ current = next && typeof next === "object" && "value" in next ? next.value : next;
93
+ }
94
+ return current;
95
+ };
96
+ const create = (context) => {
97
+ const sourceCode = context.getSourceCode();
98
+ const options = {
99
+ ...defaultOptions,
100
+ ...context.options[0] || {}
101
+ };
102
+ const componentSet = new Set(options.components);
103
+ const contextSet = getContextSet(options);
104
+ const extraProps = options.additionalProps?.length ? new Set(options.additionalProps) : null;
105
+ const { api } = getApi();
106
+ const tokenGroups = api?.tokens && typeof api.tokens === "object" ? api.tokens : null;
107
+ if (!api || !tokenGroups) return {};
108
+ const reportTokenUsage = (node, propName, tokenKey) => {
109
+ context.report({
110
+ node,
111
+ messageId: "preferTokenValues",
112
+ data: {
113
+ prop: propName,
114
+ token: tokenKey
115
+ }
116
+ });
117
+ };
118
+ const checkValue = (valueNode, propName) => {
119
+ if (!valueNode) return;
120
+ const tokenPath = getTokenPathFromNode(valueNode, sourceCode);
121
+ if (!tokenPath) return;
122
+ const [groupName, ...rest] = tokenPath.split(".");
123
+ if (!groupName || rest.length === 0) return;
124
+ if (!getPropAliases(api, propName).includes(groupName)) return;
125
+ const groupValues = tokenGroups[groupName];
126
+ if (!groupValues) return;
127
+ if (resolveTokenValue(groupValues, rest) === void 0) return;
128
+ reportTokenUsage(valueNode, propName, rest.join("."));
129
+ };
130
+ const checkObjectExpression = (objectExpression) => {
131
+ for (const property of objectExpression.properties || []) {
132
+ if (!property || property.type !== "Property") continue;
133
+ if (property.kind && property.kind !== "init") continue;
134
+ if (property.computed) continue;
135
+ const key = getPropertyName(property.key);
136
+ if (!key) continue;
137
+ const value = property.value;
138
+ const resolved = unwrapExpression(value);
139
+ if (isCssPropName(key, extraProps)) {
140
+ checkValue(value, key);
141
+ continue;
142
+ }
143
+ if (resolved?.type === "ObjectExpression" && isContextKey(key, contextSet)) {
144
+ checkObjectExpression(resolved);
145
+ continue;
146
+ }
147
+ if (resolved?.type === "ObjectExpression") checkObjectExpression(resolved);
148
+ }
149
+ };
150
+ return { JSXOpeningElement(node) {
151
+ const rootName = getJSXRootName(node.name);
152
+ if (!rootName || !componentSet.has(rootName)) return;
153
+ for (const attribute of node.attributes) {
154
+ if (!attribute || attribute.type !== "JSXAttribute") continue;
155
+ const name = getJSXAttributeName(attribute);
156
+ if (!name) continue;
157
+ if (name === "className" || name === "class") continue;
158
+ if (isCssPropName(name, extraProps)) {
159
+ checkValue(attribute.value, name);
160
+ continue;
161
+ }
162
+ if (!isContextKey(name, contextSet)) continue;
163
+ const value = unwrapExpression(attribute.value);
164
+ if (value?.type === "ObjectExpression") checkObjectExpression(value);
165
+ }
166
+ } };
167
+ };
168
+ var prefer_token_values_default = {
169
+ name: RULE_NAME,
170
+ meta: {
171
+ type: "suggestion",
172
+ docs: { description: "Prefer token keys instead of $$.token proxies when the prop has tokens." },
173
+ schema: [{
174
+ type: "object",
175
+ additionalProperties: false,
176
+ properties: {
177
+ components: {
178
+ type: "array",
179
+ items: { type: "string" }
180
+ },
181
+ additionalContexts: {
182
+ type: "array",
183
+ items: { type: "string" }
184
+ },
185
+ additionalProps: {
186
+ type: "array",
187
+ items: { type: "string" }
188
+ }
189
+ }
190
+ }],
191
+ messages: { preferTokenValues: "Use {{prop}}=\"{{token}}\" instead of $$.token for this prop." }
192
+ },
193
+ create
194
+ };
195
+
196
+ //#endregion
197
+ export { prefer_token_values_default as default };