@lvce-editor/eslint-plugin-virtual-dom 13.2.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 (2) hide show
  1. package/dist/index.js +92 -0
  2. package/package.json +12 -0
package/dist/index.js ADDED
@@ -0,0 +1,92 @@
1
+ const isPropertyNode = node => {
2
+ return typeof node === 'object' && node !== null && 'type' in node && node.type === 'Property' && 'key' in node && 'value' in node && 'computed' in node;
3
+ };
4
+ const isIdentifierNode = node => {
5
+ return typeof node === 'object' && node !== null && 'type' in node && node.type === 'Identifier' && 'name' in node;
6
+ };
7
+ const isLiteralNode = node => {
8
+ return typeof node === 'object' && node !== null && 'type' in node && node.type === 'Literal' && 'value' in node;
9
+ };
10
+ const isTemplateLiteralNode = node => {
11
+ return typeof node === 'object' && node !== null && 'type' in node && node.type === 'TemplateLiteral' && 'expressions' in node && 'quasis' in node;
12
+ };
13
+ const isBinaryExpressionNode = node => {
14
+ return typeof node === 'object' && node !== null && 'type' in node && node.type === 'BinaryExpression' && 'operator' in node && 'left' in node && 'right' in node;
15
+ };
16
+ const isClassNameKey = node => {
17
+ if (node.computed) {
18
+ return false;
19
+ }
20
+ if (isIdentifierNode(node.key)) {
21
+ return node.key.name === 'className';
22
+ }
23
+ if (isLiteralNode(node.key)) {
24
+ return node.key.value === 'className';
25
+ }
26
+ return false;
27
+ };
28
+ const isStringLiteralWithSpace = node => {
29
+ return isLiteralNode(node) && typeof node.value === 'string' && /\s/.test(node.value);
30
+ };
31
+ const hasTemplateClassSeparator = node => {
32
+ return node.quasis.some(quasi => /\s/.test(quasi.value.raw));
33
+ };
34
+ const isManualClassNameConcatenation = node => {
35
+ if (isTemplateLiteralNode(node)) {
36
+ return node.expressions.length > 0 && hasTemplateClassSeparator(node);
37
+ }
38
+ if (!isBinaryExpressionNode(node) || node.operator !== '+') {
39
+ return false;
40
+ }
41
+ return isStringLiteralWithSpace(node.left) || isStringLiteralWithSpace(node.right) || isManualClassNameConcatenation(node.left) || isManualClassNameConcatenation(node.right);
42
+ };
43
+ const meta = {
44
+ docs: {
45
+ description: 'Prefer mergeClassNames for composing virtual-dom className values'
46
+ },
47
+ messages: {
48
+ preferMergeClassNames: 'Use `mergeClassNames(...)` instead of manually concatenating `className`.'
49
+ },
50
+ type: 'suggestion'
51
+ };
52
+ const create = context => {
53
+ return {
54
+ Property(node) {
55
+ if (!isPropertyNode(node) || !isClassNameKey(node) || !isManualClassNameConcatenation(node.value)) {
56
+ return;
57
+ }
58
+ context.report({
59
+ messageId: 'preferMergeClassNames',
60
+ node: node.value
61
+ });
62
+ }
63
+ };
64
+ };
65
+
66
+ const preferMergeClassNames = {
67
+ __proto__: null,
68
+ create,
69
+ meta
70
+ };
71
+
72
+ const plugin = {
73
+ configs: {},
74
+ meta: {
75
+ name: 'virtual-dom',
76
+ version: '0.0.1'
77
+ },
78
+ rules: {
79
+ 'prefer-merge-class-names': preferMergeClassNames
80
+ }
81
+ };
82
+ const recommended = [{
83
+ files: ['**/*.{js,mjs,cjs,ts,mts,cts}'],
84
+ plugins: {
85
+ 'virtual-dom': plugin
86
+ },
87
+ rules: {
88
+ 'virtual-dom/prefer-merge-class-names': 'error'
89
+ }
90
+ }];
91
+
92
+ export { recommended as default };
package/package.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "@lvce-editor/eslint-plugin-virtual-dom",
3
+ "version": "13.2.0",
4
+ "main": "dist/index.js",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/lvce-editor/eslint-config.git"
8
+ },
9
+ "type": "module",
10
+ "license": "MIT",
11
+ "description": "ESLint rules for @lvce-editor/virtual-dom usage."
12
+ }