Skip to content

Commit 99237f0

Browse files
authored
feat(require-keywords): add require-keywords rule (#884)
<!-- πŸ‘‹ Hi, thanks for sending a PR to eslint-plugin-package-json! πŸ’–. Please fill out all fields below and make sure each item is true and [x] checked. Otherwise we may not be able to review your PR. --> ## PR Checklist - [x] Addresses an existing open issue: fixes #866 - [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/blob/main/.github/CONTRIBUTING.md) were taken ## Overview <!-- Description of what is changed and how the code change does that. --> Add `require-keywords` rule
1 parent 93b3136 commit 99237f0

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

β€ŽREADME.md

+1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ The default settings don't conflict, and Prettier plugins can quickly fix up ord
127127
| [order-properties](docs/rules/order-properties.md) | Package properties must be declared in standard order | βœ… | πŸ”§ | | |
128128
| [repository-shorthand](docs/rules/repository-shorthand.md) | Enforce either object or shorthand declaration for repository. | βœ… | πŸ”§ | | |
129129
| [require-author](docs/rules/require-author.md) | Requires the `author` property to be present. | | | | |
130+
| [require-keywords](docs/rules/require-keywords.md) | Requires the `keywords` property to be present. | | | | |
130131
| [require-name](docs/rules/require-name.md) | Requires the `name` property to be present. | βœ… | | | |
131132
| [require-version](docs/rules/require-version.md) | Requires the `version` property to be present. | βœ… | | | |
132133
| [sort-collections](docs/rules/sort-collections.md) | Dependencies, scripts, and configuration values must be declared in alphabetical order. | βœ… | πŸ”§ | | |

β€Ždocs/rules/require-keywords.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# require-keywords
2+
3+
<!-- end auto-generated rule header -->
4+
5+
This rule checks for the existence of the `"keywords"` property in a package.json,
6+
and reports a violation if it doesn't exist.
7+
8+
Example of **incorrect** code for this rule:
9+
10+
```json
11+
{
12+
"name": "thee-silver-mt-zion",
13+
"version": "13.0.0"
14+
}
15+
```
16+
17+
Example of **correct** code for this rule:
18+
19+
```json
20+
{
21+
"name": "thee-silver-mt-zion",
22+
"version": "13.0.0",
23+
"keywords": ["eslint"]
24+
}
25+
```

β€Žsrc/rules/require-properties.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { createRequirePropertyRule } from "../utils/createRequirePropertyRule.js
66
// in the format [propertyName, isRecommended]
77
const properties = [
88
["author", false],
9+
["keywords", false],
910
["name", true],
1011
["version", true],
1112
// TODO: More to come!
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { rules } from "../../rules/require-properties.js";
2+
import { ruleTester } from "./ruleTester.js";
3+
4+
ruleTester.run("require-keywords", rules["require-keywords"], {
5+
invalid: [
6+
{
7+
code: "{}",
8+
errors: [
9+
{
10+
data: { property: "keywords" },
11+
line: 1,
12+
messageId: "missing",
13+
},
14+
],
15+
},
16+
{
17+
code: `{
18+
"version": "1.0.0"
19+
}
20+
`,
21+
errors: [
22+
{
23+
data: { property: "keywords" },
24+
line: 1,
25+
messageId: "missing",
26+
},
27+
],
28+
},
29+
{
30+
code: `{
31+
"author": "Jessica Moss",
32+
"bin": {
33+
"keywords": ["test"]
34+
}
35+
}
36+
`,
37+
errors: [
38+
{
39+
data: { property: "keywords" },
40+
line: 1,
41+
messageId: "missing",
42+
},
43+
],
44+
},
45+
],
46+
valid: [`{ "keywords": ["test"] }`],
47+
});

0 commit comments

Comments
Β (0)