-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnode-param-default-wrong-for-limit.ts
46 lines (41 loc) · 1.12 KB
/
node-param-default-wrong-for-limit.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
import { LIMIT_NODE_PARAMETER } 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: `\`default\` for a Limit node parameter must be \`${LIMIT_NODE_PARAMETER.DEFAULT_VALUE}\`.`,
recommended: "strict",
},
fixable: "code",
schema: [],
messages: {
setLimitDefault: `Set ${LIMIT_NODE_PARAMETER.DEFAULT_VALUE} as default [autofixable]`,
},
},
defaultOptions: [],
create(context) {
return {
ObjectExpression(node) {
if (!id.isNodeParameter(node)) return;
if (!id.nodeParam.isLimit(node)) return;
const _default = getters.nodeParam.getDefault(node);
if (!_default) return;
if (_default.value !== LIMIT_NODE_PARAMETER.DEFAULT_VALUE) {
context.report({
messageId: "setLimitDefault",
node: _default.ast,
fix: (fixer) =>
fixer.replaceText(
_default.ast,
`default: ${LIMIT_NODE_PARAMETER.DEFAULT_VALUE}`
),
});
}
},
};
},
});