@maltjoy/eslint-rules 0.3.0 → 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 +6 -0
- package/index.js +3 -0
- package/package.json +1 -1
- package/rules/no-vjoyusercard-rating-stars-slot.js +110 -0
package/README.md
CHANGED
|
@@ -20,6 +20,12 @@ Message:
|
|
|
20
20
|
|
|
21
21
|
`Do not use VJoyInput with unit, use VJoyInputNumber instead.`
|
|
22
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
|
+
|
|
23
29
|
## Usage (flat config)
|
|
24
30
|
|
|
25
31
|
**Preset (recommended)** — active toutes les règles du design system d’un coup :
|
package/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import noVJoyButtonCircle from './rules/no-vjoybutton-circle.js';
|
|
2
2
|
import noVJoyInputTypePassword from './rules/no-vjoyinput-type-password.js';
|
|
3
3
|
import noVJoyInputUnit from './rules/no-vjoyinput-unit.js';
|
|
4
|
+
import noVJoyUserCardRatingStarsSlot from './rules/no-vjoyusercard-rating-stars-slot.js';
|
|
4
5
|
|
|
5
6
|
const rules = {
|
|
6
7
|
'no-vjoybutton-circle': noVJoyButtonCircle,
|
|
7
8
|
'no-vjoyinput-type-password': noVJoyInputTypePassword,
|
|
8
9
|
'no-vjoyinput-unit': noVJoyInputUnit,
|
|
10
|
+
'no-vjoyusercard-rating-stars-slot': noVJoyUserCardRatingStarsSlot,
|
|
9
11
|
};
|
|
10
12
|
|
|
11
13
|
const plugin = {
|
|
@@ -23,6 +25,7 @@ plugin.configs.recommended = [
|
|
|
23
25
|
'@maltjoy/eslint-rules/no-vjoybutton-circle': 'error',
|
|
24
26
|
'@maltjoy/eslint-rules/no-vjoyinput-type-password': 'error',
|
|
25
27
|
'@maltjoy/eslint-rules/no-vjoyinput-unit': 'error',
|
|
28
|
+
'@maltjoy/eslint-rules/no-vjoyusercard-rating-stars-slot': 'error',
|
|
26
29
|
},
|
|
27
30
|
},
|
|
28
31
|
];
|
package/package.json
CHANGED
|
@@ -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
|
+
};
|