forked from ivov/eslint-plugin-n8n-nodes-base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node-param-description-missing-from-dynamic-options.ts
55 lines (46 loc) · 1.38 KB
/
node-param-description-missing-from-dynamic-options.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { DYNAMIC_OPTIONS_NODE_PARAMETER } from "../constants";
import { utils } from "../ast/utils";
import { id } from "../ast/identifiers";
import { getters } from "../ast/getters";
export default utils.createRule({
name: utils.getRuleName(module),
meta: {
type: "problem",
docs: {
description:
"`description` in dynamic-options-type node parameter must be present.",
recommended: "error",
},
schema: [],
fixable: "code",
messages: {
addStandardDescription: `Add description: '${DYNAMIC_OPTIONS_NODE_PARAMETER.DESCRIPTION}' [autofixable]`,
},
},
defaultOptions: [],
create(context) {
return {
ObjectExpression(node) {
if (!id.isNodeParameter(node)) return;
if (!id.nodeParam.isOptionsType(node)) return;
const loadOptionsMethod = getters.nodeParam.getLoadOptionsMethod(node);
if (!loadOptionsMethod) return;
const description = getters.nodeParam.getDescription(node);
if (!description) {
const type = getters.nodeParam.getType(node); // insertion point
if (!type) return;
const { range, indentation } = utils.getInsertionArgs(type);
context.report({
messageId: "addStandardDescription",
node: type.ast,
fix: (fixer) =>
fixer.insertTextAfterRange(
range,
`\n${indentation}description: '${DYNAMIC_OPTIONS_NODE_PARAMETER.DESCRIPTION}',`
),
});
}
},
};
},
});