From 301e2e4005f9a1f89b62ee9f38616685374aa327 Mon Sep 17 00:00:00 2001 From: David LJ Date: Tue, 12 Nov 2024 15:41:46 +0100 Subject: [PATCH] docs: add unique dependencies rule --- README.md | 22 +++++++++++----------- docs/rules/unique-dependencies.md | 25 +++++++++++++++++++++++++ src/rules/unique-dependencies.ts | 2 +- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 757093e0..7a62bf3c 100644 --- a/README.md +++ b/README.md @@ -113,17 +113,17 @@ The default settings don't conflict, and Prettier plugins can quickly fix up ord 🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).\ 💡 Manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions). -| Name                       | Description | 💼 | 🔧 | 💡 | -| :--------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------- | :- | :- | :- | -| [order-properties](docs/rules/order-properties.md) | Package properties must be declared in standard order | ✅ | 🔧 | | -| [repository-shorthand](docs/rules/repository-shorthand.md) | Enforce either object or shorthand declaration for repository. | ✅ | 🔧 | | -| [sort-collections](docs/rules/sort-collections.md) | Dependencies, scripts, and configuration values must be declared in alphabetical order. | ✅ | 🔧 | | -| [unique-dependencies](docs/rules/unique-dependencies.md) | Enforce that if repository directory is specified, it matches the path to the package.json file | ✅ | | 💡 | -| [valid-local-dependency](docs/rules/valid-local-dependency.md) | Checks existence of local dependencies in the package.json | ✅ | | | -| [valid-name](docs/rules/valid-name.md) | Enforce that package names are valid npm package names | ✅ | | | -| [valid-package-def](docs/rules/valid-package-def.md) | Enforce that package.json has all properties required by the npm spec | ✅ | | | -| [valid-repository-directory](docs/rules/valid-repository-directory.md) | Enforce that if repository directory is specified, it matches the path to the package.json file | ✅ | | 💡 | -| [valid-version](docs/rules/valid-version.md) | Enforce that package versions are valid semver specifiers | ✅ | | | +| Name                       | Description | 💼 | 🔧 | 💡 | +| :--------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------ | :- | :- | :- | +| [order-properties](docs/rules/order-properties.md) | Package properties must be declared in standard order | ✅ | 🔧 | | +| [repository-shorthand](docs/rules/repository-shorthand.md) | Enforce either object or shorthand declaration for repository. | ✅ | 🔧 | | +| [sort-collections](docs/rules/sort-collections.md) | Dependencies, scripts, and configuration values must be declared in alphabetical order. | ✅ | 🔧 | | +| [unique-dependencies](docs/rules/unique-dependencies.md) | Checks a dependency isn't specified more than once (i.e. in `dependencies` and `devDependencies`) | ✅ | | 💡 | +| [valid-local-dependency](docs/rules/valid-local-dependency.md) | Checks existence of local dependencies in the package.json | ✅ | | | +| [valid-name](docs/rules/valid-name.md) | Enforce that package names are valid npm package names | ✅ | | | +| [valid-package-def](docs/rules/valid-package-def.md) | Enforce that package.json has all properties required by the npm spec | ✅ | | | +| [valid-repository-directory](docs/rules/valid-repository-directory.md) | Enforce that if repository directory is specified, it matches the path to the package.json file | ✅ | | 💡 | +| [valid-version](docs/rules/valid-version.md) | Enforce that package versions are valid semver specifiers | ✅ | | | diff --git a/docs/rules/unique-dependencies.md b/docs/rules/unique-dependencies.md index 26ef6b44..82e47a1b 100644 --- a/docs/rules/unique-dependencies.md +++ b/docs/rules/unique-dependencies.md @@ -5,3 +5,28 @@ 💡 This rule is manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions). + +This rule checks that every dependency is just added once to a [`package.json` key specifying dependencies](/~https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/blob/main/src/rules/unique-dependencies.ts#L8-L16). + +Example of **incorrect** code for this rule: + +```json +{ + "dependencies": { + "foo": "1.0.0" + }, + "devDependencies": { + "foo": "1.0.0" + } +} +``` + +Example of **correct** code for this rule: + +```json +{ + "dependencies": { + "foo": "1.0.0" + } +} +``` diff --git a/src/rules/unique-dependencies.ts b/src/rules/unique-dependencies.ts index cf39d9be..1d7a564e 100644 --- a/src/rules/unique-dependencies.ts +++ b/src/rules/unique-dependencies.ts @@ -96,7 +96,7 @@ export const rule = createRule({ docs: { category: "Best Practices", description: - "Enforce that if repository directory is specified, it matches the path to the package.json file", + "Checks a dependency isn't specified more than once (i.e. in `dependencies` and `devDependencies`)", recommended: true, }, hasSuggestions: true,