-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcommunity-package-json-description-still-default.ts
52 lines (47 loc) · 1.38 KB
/
community-package-json-description-still-default.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
import { id } from "../ast/identifiers";
import { getters } from "../ast/getters";
import { utils } from "../ast/utils";
import { COMMUNITY_PACKAGE_JSON } from "../constants";
import { getDefaultValue } from "../ast/utils/defaultValue";
import { docline } from "../ast";
export default utils.createRule({
name: utils.getRuleName(module),
defaultOptions: [{ description: COMMUNITY_PACKAGE_JSON.DESCRIPTION }],
meta: {
type: "problem",
docs: {
description: docline`The \`description\` value in the \`package.json\` of a community package must be different from the default value ${COMMUNITY_PACKAGE_JSON.DESCRIPTION} or a user-defined default.`,
recommended: "strict",
},
schema: [
{
type: "object",
properties: {
description: {
type: "string",
},
},
additionalProperties: false,
},
],
messages: {
updateDescription: "Update the `description` key in package.json",
},
},
create(context, options) {
return {
ObjectExpression(node) {
if (!id.isCommunityPackageJson(context.getFilename(), node)) return;
const description = getters.communityPackageJson.getDescription(node);
if (!description) return;
const defaultDescription = getDefaultValue(options, "description");
if (description.value === defaultDescription) {
context.report({
messageId: "updateDescription",
node,
});
}
},
};
},
});