-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnode-param-description-empty-string.ts
46 lines (40 loc) · 1.29 KB
/
node-param-description-empty-string.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 { 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 or in option in options-type and multi-options-type param must be filled out or removed. ${DOCUMENTATION.APPLICABLE_BY_EXTENSION_TO_DESCRIPTION_IN_OPTION}`,
recommended: "strict",
},
schema: [],
fixable: "code",
messages: {
fillOutOrRemoveDescription:
"Fill out or remove description [autofixable]",
},
},
defaultOptions: [],
create(context) {
return {
ObjectExpression(node) {
if (!id.isNodeParameter(node) && !id.isOption(node)) return;
// to prevent overlap with node-param-description-wrong-for-dynamic-options
if (getters.nodeParam.getLoadOptionsMethod(node)) return;
const description = getters.nodeParam.getDescription(node);
if (!description) return;
if (description.value === "") {
const rangeToRemove = utils.getRangeToRemove(description);
context.report({
messageId: "fillOutOrRemoveDescription",
node: description.ast,
fix: (fixer) => fixer.removeRange(rangeToRemove),
});
}
},
};
},
});