@living-architecture/riviere-extract-conventions 0.2.0 → 0.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@living-architecture/riviere-extract-conventions",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -16,14 +16,22 @@
|
|
|
16
16
|
"import": "./dist/index.js",
|
|
17
17
|
"default": "./dist/index.js"
|
|
18
18
|
},
|
|
19
|
-
"./default-config": "./src/default-extraction.config.json"
|
|
19
|
+
"./default-config": "./src/default-extraction.config.json",
|
|
20
|
+
"./eslint-plugin": {
|
|
21
|
+
"types": "./src/eslint/index.d.ts",
|
|
22
|
+
"require": "./src/eslint/index.cjs",
|
|
23
|
+
"default": "./src/eslint/index.cjs"
|
|
24
|
+
}
|
|
20
25
|
},
|
|
21
26
|
"files": [
|
|
22
27
|
"dist",
|
|
23
28
|
"src/default-extraction.config.json",
|
|
29
|
+
"src/eslint/*.cjs",
|
|
30
|
+
"src/eslint/*.d.ts",
|
|
31
|
+
"src/eslint/*.d.cts",
|
|
24
32
|
"!**/*.tsbuildinfo"
|
|
25
33
|
],
|
|
26
34
|
"dependencies": {
|
|
27
|
-
"@living-architecture/riviere-extract-config": "0.1.
|
|
35
|
+
"@living-architecture/riviere-extract-config": "0.1.4"
|
|
28
36
|
}
|
|
29
37
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const COMPONENT_DECORATORS = [
|
|
2
|
+
'DomainOpContainer',
|
|
3
|
+
'APIContainer',
|
|
4
|
+
'EventHandlerContainer',
|
|
5
|
+
'UseCase',
|
|
6
|
+
'Event',
|
|
7
|
+
'UI',
|
|
8
|
+
'Ignore',
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
const CALL_EXPRESSION_DECORATORS = ['Custom']
|
|
12
|
+
|
|
13
|
+
function getDecoratorName(expression) {
|
|
14
|
+
if (expression.type === 'Identifier') {
|
|
15
|
+
return expression.name
|
|
16
|
+
}
|
|
17
|
+
if (expression.type === 'CallExpression' && expression.callee.type === 'Identifier') {
|
|
18
|
+
return expression.callee.name
|
|
19
|
+
}
|
|
20
|
+
return null
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function hasComponentDecorator(decorators) {
|
|
24
|
+
return decorators.some((decorator) => {
|
|
25
|
+
const name = getDecoratorName(decorator.expression)
|
|
26
|
+
if (name === null) return false
|
|
27
|
+
return COMPONENT_DECORATORS.includes(name) || CALL_EXPRESSION_DECORATORS.includes(name)
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = {
|
|
32
|
+
meta: {
|
|
33
|
+
type: 'problem',
|
|
34
|
+
docs: { description: 'Require classes to have a component decorator' },
|
|
35
|
+
schema: [],
|
|
36
|
+
messages: {
|
|
37
|
+
missingDecorator:
|
|
38
|
+
"Class '{{className}}' requires a component decorator. Add one of: @UseCase, @Event, @UI, @DomainOpContainer, @APIContainer, @EventHandlerContainer, @Custom('type'), or @Ignore",
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
create(context) {
|
|
42
|
+
return {
|
|
43
|
+
ClassDeclaration(node) {
|
|
44
|
+
if (!node.id) return
|
|
45
|
+
if (hasComponentDecorator(node.decorators)) return
|
|
46
|
+
|
|
47
|
+
context.report({
|
|
48
|
+
node: node.id,
|
|
49
|
+
messageId: 'missingDecorator',
|
|
50
|
+
data: { className: node.id.name },
|
|
51
|
+
})
|
|
52
|
+
},
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
}
|