@tcy/eslint-rules 1.1.1 → 1.3.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/coverage/clover.xml +78 -3
- package/coverage/coverage-final.json +3 -0
- package/coverage/lcov-report/array-elements-per-line.js.html +1 -1
- package/coverage/lcov-report/decorator-type-enforcement.js.html +316 -0
- package/coverage/lcov-report/enforce-tailwind-important.js.html +1 -1
- package/coverage/lcov-report/export-specifiers-per-line.js.html +1 -1
- package/coverage/lcov-report/import-specifiers-per-line.js.html +1 -1
- package/coverage/lcov-report/index.html +53 -8
- package/coverage/lcov-report/index.js.html +20 -2
- package/coverage/lcov-report/jsx-expression-string-literals.js.html +1 -1
- package/coverage/lcov-report/v-model-name-match.js.html +1 -1
- package/coverage/lcov-report/vuejs-define-component.js.html +343 -0
- package/coverage/lcov-report/vuejs-define-workspace.js.html +280 -0
- package/coverage/lcov.info +175 -0
- package/dist/decorator-type-enforcement.d.ts +16 -0
- package/dist/index.d.ts +43 -0
- package/dist/vuejs-define-component.d.ts +14 -0
- package/dist/vuejs-define-workspace.d.ts +16 -0
- package/package.json +4 -4
- package/src/decorator-type-enforcement.js +77 -0
- package/src/index.js +6 -0
- package/src/vuejs-define-component.js +86 -0
- package/src/vuejs-define-workspace.js +65 -0
- package/tsconfig.json +1 -0
package/coverage/lcov.info
CHANGED
|
@@ -58,6 +58,67 @@ BRF:17
|
|
|
58
58
|
BRH:0
|
|
59
59
|
end_of_record
|
|
60
60
|
TN:
|
|
61
|
+
SF:src/decorator-type-enforcement.js
|
|
62
|
+
FN:1,(anonymous_0)
|
|
63
|
+
FN:4,(anonymous_1)
|
|
64
|
+
FN:23,(anonymous_2)
|
|
65
|
+
FN:27,(anonymous_3)
|
|
66
|
+
FN:46,(anonymous_4)
|
|
67
|
+
FN:66,(anonymous_5)
|
|
68
|
+
FNF:6
|
|
69
|
+
FNH:0
|
|
70
|
+
FNDA:0,(anonymous_0)
|
|
71
|
+
FNDA:0,(anonymous_1)
|
|
72
|
+
FNDA:0,(anonymous_2)
|
|
73
|
+
FNDA:0,(anonymous_3)
|
|
74
|
+
FNDA:0,(anonymous_4)
|
|
75
|
+
FNDA:0,(anonymous_5)
|
|
76
|
+
DA:1,0
|
|
77
|
+
DA:2,0
|
|
78
|
+
DA:3,0
|
|
79
|
+
DA:4,0
|
|
80
|
+
DA:8,0
|
|
81
|
+
DA:24,0
|
|
82
|
+
DA:26,0
|
|
83
|
+
DA:28,0
|
|
84
|
+
DA:29,0
|
|
85
|
+
DA:32,0
|
|
86
|
+
DA:33,0
|
|
87
|
+
DA:35,0
|
|
88
|
+
DA:36,0
|
|
89
|
+
DA:39,0
|
|
90
|
+
DA:40,0
|
|
91
|
+
DA:43,0
|
|
92
|
+
DA:47,0
|
|
93
|
+
DA:52,0
|
|
94
|
+
DA:53,0
|
|
95
|
+
DA:55,0
|
|
96
|
+
DA:57,0
|
|
97
|
+
DA:59,0
|
|
98
|
+
DA:60,0
|
|
99
|
+
DA:63,0
|
|
100
|
+
DA:67,0
|
|
101
|
+
DA:72,0
|
|
102
|
+
LF:26
|
|
103
|
+
LH:0
|
|
104
|
+
BRDA:2,0,0,0
|
|
105
|
+
BRDA:2,0,1,0
|
|
106
|
+
BRDA:28,1,0,0
|
|
107
|
+
BRDA:28,1,1,0
|
|
108
|
+
BRDA:28,2,0,0
|
|
109
|
+
BRDA:28,2,1,0
|
|
110
|
+
BRDA:35,3,0,0
|
|
111
|
+
BRDA:35,3,1,0
|
|
112
|
+
BRDA:39,4,0,0
|
|
113
|
+
BRDA:39,4,1,0
|
|
114
|
+
BRDA:52,5,0,0
|
|
115
|
+
BRDA:52,5,1,0
|
|
116
|
+
BRDA:59,6,0,0
|
|
117
|
+
BRDA:59,6,1,0
|
|
118
|
+
BRF:14
|
|
119
|
+
BRH:0
|
|
120
|
+
end_of_record
|
|
121
|
+
TN:
|
|
61
122
|
SF:src/enforce-tailwind-important.js
|
|
62
123
|
FN:4,(anonymous_0)
|
|
63
124
|
FN:6,(anonymous_1)
|
|
@@ -454,3 +515,117 @@ BRDA:60,11,2,0
|
|
|
454
515
|
BRF:27
|
|
455
516
|
BRH:0
|
|
456
517
|
end_of_record
|
|
518
|
+
TN:
|
|
519
|
+
SF:src/vuejs-define-component.js
|
|
520
|
+
FN:22,(anonymous_0)
|
|
521
|
+
FN:24,(anonymous_1)
|
|
522
|
+
FN:47,(anonymous_2)
|
|
523
|
+
FN:62,(anonymous_3)
|
|
524
|
+
FNF:4
|
|
525
|
+
FNH:0
|
|
526
|
+
FNDA:0,(anonymous_0)
|
|
527
|
+
FNDA:0,(anonymous_1)
|
|
528
|
+
FNDA:0,(anonymous_2)
|
|
529
|
+
FNDA:0,(anonymous_3)
|
|
530
|
+
DA:1,0
|
|
531
|
+
DA:23,0
|
|
532
|
+
DA:25,0
|
|
533
|
+
DA:28,0
|
|
534
|
+
DA:34,0
|
|
535
|
+
DA:37,0
|
|
536
|
+
DA:40,0
|
|
537
|
+
DA:41,0
|
|
538
|
+
DA:45,0
|
|
539
|
+
DA:47,0
|
|
540
|
+
DA:48,0
|
|
541
|
+
DA:49,0
|
|
542
|
+
DA:51,0
|
|
543
|
+
DA:52,0
|
|
544
|
+
DA:53,0
|
|
545
|
+
DA:62,0
|
|
546
|
+
DA:63,0
|
|
547
|
+
DA:67,0
|
|
548
|
+
DA:71,0
|
|
549
|
+
DA:72,0
|
|
550
|
+
DA:73,0
|
|
551
|
+
DA:75,0
|
|
552
|
+
DA:76,0
|
|
553
|
+
DA:80,0
|
|
554
|
+
LF:24
|
|
555
|
+
LH:0
|
|
556
|
+
BRDA:28,0,0,0
|
|
557
|
+
BRDA:28,0,1,0
|
|
558
|
+
BRDA:29,1,0,0
|
|
559
|
+
BRDA:29,1,1,0
|
|
560
|
+
BRDA:29,1,2,0
|
|
561
|
+
BRDA:29,1,3,0
|
|
562
|
+
BRDA:40,2,0,0
|
|
563
|
+
BRDA:40,2,1,0
|
|
564
|
+
BRDA:40,3,0,0
|
|
565
|
+
BRDA:40,3,1,0
|
|
566
|
+
BRDA:48,4,0,0
|
|
567
|
+
BRDA:48,4,1,0
|
|
568
|
+
BRDA:48,5,0,0
|
|
569
|
+
BRDA:48,5,1,0
|
|
570
|
+
BRDA:49,6,0,0
|
|
571
|
+
BRDA:49,6,1,0
|
|
572
|
+
BRDA:52,7,0,0
|
|
573
|
+
BRDA:52,7,1,0
|
|
574
|
+
BRDA:62,8,0,0
|
|
575
|
+
BRDA:62,8,1,0
|
|
576
|
+
BRDA:75,9,0,0
|
|
577
|
+
BRDA:75,9,1,0
|
|
578
|
+
BRF:22
|
|
579
|
+
BRH:0
|
|
580
|
+
end_of_record
|
|
581
|
+
TN:
|
|
582
|
+
SF:src/vuejs-define-workspace.js
|
|
583
|
+
FN:14,(anonymous_0)
|
|
584
|
+
FN:27,(anonymous_1)
|
|
585
|
+
FN:48,(anonymous_2)
|
|
586
|
+
FNF:3
|
|
587
|
+
FNH:0
|
|
588
|
+
FNDA:0,(anonymous_0)
|
|
589
|
+
FNDA:0,(anonymous_1)
|
|
590
|
+
FNDA:0,(anonymous_2)
|
|
591
|
+
DA:15,0
|
|
592
|
+
DA:16,0
|
|
593
|
+
DA:19,0
|
|
594
|
+
DA:22,0
|
|
595
|
+
DA:23,0
|
|
596
|
+
DA:26,0
|
|
597
|
+
DA:28,0
|
|
598
|
+
DA:31,0
|
|
599
|
+
DA:37,0
|
|
600
|
+
DA:40,0
|
|
601
|
+
DA:43,0
|
|
602
|
+
DA:44,0
|
|
603
|
+
DA:47,0
|
|
604
|
+
DA:49,0
|
|
605
|
+
DA:55,0
|
|
606
|
+
DA:56,0
|
|
607
|
+
LF:16
|
|
608
|
+
LH:0
|
|
609
|
+
BRDA:19,0,0,0
|
|
610
|
+
BRDA:19,0,1,0
|
|
611
|
+
BRDA:22,1,0,0
|
|
612
|
+
BRDA:22,1,1,0
|
|
613
|
+
BRDA:31,2,0,0
|
|
614
|
+
BRDA:31,2,1,0
|
|
615
|
+
BRDA:32,3,0,0
|
|
616
|
+
BRDA:32,3,1,0
|
|
617
|
+
BRDA:32,3,2,0
|
|
618
|
+
BRDA:32,3,3,0
|
|
619
|
+
BRDA:43,4,0,0
|
|
620
|
+
BRDA:43,4,1,0
|
|
621
|
+
BRDA:43,5,0,0
|
|
622
|
+
BRDA:43,5,1,0
|
|
623
|
+
BRDA:49,6,0,0
|
|
624
|
+
BRDA:49,6,1,0
|
|
625
|
+
BRDA:49,6,2,0
|
|
626
|
+
BRDA:49,6,3,0
|
|
627
|
+
BRDA:55,7,0,0
|
|
628
|
+
BRDA:55,7,1,0
|
|
629
|
+
BRF:20
|
|
630
|
+
BRH:0
|
|
631
|
+
end_of_record
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
declare namespace _default {
|
|
2
|
+
namespace meta {
|
|
3
|
+
let type: string;
|
|
4
|
+
namespace docs {
|
|
5
|
+
let description: string;
|
|
6
|
+
let category: string;
|
|
7
|
+
let recommended: boolean;
|
|
8
|
+
}
|
|
9
|
+
let fixable: string;
|
|
10
|
+
let schema: any[];
|
|
11
|
+
}
|
|
12
|
+
function create(context: any): {
|
|
13
|
+
PropertyDefinition(node: any): void;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export default _default;
|
package/dist/index.d.ts
CHANGED
|
@@ -101,6 +101,49 @@ declare namespace _default {
|
|
|
101
101
|
JSXOpeningElement(node: any): void;
|
|
102
102
|
};
|
|
103
103
|
};
|
|
104
|
+
'decorator-type-enforcement': {
|
|
105
|
+
meta: {
|
|
106
|
+
type: string;
|
|
107
|
+
docs: {
|
|
108
|
+
description: string;
|
|
109
|
+
category: string;
|
|
110
|
+
recommended: boolean;
|
|
111
|
+
};
|
|
112
|
+
fixable: string;
|
|
113
|
+
schema: any[];
|
|
114
|
+
};
|
|
115
|
+
create(context: any): {
|
|
116
|
+
PropertyDefinition(node: any): void;
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
'vuejs-define-component': {
|
|
120
|
+
meta: {
|
|
121
|
+
type: string;
|
|
122
|
+
docs: {
|
|
123
|
+
description: string;
|
|
124
|
+
recommended: boolean;
|
|
125
|
+
};
|
|
126
|
+
schema: any[];
|
|
127
|
+
};
|
|
128
|
+
create(context: any): {
|
|
129
|
+
ExportDefaultDeclaration(node: any): void;
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
'vuejs-define-workspace': {
|
|
133
|
+
meta: {
|
|
134
|
+
type: string;
|
|
135
|
+
docs: {
|
|
136
|
+
description: string;
|
|
137
|
+
recommended: boolean;
|
|
138
|
+
};
|
|
139
|
+
schema: any[];
|
|
140
|
+
};
|
|
141
|
+
create(context: any): {
|
|
142
|
+
ExportDefaultDeclaration?: undefined;
|
|
143
|
+
} | {
|
|
144
|
+
ExportDefaultDeclaration(node: any): void;
|
|
145
|
+
};
|
|
146
|
+
};
|
|
104
147
|
};
|
|
105
148
|
}
|
|
106
149
|
export default _default;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare namespace _default {
|
|
2
|
+
namespace meta {
|
|
3
|
+
let type: string;
|
|
4
|
+
namespace docs {
|
|
5
|
+
let description: string;
|
|
6
|
+
let recommended: boolean;
|
|
7
|
+
}
|
|
8
|
+
let schema: any[];
|
|
9
|
+
}
|
|
10
|
+
function create(context: any): {
|
|
11
|
+
ExportDefaultDeclaration(node: any): void;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export default _default;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
declare namespace _default {
|
|
2
|
+
namespace meta {
|
|
3
|
+
let type: string;
|
|
4
|
+
namespace docs {
|
|
5
|
+
let description: string;
|
|
6
|
+
let recommended: boolean;
|
|
7
|
+
}
|
|
8
|
+
let schema: any[];
|
|
9
|
+
}
|
|
10
|
+
function create(context: any): {
|
|
11
|
+
ExportDefaultDeclaration?: undefined;
|
|
12
|
+
} | {
|
|
13
|
+
ExportDefaultDeclaration(node: any): void;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export default _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tcy/eslint-rules",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "```typescript import { plugin as customRules } from 'tcy@eslint-rules/src/index.mjs';",
|
|
5
5
|
"homepage": "https://github.com/tcastelly/eslint-rules#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
"main": "src/index.js",
|
|
17
17
|
"types": "dist/index.d.ts",
|
|
18
18
|
"scripts": {
|
|
19
|
-
"clean": "rimraf dist",
|
|
20
19
|
"build:decl": "tsc",
|
|
20
|
+
"clean": "rimraf dist",
|
|
21
21
|
"prepublishOnly": "npm run clean && npm run test && npm run build:decl",
|
|
22
22
|
"test": "jest"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@babel/core": "^7.28.
|
|
26
|
-
"@babel/preset-env": "^7.28.
|
|
25
|
+
"@babel/core": "^7.28.6",
|
|
26
|
+
"@babel/preset-env": "^7.28.6",
|
|
27
27
|
"@types/jest": "^30.0.0",
|
|
28
28
|
"babel-jest": "^30.2.0",
|
|
29
29
|
"jest": "^30.2.0",
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
const unionContainsAllowedType = (typeNode, allowed) => {
|
|
2
|
+
if (typeNode.type === 'TSUnionType') {
|
|
3
|
+
return typeNode.types.some(
|
|
4
|
+
(t) => allowed.includes(t.type)
|
|
5
|
+
);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return allowed.includes(typeNode.type);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
meta: {
|
|
13
|
+
type: 'problem',
|
|
14
|
+
docs: {
|
|
15
|
+
description: 'Enforce property type based on decorator',
|
|
16
|
+
category: 'Stylistic Issues',
|
|
17
|
+
recommended: false,
|
|
18
|
+
},
|
|
19
|
+
fixable: 'code',
|
|
20
|
+
schema: [],
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
create(context) {
|
|
24
|
+
const sourceCode = context.getSourceCode();
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
PropertyDefinition(node) {
|
|
28
|
+
if (!node.decorators || !node.typeAnnotation) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
for (const decorator of node.decorators) {
|
|
33
|
+
const expr = decorator.expression;
|
|
34
|
+
|
|
35
|
+
if (expr.name === 'boolean') {
|
|
36
|
+
const typeNode = node.typeAnnotation.typeAnnotation;
|
|
37
|
+
|
|
38
|
+
// Only autofix simple, explicit types
|
|
39
|
+
if (typeNode.type === 'TSBooleanKeyword') {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
context.report({
|
|
44
|
+
node: typeNode,
|
|
45
|
+
message: 'Property decorated with @boolean must be of type "boolean"',
|
|
46
|
+
fix(fixer) {
|
|
47
|
+
return fixer.replaceText(typeNode, 'boolean');
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (expr.name === 'dbIntBoolean') {
|
|
53
|
+
const typeNode = node.typeAnnotation.typeAnnotation;
|
|
54
|
+
|
|
55
|
+
const allowedTypes = ['TSNumberKeyword', 'TSBooleanKeyword'];
|
|
56
|
+
|
|
57
|
+
const isValid = unionContainsAllowedType(typeNode, allowedTypes);
|
|
58
|
+
|
|
59
|
+
if (isValid) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
context.report({
|
|
64
|
+
node: typeNode,
|
|
65
|
+
message: 'Property decorated with @dbIntBoolean must be of type "number"',
|
|
66
|
+
fix(fixer) {
|
|
67
|
+
return fixer.replaceText(typeNode, 'boolean');
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
};
|
package/src/index.js
CHANGED
|
@@ -4,6 +4,9 @@ import exportSpecifiersPerLineRule from './export-specifiers-per-line.js';
|
|
|
4
4
|
import jsxExpressionStringLiterals from './jsx-expression-string-literals.js';
|
|
5
5
|
import enforceTailwindImportant from './enforce-tailwind-important.js';
|
|
6
6
|
import vModelNameMatch from './v-model-name-match.js';
|
|
7
|
+
import decoratorTypeEnforcement from './decorator-type-enforcement.js'
|
|
8
|
+
import vuejsDefineComponent from './vuejs-define-component.js'
|
|
9
|
+
import vuejsDefineWorkspace from './vuejs-define-workspace.js'
|
|
7
10
|
|
|
8
11
|
export default {
|
|
9
12
|
rules: {
|
|
@@ -13,5 +16,8 @@ export default {
|
|
|
13
16
|
'jsx-expression-string-literals': jsxExpressionStringLiterals,
|
|
14
17
|
'enforce-tailwind-important': enforceTailwindImportant,
|
|
15
18
|
'v-model-name-match': vModelNameMatch,
|
|
19
|
+
'decorator-type-enforcement': decoratorTypeEnforcement,
|
|
20
|
+
'vuejs-define-component': vuejsDefineComponent,
|
|
21
|
+
'vuejs-define-workspace': vuejsDefineWorkspace,
|
|
16
22
|
},
|
|
17
23
|
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
const attributesOrder = [
|
|
2
|
+
'name',
|
|
3
|
+
'route',
|
|
4
|
+
'inheritAttrs',
|
|
5
|
+
'directives',
|
|
6
|
+
'props',
|
|
7
|
+
'emits',
|
|
8
|
+
'render',
|
|
9
|
+
'setup',
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
export default {
|
|
13
|
+
meta: {
|
|
14
|
+
type: 'problem',
|
|
15
|
+
docs: {
|
|
16
|
+
description: 'Custom best practices in defineComponent',
|
|
17
|
+
recommended: false,
|
|
18
|
+
},
|
|
19
|
+
schema: [],
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
create(context) {
|
|
23
|
+
return {
|
|
24
|
+
ExportDefaultDeclaration(node) {
|
|
25
|
+
const decl = node.declaration;
|
|
26
|
+
|
|
27
|
+
// export default defineComponent(...)
|
|
28
|
+
if (
|
|
29
|
+
!decl ||
|
|
30
|
+
decl.type !== 'CallExpression' ||
|
|
31
|
+
decl.callee.type !== 'Identifier' ||
|
|
32
|
+
decl.callee.name !== 'defineComponent'
|
|
33
|
+
) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const arg = decl.arguments[0];
|
|
38
|
+
|
|
39
|
+
// defineComponent({ ... })
|
|
40
|
+
if (!arg || arg.type !== 'ObjectExpression') {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
const seenIndexes = [];
|
|
46
|
+
|
|
47
|
+
arg.properties.forEach((prop) => {
|
|
48
|
+
if (prop.type !== 'Property' || prop.computed) return;
|
|
49
|
+
if (prop.key.type !== 'Identifier') return;
|
|
50
|
+
|
|
51
|
+
const index = attributesOrder.indexOf(prop.key.name);
|
|
52
|
+
if (index !== -1) {
|
|
53
|
+
seenIndexes.push({
|
|
54
|
+
name: prop.key.name,
|
|
55
|
+
index,
|
|
56
|
+
node: prop,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// ---- name required ----
|
|
62
|
+
if (!seenIndexes.some((p) => p.name === 'name')) {
|
|
63
|
+
context.report({
|
|
64
|
+
node: arg,
|
|
65
|
+
message: 'Components defined with defineComponent must have a "name" property',
|
|
66
|
+
});
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// ---- order validation ----
|
|
71
|
+
for (let i = 1; i < seenIndexes.length; i++) {
|
|
72
|
+
const prev = seenIndexes[i - 1];
|
|
73
|
+
const curr = seenIndexes[i];
|
|
74
|
+
|
|
75
|
+
if (curr.index < prev.index) {
|
|
76
|
+
context.report({
|
|
77
|
+
node: curr.node,
|
|
78
|
+
message: `"${curr.name}" should appear before "${prev.name}" in defineComponent options`,
|
|
79
|
+
});
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
meta: {
|
|
5
|
+
type: 'problem',
|
|
6
|
+
docs: {
|
|
7
|
+
description:
|
|
8
|
+
'Require a route object in defineComponent for Workspace* and Page* files',
|
|
9
|
+
recommended: false,
|
|
10
|
+
},
|
|
11
|
+
schema: [],
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
create(context) {
|
|
15
|
+
const filename = context.getFilename();
|
|
16
|
+
const basename = path.basename(filename);
|
|
17
|
+
|
|
18
|
+
const requiresRoute =
|
|
19
|
+
basename.startsWith('Workspace') || basename.startsWith('Page');
|
|
20
|
+
|
|
21
|
+
// If filename doesn't match, do nothing
|
|
22
|
+
if (!requiresRoute) {
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
ExportDefaultDeclaration(node) {
|
|
28
|
+
const decl = node.declaration;
|
|
29
|
+
|
|
30
|
+
// export default defineComponent(...)
|
|
31
|
+
if (
|
|
32
|
+
!decl ||
|
|
33
|
+
decl.type !== 'CallExpression' ||
|
|
34
|
+
decl.callee.type !== 'Identifier' ||
|
|
35
|
+
decl.callee.name !== 'defineComponent'
|
|
36
|
+
) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const arg = decl.arguments[0];
|
|
41
|
+
|
|
42
|
+
// defineComponent({ ... })
|
|
43
|
+
if (!arg || arg.type !== 'ObjectExpression') {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const hasRoute = arg.properties.some(
|
|
48
|
+
(prop) =>
|
|
49
|
+
prop.type === 'Property' &&
|
|
50
|
+
!prop.computed &&
|
|
51
|
+
prop.key.type === 'Identifier' &&
|
|
52
|
+
prop.key.name === 'route'
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
if (!hasRoute) {
|
|
56
|
+
context.report({
|
|
57
|
+
node: arg,
|
|
58
|
+
message:
|
|
59
|
+
'Components in Workspace* or Page* files must define a "route" object',
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
};
|