eslint-plugin-package-json 0.52.0 → 0.52.1

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,17 @@
1
1
  # Changelog
2
2
 
3
- # [0.52.0](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/compare/v0.51.0...v0.52.0) (2025-08-07)
3
+ ## [0.52.1](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/compare/v0.52.0...v0.52.1) (2025-08-07)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **sort-collections:** align sorting of scripts with `prettier-plugin-packagejson` ([#1203](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/1203)) ([1f5c590](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commit/1f5c590adc846194766127ab962f8efa72942d06)), closes [#753](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/753)
4
9
 
10
+ # [0.52.0](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/compare/v0.51.0...v0.52.0) (2025-08-07)
5
11
 
6
12
  ### Features
7
13
 
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)
14
+ - **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)
9
15
 
10
16
  # [0.51.0](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/compare/v0.50.0...v0.51.0) (2025-08-05)
11
17
 
@@ -90,6 +90,7 @@ const rule = createRule({
90
90
  };
91
91
  },
92
92
  meta: {
93
+ defaultOptions: [{ ignoreProperties: [] }],
93
94
  docs: {
94
95
  category: "Best Practices",
95
96
  description: "Reports on unnecessary empty arrays and objects.",
@@ -106,6 +107,7 @@ const rule = createRule({
106
107
  additionalProperties: false,
107
108
  properties: {
108
109
  ignoreProperties: {
110
+ description: "Array of top-level properties to ignore.",
109
111
  items: {
110
112
  type: "string"
111
113
  },
@@ -85,6 +85,7 @@ const rule = createRule({
85
85
  };
86
86
  },
87
87
  meta: {
88
+ defaultOptions: [{ order: "sort-package-json" }],
88
89
  docs: {
89
90
  category: "Best Practices",
90
91
  description: "Package properties must be declared in standard order",
@@ -110,7 +111,8 @@ const rule = createRule({
110
111
  },
111
112
  type: ["array"]
112
113
  }
113
- ]
114
+ ],
115
+ description: "Specifies the sorting order of top-level properties."
114
116
  }
115
117
  },
116
118
  type: "object"
@@ -89,6 +89,7 @@ const rule = createRule({
89
89
  };
90
90
  },
91
91
  meta: {
92
+ defaultOptions: [{ form: "object" }],
92
93
  docs: {
93
94
  category: "Best Practices",
94
95
  description: "Enforce either object or shorthand declaration for repository.",
@@ -104,6 +105,7 @@ const rule = createRule({
104
105
  additionalProperties: false,
105
106
  properties: {
106
107
  form: {
108
+ description: "Specifies which repository form to enforce.",
107
109
  enum: ["object", "shorthand"],
108
110
  type: ["string"]
109
111
  }
@@ -12,21 +12,25 @@ const schemaOptions = {
12
12
  additionalProperties: false,
13
13
  properties: {
14
14
  forDependencyTypes: {
15
+ description: "Apply a range type restriction for an entire group of dependencies by which type of dependencies they belong to.",
15
16
  items: {
16
17
  enum: DEPENDENCY_TYPES
17
18
  },
18
19
  type: "array"
19
20
  },
20
21
  forPackages: {
22
+ description: "The exact name of a package, or a regex pattern used to match a group of packages by name.",
21
23
  items: {
22
24
  type: "string"
23
25
  },
24
26
  type: "array"
25
27
  },
26
28
  forVersions: {
29
+ description: "Apply a restriction to a specific semver range.",
27
30
  type: "string"
28
31
  },
29
32
  rangeType: {
33
+ description: "Identifies which range type or types you want to apply to packages that match any of the other match options (or all dependencies if no other options are provided).",
30
34
  oneOf: [
31
35
  {
32
36
  enum: RANGE_TYPES
@@ -176,6 +180,7 @@ const rule = createRule({
176
180
  };
177
181
  },
178
182
  meta: {
183
+ defaultOptions: [[]],
179
184
  docs: {
180
185
  description: "Restricts the range of dependencies to allow or disallow specific types of ranges."
181
186
  },
@@ -191,6 +196,7 @@ const rule = createRule({
191
196
  oneOf: [
192
197
  schemaOptions,
193
198
  {
199
+ description: "Array of configuration options, specifying range requirements.",
194
200
  items: schemaOptions,
195
201
  type: "array"
196
202
  }
@@ -1,3 +1,4 @@
1
+ import sortPackageJson from "sort-package-json";
1
2
  import { createRule } from "../createRule.js";
2
3
  const defaultCollections = /* @__PURE__ */ new Set([
3
4
  "config",
@@ -37,38 +38,27 @@ const rule = createRule({
37
38
  return;
38
39
  }
39
40
  const currentOrder = collection.properties;
40
- const properties = new Set(
41
- currentOrder.map(
42
- (prop) => prop.key.value
43
- )
44
- );
45
- const desiredOrder = currentOrder.slice().sort((a, b) => {
46
- let aKey = a.key.value;
47
- let bKey = b.key.value;
48
- if (keyPartsReversed.at(-1) !== "scripts") {
41
+ let desiredOrder;
42
+ if (keyPartsReversed.at(-1) !== "scripts") {
43
+ desiredOrder = currentOrder.slice().sort((a, b) => {
44
+ const aKey = a.key.value;
45
+ const bKey = b.key.value;
49
46
  return aKey > bKey ? 1 : -1;
50
- } else {
51
- let modifier = 0;
52
- if (aKey.startsWith("pre") && properties.has(aKey.substring(3))) {
53
- aKey = aKey.substring(3);
54
- modifier -= 1;
55
- } else if (aKey.startsWith("post") && properties.has(aKey.substring(4))) {
56
- aKey = aKey.substring(4);
57
- modifier += 1;
58
- }
59
- if (bKey.startsWith("pre") && properties.has(bKey.substring(3))) {
60
- bKey = bKey.substring(3);
61
- modifier += 1;
62
- } else if (bKey.startsWith("post") && properties.has(bKey.substring(4))) {
63
- bKey = bKey.substring(4);
64
- modifier -= 1;
65
- }
66
- if (aKey === bKey) {
67
- return modifier;
68
- }
69
- return aKey > bKey ? 1 : -1;
70
- }
71
- });
47
+ });
48
+ } else {
49
+ const scriptsSource = context.sourceCode.getText(node);
50
+ const minimalJson = JSON.parse(`{${scriptsSource}}`);
51
+ const { scripts: sortedScripts } = sortPackageJson(minimalJson);
52
+ const propertyNodeMap = Object.fromEntries(
53
+ collection.properties.map((prop) => [
54
+ prop.key.value,
55
+ prop
56
+ ])
57
+ );
58
+ desiredOrder = Object.keys(sortedScripts).map(
59
+ (prop) => propertyNodeMap[prop]
60
+ );
61
+ }
72
62
  if (currentOrder.some(
73
63
  (property, i) => desiredOrder[i] !== property
74
64
  )) {
@@ -103,6 +93,7 @@ const rule = createRule({
103
93
  };
104
94
  },
105
95
  meta: {
96
+ defaultOptions: [Array.from(defaultCollections)],
106
97
  docs: {
107
98
  category: "Best Practices",
108
99
  description: "Dependencies, scripts, and configuration values must be declared in alphabetical order.",
@@ -114,6 +105,7 @@ const rule = createRule({
114
105
  },
115
106
  schema: [
116
107
  {
108
+ description: "Array of package properties to require sorting.",
117
109
  items: {
118
110
  type: "string"
119
111
  },
@@ -51,6 +51,7 @@ const rule = createRule({
51
51
  };
52
52
  },
53
53
  meta: {
54
+ defaultOptions: [{ enforceCase: false }],
54
55
  docs: {
55
56
  category: "Best Practices",
56
57
  description: "Enforce that the `bin` property is valid.",
@@ -67,7 +68,7 @@ const rule = createRule({
67
68
  additionalProperties: false,
68
69
  properties: {
69
70
  enforceCase: {
70
- default: false,
71
+ description: "Enforce that the bin's keys should be in kebab case.",
71
72
  type: "boolean"
72
73
  }
73
74
  },
@@ -29,6 +29,7 @@ const rule = createRule({
29
29
  },
30
30
  // eslint-disable-next-line eslint-plugin/prefer-message-ids
31
31
  meta: {
32
+ defaultOptions: [{ ignoreProperties: [] }],
32
33
  docs: {
33
34
  category: "Best Practices",
34
35
  description: "Enforce that package.json has all properties required by the npm spec",
@@ -39,6 +40,7 @@ const rule = createRule({
39
40
  additionalProperties: false,
40
41
  properties: {
41
42
  ignoreProperties: {
43
+ description: "Array of top-level package properties to ignore.",
42
44
  items: {
43
45
  type: "string"
44
46
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-package-json",
3
- "version": "0.52.0",
3
+ "version": "0.52.1",
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": {
@@ -44,7 +44,7 @@
44
44
  "*": "prettier --ignore-unknown --write"
45
45
  },
46
46
  "dependencies": {
47
- "@altano/repository-tools": "^2.0.0",
47
+ "@altano/repository-tools": "^2.0.1",
48
48
  "change-case": "^5.4.4",
49
49
  "detect-indent": "^7.0.1",
50
50
  "detect-newline": "^4.0.1",
@@ -52,8 +52,8 @@
52
52
  "package-json-validator": "~0.27.0",
53
53
  "semver": "^7.5.4",
54
54
  "sort-object-keys": "^1.1.3",
55
- "sort-package-json": "^3.0.0",
56
- "validate-npm-package-name": "^6.0.0"
55
+ "sort-package-json": "^3.3.0",
56
+ "validate-npm-package-name": "^6.0.2"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@eslint-community/eslint-plugin-eslint-comments": "4.5.0",
@@ -71,7 +71,7 @@
71
71
  "create-typescript-app": "2.46.1",
72
72
  "eslint": "9.32.0",
73
73
  "eslint-doc-generator": "2.2.0",
74
- "eslint-plugin-eslint-plugin": "6.5.0",
74
+ "eslint-plugin-eslint-plugin": "7.0.0",
75
75
  "eslint-plugin-jsdoc": "52.0.0",
76
76
  "eslint-plugin-jsonc": "2.20.0",
77
77
  "eslint-plugin-markdown": "5.1.0",