eslint-plugin-package-json 0.50.0 → 0.52.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,11 +1,23 @@
1
1
  # Changelog
2
2
 
3
- # [0.50.0](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/compare/v0.49.0...v0.50.0) (2025-08-05)
3
+ # [0.52.0](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/compare/v0.51.0...v0.52.0) (2025-08-07)
4
+
5
+
6
+ ### Features
7
+
8
+ * **valid-description:** add new rule for validating `description` ([#1204](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/1204)) ([4acb265](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commit/4acb26563c0cacb5834c8b53dae68fb291c0ffd1)), closes [#823](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/823)
4
9
 
10
+ # [0.51.0](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/compare/v0.50.0...v0.51.0) (2025-08-05)
11
+
12
+ ### Features
13
+
14
+ - add `ignorePrivate` option to all `require-*` rules ([#1158](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/1158)) ([055009b](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commit/055009bf864c9f8db153bf0c5bb9568d023abe12)), closes [#1092](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/1092)
15
+
16
+ # [0.50.0](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/compare/v0.49.0...v0.50.0) (2025-08-05)
5
17
 
6
18
  ### Features
7
19
 
8
- * add new `require-` rules for `bugs`, `bundleDependencies`, `dependencies`, and more ([#1197](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/1197)) ([0a06664](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commit/0a0666404d5659ea8eb8717516aa3c3b6374af26)), closes [#862](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/862) [#863](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/863) [#811](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/811) [#809](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/809) [#801](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/801) [#797](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/797)
20
+ - add new `require-` rules for `bugs`, `bundleDependencies`, `dependencies`, and more ([#1197](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/1197)) ([0a06664](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commit/0a0666404d5659ea8eb8717516aa3c3b6374af26)), closes [#862](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/862) [#863](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/863) [#811](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/811) [#809](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/809) [#801](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/801) [#797](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/797)
9
21
 
10
22
  # [0.49.0](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/compare/v0.48.0...v0.49.0) (2025-08-05)
11
23
 
package/README.md CHANGED
@@ -101,6 +101,40 @@ module.exports = {
101
101
  };
102
102
  ```
103
103
 
104
+ ### Settings
105
+
106
+ Some rules can be configured in ESLint shared settings.
107
+ You can set them in `settings.packageJson` in an ESLint flat config.
108
+
109
+ Example:
110
+
111
+ ```ts
112
+ // eslint.config.ts
113
+ import packageJson from "eslint-plugin-package-json";
114
+
115
+ export default {
116
+ plugins: {
117
+ "package-json": packageJson,
118
+ },
119
+ rules: {
120
+ // `description` won't be required in package.json with `"private": true`
121
+ "package-json/require-description": "error",
122
+ },
123
+ settings: {
124
+ packageJson: {
125
+ enforceForPrivate: false,
126
+ },
127
+ },
128
+ };
129
+ ```
130
+
131
+ #### `enforceForPrivate`
132
+
133
+ **Type:** `boolean`
134
+
135
+ Determines whether `require-*` rules, if used, should enforce the presence of the corresponding property in package.json files with `"private": true`.
136
+ By default, all `require-*` rules except for [`require-name`](docs/rules/require-name.md) and [`require-version`](docs/rules/require-version.md) will report if the corresponding property is missing in package.json with `"private": true`.
137
+
104
138
  ### Usage Alongside Prettier
105
139
 
106
140
  **[`prettier-plugin-packagejson`](https://github.com/matzkoh/prettier-plugin-packagejson)** is a [Prettier plugin](https://prettier.io/docs/en/plugins) that enforces the same `package.json` keys ordering as the [`order-properties`](docs/rules/order-properties.md) and [sort-collections](docs/rules/sort-collections.md) rules with default options.
@@ -149,6 +183,7 @@ The default settings don't conflict, and Prettier plugins can quickly fix up ord
149
183
  | [valid-config](docs/rules/valid-config.md) | Enforce that the `config` property is valid. | ✔️ ✅ | | | |
150
184
  | [valid-cpu](docs/rules/valid-cpu.md) | Enforce that the `cpu` property is valid. | ✔️ ✅ | | | |
151
185
  | [valid-dependencies](docs/rules/valid-dependencies.md) | Enforce that the `dependencies` property is valid. | ✔️ ✅ | | | |
186
+ | [valid-description](docs/rules/valid-description.md) | Enforce that the `description` property is valid. | ✔️ ✅ | | | |
152
187
  | [valid-devDependencies](docs/rules/valid-devDependencies.md) | Enforce that the `devDependencies` property is valid. | ✔️ ✅ | | | |
153
188
  | [valid-license](docs/rules/valid-license.md) | Enforce that the `license` property is valid. | ✔️ ✅ | | | |
154
189
  | [valid-local-dependency](docs/rules/valid-local-dependency.md) | Checks existence of local dependencies in the package.json | | | | ❌ |
@@ -212,7 +247,7 @@ Thanks! 🗂
212
247
  <td align="center" valign="top" width="14.28%"><a href="https://davidlj95.com"><img src="https://avatars.githubusercontent.com/u/8050648?v=4?s=100" width="100px;" alt="David LJ"/><br /><sub><b>David LJ</b></sub></a><br /><a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commits?author=davidlj95" title="Documentation">📖</a></td>
213
248
  <td align="center" valign="top" width="14.28%"><a href="http://lishaduck.github.io"><img src="https://avatars.githubusercontent.com/u/88557639?v=4?s=100" width="100px;" alt="Eli"/><br /><sub><b>Eli</b></sub></a><br /><a href="#ideas-lishaduck" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues?q=author%3Alishaduck" title="Bug reports">🐛</a></td>
214
249
  <td align="center" valign="top" width="14.28%"><a href="http://heggria.site"><img src="https://avatars.githubusercontent.com/u/34475327?v=4?s=100" width="100px;" alt="Heggria"/><br /><sub><b>Heggria</b></sub></a><br /><a href="#ideas-heggria" title="Ideas, Planning, & Feedback">🤔</a></td>
215
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/Zamiell"><img src="https://avatars.githubusercontent.com/u/5511220?v=4?s=100" width="100px;" alt="James"/><br /><sub><b>James</b></sub></a><br /><a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commits?author=Zamiell" title="Code">💻</a></td>
250
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/Zamiell"><img src="https://avatars.githubusercontent.com/u/5511220?v=4?s=100" width="100px;" alt="James"/><br /><sub><b>James</b></sub></a><br /><a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commits?author=Zamiell" title="Code">💻</a> <a href="#ideas-Zamiell" title="Ideas, Planning, & Feedback">🤔</a></td>
216
251
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/zetlen"><img src="https://avatars.githubusercontent.com/u/1643758?v=4?s=100" width="100px;" alt="James Zetlen"/><br /><sub><b>James Zetlen</b></sub></a><br /><a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commits?author=zetlen" title="Code">💻</a> <a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues?q=author%3Azetlen" title="Bug reports">🐛</a> <a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commits?author=zetlen" title="Documentation">📖</a> <a href="#infra-zetlen" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#maintenance-zetlen" title="Maintenance">🚧</a> <a href="#tool-zetlen" title="Tools">🔧</a></td>
217
252
  <td align="center" valign="top" width="14.28%"><a href="https://piranna.github.io/"><img src="https://avatars.githubusercontent.com/u/532414?v=4?s=100" width="100px;" alt="Jesús Leganés-Combarro"/><br /><sub><b>Jesús Leganés-Combarro</b></sub></a><br /><a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commits?author=piranna" title="Code">💻</a></td>
218
253
  <td align="center" valign="top" width="14.28%"><a href="http://www.joshuakgoldberg.com/"><img src="https://avatars.githubusercontent.com/u/3335181?v=4?s=100" width="100px;" alt="Josh Goldberg ✨"/><br /><sub><b>Josh Goldberg ✨</b></sub></a><br /><a href="#tool-JoshuaKGoldberg" title="Tools">🔧</a> <a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues?q=author%3AJoshuaKGoldberg" title="Bug reports">🐛</a> <a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commits?author=JoshuaKGoldberg" title="Code">💻</a> <a href="#infra-JoshuaKGoldberg" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commits?author=JoshuaKGoldberg" title="Documentation">📖</a> <a href="#maintenance-JoshuaKGoldberg" title="Maintenance">🚧</a> <a href="#ideas-JoshuaKGoldberg" title="Ideas, Planning, & Feedback">🤔</a> <a href="#content-JoshuaKGoldberg" title="Content">🖋</a> <a href="#projectManagement-JoshuaKGoldberg" title="Project Management">📆</a></td>
@@ -14,8 +14,20 @@ interface JsonAstBodyStatement extends ESTree.ExpressionStatement {
14
14
  interface PackageJsonAst extends AST$1.Program {
15
15
  body: [JsonAstBodyStatement];
16
16
  }
17
+ interface PackageJsonPluginSettings {
18
+ /**
19
+ * Whether `require-*` rules, if used, should enforce the presence of
20
+ * the corresponding property *in package.json files with `"private": true`*.
21
+ *
22
+ * If not specified, it will not enforce the presence only of `name` and `version` properties.
23
+ */
24
+ enforceForPrivate?: boolean;
25
+ }
17
26
  interface PackageJsonRuleContext<Options extends unknown[] = unknown[]> extends Rule.RuleContext {
18
27
  options: Options;
28
+ settings: {
29
+ packageJson?: PackageJsonPluginSettings;
30
+ };
19
31
  sourceCode: PackageJsonSourceCode;
20
32
  }
21
33
  interface PackageJsonRuleModule<Options extends unknown[] = unknown[]> {
@@ -30,4 +42,4 @@ declare function createRule<Options extends unknown[]>(rule: PackageJsonRuleModu
30
42
  meta: Rule.RuleMetaData;
31
43
  };
32
44
 
33
- export { type JsonAstBodyExpression, type JsonAstBodyProperty, type JsonAstBodyStatement, type PackageJsonAst, type PackageJsonRuleContext, type PackageJsonRuleModule, type PackageJsonSourceCode, createRule };
45
+ export { type JsonAstBodyExpression, type JsonAstBodyProperty, type JsonAstBodyStatement, type PackageJsonAst, type PackageJsonPluginSettings, type PackageJsonRuleContext, type PackageJsonRuleModule, type PackageJsonSourceCode, createRule };
package/lib/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as jsonc_eslint_parser from 'jsonc-eslint-parser';
2
2
  import { PackageJsonRuleModule } from './createRule.js';
3
+ export { PackageJsonPluginSettings } from './createRule.js';
3
4
  import { plugin } from './plugin.js';
4
5
  import 'estree';
5
6
  import 'eslint';
@@ -1,9 +1,15 @@
1
- import { PackageJsonRuleModule } from '../createRule.js';
1
+ import * as eslint from 'eslint';
2
+ import * as jsonc_eslint_parser from 'jsonc-eslint-parser';
3
+ import { PackageJsonRuleContext } from '../createRule.js';
2
4
  import 'estree';
3
- import 'eslint';
4
- import 'jsonc-eslint-parser';
5
5
 
6
- /** All require- flavor rules */
7
- declare const rules: Record<string, PackageJsonRuleModule<unknown[]>>;
6
+ declare const rules: {
7
+ [k: string]: {
8
+ create(context: PackageJsonRuleContext<[({
9
+ ignorePrivate?: boolean;
10
+ } | undefined)?]>): jsonc_eslint_parser.RuleListener;
11
+ meta: eslint.Rule.RuleMetaData;
12
+ };
13
+ };
8
14
 
9
15
  export { rules };
@@ -1,31 +1,28 @@
1
- import { createSimpleRequirePropertyRule } from "../utils/createSimpleRequirePropertyRule.js";
1
+ import {
2
+ createSimpleRequirePropertyRule
3
+ } from "../utils/createSimpleRequirePropertyRule.js";
2
4
  const properties = [
3
- ["author", false],
4
- ["bugs", false],
5
- ["bundleDependencies", false],
6
- ["dependencies", false],
7
- ["devDependencies", false],
8
- ["description", true],
9
- ["engines", false],
10
- ["files", false],
11
- ["keywords", false],
12
- ["name", true],
13
- ["optionalDependencies", false],
14
- ["peerDependencies", false],
15
- ["type", true],
16
- ["types", false],
17
- ["version", true]
18
- // TODO: More to come!
5
+ ["author"],
6
+ ["bugs"],
7
+ ["bundleDependencies"],
8
+ ["dependencies"],
9
+ ["description", { isRecommended: true }],
10
+ ["devDependencies"],
11
+ ["engines"],
12
+ ["files"],
13
+ ["keywords"],
14
+ ["name", { ignorePrivateDefault: true, isRecommended: true }],
15
+ ["optionalDependencies"],
16
+ ["peerDependencies"],
17
+ ["type", { isRecommended: true }],
18
+ ["types"],
19
+ ["version", { ignorePrivateDefault: true, isRecommended: true }]
19
20
  ];
20
- const rules = properties.reduce(
21
- (acc, [propertyName, isRecommended]) => {
22
- acc[`require-${propertyName}`] = createSimpleRequirePropertyRule(
23
- propertyName,
24
- isRecommended
25
- );
26
- return acc;
27
- },
28
- {}
21
+ const rules = Object.fromEntries(
22
+ properties.map(([propertyName, options]) => [
23
+ `require-${propertyName}`,
24
+ createSimpleRequirePropertyRule(propertyName, options)
25
+ ])
29
26
  );
30
27
  export {
31
28
  rules
@@ -4,6 +4,7 @@ import {
4
4
  validateConfig,
5
5
  validateCpu,
6
6
  validateDependencies,
7
+ validateDescription,
7
8
  validateLicense,
8
9
  validateScripts,
9
10
  validateType
@@ -23,6 +24,7 @@ const properties = [
23
24
  ["config", validateConfig],
24
25
  ["cpu", validateCpu],
25
26
  ["dependencies", validateDependencies],
27
+ ["description", validateDescription],
26
28
  ["devDependencies", validateDependencies],
27
29
  ["license", validateLicense],
28
30
  ["optionalDependencies", validateDependencies],
@@ -3,15 +3,28 @@ import * as jsonc_eslint_parser from 'jsonc-eslint-parser';
3
3
  import { PackageJsonRuleContext } from '../createRule.js';
4
4
  import 'estree';
5
5
 
6
+ interface CreateRequirePropertyRuleOptions {
7
+ /**
8
+ * The default value of `ignorePrivate` rule option.
9
+ */
10
+ ignorePrivateDefault?: boolean;
11
+ /**
12
+ * Whether the rule should be included in the recommended config.
13
+ */
14
+ isRecommended?: boolean;
15
+ }
16
+ type Options = [{
17
+ ignorePrivate?: boolean;
18
+ }?];
6
19
  /**
7
20
  * Given a top-level property name, create a rule that requires that property to be present.
8
21
  * Optionally, include it in the recommended config.
9
22
  * Note: this will only create a basic require rule, with no options. If you need
10
23
  * to create a more complex rule, create it in its own file.
11
24
  */
12
- declare const createSimpleRequirePropertyRule: (propertyName: string, isRecommended?: boolean) => {
13
- create(context: PackageJsonRuleContext<unknown[]>): jsonc_eslint_parser.RuleListener;
25
+ declare const createSimpleRequirePropertyRule: (propertyName: string, { ignorePrivateDefault, isRecommended, }?: CreateRequirePropertyRuleOptions) => {
26
+ create(context: PackageJsonRuleContext<Options>): jsonc_eslint_parser.RuleListener;
14
27
  meta: eslint.Rule.RuleMetaData;
15
28
  };
16
29
 
17
- export { createSimpleRequirePropertyRule };
30
+ export { type CreateRequirePropertyRuleOptions, createSimpleRequirePropertyRule };
@@ -1,10 +1,20 @@
1
1
  import { createRule } from "../createRule.js";
2
2
  import { isJSONStringLiteral } from "./predicates.js";
3
- const createSimpleRequirePropertyRule = (propertyName, isRecommended = false) => {
3
+ const createSimpleRequirePropertyRule = (propertyName, {
4
+ ignorePrivateDefault = false,
5
+ isRecommended
6
+ } = {}) => {
4
7
  return createRule({
5
8
  create(context) {
9
+ const enforceForPrivate = context.settings.packageJson?.enforceForPrivate;
10
+ const ignorePrivate = context.options[0]?.ignorePrivate ?? (typeof enforceForPrivate === "boolean" ? !enforceForPrivate : ignorePrivateDefault);
6
11
  return {
7
12
  "Program > JSONExpressionStatement > JSONObjectExpression"(node) {
13
+ if (ignorePrivate && node.properties.some(
14
+ (property) => isJSONStringLiteral(property.key) && property.key.value === "private" && property.value.type === "JSONLiteral" && property.value.value === true
15
+ )) {
16
+ return;
17
+ }
8
18
  if (!node.properties.some(
9
19
  (property) => isJSONStringLiteral(property.key) && property.key.value === propertyName
10
20
  )) {
@@ -25,7 +35,18 @@ const createSimpleRequirePropertyRule = (propertyName, isRecommended = false) =>
25
35
  messages: {
26
36
  missing: "Property '{{property}}' is required."
27
37
  },
28
- schema: [],
38
+ schema: [
39
+ {
40
+ additionalProperties: false,
41
+ properties: {
42
+ ignorePrivate: {
43
+ default: ignorePrivateDefault,
44
+ type: "boolean"
45
+ }
46
+ },
47
+ type: "object"
48
+ }
49
+ ],
29
50
  type: "suggestion"
30
51
  }
31
52
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-package-json",
3
- "version": "0.50.0",
3
+ "version": "0.52.0",
4
4
  "description": "Rules for consistent, readable, and valid package.json files. 🗂️",
5
5
  "homepage": "https://github.com/JoshuaKGoldberg/eslint-plugin-package-json#readme",
6
6
  "bugs": {
@@ -49,7 +49,7 @@
49
49
  "detect-indent": "^7.0.1",
50
50
  "detect-newline": "^4.0.1",
51
51
  "eslint-fix-utils": "~0.4.0",
52
- "package-json-validator": "~0.25.0",
52
+ "package-json-validator": "~0.27.0",
53
53
  "semver": "^7.5.4",
54
54
  "sort-object-keys": "^1.1.3",
55
55
  "sort-package-json": "^3.0.0",
@@ -93,7 +93,7 @@
93
93
  "release-it": "19.0.1",
94
94
  "sentences-per-line": "0.3.0",
95
95
  "tsup": "8.5.0",
96
- "typescript": "5.8.2",
96
+ "typescript": "5.9.2",
97
97
  "typescript-eslint": "8.38.0",
98
98
  "vitest": "3.2.0"
99
99
  },
@@ -101,7 +101,7 @@
101
101
  "eslint": ">=8.0.0",
102
102
  "jsonc-eslint-parser": "^2.0.0"
103
103
  },
104
- "packageManager": "pnpm@10.13.0",
104
+ "packageManager": "pnpm@10.14.0",
105
105
  "engines": {
106
106
  "node": "^=20.19.0 || >=22.12.0"
107
107
  },