eslint-plugin-package-json 0.76.0 → 0.77.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 +8 -2
- package/lib/rules/unique-dependencies.mjs +40 -12
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
# [0.
|
|
3
|
+
# [0.77.0](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/compare/v0.76.0...v0.77.0) (2025-11-15)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **unique-dependencies:** report cross-group duplicates ([#1398](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/1398)) ([94b690e](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commit/94b690e1996ec271ba743225ccecf66691f97e01)), closes [#1007](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/1007)
|
|
4
9
|
|
|
10
|
+
# [0.76.0](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/compare/v0.75.0...v0.76.0) (2025-11-15)
|
|
5
11
|
|
|
6
12
|
### Features
|
|
7
13
|
|
|
8
|
-
|
|
14
|
+
- **valid-engines:** add new rule for validating `engines` ([#1397](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/1397)) ([ba834f0](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commit/ba834f00651b64f2bc0cf58cf41d768bd6cee5eb)), closes [#826](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/826)
|
|
9
15
|
|
|
10
16
|
# [0.75.0](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/compare/v0.73.0...v0.75.0) (2025-11-15)
|
|
11
17
|
|
|
@@ -14,6 +14,12 @@ const dependencyPropertyNames = new Set([
|
|
|
14
14
|
]);
|
|
15
15
|
const rule = createRule({
|
|
16
16
|
create(context) {
|
|
17
|
+
const dependenciesCache = {
|
|
18
|
+
dependencies: [],
|
|
19
|
+
devDependencies: [],
|
|
20
|
+
peerDependencies: []
|
|
21
|
+
};
|
|
22
|
+
const trackForCrossGroupUniqueness = Object.keys(dependenciesCache);
|
|
17
23
|
function check(elements, getNodeToRemove) {
|
|
18
24
|
const seen = /* @__PURE__ */ new Set();
|
|
19
25
|
for (const element of elements.filter(isNotNullish).filter(isJSONStringLiteral).reverse()) if (seen.has(element.value)) report(element, elements);
|
|
@@ -30,17 +36,38 @@ const rule = createRule({
|
|
|
30
36
|
});
|
|
31
37
|
}
|
|
32
38
|
}
|
|
33
|
-
return {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
return {
|
|
40
|
+
"Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.type=JSONLiteral]"(node) {
|
|
41
|
+
if (!dependencyPropertyNames.has(node.key.value)) return;
|
|
42
|
+
switch (node.value.type) {
|
|
43
|
+
case "JSONArrayExpression":
|
|
44
|
+
check(node.value.elements, (element) => element);
|
|
45
|
+
break;
|
|
46
|
+
case "JSONObjectExpression":
|
|
47
|
+
check(node.value.properties.map((property) => property.key), (property) => property.parent);
|
|
48
|
+
if (trackForCrossGroupUniqueness.includes(node.key.value)) dependenciesCache[node.key.value] = node.value.properties;
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"Program:exit"() {
|
|
53
|
+
const dependencyNames = new Set(dependenciesCache.dependencies.map((node) => node.key).filter(isJSONStringLiteral).map((dependencyNameNode) => dependencyNameNode.value));
|
|
54
|
+
if (!dependencyNames.size) return;
|
|
55
|
+
for (const dependencyType of ["devDependencies", "peerDependencies"]) {
|
|
56
|
+
const otherDependencies = dependenciesCache[dependencyType];
|
|
57
|
+
for (const otherDependencyNode of otherDependencies) {
|
|
58
|
+
const otherDependencyKey = otherDependencyNode.key;
|
|
59
|
+
if (isJSONStringLiteral(otherDependencyKey) && dependencyNames.has(otherDependencyKey.value)) context.report({
|
|
60
|
+
messageId: "crossGroupDuplicate",
|
|
61
|
+
node: otherDependencyNode,
|
|
62
|
+
suggest: [{
|
|
63
|
+
fix: fixRemoveObjectProperty(context, otherDependencyNode),
|
|
64
|
+
messageId: "remove"
|
|
65
|
+
}]
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
42
69
|
}
|
|
43
|
-
}
|
|
70
|
+
};
|
|
44
71
|
},
|
|
45
72
|
meta: {
|
|
46
73
|
docs: {
|
|
@@ -50,8 +77,9 @@ const rule = createRule({
|
|
|
50
77
|
},
|
|
51
78
|
hasSuggestions: true,
|
|
52
79
|
messages: {
|
|
53
|
-
|
|
54
|
-
|
|
80
|
+
crossGroupDuplicate: "Dependency is also declared in \"dependencies\" and is redundant",
|
|
81
|
+
overridden: "Dependency is overridden by a duplicate entry later on",
|
|
82
|
+
remove: "Remove this redundant dependency"
|
|
55
83
|
},
|
|
56
84
|
schema: [],
|
|
57
85
|
type: "suggestion"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-package-json",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.77.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": {
|