@maltjoy/eslint-rules 0.5.0 → 0.6.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.
Files changed (44) hide show
  1. package/README.md +59 -2
  2. package/index.js +83 -11
  3. package/package.json +1 -1
  4. package/rules/accessibility/require-vjoyiconbutton-label.js +47 -0
  5. package/rules/{require-vjoytemplate-template-title-heading.js → accessibility/require-vjoytemplate-template-title-heading.js} +2 -1
  6. package/rules/{no-vjoyavatar-fullname-totalnumber.js → components/no-vjoyavatar-fullname-totalnumber.js} +1 -1
  7. package/rules/{no-vjoyavatar-photourl-totalnumber.js → components/no-vjoyavatar-photourl-totalnumber.js} +1 -1
  8. package/rules/{no-vjoybutton-circle.js → components/no-vjoybutton-circle.js} +1 -1
  9. package/rules/components/no-vjoybutton-icon-only.js +59 -0
  10. package/rules/components/no-vjoybutton-white-variant.js +94 -0
  11. package/rules/components/no-vjoycollapse-single-item.js +55 -0
  12. package/rules/components/no-vjoycollapseitem-outside-collapse.js +15 -0
  13. package/rules/components/no-vjoycompanyavatar.js +16 -0
  14. package/rules/components/no-vjoyformerror-no-html-error-text.js +66 -0
  15. package/rules/components/no-vjoyformerror-visible-prop.js +18 -0
  16. package/rules/{no-vjoyformgroup-vjoyradio.js → components/no-vjoyformgroup-vjoyradio.js} +1 -1
  17. package/rules/components/no-vjoyfunnelfooter-slot.js +89 -0
  18. package/rules/{no-vjoyinput-type-password.js → components/no-vjoyinput-type-password.js} +1 -1
  19. package/rules/{no-vjoyinput-unit.js → components/no-vjoyinput-unit.js} +1 -1
  20. package/rules/components/no-vjoymenu-items-prop.js +19 -0
  21. package/rules/{no-vjoymenu-vjoypanel.js → components/no-vjoymenu-vjoypanel.js} +1 -1
  22. package/rules/components/no-vjoymenuitem-outside-menu.js +15 -0
  23. package/rules/components/no-vjoyradio-outside-group.js +16 -0
  24. package/rules/components/no-vjoyselectableitem-group.js +17 -0
  25. package/rules/components/no-vjoyselectableitem.js +55 -0
  26. package/rules/components/no-vjoysnackbar-direct.js +18 -0
  27. package/rules/components/no-vjoystep-outside-stepper.js +15 -0
  28. package/rules/components/no-vjoytab-outside-tabs.js +15 -0
  29. package/rules/components/no-vjoytooltip-enable-click-in-content.js +18 -0
  30. package/rules/{no-vjoyusercard-rating-stars-slot.js → components/no-vjoyusercard-rating-stars-slot.js} +1 -1
  31. package/rules/{require-vjoymenu-template-sidebar.js → components/require-vjoymenu-template-sidebar.js} +1 -1
  32. package/rules/{require-vjoytemplate-template-title.js → components/require-vjoytemplate-template-title.js} +1 -1
  33. package/rules/tokens/no-arbitrary-font-size.js +24 -0
  34. package/rules/tokens/no-hardcoded-color-names.js +22 -0
  35. package/rules/tokens/no-hardcoded-hex-colors-in-vue.js +22 -0
  36. package/rules/tokens/no-hardcoded-rgb-colors-in-vue.js +22 -0
  37. package/rules/tokens/no-inline-style-colors.js +23 -0
  38. package/rules/tokens/prefer-joy-color-classes.js +128 -0
  39. package/rules/tokens/vue-style-visitors.js +168 -0
  40. package/rules/utils/accessible-label.js +103 -0
  41. package/rules/utils/forbidden-attribute.js +1 -1
  42. package/rules/utils/forbidden-element.js +36 -0
  43. package/rules/utils/require-ancestor.js +47 -0
  44. package/rules/utils/style-inspection.js +439 -0
@@ -0,0 +1,89 @@
1
+ import {
2
+ createTemplateBodyVisitor,
3
+ getStaticName,
4
+ isElementNamed,
5
+ isNamedSlotTemplate,
6
+ } from '../utils/vue-ast.js';
7
+
8
+ const SLOT_NAME = 'funnel-footer';
9
+ const ERROR_MESSAGE =
10
+ 'VJoyFunnel funnel-footer slot is deprecated, use VJoyFunnelFooter in the default slot instead.';
11
+
12
+ function isVJoyFunnelElement(node) {
13
+ return isElementNamed(node, ['vjoyfunnel', 'v-joy-funnel']);
14
+ }
15
+
16
+ function isDeprecatedFunnelFooterSlot(node) {
17
+ return isNamedSlotTemplate(node, SLOT_NAME);
18
+ }
19
+
20
+ function isDeprecatedFunnelFooterSlotAttribute(node) {
21
+ if (node?.type !== 'VAttribute') {
22
+ return false;
23
+ }
24
+
25
+ if (!node.directive) {
26
+ return (
27
+ node.key?.name === 'slot' &&
28
+ node.value?.type === 'VLiteral' &&
29
+ node.value.value === SLOT_NAME
30
+ );
31
+ }
32
+
33
+ const directiveName = node.key?.name?.name;
34
+ const argumentName = getStaticName(node.key?.argument);
35
+
36
+ return directiveName === 'slot' && argumentName === SLOT_NAME;
37
+ }
38
+
39
+ function reportDeprecatedFunnelFooterSlot(context, node) {
40
+ if (!Array.isArray(node?.startTag?.attributes)) {
41
+ return;
42
+ }
43
+
44
+ node.startTag.attributes.forEach((attribute) => {
45
+ if (isDeprecatedFunnelFooterSlotAttribute(attribute)) {
46
+ context.report({
47
+ node: attribute,
48
+ messageId: 'deprecatedFunnelFooterSlot',
49
+ });
50
+ }
51
+ });
52
+ }
53
+
54
+ export default {
55
+ meta: {
56
+ type: 'suggestion',
57
+ docs: {
58
+ description: 'disallow deprecated funnel-footer slot on VJoyFunnel',
59
+ details:
60
+ 'The funnel-footer slot on VJoyFunnel is deprecated. Place VJoyFunnelFooter in the default slot instead.',
61
+ examples: {
62
+ incorrect:
63
+ '<VJoyFunnel>\n <template #funnel-footer>Footer</template>\n</VJoyFunnel>',
64
+ correct:
65
+ '<VJoyFunnel>\n <VJoyFunnelFooter>Footer</VJoyFunnelFooter>\n</VJoyFunnel>',
66
+ },
67
+ recommended: true,
68
+ },
69
+ schema: [],
70
+ messages: {
71
+ deprecatedFunnelFooterSlot: ERROR_MESSAGE,
72
+ },
73
+ },
74
+ create(context) {
75
+ return createTemplateBodyVisitor((node, parentElement) => {
76
+ if (parentElement && isVJoyFunnelElement(parentElement) && node.name === 'template') {
77
+ if (isDeprecatedFunnelFooterSlot(node)) {
78
+ context.report({
79
+ node,
80
+ messageId: 'deprecatedFunnelFooterSlot',
81
+ });
82
+ return;
83
+ }
84
+
85
+ reportDeprecatedFunnelFooterSlot(context, node);
86
+ }
87
+ });
88
+ },
89
+ };
@@ -1,4 +1,4 @@
1
- import { createTemplateBodyVisitor, isElementNamed } from './utils/vue-ast.js';
1
+ import { createTemplateBodyVisitor, isElementNamed } from '../utils/vue-ast.js';
2
2
 
3
3
  const ERROR_MESSAGE =
4
4
  'Do not use VJoyInput with type="password", use VJoyInputPassword instead.';
@@ -1,4 +1,4 @@
1
- import { createForbiddenAttributeRule } from './utils/forbidden-attribute.js';
1
+ import { createForbiddenAttributeRule } from '../utils/forbidden-attribute.js';
2
2
 
3
3
  const ERROR_MESSAGE =
4
4
  'Do not use VJoyInput with unit property, use VJoyInputNumber instead.';
@@ -0,0 +1,19 @@
1
+ import { createForbiddenAttributeRule } from '../utils/forbidden-attribute.js';
2
+
3
+ const ERROR_MESSAGE =
4
+ 'VJoyMenu items property is deprecated, use VJoyMenuItem in the default slot instead.';
5
+
6
+ export default createForbiddenAttributeRule({
7
+ attributeName: 'items',
8
+ elementNames: ['vjoymenu', 'v-joy-menu'],
9
+ description: 'disallow deprecated items prop on VJoyMenu',
10
+ details:
11
+ 'The items prop on VJoyMenu is deprecated. Render menu entries with VJoyMenuItem components in the default slot.',
12
+ examples: {
13
+ incorrect: '<VJoyMenu :items="menuItems" />',
14
+ correct:
15
+ '<VJoyMenu>\n <VJoyMenuItem label="Settings" />\n</VJoyMenu>',
16
+ },
17
+ message: ERROR_MESSAGE,
18
+ messageId: 'deprecatedMenuItemsProp',
19
+ });
@@ -2,7 +2,7 @@ import {
2
2
  containsElement,
3
3
  createTemplateBodyVisitor,
4
4
  isElementNamed,
5
- } from './utils/vue-ast.js';
5
+ } from '../utils/vue-ast.js';
6
6
 
7
7
  const ERROR_MESSAGE = 'Never use a VJoyMenu inside a VJoyPanel.';
8
8
 
@@ -0,0 +1,15 @@
1
+ import { createRequireAncestorRule } from '../utils/require-ancestor.js';
2
+
3
+ export default createRequireAncestorRule({
4
+ childElementNames: ['vjoymenuitem', 'v-joy-menu-item'],
5
+ parentElementNames: ['vjoymenu', 'v-joy-menu'],
6
+ description: 'disallow VJoyMenuItem outside VJoyMenu',
7
+ details: 'VJoyMenuItem must be used inside VJoyMenu.',
8
+ examples: {
9
+ incorrect: '<VJoyMenuItem label="Settings" />',
10
+ correct:
11
+ '<VJoyMenu>\n <VJoyMenuItem label="Settings" />\n</VJoyMenu>',
12
+ },
13
+ message: 'VJoyMenuItem must be used inside VJoyMenu.',
14
+ messageId: 'requireMenu',
15
+ });
@@ -0,0 +1,16 @@
1
+ import { createRequireAncestorRule } from '../utils/require-ancestor.js';
2
+
3
+ export default createRequireAncestorRule({
4
+ childElementNames: ['vjoyradio', 'v-joy-radio'],
5
+ parentElementNames: ['vjoyradiogroup', 'v-joy-radio-group'],
6
+ description: 'disallow VJoyRadio outside VJoyRadioGroup',
7
+ details:
8
+ 'VJoyRadio must be used inside VJoyRadioGroup to provide the expected fieldset semantics, grouping, and accessibility behavior.',
9
+ examples: {
10
+ incorrect: '<VJoyRadio value="daily" />',
11
+ correct:
12
+ '<VJoyRadioGroup v-model="frequency">\n <VJoyRadio value="daily" />\n</VJoyRadioGroup>',
13
+ },
14
+ message: 'VJoyRadio must be used inside VJoyRadioGroup.',
15
+ messageId: 'requireRadioGroup',
16
+ });
@@ -0,0 +1,17 @@
1
+ import { createForbiddenElementRule } from '../utils/forbidden-element.js';
2
+
3
+ const ERROR_MESSAGE =
4
+ 'VJoySelectableItemGroup is deprecated, use VJoyCheckboxGroup, VJoyRadioGroup, VJoyButtonCard, or VJoyCheckboxCard instead.';
5
+
6
+ export default createForbiddenElementRule({
7
+ elementNames: ['vjoyselectableitemgroup', 'v-joy-selectable-item-group'],
8
+ description: 'disallow deprecated VJoySelectableItemGroup usage',
9
+ details:
10
+ 'VJoySelectableItemGroup is deprecated. Choose VJoyCheckboxGroup, VJoyRadioGroup, VJoyButtonCard, or VJoyCheckboxCard depending on the interaction.',
11
+ examples: {
12
+ incorrect: '<VJoySelectableItemGroup v-model:value="value" :options="options" />',
13
+ correct: '<VJoyCheckboxGroup v-model:value="value" :options="options" />',
14
+ },
15
+ message: ERROR_MESSAGE,
16
+ messageId: 'deprecatedSelectableItemGroup',
17
+ });
@@ -0,0 +1,55 @@
1
+ import { createTemplateBodyVisitor, isElementNamed } from '../utils/vue-ast.js';
2
+
3
+ const ERROR_MESSAGE =
4
+ 'VJoySelectableItem is deprecated, use VJoyCheckboxGroup, VJoyRadioGroup, VJoyButtonCard, or VJoyCheckboxCard instead.';
5
+
6
+ const SELECTABLE_ITEM_NAMES = ['vjoyselectableitem', 'v-joy-selectable-item'];
7
+ const SELECTABLE_ITEM_GROUP_NAMES = [
8
+ 'vjoyselectableitemgroup',
9
+ 'v-joy-selectable-item-group',
10
+ ];
11
+
12
+ function isVJoySelectableItemElement(node) {
13
+ return isElementNamed(node, SELECTABLE_ITEM_NAMES);
14
+ }
15
+
16
+ function hasSelectableItemGroupAncestor(ancestors) {
17
+ return ancestors.some((ancestor) => isElementNamed(ancestor, SELECTABLE_ITEM_GROUP_NAMES));
18
+ }
19
+
20
+ export default {
21
+ meta: {
22
+ type: 'suggestion',
23
+ docs: {
24
+ description: 'disallow deprecated VJoySelectableItem usage outside its group component',
25
+ details:
26
+ 'VJoySelectableItem is deprecated. Use VJoyCheckboxGroup, VJoyRadioGroup, VJoyButtonCard, or VJoyCheckboxCard instead of composing selectable items manually.',
27
+ examples: {
28
+ incorrect: '<VJoySelectableItem value="option-a" name="choice" />',
29
+ correct:
30
+ '<VJoyRadioGroup v-model="choice">\n <VJoyRadio value="option-a" name="choice" />\n</VJoyRadioGroup>',
31
+ },
32
+ recommended: true,
33
+ },
34
+ schema: [],
35
+ messages: {
36
+ deprecatedSelectableItem: ERROR_MESSAGE,
37
+ },
38
+ },
39
+ create(context) {
40
+ return createTemplateBodyVisitor((node, _parentElement, ancestors) => {
41
+ if (!isVJoySelectableItemElement(node)) {
42
+ return;
43
+ }
44
+
45
+ if (hasSelectableItemGroupAncestor(ancestors)) {
46
+ return;
47
+ }
48
+
49
+ context.report({
50
+ node,
51
+ messageId: 'deprecatedSelectableItem',
52
+ });
53
+ });
54
+ },
55
+ };
@@ -0,0 +1,18 @@
1
+ import { createForbiddenElementRule } from '../utils/forbidden-element.js';
2
+
3
+ const ERROR_MESSAGE =
4
+ 'Do not use VJoySnackbar directly, use pushVJoySnackbar from @maltjoy/core-vue instead.';
5
+
6
+ export default createForbiddenElementRule({
7
+ elementNames: ['vjoysnackbar', 'v-joy-snackbar'],
8
+ description: 'disallow direct VJoySnackbar usage in templates',
9
+ details:
10
+ 'VJoySnackbar should not be rendered directly. Use the pushVJoySnackbar service from @maltjoy/core-vue.',
11
+ examples: {
12
+ incorrect: '<VJoySnackbar message="Saved" />',
13
+ correct:
14
+ "import { pushVJoySnackbar } from '@maltjoy/core-vue';\n\npushVJoySnackbar({ props: { message: 'Saved' } });",
15
+ },
16
+ message: ERROR_MESSAGE,
17
+ messageId: 'usePushVJoySnackbar',
18
+ });
@@ -0,0 +1,15 @@
1
+ import { createRequireAncestorRule } from '../utils/require-ancestor.js';
2
+
3
+ export default createRequireAncestorRule({
4
+ childElementNames: ['vjoystep', 'v-joy-step'],
5
+ parentElementNames: ['vjoystepper', 'v-joy-stepper'],
6
+ description: 'disallow VJoyStep outside VJoyStepper',
7
+ details: 'VJoyStep must be used inside VJoyStepper.',
8
+ examples: {
9
+ incorrect: '<VJoyStep label="Profile" />',
10
+ correct:
11
+ '<VJoyStepper>\n <VJoyStep label="Profile" />\n</VJoyStepper>',
12
+ },
13
+ message: 'VJoyStep must be used inside VJoyStepper.',
14
+ messageId: 'requireStepper',
15
+ });
@@ -0,0 +1,15 @@
1
+ import { createRequireAncestorRule } from '../utils/require-ancestor.js';
2
+
3
+ export default createRequireAncestorRule({
4
+ childElementNames: ['vjoytab', 'v-joy-tab'],
5
+ parentElementNames: ['vjoytabs', 'v-joy-tabs'],
6
+ description: 'disallow VJoyTab outside VJoyTabs',
7
+ details: 'VJoyTab must be used inside VJoyTabs.',
8
+ examples: {
9
+ incorrect: '<VJoyTab label="Overview" />',
10
+ correct:
11
+ '<VJoyTabs>\n <VJoyTab label="Overview" />\n</VJoyTabs>',
12
+ },
13
+ message: 'VJoyTab must be used inside VJoyTabs.',
14
+ messageId: 'requireTabs',
15
+ });
@@ -0,0 +1,18 @@
1
+ import { createForbiddenAttributeRule } from '../utils/forbidden-attribute.js';
2
+
3
+ const ERROR_MESSAGE =
4
+ 'VJoyTooltip enable-click-in-content property is deprecated and enabled by default. Remove it.';
5
+
6
+ export default createForbiddenAttributeRule({
7
+ attributeName: 'enable-click-in-content',
8
+ elementNames: ['vjoytooltip', 'v-joy-tooltip'],
9
+ description: 'disallow deprecated enable-click-in-content prop on VJoyTooltip',
10
+ details:
11
+ 'The enable-click-in-content prop on VJoyTooltip is deprecated because the behavior is now enabled by default.',
12
+ examples: {
13
+ incorrect: '<VJoyTooltip enable-click-in-content text="Help" />',
14
+ correct: '<VJoyTooltip text="Help" />',
15
+ },
16
+ message: ERROR_MESSAGE,
17
+ messageId: 'deprecatedEnableClickInContent',
18
+ });
@@ -2,7 +2,7 @@ import {
2
2
  createTemplateBodyVisitor,
3
3
  getStaticName,
4
4
  isElementNamed,
5
- } from './utils/vue-ast.js';
5
+ } from '../utils/vue-ast.js';
6
6
 
7
7
  const SLOT_NAME = 'user-card-rating-stars';
8
8
  const ERROR_MESSAGE =
@@ -2,7 +2,7 @@ import {
2
2
  createTemplateBodyVisitor,
3
3
  isElementNamed,
4
4
  isNamedSlotTemplate,
5
- } from './utils/vue-ast.js';
5
+ } from '../utils/vue-ast.js';
6
6
 
7
7
  const ERROR_MESSAGE =
8
8
  'VJoyMenu must be used inside the VJoyTemplate #template-sidebar slot.';
@@ -2,7 +2,7 @@ import {
2
2
  createTemplateBodyVisitor,
3
3
  isElementNamed,
4
4
  isNamedSlotTemplate,
5
- } from './utils/vue-ast.js';
5
+ } from '../utils/vue-ast.js';
6
6
 
7
7
  const ERROR_MESSAGE = 'VJoyTemplate must have a template-title slot.';
8
8
  const TEMPLATE_TITLE_SLOT = 'template-title';
@@ -0,0 +1,24 @@
1
+ import {
2
+ createVueStyleInspectionRule,
3
+ inspectStyleExpressionForFontSize,
4
+ inspectStyleTextForArbitraryFontSize,
5
+ } from './vue-style-visitors.js';
6
+
7
+ const ERROR_MESSAGE =
8
+ 'Avoid arbitrary font-size values in Vue files. Use @maltjoy/themes tokens such as var(--joy-font-size-primary-400) or typography classes like joy-font-primary-400.';
9
+
10
+ export default createVueStyleInspectionRule({
11
+ description: 'disallow arbitrary font-size values in Vue templates and style blocks',
12
+ details:
13
+ 'Font sizes should come from the Joy typography scale. Prefer VJoyText with classes such as joy-font-primary-400, utility classes such as joy-font-size-primary-400, or CSS variables such as var(--joy-font-size-primary-400) instead of px, rem, or em literals.',
14
+ examples: {
15
+ incorrect:
16
+ '<div style="font-size: 14px" />\n\n<style scoped>\n.title {\n font-size: 16px;\n}\n</style>',
17
+ correct:
18
+ '<VJoyText class="joy-font-primary-400" />\n\n<style scoped>\n.title {\n font-size: var(--joy-font-size-primary-400);\n}\n</style>',
19
+ },
20
+ messageId: 'arbitraryFontSize',
21
+ message: ERROR_MESSAGE,
22
+ inspectStyleText: inspectStyleTextForArbitraryFontSize,
23
+ inspectStyleExpression: inspectStyleExpressionForFontSize,
24
+ });
@@ -0,0 +1,22 @@
1
+ import {
2
+ createVueStyleInspectionRule,
3
+ inspectStyleTextForNamedColors,
4
+ } from './vue-style-visitors.js';
5
+
6
+ const ERROR_MESSAGE =
7
+ 'Avoid hardcoded CSS color names in Vue files. Use @maltjoy/themes design tokens such as var(--joy-color-*) or joy-color-* classes.';
8
+
9
+ export default createVueStyleInspectionRule({
10
+ description: 'disallow hardcoded CSS color names in Vue templates and style blocks',
11
+ details:
12
+ 'Named CSS colors such as red or white bypass the Joy design token system. Prefer CSS variables from @maltjoy/themes or Joy utility classes.',
13
+ examples: {
14
+ incorrect:
15
+ '<div style="color: red" />\n\n<style scoped>\n.title {\n background-color: white;\n}\n</style>',
16
+ correct:
17
+ '<div class="joy-color-error-50" />\n\n<style scoped>\n.title {\n background-color: var(--joy-color-neutral-0);\n}\n</style>',
18
+ },
19
+ messageId: 'hardcodedColorName',
20
+ message: ERROR_MESSAGE,
21
+ inspectStyleText: inspectStyleTextForNamedColors,
22
+ });
@@ -0,0 +1,22 @@
1
+ import {
2
+ createVueStyleInspectionRule,
3
+ inspectStyleTextForHexColors,
4
+ } from './vue-style-visitors.js';
5
+
6
+ const ERROR_MESSAGE =
7
+ 'Avoid hardcoded hex colors in Vue files. Use @maltjoy/themes design tokens such as var(--joy-color-*).';
8
+
9
+ export default createVueStyleInspectionRule({
10
+ description: 'disallow hardcoded hex colors in Vue templates and style blocks',
11
+ details:
12
+ 'Hardcoded hex colors bypass the Joy design token system. Prefer CSS variables from @maltjoy/themes, for example var(--joy-color-primary-30).',
13
+ examples: {
14
+ incorrect:
15
+ '<div style="color: #0F6378" />\n\n<style scoped>\n.title {\n color: #fff;\n}\n</style>',
16
+ correct:
17
+ '<div class="joy-color-primary-30" />\n\n<style scoped>\n.title {\n color: var(--joy-color-neutral-0);\n}\n</style>',
18
+ },
19
+ messageId: 'hardcodedHex',
20
+ message: ERROR_MESSAGE,
21
+ inspectStyleText: inspectStyleTextForHexColors,
22
+ });
@@ -0,0 +1,22 @@
1
+ import {
2
+ createVueStyleInspectionRule,
3
+ inspectStyleTextForRgbColors,
4
+ } from './vue-style-visitors.js';
5
+
6
+ const ERROR_MESSAGE =
7
+ 'Avoid hardcoded rgb/rgba colors in Vue files. Use @maltjoy/themes design tokens such as var(--joy-color-*).';
8
+
9
+ export default createVueStyleInspectionRule({
10
+ description: 'disallow hardcoded rgb/rgba colors in Vue templates and style blocks',
11
+ details:
12
+ 'Hardcoded rgb/rgba colors bypass the Joy design token system. Prefer CSS variables from @maltjoy/themes, for example var(--joy-color-primary-30).',
13
+ examples: {
14
+ incorrect:
15
+ '<div style="color: rgb(15, 99, 120)" />\n\n<style scoped>\n.title {\n background-color: rgba(0, 0, 0, 0.5);\n}\n</style>',
16
+ correct:
17
+ '<div class="joy-color-primary-30" />\n\n<style scoped>\n.title {\n background-color: var(--joy-color-neutral-60);\n}\n</style>',
18
+ },
19
+ messageId: 'hardcodedRgb',
20
+ message: ERROR_MESSAGE,
21
+ inspectStyleText: inspectStyleTextForRgbColors,
22
+ });
@@ -0,0 +1,23 @@
1
+ import {
2
+ createVueStyleInspectionRule,
3
+ inspectStyleExpressionForInlineColors,
4
+ inspectStyleTextForInlineColors,
5
+ } from './vue-style-visitors.js';
6
+
7
+ const ERROR_MESSAGE =
8
+ 'Avoid inline color styles in Vue templates. Use Joy utility classes or component styles with design tokens instead.';
9
+
10
+ export default createVueStyleInspectionRule({
11
+ description: 'disallow inline color styles in Vue templates',
12
+ details:
13
+ 'Inline color styles make theming and consistency harder to maintain. Use Joy CSS classes, SCSS with var(--joy-*), or component styles instead of style or :style color declarations.',
14
+ examples: {
15
+ incorrect: '<div style="color: var(--joy-color-neutral-90)" />',
16
+ correct: '<div class="joy-color-neutral-90" />',
17
+ },
18
+ messageId: 'inlineStyleColor',
19
+ message: ERROR_MESSAGE,
20
+ includeStyleBlocks: false,
21
+ inspectStyleText: inspectStyleTextForInlineColors,
22
+ inspectStyleExpression: inspectStyleExpressionForInlineColors,
23
+ });
@@ -0,0 +1,128 @@
1
+ import { createTemplateBodyVisitor } from '../utils/vue-ast.js';
2
+ import {
3
+ elementHasClassName,
4
+ extractJoyColorVarName,
5
+ getPropertyName,
6
+ getSuggestedJoyColorClass,
7
+ isBoundStyleAttribute,
8
+ isColorPropertyName,
9
+ isStaticStyleAttribute,
10
+ iterateJoyColorVarDeclarations,
11
+ } from '../utils/style-inspection.js';
12
+
13
+ const WARNING_MESSAGE =
14
+ 'Prefer Joy color utility classes such as {{ suggestedClass }} instead of inline var(--joy-color-*).';
15
+
16
+ function reportMissingJoyColorClass(context, node, declaration, messageId) {
17
+ const suggestedClass = declaration.data?.suggestedClass;
18
+
19
+ if (!suggestedClass || elementHasClassName(node, suggestedClass)) {
20
+ return;
21
+ }
22
+
23
+ context.report({
24
+ loc: {
25
+ start: context.sourceCode.getLocFromIndex(declaration.index),
26
+ end: context.sourceCode.getLocFromIndex(declaration.index + declaration.length),
27
+ },
28
+ messageId,
29
+ data: { suggestedClass },
30
+ });
31
+ }
32
+
33
+ function inspectInlineStyleText(context, node, text, startIndex, messageId) {
34
+ for (const declaration of iterateJoyColorVarDeclarations(text)) {
35
+ reportMissingJoyColorClass(context, node, {
36
+ ...declaration,
37
+ index: startIndex + declaration.index,
38
+ }, messageId);
39
+ }
40
+ }
41
+
42
+ function inspectStyleExpression(context, node, expression, attribute, messageId) {
43
+ if (expression?.type !== 'ObjectExpression') {
44
+ return;
45
+ }
46
+
47
+ expression.properties.forEach((property) => {
48
+ if (property.type !== 'Property') {
49
+ return;
50
+ }
51
+
52
+ const propertyName = getPropertyName(property);
53
+
54
+ if (
55
+ !isColorPropertyName(propertyName) ||
56
+ property.value?.type !== 'Literal' ||
57
+ typeof property.value.value !== 'string'
58
+ ) {
59
+ return;
60
+ }
61
+
62
+ const cssVarName = extractJoyColorVarName(property.value.value);
63
+ const suggestedClass = cssVarName
64
+ ? getSuggestedJoyColorClass(propertyName, cssVarName)
65
+ : undefined;
66
+
67
+ if (!suggestedClass || elementHasClassName(node, suggestedClass)) {
68
+ return;
69
+ }
70
+
71
+ context.report({
72
+ node: attribute,
73
+ messageId,
74
+ data: { suggestedClass },
75
+ });
76
+ });
77
+ }
78
+
79
+ export default {
80
+ meta: {
81
+ type: 'suggestion',
82
+ docs: {
83
+ description: 'prefer Joy color utility classes over inline var(--joy-color-*) styles',
84
+ details:
85
+ 'When setting text or background colors inline with Joy CSS variables, prefer the matching utility classes from @maltjoy/themes such as joy-color-primary-30 or joy-bgcolor-neutral-0.',
86
+ examples: {
87
+ incorrect: '<div style="color: var(--joy-color-primary-30)" />',
88
+ correct: '<div class="joy-color-primary-30" />',
89
+ },
90
+ recommended: true,
91
+ category: 'tokens',
92
+ },
93
+ schema: [],
94
+ messages: {
95
+ preferJoyColorClass: WARNING_MESSAGE,
96
+ },
97
+ },
98
+ create(context) {
99
+ return createTemplateBodyVisitor((node) => {
100
+ if (!Array.isArray(node.startTag?.attributes)) {
101
+ return;
102
+ }
103
+
104
+ node.startTag.attributes.forEach((attribute) => {
105
+ if (isStaticStyleAttribute(attribute)) {
106
+ inspectInlineStyleText(
107
+ context,
108
+ node,
109
+ attribute.value.value,
110
+ attribute.value.range[0],
111
+ 'preferJoyColorClass',
112
+ );
113
+ return;
114
+ }
115
+
116
+ if (isBoundStyleAttribute(attribute)) {
117
+ inspectStyleExpression(
118
+ context,
119
+ node,
120
+ attribute.value?.expression,
121
+ attribute,
122
+ 'preferJoyColorClass',
123
+ );
124
+ }
125
+ });
126
+ });
127
+ },
128
+ };