Skip to content

Commit 7626cd9

Browse files
authored
feat: add require-packageManager rule (#1620)
<!-- πŸ‘‹ 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 #1546 - [x] That issue was marked as [`status: accepting prs`](https://github.com/michaelfaith/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/michaelfaith/eslint-plugin-package-json/blob/main/.github/CONTRIBUTING.md) were taken ## Overview This change adds a new rule to require the `packageManager` property is present.
1 parent ded1928 commit 7626cd9

File tree

4 files changed

+88
-3
lines changed

4 files changed

+88
-3
lines changed

β€Ž.github/workflows/ci.ymlβ€Ž

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ jobs:
6868
node-version: ${{ matrix.node-version }}
6969
- run: pnpm install -D eslint@${{ matrix.eslint-version }}
7070
- run: pnpm run test --coverage
71-
- env:
72-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
71+
- uses: codecov/codecov-action@v5
7372
if: always()
74-
uses: codecov/codecov-action@v5
73+
env:
74+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
75+
7576
type_check:
7677
name: Type Check (ESLint ${{ matrix.eslint-version }})
7778
runs-on: ubuntu-latest

β€ŽREADME.mdβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ The default settings don't conflict, and Prettier plugins can quickly fix up ord
230230
| [require-license](docs/rules/require-license.md) | Requires the `license` property to be present. | βœ”οΈ βœ… πŸ“¦ | | | |
231231
| [require-name](docs/rules/require-name.md) | Requires the `name` property to be present. | βœ”οΈ βœ… πŸ“¦ | | | |
232232
| [require-optionalDependencies](docs/rules/require-optionalDependencies.md) | Requires the `optionalDependencies` property to be present. | | | | |
233+
| [require-packageManager](docs/rules/require-packageManager.md) | Requires the `packageManager` property to be present. | | | | |
233234
| [require-peerDependencies](docs/rules/require-peerDependencies.md) | Requires the `peerDependencies` property to be present. | | | | |
234235
| [require-repository](docs/rules/require-repository.md) | Requires the `repository` property to be present. | βœ”οΈ βœ… πŸ“¦ | | | |
235236
| [require-scripts](docs/rules/require-scripts.md) | Requires the `scripts` property to be present. | | | | |
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# require-packageManager
2+
3+
<!-- end auto-generated rule header -->
4+
5+
This rule checks for the existence of the `packageManager` property in a package.json, and reports a violation if it doesn't exist.
6+
7+
Example of **incorrect** code for this rule:
8+
9+
```json
10+
{
11+
"name": "thee-silver-mt-zion",
12+
"version": "13.0.0"
13+
}
14+
```
15+
16+
Example of **correct** code for this rule:
17+
18+
```json
19+
{
20+
"name": "thee-silver-mt-zion",
21+
"version": "13.0.0",
22+
"packageManager": "pnpm@10.30.0"
23+
}
24+
```
25+
26+
## Options
27+
28+
<!-- begin auto-generated rule options list -->
29+
30+
| Name | Description | Type | Default |
31+
| :-------------- | :------------------------------------------------------------------------------------------ | :------ | :------ |
32+
| `ignorePrivate` | Determines if this rule should be enforced when the package's `private` property is `true`. | Boolean | `false` |
33+
34+
<!-- end auto-generated rule options list -->
35+
36+
```json
37+
{
38+
"package-json/require-packageManager": [
39+
"error",
40+
{
41+
"ignorePrivate": true
42+
}
43+
]
44+
}
45+
```
46+
47+
Example of **incorrect** code for this rule with the `{ "ignorePrivate": false }` option:
48+
49+
```json
50+
{
51+
"private": true
52+
}
53+
```
54+
55+
Example of **correct** code for this rule with the `{ "ignorePrivate": false }` option:
56+
57+
```json
58+
{
59+
"private": true,
60+
"packageManager": "pnpm@10.30.0"
61+
}
62+
```
63+
64+
Example of **incorrect** code for this rule with the `{ "ignorePrivate": true }` option:
65+
66+
```json
67+
{
68+
"private": false
69+
}
70+
```
71+
72+
```json
73+
{}
74+
```
75+
76+
Example of **correct** code for this rule with the `{ "ignorePrivate": true }` option:
77+
78+
```json
79+
{
80+
"private": true
81+
}
82+
```

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const propertyConfig: [
2121
["license", { ignorePrivateDefault: true, isRecommended: true }],
2222
["name", { ignorePrivateDefault: true, isRecommended: true }],
2323
["optionalDependencies"],
24+
["packageManager"],
2425
["peerDependencies"],
2526
["repository", { ignorePrivateDefault: true, isRecommended: true }],
2627
["scripts"],

0 commit comments

Comments
Β (0)