forked from ivov/eslint-plugin-n8n-nodes-base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcred-class-field-documentation-url-missing.ts
57 lines (47 loc) · 1.33 KB
/
cred-class-field-documentation-url-missing.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
56
57
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:
"`documentationUrl` field in credential class must be present.",
recommended: "error",
},
fixable: "code",
schema: [],
messages: {
addDocumentationUrl: "Add `documentationUrl` [autofixable]",
},
},
defaultOptions: [],
create(context) {
return {
ClassDeclaration(node) {
if (!id.isCredentialClass(node)) return;
const { body: classBody } = node;
const documentationUrl =
getters.credClassBody.getDocumentationUrl(classBody);
if (!documentationUrl) {
const displayName = getters.credClassBody.getDisplayName(classBody); // insertion point
if (!displayName) return;
const className = getters.credClassBody.getName(classBody);
if (!className) return;
const { indentation, range } = utils.getInsertionArgs(displayName);
const fixed = className.value.replace(/(OAuth2)?Api/g, "");
context.report({
messageId: "addDocumentationUrl",
node: classBody,
fix: (fixer) =>
fixer.insertTextAfterRange(
range,
`\n${indentation}documentationUrl = '${fixed}';`
),
});
}
},
};
},
});