-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnode-param-type-options-password-missing.ts
78 lines (65 loc) · 2.07 KB
/
node-param-type-options-password-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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { utils } from "../ast/utils";
import { getters } from "../ast/getters";
import {
FALSE_POSITIVE_NODE_SENSITIVE_PARAM_NAMES,
NODE_SENSITIVE_PARAM_NAMES,
} from "../constants";
const isFalsePositive = (paramName: string) =>
FALSE_POSITIVE_NODE_SENSITIVE_PARAM_NAMES.includes(paramName);
const isSensitive = (paramName: string) => {
if (isFalsePositive(paramName)) return false;
return NODE_SENSITIVE_PARAM_NAMES.some((sensitiveName) =>
paramName.toLowerCase().includes(sensitiveName.toLowerCase())
);
};
const sensitiveStrings = NODE_SENSITIVE_PARAM_NAMES.map((i) => `\`${i}\``).join(
","
);
export default utils.createRule({
name: utils.getRuleName(module),
meta: {
type: "problem",
docs: {
description: `In a sensitive string-type parameter, \`typeOptions.password\` must be set to \`true\` to obscure the input. A node parameter name is sensitive if it contains the strings: ${sensitiveStrings}. See exceptions in source.`,
recommended: "strict",
},
fixable: "code",
schema: [],
messages: {
addPasswordAutofixable:
"Add `typeOptions.password` with `true` [autofixable]",
addPasswordNonAutofixable:
"Add `typeOptions.password` with `true` [non-autofixable]",
},
},
defaultOptions: [],
create(context) {
return {
ObjectExpression(node) {
const name = getters.nodeParam.getName(node);
if (!name || !isSensitive(name.value)) return;
const type = getters.nodeParam.getType(node);
if (!type || type.value !== "string") return;
const typeOptions = getters.nodeParam.getTypeOptions(node);
if (typeOptions?.value.password === true) return;
if (typeOptions) {
return context.report({
messageId: "addPasswordNonAutofixable",
node: typeOptions.ast,
// @TODO: Autofix this case
});
}
const { indentation, range } = utils.getInsertionArgs(type);
context.report({
messageId: "addPasswordAutofixable",
node: type.ast,
fix: (fixer) =>
fixer.insertTextAfterRange(
range,
`\n${indentation}typeOptions: { password: true },`
),
});
},
};
},
});