forked from ivov/eslint-plugin-n8n-nodes-base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode-param-description-url-missing-protocol.ts
49 lines (44 loc) · 1.3 KB
/
node-param-description-url-missing-protocol.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
import { DOCUMENTATION } 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 node parameter must include protocol e.g. \`https://\` when containing a URL. ${DOCUMENTATION.APPLICABLE_BY_EXTENSION_TO_DESCRIPTION_IN_OPTION}`,
recommended: "error",
},
fixable: "code",
schema: [],
messages: {
addProtocol: "Prepend 'https://' [autofixable]",
},
},
defaultOptions: [],
create(context) {
return {
ObjectExpression(node) {
if (!id.isNodeParameter(node) && !id.isOption(node)) return;
const description = getters.nodeParam.getDescription(node);
if (!description) return;
if (
/<a href=/.test(description.value) &&
!/href=["']https:\/\//.test(description.value) // opinionated: https, not http
) {
const withProtocol = description.value.replace(
/href=(['"])/g,
'href=\$1https://'
);
const fixed = utils.keyValue("description", withProtocol);
context.report({
messageId: "addProtocol",
node: description.ast,
fix: (fixer) => fixer.replaceText(description.ast, fixed),
});
}
},
};
},
});