@maltjoy/eslint-rules 0.4.0 → 0.6.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.
Files changed (48) hide show
  1. package/README.md +100 -1
  2. package/index.js +97 -4
  3. package/package.json +1 -1
  4. package/rules/accessibility/require-vjoyiconbutton-label.js +92 -0
  5. package/rules/accessibility/require-vjoytemplate-template-title-heading.js +61 -0
  6. package/rules/components/no-vjoyavatar-fullname-totalnumber.js +14 -0
  7. package/rules/components/no-vjoyavatar-photourl-totalnumber.js +14 -0
  8. package/rules/components/no-vjoybutton-circle.js +17 -0
  9. package/rules/components/no-vjoybutton-icon-only.js +87 -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/components/no-vjoyformgroup-vjoyradio.js +54 -0
  17. package/rules/components/no-vjoyfunnelfooter-slot.js +89 -0
  18. package/rules/{no-vjoyinput-type-password.js → components/no-vjoyinput-type-password.js} +18 -36
  19. package/rules/components/no-vjoyinput-unit.js +17 -0
  20. package/rules/components/no-vjoymenu-items-prop.js +19 -0
  21. package/rules/components/no-vjoymenu-vjoypanel.js +49 -0
  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/components/no-vjoyusercard-rating-stars-slot.js +79 -0
  31. package/rules/components/require-vjoymenu-template-sidebar.js +62 -0
  32. package/rules/components/require-vjoytemplate-template-title.js +52 -0
  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/forbidden-attribute.js +58 -0
  41. package/rules/utils/forbidden-element.js +36 -0
  42. package/rules/utils/require-ancestor.js +47 -0
  43. package/rules/utils/style-inspection.js +439 -0
  44. package/rules/utils/vjoyavatar.js +69 -0
  45. package/rules/utils/vue-ast.js +81 -0
  46. package/rules/no-vjoybutton-circle.js +0 -74
  47. package/rules/no-vjoyinput-unit.js +0 -75
  48. package/rules/no-vjoyusercard-rating-stars-slot.js +0 -110
@@ -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
+ });
@@ -0,0 +1,79 @@
1
+ import {
2
+ createTemplateBodyVisitor,
3
+ getStaticName,
4
+ isElementNamed,
5
+ } from '../utils/vue-ast.js';
6
+
7
+ const SLOT_NAME = 'user-card-rating-stars';
8
+ const ERROR_MESSAGE =
9
+ 'Do not use VJoyUserCard user-card-rating-stars slot, use the default slot instead.';
10
+
11
+ function isVJoyUserCardElement(node) {
12
+ return isElementNamed(node, ['vjoyusercard']);
13
+ }
14
+
15
+ function isDeprecatedSlotAttribute(node) {
16
+ if (node?.type !== 'VAttribute') {
17
+ return false;
18
+ }
19
+
20
+ if (!node.directive) {
21
+ return (
22
+ node.key?.name === 'slot' &&
23
+ node.value?.type === 'VLiteral' &&
24
+ node.value.value === SLOT_NAME
25
+ );
26
+ }
27
+
28
+ const directiveName = node.key?.name?.name;
29
+ const argumentName = getStaticName(node.key?.argument);
30
+
31
+ return directiveName === 'slot' && argumentName === SLOT_NAME;
32
+ }
33
+
34
+ function reportDeprecatedSlotAttribute(context, node) {
35
+ if (!Array.isArray(node?.startTag?.attributes)) {
36
+ return;
37
+ }
38
+
39
+ node.startTag.attributes.forEach((attribute) => {
40
+ if (isDeprecatedSlotAttribute(attribute)) {
41
+ context.report({
42
+ node: attribute,
43
+ messageId: 'useDefaultSlot',
44
+ });
45
+ }
46
+ });
47
+ }
48
+
49
+ export default {
50
+ meta: {
51
+ type: 'suggestion',
52
+ docs: {
53
+ description: 'disallow deprecated user-card-rating-stars slot on VJoyUserCard',
54
+ details:
55
+ 'The user-card-rating-stars slot on VJoyUserCard is deprecated. Put the rating content in the default slot.',
56
+ examples: {
57
+ incorrect:
58
+ '<VJoyUserCard>\n <template #user-card-rating-stars>\n <RatingStars />\n </template>\n</VJoyUserCard>',
59
+ correct: '<VJoyUserCard>\n <RatingStars />\n</VJoyUserCard>',
60
+ },
61
+ recommended: true,
62
+ },
63
+ schema: [],
64
+ messages: {
65
+ useDefaultSlot: ERROR_MESSAGE,
66
+ },
67
+ },
68
+ create(context) {
69
+ return createTemplateBodyVisitor((node, parentElement) => {
70
+ if (isVJoyUserCardElement(node)) {
71
+ reportDeprecatedSlotAttribute(context, node);
72
+ }
73
+
74
+ if (parentElement && isVJoyUserCardElement(parentElement) && node.name === 'template') {
75
+ reportDeprecatedSlotAttribute(context, node);
76
+ }
77
+ });
78
+ },
79
+ };
@@ -0,0 +1,62 @@
1
+ import {
2
+ createTemplateBodyVisitor,
3
+ isElementNamed,
4
+ isNamedSlotTemplate,
5
+ } from '../utils/vue-ast.js';
6
+
7
+ const ERROR_MESSAGE =
8
+ 'VJoyMenu must be used inside the VJoyTemplate #template-sidebar slot.';
9
+ const TEMPLATE_SIDEBAR_SLOT = 'template-sidebar';
10
+
11
+ function isVJoyMenuElement(node) {
12
+ return isElementNamed(node, ['vjoymenu', 'v-joy-menu']);
13
+ }
14
+
15
+ function isVJoyTemplateElement(node) {
16
+ return isElementNamed(node, ['vjoytemplate', 'v-joy-template']);
17
+ }
18
+
19
+ function isTemplateSidebarSlot(node) {
20
+ return isNamedSlotTemplate(node, TEMPLATE_SIDEBAR_SLOT);
21
+ }
22
+
23
+ function isInsideTemplateSidebar(ancestors) {
24
+ return ancestors.some((ancestor, index) => {
25
+ return (
26
+ isVJoyTemplateElement(ancestor) &&
27
+ isTemplateSidebarSlot(ancestors[index + 1])
28
+ );
29
+ });
30
+ }
31
+
32
+ export default {
33
+ meta: {
34
+ type: 'suggestion',
35
+ docs: {
36
+ description: 'require VJoyMenu to be inside the VJoyTemplate template-sidebar slot',
37
+ details:
38
+ 'VJoyMenu must be placed in the direct template-sidebar slot of VJoyTemplate.',
39
+ examples: {
40
+ incorrect:
41
+ '<VJoyTemplate>\n <template #template-main>\n <VJoyMenu />\n </template>\n</VJoyTemplate>',
42
+ correct:
43
+ '<VJoyTemplate>\n <template #template-sidebar>\n <VJoyMenu />\n </template>\n</VJoyTemplate>',
44
+ },
45
+ recommended: true,
46
+ },
47
+ schema: [],
48
+ messages: {
49
+ useTemplateSidebar: ERROR_MESSAGE,
50
+ },
51
+ },
52
+ create(context) {
53
+ return createTemplateBodyVisitor((node, _parentElement, ancestors) => {
54
+ if (isVJoyMenuElement(node) && !isInsideTemplateSidebar(ancestors)) {
55
+ context.report({
56
+ node,
57
+ messageId: 'useTemplateSidebar',
58
+ });
59
+ }
60
+ });
61
+ },
62
+ };
@@ -0,0 +1,52 @@
1
+ import {
2
+ createTemplateBodyVisitor,
3
+ isElementNamed,
4
+ isNamedSlotTemplate,
5
+ } from '../utils/vue-ast.js';
6
+
7
+ const ERROR_MESSAGE = 'VJoyTemplate must have a template-title slot.';
8
+ const TEMPLATE_TITLE_SLOT = 'template-title';
9
+
10
+ function isVJoyTemplateElement(node) {
11
+ return isElementNamed(node, ['vjoytemplate', 'v-joy-template']);
12
+ }
13
+
14
+ function isTemplateTitleSlot(node) {
15
+ return isNamedSlotTemplate(node, TEMPLATE_TITLE_SLOT);
16
+ }
17
+
18
+ function hasTemplateTitleSlot(node) {
19
+ return Array.isArray(node.children) && node.children.some(isTemplateTitleSlot);
20
+ }
21
+
22
+ export default {
23
+ meta: {
24
+ type: 'suggestion',
25
+ docs: {
26
+ description: 'require VJoyTemplate to provide the template-title slot',
27
+ details:
28
+ 'Every VJoyTemplate must provide a direct template-title slot so pages have a consistent title region.',
29
+ examples: {
30
+ incorrect:
31
+ '<VJoyTemplate>\n <template #template-main>Content</template>\n</VJoyTemplate>',
32
+ correct:
33
+ '<VJoyTemplate>\n <template #template-title>\n <h1>Page title</h1>\n </template>\n <template #template-main>Content</template>\n</VJoyTemplate>',
34
+ },
35
+ recommended: true,
36
+ },
37
+ schema: [],
38
+ messages: {
39
+ requireTemplateTitle: ERROR_MESSAGE,
40
+ },
41
+ },
42
+ create(context) {
43
+ return createTemplateBodyVisitor((node) => {
44
+ if (isVJoyTemplateElement(node) && !hasTemplateTitleSlot(node)) {
45
+ context.report({
46
+ node,
47
+ messageId: 'requireTemplateTitle',
48
+ });
49
+ }
50
+ });
51
+ },
52
+ };
@@ -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
+ };
@@ -0,0 +1,168 @@
1
+ import { createTemplateBodyVisitor } from '../utils/vue-ast.js';
2
+ import {
3
+ collectStringLiteralsFromExpression,
4
+ isBoundStyleAttribute,
5
+ isStaticStyleAttribute,
6
+ iterateStyleBlockContents,
7
+ objectExpressionHasColorProperty,
8
+ objectExpressionHasFontSizeProperty,
9
+ reportArbitraryFontSizesInText,
10
+ reportHexColorsInText,
11
+ reportNamedColorsInText,
12
+ reportRgbColorsInText,
13
+ styleStringHasColorDeclaration,
14
+ } from '../utils/style-inspection.js';
15
+
16
+ function visitStyleAttribute(context, attribute, handlers) {
17
+ if (isStaticStyleAttribute(attribute)) {
18
+ handlers.onStyleText?.(attribute.value.value, attribute.value.range[0]);
19
+ return;
20
+ }
21
+
22
+ if (!isBoundStyleAttribute(attribute)) {
23
+ return;
24
+ }
25
+
26
+ const expression = attribute.value?.expression;
27
+ handlers.onStyleExpression?.(expression, attribute);
28
+
29
+ collectStringLiteralsFromExpression(expression).forEach((literal) => {
30
+ if (typeof literal.value === 'string') {
31
+ handlers.onStyleText?.(literal.value, literal.range[0]);
32
+ }
33
+ });
34
+ }
35
+
36
+ export function createVueStyleInspectionRule({
37
+ description,
38
+ details,
39
+ examples,
40
+ messageId,
41
+ message,
42
+ inspectStyleText,
43
+ inspectStyleExpression,
44
+ includeStyleBlocks = true,
45
+ }) {
46
+ return {
47
+ meta: {
48
+ type: 'suggestion',
49
+ docs: {
50
+ description,
51
+ details,
52
+ examples,
53
+ recommended: true,
54
+ category: 'tokens',
55
+ },
56
+ schema: [],
57
+ messages: {
58
+ [messageId]: message,
59
+ },
60
+ },
61
+ create(context) {
62
+ const handlers = {
63
+ onStyleText(text, startIndex) {
64
+ inspectStyleText(context, text, startIndex, messageId);
65
+ },
66
+ onStyleExpression(expression, attribute) {
67
+ inspectStyleExpression?.(context, expression, attribute, messageId);
68
+ },
69
+ };
70
+
71
+ const templateVisitor = createTemplateBodyVisitor((node) => {
72
+ if (!Array.isArray(node.startTag?.attributes)) {
73
+ return;
74
+ }
75
+
76
+ node.startTag.attributes.forEach((attribute) => {
77
+ visitStyleAttribute(context, attribute, handlers);
78
+ });
79
+ });
80
+
81
+ return {
82
+ Program(node) {
83
+ if (includeStyleBlocks) {
84
+ for (const block of iterateStyleBlockContents(context.sourceCode)) {
85
+ inspectStyleText(context, block.content, block.startIndex, messageId);
86
+ }
87
+ }
88
+
89
+ templateVisitor.Program(node);
90
+ },
91
+ };
92
+ },
93
+ };
94
+ }
95
+
96
+ export function inspectStyleTextForHexColors(context, text, startIndex, messageId) {
97
+ reportHexColorsInText(context, text, startIndex, messageId);
98
+ }
99
+
100
+ export function inspectStyleTextForRgbColors(context, text, startIndex, messageId) {
101
+ reportRgbColorsInText(context, text, startIndex, messageId);
102
+ }
103
+
104
+ export function inspectStyleTextForNamedColors(context, text, startIndex, messageId) {
105
+ reportNamedColorsInText(context, text, startIndex, messageId);
106
+ }
107
+
108
+ export function inspectStyleTextForInlineColors(context, text, startIndex, messageId) {
109
+ if (styleStringHasColorDeclaration(text)) {
110
+ context.report({
111
+ loc: {
112
+ start: context.sourceCode.getLocFromIndex(startIndex),
113
+ end: context.sourceCode.getLocFromIndex(startIndex + text.length),
114
+ },
115
+ messageId,
116
+ });
117
+ }
118
+ }
119
+
120
+ export function inspectStyleTextForArbitraryFontSize(context, text, startIndex, messageId) {
121
+ reportArbitraryFontSizesInText(context, text, startIndex, messageId);
122
+ }
123
+
124
+ export function inspectStyleExpressionForInlineColors(context, expression, attribute, messageId) {
125
+ if (objectExpressionHasColorProperty(expression)) {
126
+ context.report({
127
+ node: attribute,
128
+ messageId,
129
+ });
130
+ }
131
+ }
132
+
133
+ export function inspectStyleExpressionForFontSize(context, expression, attribute, messageId) {
134
+ if (objectExpressionHasFontSizeProperty(expression)) {
135
+ context.report({
136
+ node: attribute,
137
+ messageId,
138
+ });
139
+ }
140
+
141
+ if (expression?.type === 'ObjectExpression') {
142
+ expression.properties.forEach((property) => {
143
+ if (property.type !== 'Property') {
144
+ return;
145
+ }
146
+
147
+ const propertyName = property.key?.type === 'Identifier'
148
+ ? property.key.name
149
+ : property.key?.value;
150
+
151
+ if (propertyName !== 'fontSize' && propertyName !== 'font-size') {
152
+ return;
153
+ }
154
+
155
+ if (
156
+ property.value?.type === 'Literal' &&
157
+ typeof property.value.value === 'string'
158
+ ) {
159
+ reportArbitraryFontSizesInText(
160
+ context,
161
+ `font-size: ${property.value.value}`,
162
+ property.value.range[0],
163
+ messageId,
164
+ );
165
+ }
166
+ });
167
+ }
168
+ }
@@ -0,0 +1,58 @@
1
+ import { createTemplateBodyVisitor, isElementNamed } from './vue-ast.js';
2
+
3
+ export function isStaticOrBoundAttributeNamed(node, attributeName) {
4
+ if (node?.type !== 'VAttribute') {
5
+ return false;
6
+ }
7
+
8
+ if (!node.directive) {
9
+ return node.key?.name === attributeName;
10
+ }
11
+
12
+ return (
13
+ node.key?.name?.name === 'bind' &&
14
+ node.key?.argument?.name === attributeName
15
+ );
16
+ }
17
+
18
+ export function createForbiddenAttributeRule({
19
+ attributeName,
20
+ description,
21
+ details,
22
+ elementNames,
23
+ examples,
24
+ message,
25
+ messageId,
26
+ }) {
27
+ return {
28
+ meta: {
29
+ type: 'suggestion',
30
+ docs: {
31
+ description,
32
+ details,
33
+ examples,
34
+ recommended: true,
35
+ },
36
+ schema: [],
37
+ messages: {
38
+ [messageId]: message,
39
+ },
40
+ },
41
+ create(context) {
42
+ return createTemplateBodyVisitor((node) => {
43
+ if (!isElementNamed(node, elementNames) || !Array.isArray(node.startTag?.attributes)) {
44
+ return;
45
+ }
46
+
47
+ node.startTag.attributes.forEach((attribute) => {
48
+ if (isStaticOrBoundAttributeNamed(attribute, attributeName)) {
49
+ context.report({
50
+ node: attribute,
51
+ messageId,
52
+ });
53
+ }
54
+ });
55
+ });
56
+ },
57
+ };
58
+ }