@maltjoy/eslint-rules 0.2.1 → 0.4.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.
package/README.md CHANGED
@@ -14,6 +14,18 @@ Message:
14
14
 
15
15
  - `no-vjoyinput-type-password`: disallow `VJoyInput` with `type="password"` (or a literal `:type` bound to `password`). Use `VJoyInputPassword` instead.
16
16
 
17
+ - `no-vjoyinput-unit`: disallow `unit` prop usage on `VJoyInput`. Use `VJoyInputNumber` instead.
18
+
19
+ Message:
20
+
21
+ `Do not use VJoyInput with unit, use VJoyInputNumber instead.`
22
+
23
+ - `no-vjoyusercard-rating-stars-slot`: disallow `user-card-rating-stars` slot usage on `VJoyUserCard`. Use the default slot instead.
24
+
25
+ Message:
26
+
27
+ `Do not use VJoyUserCard user-card-rating-stars slot, use the default slot instead.`
28
+
17
29
  ## Usage (flat config)
18
30
 
19
31
  **Preset (recommended)** — active toutes les règles du design system d’un coup :
package/index.js CHANGED
@@ -1,9 +1,13 @@
1
1
  import noVJoyButtonCircle from './rules/no-vjoybutton-circle.js';
2
2
  import noVJoyInputTypePassword from './rules/no-vjoyinput-type-password.js';
3
+ import noVJoyInputUnit from './rules/no-vjoyinput-unit.js';
4
+ import noVJoyUserCardRatingStarsSlot from './rules/no-vjoyusercard-rating-stars-slot.js';
3
5
 
4
6
  const rules = {
5
7
  'no-vjoybutton-circle': noVJoyButtonCircle,
6
8
  'no-vjoyinput-type-password': noVJoyInputTypePassword,
9
+ 'no-vjoyinput-unit': noVJoyInputUnit,
10
+ 'no-vjoyusercard-rating-stars-slot': noVJoyUserCardRatingStarsSlot,
7
11
  };
8
12
 
9
13
  const plugin = {
@@ -20,6 +24,8 @@ plugin.configs.recommended = [
20
24
  rules: {
21
25
  '@maltjoy/eslint-rules/no-vjoybutton-circle': 'error',
22
26
  '@maltjoy/eslint-rules/no-vjoyinput-type-password': 'error',
27
+ '@maltjoy/eslint-rules/no-vjoyinput-unit': 'error',
28
+ '@maltjoy/eslint-rules/no-vjoyusercard-rating-stars-slot': 'error',
23
29
  },
24
30
  },
25
31
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maltjoy/eslint-rules",
3
- "version": "0.2.1",
3
+ "version": "0.4.0",
4
4
  "description": "Custom ESLint rules for the @maltjoy/core-vue design system",
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -0,0 +1,75 @@
1
+ const ERROR_MESSAGE =
2
+ 'Do not use VJoyInput with unit property, use VJoyInputNumber instead.';
3
+
4
+ function isUnitAttribute(node) {
5
+ if (!node || node.type !== 'VAttribute') {
6
+ return false;
7
+ }
8
+
9
+ if (!node.directive) {
10
+ return node.key && node.key.name === 'unit';
11
+ }
12
+
13
+ const directiveName = node.key && node.key.name && node.key.name.name;
14
+ const argumentName = node.key && node.key.argument && node.key.argument.name;
15
+
16
+ return directiveName === 'bind' && argumentName === 'unit';
17
+ }
18
+
19
+ function isVJoyInputElement(node) {
20
+ if (!node || node.type !== 'VElement' || typeof node.name !== 'string') {
21
+ return false;
22
+ }
23
+
24
+ return node.name.toLowerCase() === 'vjoyinput';
25
+ }
26
+
27
+ export default {
28
+ meta: {
29
+ type: 'suggestion',
30
+ docs: {
31
+ description: 'disallow VJoyInput with unit prop; use VJoyInputNumber',
32
+ recommended: false,
33
+ },
34
+ schema: [],
35
+ messages: {
36
+ useVJoyInputNumber: ERROR_MESSAGE,
37
+ },
38
+ },
39
+ create(context) {
40
+ function visitElement(node) {
41
+ if (!node || node.type !== 'VElement') {
42
+ return;
43
+ }
44
+
45
+ if (isVJoyInputElement(node) && node.startTag && Array.isArray(node.startTag.attributes)) {
46
+ node.startTag.attributes.forEach((attribute) => {
47
+ if (isUnitAttribute(attribute)) {
48
+ context.report({
49
+ node: attribute,
50
+ messageId: 'useVJoyInputNumber',
51
+ });
52
+ }
53
+ });
54
+ }
55
+
56
+ if (!Array.isArray(node.children)) {
57
+ return;
58
+ }
59
+
60
+ node.children.forEach((child) => {
61
+ visitElement(child);
62
+ });
63
+ }
64
+
65
+ return {
66
+ Program(programNode) {
67
+ if (!programNode || !programNode.templateBody) {
68
+ return;
69
+ }
70
+
71
+ visitElement(programNode.templateBody);
72
+ },
73
+ };
74
+ },
75
+ };
@@ -0,0 +1,110 @@
1
+ const SLOT_NAME = 'user-card-rating-stars';
2
+ const ERROR_MESSAGE =
3
+ 'Do not use VJoyUserCard user-card-rating-stars slot, use the default slot instead.';
4
+
5
+ function getStaticName(node) {
6
+ if (!node) {
7
+ return undefined;
8
+ }
9
+
10
+ if (typeof node.name === 'string') {
11
+ return node.name;
12
+ }
13
+
14
+ if (typeof node.value === 'string') {
15
+ return node.value;
16
+ }
17
+
18
+ return undefined;
19
+ }
20
+
21
+ function isVJoyUserCardElement(node) {
22
+ if (!node || node.type !== 'VElement' || typeof node.name !== 'string') {
23
+ return false;
24
+ }
25
+
26
+ return node.name.toLowerCase() === 'vjoyusercard';
27
+ }
28
+
29
+ function isDeprecatedSlotAttribute(node) {
30
+ if (!node || node.type !== 'VAttribute') {
31
+ return false;
32
+ }
33
+
34
+ if (!node.directive) {
35
+ return (
36
+ node.key &&
37
+ node.key.name === 'slot' &&
38
+ node.value &&
39
+ node.value.type === 'VLiteral' &&
40
+ node.value.value === SLOT_NAME
41
+ );
42
+ }
43
+
44
+ const directiveName = node.key && node.key.name && node.key.name.name;
45
+ const argumentName = getStaticName(node.key && node.key.argument);
46
+
47
+ return directiveName === 'slot' && argumentName === SLOT_NAME;
48
+ }
49
+
50
+ function reportDeprecatedSlotAttribute(context, node) {
51
+ if (!node || !node.startTag || !Array.isArray(node.startTag.attributes)) {
52
+ return;
53
+ }
54
+
55
+ node.startTag.attributes.forEach((attribute) => {
56
+ if (isDeprecatedSlotAttribute(attribute)) {
57
+ context.report({
58
+ node: attribute,
59
+ messageId: 'useDefaultSlot',
60
+ });
61
+ }
62
+ });
63
+ }
64
+
65
+ export default {
66
+ meta: {
67
+ type: 'suggestion',
68
+ docs: {
69
+ description: 'disallow deprecated user-card-rating-stars slot on VJoyUserCard',
70
+ recommended: false,
71
+ },
72
+ schema: [],
73
+ messages: {
74
+ useDefaultSlot: ERROR_MESSAGE,
75
+ },
76
+ },
77
+ create(context) {
78
+ function visitElement(node, parentElement) {
79
+ if (!node || node.type !== 'VElement') {
80
+ return;
81
+ }
82
+
83
+ if (isVJoyUserCardElement(node)) {
84
+ reportDeprecatedSlotAttribute(context, node);
85
+ }
86
+
87
+ if (parentElement && isVJoyUserCardElement(parentElement) && node.name === 'template') {
88
+ reportDeprecatedSlotAttribute(context, node);
89
+ }
90
+
91
+ if (!Array.isArray(node.children)) {
92
+ return;
93
+ }
94
+
95
+ node.children.forEach((child) => {
96
+ visitElement(child, node);
97
+ });
98
+ }
99
+
100
+ return {
101
+ Program(programNode) {
102
+ if (!programNode || !programNode.templateBody) {
103
+ return;
104
+ }
105
+
106
+ visitElement(programNode.templateBody);
107
+ },
108
+ };
109
+ },
110
+ };