forked from ivov/eslint-plugin-n8n-nodes-base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode-param-placeholder-miscased-id.ts
54 lines (47 loc) · 1.34 KB
/
node-param-placeholder-miscased-id.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
import { MISCASED_ID_REGEX } 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:
"`ID` in `placeholder` in node parameter must be fully uppercased.",
recommended: "error",
},
fixable: "code",
schema: [],
messages: {
uppercaseId: "Use 'ID' [autofixable]",
},
},
defaultOptions: [],
create(context) {
return {
ObjectExpression(node) {
if (!id.isNodeParameter(node) && !id.isOption(node)) return;
const placeholder = getters.nodeParam.getPlaceholder(node);
if (!placeholder || isToleratedException(placeholder.value)) return;
if (MISCASED_ID_REGEX.test(placeholder.value)) {
const correctlyCased = placeholder.value
.replace(/\bid\b/i, "ID")
.replace(/\bids\b/i, "IDs");
const fixed = utils.keyValue("placeholder", correctlyCased);
context.report({
messageId: "uppercaseId",
node: placeholder.ast,
fix: (fixer) => fixer.replaceText(placeholder.ast, fixed),
});
}
},
};
},
});
function isToleratedException(placeholderValue: string) {
return (
placeholderValue.includes("SELECT") ||
placeholderValue.includes("id, name".replace(/\s/, ""))
);
}