Skip to content

Commit 4d802c5

Browse files
authored
feat!: add require-repository rule (#1491)
<!-- πŸ‘‹ 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 #867 - [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 Add repository to properties listed in `src/rules/require-properties.ts`.
1 parent 635696c commit 4d802c5

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed

β€ŽREADME.mdβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ The default settings don't conflict, and Prettier plugins can quickly fix up ord
227227
| [require-name](docs/rules/require-name.md) | Requires the `name` property to be present. | βœ”οΈ βœ… πŸ“¦ | | | |
228228
| [require-optionalDependencies](docs/rules/require-optionalDependencies.md) | Requires the `optionalDependencies` property to be present. | | | | |
229229
| [require-peerDependencies](docs/rules/require-peerDependencies.md) | Requires the `peerDependencies` property to be present. | | | | |
230+
| [require-repository](docs/rules/require-repository.md) | Requires the `repository` property to be present. | πŸ“¦ | | | |
230231
| [require-sideEffects](docs/rules/require-sideEffects.md) | Requires the `sideEffects` property to be present. | πŸ“¦ | | | |
231232
| [require-type](docs/rules/require-type.md) | Requires the `type` property to be present. | βœ”οΈ βœ… πŸ“¦ | | | |
232233
| [require-types](docs/rules/require-types.md) | Requires the `types` property to be present. | | | | |
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# require-repository
2+
3+
πŸ’Ό This rule is enabled in the πŸ“¦ `recommended-publishable` config.
4+
5+
<!-- end auto-generated rule header -->
6+
7+
This rule checks for the existence of the `"repository"` property in a package.json, and reports a violation if it doesn't exist.
8+
9+
Example of **incorrect** code for this rule:
10+
11+
```json
12+
{
13+
"name": "thee-silver-mt-zion",
14+
"version": "13.0.0"
15+
}
16+
```
17+
18+
Examples of **correct** code for this rule:
19+
20+
```json
21+
{
22+
"name": "thee-silver-mt-zion",
23+
"version": "13.0.0",
24+
"repository": "github:owner/project"
25+
}
26+
```
27+
28+
```json
29+
{
30+
"name": "thee-silver-mt-zion",
31+
"version": "13.0.0",
32+
"repository": {
33+
"type": "git",
34+
"url": "https://github.com/owner/project"
35+
}
36+
}
37+
```
38+
39+
## Options
40+
41+
<!-- begin auto-generated rule options list -->
42+
43+
| Name | Description | Type | Default |
44+
| :-------------- | :------------------------------------------------------------------------------------------ | :------ | :------ |
45+
| `ignorePrivate` | Determines if this rule should be enforced when the package's `private` property is `true`. | Boolean | `true` |
46+
47+
<!-- end auto-generated rule options list -->
48+
49+
You can set the `ignorePrivate` option to `true` to ignore package.json files with `"private": true` (default: `false`).
50+
51+
```json
52+
{
53+
"package-json/require-repository": [
54+
"error",
55+
{
56+
"ignorePrivate": false
57+
}
58+
]
59+
}
60+
```
61+
62+
Example of **incorrect** code for this rule with the `{ "ignorePrivate": false }` option:
63+
64+
```json
65+
{
66+
"private": true
67+
}
68+
```
69+
70+
Example of **correct** code for this rule with the `{ "ignorePrivate": false }` option:
71+
72+
```json
73+
{
74+
"private": true,
75+
"repository": "github:owner/project"
76+
}
77+
```
78+
79+
Example of **incorrect** code for this rule with the `{ "ignorePrivate": true }` option:
80+
81+
```json
82+
{
83+
"private": false
84+
}
85+
```
86+
87+
```json
88+
{}
89+
```
90+
91+
Example of **correct** code for this rule with the `{ "ignorePrivate": true }` option:
92+
93+
```json
94+
{
95+
"private": true
96+
}
97+
```

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const properties: [name: string, options?: CreateRequirePropertyRuleOptions][] =
2020
["name", { ignorePrivateDefault: true, isRecommended: true }],
2121
["optionalDependencies"],
2222
["peerDependencies"],
23+
["repository", { category: "Publishable", ignorePrivateDefault: true }],
2324
["sideEffects", { category: "Publishable" }],
2425
["type", { isRecommended: true }],
2526
["types"],

0 commit comments

Comments
Β (0)