forked from ivov/eslint-plugin-n8n-nodes-base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cred-class-field-unobscured-sensitive-input.ts
51 lines (42 loc) · 1.21 KB
/
cred-class-field-unobscured-sensitive-input.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
import { utils } from "../ast/utils";
import { getters } from "../ast/getters";
const SENSITIVE_INPUT_NAMES = ['password', 'accessToken', 'apiKey'];
export default utils.createRule({
name: utils.getRuleName(module),
meta: {
type: "problem",
docs: {
description:
"`typeOptions.password` must be set to `true` in a sensitive node parameter, to obscure the input.",
recommended: "error",
},
fixable: 'code',
schema: [],
messages: {
addTypeOptionsPassword: "Add `typeOptions.password` [autofixable]",
},
},
defaultOptions: [],
create(context) {
return {
ObjectExpression(node) {
const name = getters.nodeParam.getName(node);
if (!name || !SENSITIVE_INPUT_NAMES.includes(name.value)) return;
const typeOptions = getters.nodeParam.getTypeOptions(node);
if (typeOptions?.value.password === true) return;
const type = getters.nodeParam.getType(node);
if (!type) return;
const { indentation, range } = utils.getInsertionArgs(type);
context.report({
messageId: "addTypeOptionsPassword",
node: type.ast,
fix: (fixer) =>
fixer.insertTextAfterRange(
range,
`\n${indentation}typeOptions: { password: true },`
),
});
},
};
},
});