forked from ivov/eslint-plugin-n8n-nodes-base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
community-package-json-author-name-missing.ts
50 lines (44 loc) · 1.16 KB
/
community-package-json-author-name-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
import { id } from "../ast/identifiers";
import { getters } from "../ast/getters";
import { utils } from "../ast/utils";
import { AST_NODE_TYPES, TSESTree } from "@typescript-eslint/utils";
export default utils.createRule({
name: utils.getRuleName(module),
meta: {
type: "problem",
docs: {
description:
"The `author.name` key must be present in the `package.json` of a community package.",
recommended: "error",
},
schema: [],
messages: {
addAuthorName: "Add an `author.name` key to package.json",
},
},
defaultOptions: [],
create(context) {
return {
ObjectExpression(node) {
if (!id.isCommunityPackageJson(context.getFilename(), node)) return;
const author = getters.communityPackageJson.getAuthor(node);
if (!author) return;
if (!hasAuthorName(author)) {
context.report({
messageId: "addAuthorName",
node,
});
}
},
};
},
});
function hasAuthorName(author: { ast: TSESTree.ObjectLiteralElement }) {
if (
author.ast.type === AST_NODE_TYPES.Property &&
author.ast.value.type === AST_NODE_TYPES.ObjectExpression
) {
return author.ast.value.properties.some(id.hasNameLiteral);
}
return false;
}