Skip to content

Commit 92325bc

Browse files
committed
docs: provide more examples
1 parent 7269e63 commit 92325bc

File tree

1 file changed

+76
-3
lines changed

1 file changed

+76
-3
lines changed

docs/rules/restrict-dependency-ranges.md

+76-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@ of semver range (e.g. `^`). There are several options for specifying which depen
99
a range type restriction should be applied to, including dependency type,
1010
package name (or name regex pattern), and version range (e.g. '<1').
1111

12+
```ts
13+
export default [
14+
{
15+
"package-json/restrict-dependency-ranges": [
16+
"error",
17+
// Require that packages with 0.x.x versions are pinned
18+
{
19+
forVersions: "<1",
20+
rangeType: "pin",
21+
},
22+
],
23+
},
24+
];
25+
```
26+
1227
If you provide multiple options and a dependency matches more than one of the
1328
options, the last option that matches will take precedent for that dependency.
1429
This allows you to define more general rules that apply to all dependencies (or large
@@ -23,8 +38,8 @@ or focus on some subset of dependencies.
2338
| Name | Type | Required |
2439
| :------------------- | :----------------------- | :------- |
2540
| `forDependencyTypes` | DependencyType[] | |
26-
| `forPackages` | String[] | |
27-
| `forVersions` | String | |
41+
| `forPackages` | string[] | |
42+
| `forVersions` | string | |
2843
| `rangeType` | RangeType \| RangeType[] | Yes |
2944

3045
You can provide a single options object consisting of the above, or an array
@@ -42,23 +57,81 @@ Options are
4257
- optionalDependencies
4358
- peerDependencies
4459

60+
```ts
61+
export default [
62+
{
63+
"package-json/restrict-dependency-ranges": [
64+
"error",
65+
// Require that all dev dependencies are pinned
66+
{
67+
forDependencyTypes: ["devDependencies"],
68+
rangeType: "pin",
69+
},
70+
],
71+
},
72+
];
73+
```
74+
4575
### `forPackages`
4676

4777
This can be the exact name of a package, or a regex pattern used to match a
4878
group of packages by name (e.g. `@typescript-eslint/*`).
4979

80+
```ts
81+
export default [
82+
{
83+
"package-json/restrict-dependency-ranges": [
84+
"error",
85+
// Restrict typescript to tilde ranges
86+
{
87+
forPackages: "typescript",
88+
rangeType: "tilde",
89+
},
90+
],
91+
},
92+
];
93+
```
94+
5095
### `forVersions`
5196

5297
You can use this to apply a restriction to a specific semver range. For example,
5398
a common use case is to pin "unstable" dependencies (packages that have
5499
a version in the `0.x.x` range). You can do this by setting `forVersions` to `'<1'`.
55100

101+
```ts
102+
export default [
103+
{
104+
"package-json/restrict-dependency-ranges": [
105+
"error",
106+
// Require that all deps should use ^
107+
{
108+
rangeType: "caret",
109+
},
110+
],
111+
},
112+
];
113+
```
114+
56115
### `rangeType`
57116

58117
This is the only required option, and identifies which range type or types you
59118
want to apply to packages that match any of the other match options (or all
60119
dependencies if no other options are provided).
61120

121+
```ts
122+
export default [
123+
{
124+
"package-json/restrict-dependency-ranges": [
125+
"error",
126+
// Require that all deps should use ^
127+
{
128+
rangeType: "caret",
129+
},
130+
],
131+
},
132+
];
133+
```
134+
62135
## Example
63136

64137
```ts
@@ -78,7 +151,7 @@ export default [
78151
rangeType: "tilde",
79152
},
80153

81-
// Require packages that have 0.x.x versions are pinned
154+
// Require that packages with 0.x.x versions are pinned
82155
{
83156
forVersions: "<1",
84157
rangeType: "pin",

0 commit comments

Comments
 (0)