eslint-plugin-package-json 0.88.0 → 0.88.2
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 +19 -0
- package/README.md +2 -1
- package/lib/plugin.mjs +9 -9
- package/lib/rules/require-properties.d.mts +3 -1
- package/lib/rules/require-properties.mjs +8 -4
- package/lib/utils/createSimpleRequirePropertyRule.d.mts +3 -0
- package/lib/utils/createSimpleRequirePropertyRule.mjs +6 -1
- package/package.json +13 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.88.2](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/compare/v0.88.1...v0.88.2) (2026-01-23)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **require-type:** add auto-fix ([#1534](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/1534)) ([c8e44e4](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commit/c8e44e472ac94fc61e0f79e00e4ac2f371718d38))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **deps:** update dependency package-json-validator to ~0.60.0 ([#1513](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/1513)) ([5b300b6](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commit/5b300b64c52c233b5835b1fda1815551ac0f77b6))
|
|
14
|
+
|
|
15
|
+
## [0.88.1](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/compare/v0.88.0...v0.88.1) (2026-01-07)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
* add require-scripts rule ([#1505](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/1505)) ([f326161](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commit/f326161f63a812c5a3c92a914d17d9ef6fc5dbd2))
|
|
21
|
+
|
|
3
22
|
## [0.88.0](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/compare/v0.87.1...v0.88.0) (2026-01-04)
|
|
4
23
|
|
|
5
24
|
|
package/README.md
CHANGED
|
@@ -228,8 +228,9 @@ The default settings don't conflict, and Prettier plugins can quickly fix up ord
|
|
|
228
228
|
| [require-optionalDependencies](docs/rules/require-optionalDependencies.md) | Requires the `optionalDependencies` property to be present. | | | | |
|
|
229
229
|
| [require-peerDependencies](docs/rules/require-peerDependencies.md) | Requires the `peerDependencies` property to be present. | | | | |
|
|
230
230
|
| [require-repository](docs/rules/require-repository.md) | Requires the `repository` property to be present. | 📦 | | | |
|
|
231
|
+
| [require-scripts](docs/rules/require-scripts.md) | Requires the `scripts` property to be present. | | | | |
|
|
231
232
|
| [require-sideEffects](docs/rules/require-sideEffects.md) | Requires the `sideEffects` property to be present. | 📦 | | | |
|
|
232
|
-
| [require-type](docs/rules/require-type.md) | Requires the `type` property to be present. | ✔️ ✅ 📦 |
|
|
233
|
+
| [require-type](docs/rules/require-type.md) | Requires the `type` property to be present. | ✔️ ✅ 📦 | 🔧 | | |
|
|
233
234
|
| [require-types](docs/rules/require-types.md) | Requires the `types` property to be present. | | | | |
|
|
234
235
|
| [require-version](docs/rules/require-version.md) | Requires the `version` property to be present. | ✔️ ✅ 📦 | | | |
|
|
235
236
|
| [restrict-dependency-ranges](docs/rules/restrict-dependency-ranges.md) | Restricts the range of dependencies to allow or disallow specific types of ranges. | | | 💡 | |
|
package/lib/plugin.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { rule as rule$4 } from "./rules/no-redundant-publishConfig.mjs";
|
|
|
6
6
|
import { rule as rule$5 } from "./rules/order-properties.mjs";
|
|
7
7
|
import { rule as rule$6 } from "./rules/repository-shorthand.mjs";
|
|
8
8
|
import { rule as rule$7 } from "./rules/require-attribution.mjs";
|
|
9
|
-
import { rules } from "./rules/require-properties.mjs";
|
|
9
|
+
import { rules as rules$1 } from "./rules/require-properties.mjs";
|
|
10
10
|
import { rule as rule$8 } from "./rules/restrict-dependency-ranges.mjs";
|
|
11
11
|
import { rule as rule$9 } from "./rules/restrict-private-properties.mjs";
|
|
12
12
|
import { rule as rule$10 } from "./rules/scripts-name-casing.mjs";
|
|
@@ -15,7 +15,7 @@ import { rule as rule$12 } from "./rules/specify-peers-locally.mjs";
|
|
|
15
15
|
import { rule as rule$13 } from "./rules/unique-dependencies.mjs";
|
|
16
16
|
import { rule as rule$14 } from "./rules/valid-name.mjs";
|
|
17
17
|
import { rule as rule$15 } from "./rules/valid-package-definition.mjs";
|
|
18
|
-
import { rules as rules$
|
|
18
|
+
import { rules as rules$2 } from "./rules/valid-properties.mjs";
|
|
19
19
|
import { rule as rule$16 } from "./rules/valid-repository-directory.mjs";
|
|
20
20
|
import { rule as rule$17 } from "./rules/valid-version.mjs";
|
|
21
21
|
import { createRequire } from "node:module";
|
|
@@ -23,7 +23,7 @@ import * as parserJsonc from "jsonc-eslint-parser";
|
|
|
23
23
|
|
|
24
24
|
//#region src/plugin.ts
|
|
25
25
|
const require = createRequire(import.meta.url);
|
|
26
|
-
const rules
|
|
26
|
+
const rules = {
|
|
27
27
|
"bin-name-casing": rule,
|
|
28
28
|
"exports-subpaths-style": rule$1,
|
|
29
29
|
"no-empty-fields": rule$2,
|
|
@@ -31,7 +31,7 @@ const rules$2 = {
|
|
|
31
31
|
"no-redundant-publishConfig": rule$4,
|
|
32
32
|
"order-properties": rule$5,
|
|
33
33
|
"require-attribution": rule$7,
|
|
34
|
-
...rules,
|
|
34
|
+
...rules$1,
|
|
35
35
|
"repository-shorthand": rule$6,
|
|
36
36
|
"restrict-dependency-ranges": rule$8,
|
|
37
37
|
"restrict-private-properties": rule$9,
|
|
@@ -39,18 +39,18 @@ const rules$2 = {
|
|
|
39
39
|
"sort-collections": rule$11,
|
|
40
40
|
"specify-peers-locally": rule$12,
|
|
41
41
|
"unique-dependencies": rule$13,
|
|
42
|
-
...rules$
|
|
42
|
+
...rules$2,
|
|
43
43
|
"valid-name": rule$14,
|
|
44
44
|
"valid-package-definition": rule$15,
|
|
45
45
|
"valid-repository-directory": rule$16,
|
|
46
46
|
"valid-version": rule$17
|
|
47
47
|
};
|
|
48
|
-
const recommendedRules = { ...Object.fromEntries(Object.entries(rules
|
|
48
|
+
const recommendedRules = { ...Object.fromEntries(Object.entries(rules).filter(([, rule$18]) => rule$18.meta.docs?.recommended).map(([name$1]) => ["package-json/" + name$1, "error"])) };
|
|
49
49
|
const recommendedPublishableRules = {
|
|
50
50
|
...recommendedRules,
|
|
51
|
-
...Object.fromEntries(Object.entries(rules
|
|
51
|
+
...Object.fromEntries(Object.entries(rules).filter(([, rule$18]) => rule$18.meta.docs?.category === "Publishable").map(([name$1]) => ["package-json/" + name$1, "error"]))
|
|
52
52
|
};
|
|
53
|
-
const stylisticRules = { ...Object.fromEntries(Object.entries(rules
|
|
53
|
+
const stylisticRules = { ...Object.fromEntries(Object.entries(rules).filter(([, rule$18]) => rule$18.meta.docs?.category === "Stylistic").map(([name$1]) => ["package-json/" + name$1, "error"])) };
|
|
54
54
|
const { name, version } = require("../package.json");
|
|
55
55
|
const plugin = {
|
|
56
56
|
configs: {
|
|
@@ -90,7 +90,7 @@ const plugin = {
|
|
|
90
90
|
name,
|
|
91
91
|
version
|
|
92
92
|
},
|
|
93
|
-
rules
|
|
93
|
+
rules
|
|
94
94
|
};
|
|
95
95
|
|
|
96
96
|
//#endregion
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { PackageJsonRuleModule } from "../createRule.mjs";
|
|
2
|
+
import { CreateRequirePropertyRuleOptions } from "../utils/createSimpleRequirePropertyRule.mjs";
|
|
2
3
|
|
|
3
4
|
//#region src/rules/require-properties.d.ts
|
|
5
|
+
declare const propertyConfig: [name: string, options?: CreateRequirePropertyRuleOptions][];
|
|
4
6
|
declare const rules: {
|
|
5
7
|
[k: string]: PackageJsonRuleModule<[({
|
|
6
8
|
ignorePrivate: boolean;
|
|
@@ -17,4 +19,4 @@ declare const rules: {
|
|
|
17
19
|
}]>;
|
|
18
20
|
};
|
|
19
21
|
//#endregion
|
|
20
|
-
export { rules };
|
|
22
|
+
export { propertyConfig, rules };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createSimpleRequirePropertyRule } from "../utils/createSimpleRequirePropertyRule.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/rules/require-properties.ts
|
|
4
|
-
const
|
|
4
|
+
const propertyConfig = [
|
|
5
5
|
["author"],
|
|
6
6
|
["bugs"],
|
|
7
7
|
["bundleDependencies"],
|
|
@@ -27,18 +27,22 @@ const properties = [
|
|
|
27
27
|
category: "Publishable",
|
|
28
28
|
ignorePrivateDefault: true
|
|
29
29
|
}],
|
|
30
|
+
["scripts"],
|
|
30
31
|
["sideEffects", { category: "Publishable" }],
|
|
31
|
-
["type", {
|
|
32
|
+
["type", {
|
|
33
|
+
fixValue: "commonjs",
|
|
34
|
+
isRecommended: true
|
|
35
|
+
}],
|
|
32
36
|
["types"],
|
|
33
37
|
["version", {
|
|
34
38
|
ignorePrivateDefault: true,
|
|
35
39
|
isRecommended: true
|
|
36
40
|
}]
|
|
37
41
|
];
|
|
38
|
-
const rules = Object.fromEntries(
|
|
42
|
+
const rules = Object.fromEntries(propertyConfig.map(([propertyName, options]) => {
|
|
39
43
|
const { rule, ruleName } = createSimpleRequirePropertyRule(propertyName, options);
|
|
40
44
|
return [ruleName, rule];
|
|
41
45
|
}));
|
|
42
46
|
|
|
43
47
|
//#endregion
|
|
44
|
-
export { rules };
|
|
48
|
+
export { propertyConfig, rules };
|
|
@@ -6,6 +6,8 @@ interface CreateRequirePropertyRuleOptions {
|
|
|
6
6
|
* The category for this rule.
|
|
7
7
|
*/
|
|
8
8
|
category?: "Publishable" | (string & {});
|
|
9
|
+
/** The value to use when fixing a violation when this property is missing */
|
|
10
|
+
fixValue?: unknown;
|
|
9
11
|
/**
|
|
10
12
|
* The default value of `ignorePrivate` rule option.
|
|
11
13
|
*/
|
|
@@ -23,6 +25,7 @@ interface CreateRequirePropertyRuleOptions {
|
|
|
23
25
|
*/
|
|
24
26
|
declare const createSimpleRequirePropertyRule: (propertyName: string, {
|
|
25
27
|
category,
|
|
28
|
+
fixValue,
|
|
26
29
|
ignorePrivateDefault,
|
|
27
30
|
isRecommended
|
|
28
31
|
}?: CreateRequirePropertyRuleOptions) => {
|
|
@@ -8,7 +8,7 @@ import { isJSONStringLiteral } from "./predicates.mjs";
|
|
|
8
8
|
* Note: this will only create a basic require rule, with no options. If you need
|
|
9
9
|
* to create a more complex rule, create it in its own file.
|
|
10
10
|
*/
|
|
11
|
-
const createSimpleRequirePropertyRule = (propertyName, { category, ignorePrivateDefault = false, isRecommended } = {}) => {
|
|
11
|
+
const createSimpleRequirePropertyRule = (propertyName, { category, fixValue, ignorePrivateDefault = false, isRecommended } = {}) => {
|
|
12
12
|
const ruleName = `require-${propertyName}`;
|
|
13
13
|
return {
|
|
14
14
|
rule: createRule({
|
|
@@ -19,6 +19,10 @@ const createSimpleRequirePropertyRule = (propertyName, { category, ignorePrivate
|
|
|
19
19
|
if (ignorePrivate && node.properties.some((property) => isJSONStringLiteral(property.key) && property.key.value === "private" && property.value.type === "JSONLiteral" && property.value.value === true)) return;
|
|
20
20
|
if (!node.properties.some((property) => isJSONStringLiteral(property.key) && property.key.value === propertyName)) context.report({
|
|
21
21
|
data: { property: propertyName },
|
|
22
|
+
fix: fixValue === void 0 ? void 0 : function* (fixer) {
|
|
23
|
+
yield fixer.insertTextAfterRange([0, 1], `\n "${propertyName}": ${JSON.stringify(fixValue)}`);
|
|
24
|
+
yield node.properties.length > 0 ? fixer.insertTextAfterRange([0, 1], ",") : fixer.insertTextAfterRange([0, 1], "\n");
|
|
25
|
+
},
|
|
22
26
|
messageId: "missing",
|
|
23
27
|
node: context.sourceCode.ast
|
|
24
28
|
});
|
|
@@ -30,6 +34,7 @@ const createSimpleRequirePropertyRule = (propertyName, { category, ignorePrivate
|
|
|
30
34
|
description: `Requires the \`${propertyName}\` property to be present.`,
|
|
31
35
|
recommended: isRecommended
|
|
32
36
|
},
|
|
37
|
+
fixable: fixValue === void 0 ? void 0 : "code",
|
|
33
38
|
messages: { missing: "Property '{{property}}' is required." },
|
|
34
39
|
schema: [{
|
|
35
40
|
additionalProperties: false,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-package-json",
|
|
3
|
-
"version": "0.88.
|
|
3
|
+
"version": "0.88.2",
|
|
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,14 +49,14 @@
|
|
|
49
49
|
"detect-indent": "^7.0.2",
|
|
50
50
|
"detect-newline": "^4.0.1",
|
|
51
51
|
"eslint-fix-utils": "~0.4.0",
|
|
52
|
-
"package-json-validator": "~0.
|
|
52
|
+
"package-json-validator": "~0.60.0",
|
|
53
53
|
"semver": "^7.7.3",
|
|
54
54
|
"sort-object-keys": "^2.0.0",
|
|
55
55
|
"sort-package-json": "^3.4.0",
|
|
56
56
|
"validate-npm-package-name": "^7.0.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@eslint-community/eslint-plugin-eslint-comments": "4.
|
|
59
|
+
"@eslint-community/eslint-plugin-eslint-comments": "4.6.0",
|
|
60
60
|
"@eslint/js": "9.39.1",
|
|
61
61
|
"@eslint/markdown": "7.5.1",
|
|
62
62
|
"@types/estree": "1.0.8",
|
|
@@ -67,30 +67,30 @@
|
|
|
67
67
|
"@vitest/eslint-plugin": "1.6.1",
|
|
68
68
|
"console-fail-test": "0.6.0",
|
|
69
69
|
"eslint": "9.39.1",
|
|
70
|
-
"eslint-doc-generator": "
|
|
71
|
-
"eslint-plugin-eslint-plugin": "7.
|
|
72
|
-
"eslint-plugin-jsdoc": "
|
|
70
|
+
"eslint-doc-generator": "3.0.2",
|
|
71
|
+
"eslint-plugin-eslint-plugin": "7.3.0",
|
|
72
|
+
"eslint-plugin-jsdoc": "62.3.0",
|
|
73
73
|
"eslint-plugin-jsonc": "2.21.0",
|
|
74
74
|
"eslint-plugin-markdown-links": "0.7.1",
|
|
75
75
|
"eslint-plugin-n": "17.23.1",
|
|
76
76
|
"eslint-plugin-node-dependencies": "1.3.0",
|
|
77
|
-
"eslint-plugin-perfectionist": "5.
|
|
77
|
+
"eslint-plugin-perfectionist": "5.3.0",
|
|
78
78
|
"eslint-plugin-regexp": "2.10.0",
|
|
79
79
|
"eslint-plugin-unicorn": "62.0.0",
|
|
80
|
-
"eslint-plugin-yml": "
|
|
80
|
+
"eslint-plugin-yml": "3.0.0",
|
|
81
81
|
"husky": "9.1.7",
|
|
82
82
|
"jiti": "2.6.1",
|
|
83
83
|
"json-schema-to-ts": "3.1.1",
|
|
84
84
|
"jsonc-eslint-parser": "2.4.1",
|
|
85
|
-
"knip": "5.
|
|
85
|
+
"knip": "5.82.0",
|
|
86
86
|
"lint-staged": "16.2.7",
|
|
87
|
-
"prettier": "3.
|
|
87
|
+
"prettier": "3.8.0",
|
|
88
88
|
"prettier-plugin-curly": "0.4.0",
|
|
89
|
-
"prettier-plugin-packagejson": "
|
|
89
|
+
"prettier-plugin-packagejson": "3.0.0",
|
|
90
90
|
"prettier-plugin-sh": "0.18.0",
|
|
91
|
-
"tsdown": "0.
|
|
91
|
+
"tsdown": "0.19.0",
|
|
92
92
|
"typescript": "5.9.3",
|
|
93
|
-
"typescript-eslint": "8.
|
|
93
|
+
"typescript-eslint": "8.53.0",
|
|
94
94
|
"vitest": "4.0.13"
|
|
95
95
|
},
|
|
96
96
|
"peerDependencies": {
|