diff --git a/README.md b/README.md index e6c12397..94f9699c 100644 --- a/README.md +++ b/README.md @@ -227,6 +227,7 @@ The default settings don't conflict, and Prettier plugins can quickly fix up ord | [require-name](docs/rules/require-name.md) | Requires the `name` property to be present. | ✔️ ✅ 📦 | | | | | [require-optionalDependencies](docs/rules/require-optionalDependencies.md) | Requires the `optionalDependencies` property to be present. | | | | | | [require-peerDependencies](docs/rules/require-peerDependencies.md) | Requires the `peerDependencies` property to be present. | | | | | +| [require-repository](docs/rules/require-repository.md) | Requires the `repository` property to be present. | 📦 | | | | | [require-sideEffects](docs/rules/require-sideEffects.md) | Requires the `sideEffects` property to be present. | 📦 | | | | | [require-type](docs/rules/require-type.md) | Requires the `type` property to be present. | ✔️ ✅ 📦 | | | | | [require-types](docs/rules/require-types.md) | Requires the `types` property to be present. | | | | | diff --git a/docs/rules/require-repository.md b/docs/rules/require-repository.md new file mode 100644 index 00000000..085470c7 --- /dev/null +++ b/docs/rules/require-repository.md @@ -0,0 +1,97 @@ +# require-repository + +💼 This rule is enabled in the 📦 `recommended-publishable` config. + + + +This rule checks for the existence of the `"repository"` property in a package.json, and reports a violation if it doesn't exist. + +Example of **incorrect** code for this rule: + +```json +{ + "name": "thee-silver-mt-zion", + "version": "13.0.0" +} +``` + +Examples of **correct** code for this rule: + +```json +{ + "name": "thee-silver-mt-zion", + "version": "13.0.0", + "repository": "github:owner/project" +} +``` + +```json +{ + "name": "thee-silver-mt-zion", + "version": "13.0.0", + "repository": { + "type": "git", + "url": "https://github.com/owner/project" + } +} +``` + +## Options + + + +| Name | Description | Type | Default | +| :-------------- | :------------------------------------------------------------------------------------------ | :------ | :------ | +| `ignorePrivate` | Determines if this rule should be enforced when the package's `private` property is `true`. | Boolean | `true` | + + + +You can set the `ignorePrivate` option to `true` to ignore package.json files with `"private": true` (default: `false`). + +```json +{ + "package-json/require-repository": [ + "error", + { + "ignorePrivate": false + } + ] +} +``` + +Example of **incorrect** code for this rule with the `{ "ignorePrivate": false }` option: + +```json +{ + "private": true +} +``` + +Example of **correct** code for this rule with the `{ "ignorePrivate": false }` option: + +```json +{ + "private": true, + "repository": "github:owner/project" +} +``` + +Example of **incorrect** code for this rule with the `{ "ignorePrivate": true }` option: + +```json +{ + "private": false +} +``` + +```json +{} +``` + +Example of **correct** code for this rule with the `{ "ignorePrivate": true }` option: + +```json +{ + "private": true +} +``` diff --git a/src/rules/require-properties.ts b/src/rules/require-properties.ts index 42da24b6..c9f00147 100644 --- a/src/rules/require-properties.ts +++ b/src/rules/require-properties.ts @@ -20,6 +20,7 @@ const properties: [name: string, options?: CreateRequirePropertyRuleOptions][] = ["name", { ignorePrivateDefault: true, isRecommended: true }], ["optionalDependencies"], ["peerDependencies"], + ["repository", { category: "Publishable", ignorePrivateDefault: true }], ["sideEffects", { category: "Publishable" }], ["type", { isRecommended: true }], ["types"],