eslint-plugin-package-json 1.4.0 → 1.6.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.
Files changed (146) hide show
  1. package/README.md +107 -106
  2. package/{lib/node_modules/.pnpm/@types_estree@1.0.8/node_modules/@types/estree/index.d.mts → dist/createRule-B1Ow8h0I.d.mts} +104 -1
  3. package/dist/experimental/index.d.mts +68 -0
  4. package/{lib/experimental/plugin.mjs → dist/experimental/index.mjs} +10 -5
  5. package/dist/index.d.mts +99 -0
  6. package/{lib → dist}/index.mjs +1 -1
  7. package/dist/plugin-kxKPlCNd.mjs +1737 -0
  8. package/package.json +26 -24
  9. package/lib/createRule.d.mts +0 -59
  10. package/lib/createRule.mjs +0 -24
  11. package/lib/experimental/index.d.mts +0 -34
  12. package/lib/experimental/index.mjs +0 -7
  13. package/lib/experimental/plugin.d.mts +0 -40
  14. package/lib/index.d.mts +0 -49
  15. package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/definitions/deserializationPattern.d.mts +0 -7
  16. package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/definitions/fromSchemaOptions.d.mts +0 -20
  17. package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/definitions/jsonSchema.d.mts +0 -60
  18. package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/index.d.mts +0 -11
  19. package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-options.d.mts +0 -16
  20. package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/allOf.d.mts +0 -13
  21. package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/anyOf.d.mts +0 -14
  22. package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/array.d.mts +0 -58
  23. package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/const.d.mts +0 -14
  24. package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/deserialize.d.mts +0 -13
  25. package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/enum.d.mts +0 -14
  26. package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/ifThenElse.d.mts +0 -20
  27. package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/index.d.mts +0 -34
  28. package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/multipleTypes.d.mts +0 -14
  29. package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/not.d.mts +0 -20
  30. package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/nullable.d.mts +0 -14
  31. package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/object.d.mts +0 -34
  32. package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/oneOf.d.mts +0 -14
  33. package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/references/external.d.mts +0 -22
  34. package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/references/index.d.mts +0 -13
  35. package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/references/internal.d.mts +0 -8
  36. package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/references/utils.d.mts +0 -12
  37. package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/singleType.d.mts +0 -24
  38. package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/utils.d.mts +0 -20
  39. package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/type-utils/and.d.mts +0 -4
  40. package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/type-utils/extends.d.mts +0 -4
  41. package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/type-utils/get.d.mts +0 -4
  42. package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/type-utils/join.d.mts +0 -4
  43. package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/type-utils/not.d.mts +0 -4
  44. package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/type-utils/pop.d.mts +0 -4
  45. package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/type-utils/split.d.mts +0 -7
  46. package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/type-utils/tail.d.mts +0 -4
  47. package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/type-utils/writable.d.mts +0 -4
  48. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/any.d.mts +0 -20
  49. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/array.d.mts +0 -28
  50. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/const.d.mts +0 -25
  51. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/enum.d.mts +0 -25
  52. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/exclusion/any.d.mts +0 -16
  53. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/exclusion/array.d.mts +0 -20
  54. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/exclusion/const.d.mts +0 -28
  55. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/exclusion/enum.d.mts +0 -23
  56. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/exclusion/index.d.mts +0 -24
  57. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/exclusion/object.d.mts +0 -44
  58. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/exclusion/primitive.d.mts +0 -16
  59. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/exclusion/tuple.d.mts +0 -43
  60. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/exclusion/union.d.mts +0 -13
  61. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/exclusion/utils.d.mts +0 -35
  62. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/intersection/any.d.mts +0 -23
  63. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/intersection/array.d.mts +0 -24
  64. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/intersection/const.d.mts +0 -34
  65. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/intersection/enum.d.mts +0 -26
  66. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/intersection/index.d.mts +0 -24
  67. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/intersection/object.d.mts +0 -25
  68. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/intersection/primitive.d.mts +0 -23
  69. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/intersection/tuple.d.mts +0 -26
  70. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/intersection/union.d.mts +0 -17
  71. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/intersection/utils.d.mts +0 -10
  72. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/never.d.mts +0 -9
  73. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/object.d.mts +0 -49
  74. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/primitive.d.mts +0 -26
  75. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/resolve.d.mts +0 -22
  76. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/tuple.d.mts +0 -36
  77. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/type.d.mts +0 -18
  78. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/union.d.mts +0 -23
  79. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/utils.d.mts +0 -7
  80. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/and.d.mts +0 -4
  81. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/extends.d.mts +0 -7
  82. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/if.d.mts +0 -4
  83. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/intersectUnion.d.mts +0 -4
  84. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/isNever.d.mts +0 -4
  85. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/merge.d.mts +0 -6
  86. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/not.d.mts +0 -4
  87. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/or.d.mts +0 -4
  88. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/prettify.d.mts +0 -6
  89. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/tail.d.mts +0 -4
  90. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/unionLast.d.mts +0 -6
  91. package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/unionPop.d.mts +0 -6
  92. package/lib/plugin.d.mts +0 -56
  93. package/lib/plugin.mjs +0 -91
  94. package/lib/rules/bin-name-casing.d.mts +0 -6
  95. package/lib/rules/bin-name-casing.mjs +0 -41
  96. package/lib/rules/exports-subpaths-style.d.mts +0 -18
  97. package/lib/rules/exports-subpaths-style.mjs +0 -71
  98. package/lib/rules/no-empty-fields.d.mts +0 -20
  99. package/lib/rules/no-empty-fields.mjs +0 -90
  100. package/lib/rules/no-local-dependencies.d.mts +0 -17
  101. package/lib/rules/no-local-dependencies.mjs +0 -47
  102. package/lib/rules/no-redundant-files.d.mts +0 -6
  103. package/lib/rules/no-redundant-files.mjs +0 -99
  104. package/lib/rules/no-redundant-publishConfig.d.mts +0 -6
  105. package/lib/rules/no-redundant-publishConfig.mjs +0 -50
  106. package/lib/rules/order-properties.d.mts +0 -25
  107. package/lib/rules/order-properties.mjs +0 -64
  108. package/lib/rules/repository-shorthand.d.mts +0 -18
  109. package/lib/rules/repository-shorthand.mjs +0 -111
  110. package/lib/rules/require-attribution.d.mts +0 -22
  111. package/lib/rules/require-attribution.mjs +0 -91
  112. package/lib/rules/require-properties.d.mts +0 -22
  113. package/lib/rules/require-properties.mjs +0 -73
  114. package/lib/rules/restrict-dependency-ranges.d.mts +0 -92
  115. package/lib/rules/restrict-dependency-ranges.mjs +0 -147
  116. package/lib/rules/restrict-private-properties.d.mts +0 -20
  117. package/lib/rules/restrict-private-properties.mjs +0 -53
  118. package/lib/rules/restrict-top-level-properties.d.mts +0 -39
  119. package/lib/rules/restrict-top-level-properties.mjs +0 -73
  120. package/lib/rules/scripts-name-casing.d.mts +0 -6
  121. package/lib/rules/scripts-name-casing.mjs +0 -44
  122. package/lib/rules/sort-collections.d.mts +0 -35
  123. package/lib/rules/sort-collections.mjs +0 -111
  124. package/lib/rules/specify-peers-locally.d.mts +0 -6
  125. package/lib/rules/specify-peers-locally.mjs +0 -63
  126. package/lib/rules/unique-dependencies.d.mts +0 -6
  127. package/lib/rules/unique-dependencies.mjs +0 -86
  128. package/lib/rules/valid-peerDependenciesMeta-relationship.d.mts +0 -6
  129. package/lib/rules/valid-peerDependenciesMeta-relationship.mjs +0 -50
  130. package/lib/rules/valid-properties.d.mts +0 -9
  131. package/lib/rules/valid-properties.mjs +0 -58
  132. package/lib/rules/valid-repository-directory.d.mts +0 -6
  133. package/lib/rules/valid-repository-directory.mjs +0 -73
  134. package/lib/types/estree.d.mts +0 -8
  135. package/lib/utils/createSimpleRequirePropertyRule.d.mts +0 -48
  136. package/lib/utils/createSimpleRequirePropertyRule.mjs +0 -59
  137. package/lib/utils/createSimpleValidPropertyRule.d.mts +0 -17
  138. package/lib/utils/createSimpleValidPropertyRule.mjs +0 -57
  139. package/lib/utils/findPropertyWithKeyValue.d.mts +0 -10
  140. package/lib/utils/findPropertyWithKeyValue.mjs +0 -6
  141. package/lib/utils/formatErrors.d.mts +0 -9
  142. package/lib/utils/formatErrors.mjs +0 -12
  143. package/lib/utils/isPackageJson.d.mts +0 -4
  144. package/lib/utils/isPackageJson.mjs +0 -4
  145. package/lib/utils/predicates.d.mts +0 -7
  146. package/lib/utils/predicates.mjs +0 -9
@@ -1,86 +0,0 @@
1
- import { createRule } from "../createRule.mjs";
2
- import { isJSONStringLiteral, isNotNullish } from "../utils/predicates.mjs";
3
- import { fixRemoveArrayElement, fixRemoveObjectProperty } from "eslint-fix-utils";
4
- //#region src/rules/unique-dependencies.ts
5
- const dependencyPropertyNames = new Set([
6
- "bundledDependencies",
7
- "bundleDependencies",
8
- "dependencies",
9
- "devDependencies",
10
- "optionalDependencies",
11
- "overrides",
12
- "peerDependencies"
13
- ]);
14
- const rule = createRule({
15
- create(context) {
16
- const dependenciesCache = {
17
- dependencies: [],
18
- devDependencies: [],
19
- peerDependencies: []
20
- };
21
- const trackForCrossGroupUniqueness = Object.keys(dependenciesCache);
22
- function check(elements, getNodeToRemove) {
23
- const seen = /* @__PURE__ */ new Set();
24
- for (const element of elements.filter(isNotNullish).filter(isJSONStringLiteral).reverse()) if (seen.has(element.value)) report(element);
25
- else seen.add(element.value);
26
- function report(node) {
27
- const removal = getNodeToRemove(node);
28
- context.report({
29
- messageId: "overridden",
30
- node,
31
- suggest: [{
32
- fix: removal.type === "JSONProperty" ? fixRemoveObjectProperty(context, removal) : fixRemoveArrayElement(context, removal, elements),
33
- messageId: "remove"
34
- }]
35
- });
36
- }
37
- }
38
- return {
39
- "Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.type=JSONLiteral]"(node) {
40
- if (!dependencyPropertyNames.has(node.key.value)) return;
41
- const nodeValueType = node.value.type;
42
- if (nodeValueType === "JSONArrayExpression") check(node.value.elements, (element) => element);
43
- if (nodeValueType === "JSONObjectExpression") {
44
- check(node.value.properties.map((property) => property.key), (property) => property.parent);
45
- if (trackForCrossGroupUniqueness.includes(node.key.value)) dependenciesCache[node.key.value] = node.value.properties;
46
- }
47
- },
48
- "Program:exit"() {
49
- const dependencyNames = new Set(dependenciesCache.dependencies.map((node) => node.key).filter(isJSONStringLiteral).map((dependencyNameNode) => dependencyNameNode.value));
50
- if (!dependencyNames.size) return;
51
- for (const dependencyType of ["devDependencies", "peerDependencies"]) {
52
- const otherDependencies = dependenciesCache[dependencyType];
53
- for (const otherDependencyNode of otherDependencies) {
54
- const otherDependencyKey = otherDependencyNode.key;
55
- if (isJSONStringLiteral(otherDependencyKey) && dependencyNames.has(otherDependencyKey.value)) context.report({
56
- messageId: "crossGroupDuplicate",
57
- node: otherDependencyNode,
58
- suggest: [{
59
- fix: fixRemoveObjectProperty(context, otherDependencyNode),
60
- messageId: "remove"
61
- }]
62
- });
63
- }
64
- }
65
- }
66
- };
67
- },
68
- meta: {
69
- docs: {
70
- category: "Best Practices",
71
- description: "Checks a dependency isn't specified more than once (i.e. in `dependencies` and `devDependencies`)",
72
- recommended: true
73
- },
74
- hasSuggestions: true,
75
- messages: {
76
- crossGroupDuplicate: "Dependency is also declared in \"dependencies\" and is redundant",
77
- overridden: "Dependency is overridden by a duplicate entry later on",
78
- remove: "Remove this redundant dependency"
79
- },
80
- schema: [],
81
- type: "suggestion"
82
- },
83
- name: "unique-dependencies"
84
- });
85
- //#endregion
86
- export { rule };
@@ -1,6 +0,0 @@
1
- import { PackageJsonRuleModule } from "../createRule.mjs";
2
-
3
- //#region src/rules/valid-peerDependenciesMeta-relationship.d.ts
4
- declare const rule: PackageJsonRuleModule<[], []>;
5
- //#endregion
6
- export { rule };
@@ -1,50 +0,0 @@
1
- import { createRule } from "../createRule.mjs";
2
- import { isJSONStringLiteral } from "../utils/predicates.mjs";
3
- import { fixRemoveObjectProperty } from "eslint-fix-utils";
4
- //#region src/rules/valid-peerDependenciesMeta-relationship.ts
5
- const rule = createRule({
6
- create(context) {
7
- const peerDependencies = /* @__PURE__ */ new Set();
8
- const peerDependenciesMeta = /* @__PURE__ */ new Map();
9
- return {
10
- "Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.value=peerDependencies]"(node) {
11
- if (node.value.type === "JSONObjectExpression") {
12
- for (const property of node.value.properties) if (isJSONStringLiteral(property.key)) peerDependencies.add(property.key.value);
13
- }
14
- },
15
- "Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.value=peerDependenciesMeta]"(node) {
16
- if (node.value.type === "JSONObjectExpression") {
17
- for (const property of node.value.properties) if (isJSONStringLiteral(property.key)) peerDependenciesMeta.set(property.key.value, property);
18
- }
19
- },
20
- "Program:exit"() {
21
- for (const [dependencyName, propertyNode] of peerDependenciesMeta) if (!peerDependencies.has(dependencyName)) context.report({
22
- data: { dependencyName },
23
- messageId: "unnecessaryPeerDependency",
24
- node: propertyNode,
25
- suggest: [{
26
- fix: fixRemoveObjectProperty(context, propertyNode),
27
- messageId: "removePeerDependencyMeta"
28
- }]
29
- });
30
- }
31
- };
32
- },
33
- meta: {
34
- docs: {
35
- category: "Best Practices",
36
- description: "Enforces that any dependencies declared in `peerDependenciesMeta` are also defined in the package's `peerDependencies`.",
37
- recommended: true
38
- },
39
- hasSuggestions: true,
40
- messages: {
41
- removePeerDependencyMeta: "Remove from `peerDependenciesMeta`.",
42
- unnecessaryPeerDependency: "Dependency '{{ dependencyName }}' is declared in `peerDependenciesMeta` but not in `peerDependencies`."
43
- },
44
- schema: [],
45
- type: "problem"
46
- },
47
- name: "valid-peerDependenciesMeta-relationship"
48
- });
49
- //#endregion
50
- export { rule };
@@ -1,9 +0,0 @@
1
- import { PackageJsonRuleModule } from "../createRule.mjs";
2
-
3
- //#region src/rules/valid-properties.d.ts
4
- /** All basic valid- flavor rules */
5
- declare const rules: {
6
- [k: string]: PackageJsonRuleModule<[], []>;
7
- };
8
- //#endregion
9
- export { rules };
@@ -1,58 +0,0 @@
1
- import { createSimpleValidPropertyRule } from "../utils/createSimpleValidPropertyRule.mjs";
2
- import { validateAuthor, validateBin, validateBrowser, validateBugs, validateBundleDependencies, validateConfig, validateContributors, validateCpu, validateDependencies, validateDescription, validateDevEngines, validateDirectories, validateEngines, validateExports, validateFiles, validateFunding, validateGypfile, validateHomepage, validateKeywords, validateLibc, validateLicense, validateMain, validateMan, validateName, validateOs, validatePackageManager, validatePeerDependenciesMeta, validatePrivate, validatePublishConfig, validateRepository, validateScripts, validateSideEffects, validateType, validateVersion, validateWorkspaces } from "package-json-validator";
3
- /** All basic valid- flavor rules */
4
- const rules = Object.fromEntries([
5
- ["author", validateAuthor],
6
- ["bin", validateBin],
7
- ["browser", validateBrowser],
8
- ["bugs", validateBugs],
9
- ["bundleDependencies", {
10
- aliases: ["bundledDependencies"],
11
- validator: validateBundleDependencies
12
- }],
13
- ["config", validateConfig],
14
- ["contributors", validateContributors],
15
- ["cpu", validateCpu],
16
- ["description", validateDescription],
17
- ["dependencies", validateDependencies],
18
- ["devDependencies", validateDependencies],
19
- ["devEngines", validateDevEngines],
20
- ["directories", validateDirectories],
21
- ["engines", validateEngines],
22
- ["exports", validateExports],
23
- ["files", validateFiles],
24
- ["funding", validateFunding],
25
- ["gypfile", validateGypfile],
26
- ["homepage", validateHomepage],
27
- ["keywords", validateKeywords],
28
- ["libc", validateLibc],
29
- ["license", validateLicense],
30
- ["main", validateMain],
31
- ["man", validateMan],
32
- ["module", validateMain],
33
- ["name", validateName],
34
- ["optionalDependencies", validateDependencies],
35
- ["os", validateOs],
36
- ["packageManager", validatePackageManager],
37
- ["peerDependencies", validateDependencies],
38
- ["peerDependenciesMeta", validatePeerDependenciesMeta],
39
- ["private", validatePrivate],
40
- ["publishConfig", validatePublishConfig],
41
- ["repository", validateRepository],
42
- ["scripts", validateScripts],
43
- ["sideEffects", validateSideEffects],
44
- ["type", validateType],
45
- ["version", validateVersion],
46
- ["workspaces", validateWorkspaces]
47
- ].map(([propertyName, validationFunctionOrOptions]) => {
48
- let validationFunction;
49
- let aliases = [];
50
- if (typeof validationFunctionOrOptions === "object") {
51
- validationFunction = validationFunctionOrOptions.validator;
52
- aliases = validationFunctionOrOptions.aliases;
53
- } else validationFunction = validationFunctionOrOptions;
54
- const { rule, ruleName } = createSimpleValidPropertyRule(propertyName, validationFunction, aliases);
55
- return [ruleName, rule];
56
- }));
57
- //#endregion
58
- export { rules };
@@ -1,6 +0,0 @@
1
- import { PackageJsonRuleModule } from "../createRule.mjs";
2
-
3
- //#region src/rules/valid-repository-directory.d.ts
4
- declare const rule: PackageJsonRuleModule<[], []>;
5
- //#endregion
6
- export { rule };
@@ -1,73 +0,0 @@
1
- import { createRule } from "../createRule.mjs";
2
- import { findPropertyWithKeyValue } from "../utils/findPropertyWithKeyValue.mjs";
3
- import path from "node:path";
4
- import { sep } from "node:path/posix";
5
- import { findRootSync } from "@altano/repository-tools";
6
- //#region src/rules/valid-repository-directory.ts
7
- /**
8
- * Checks if the child path appears at the end of the parent path.
9
- * @example '/a/b/c', 'c' => true
10
- * @example '/a/b/c', 'b/c' => true
11
- * @example '/a/b/c', 'b' => false
12
- * @example '/a/b/c', 'd' => false
13
- */
14
- const pathEndsWith = (parent, child) => {
15
- if (parent === child) return true;
16
- const segments = parent.split(path.sep);
17
- let pathToCheck = "";
18
- return segments.reverse().some((segment) => {
19
- pathToCheck = path.join(segment, pathToCheck);
20
- if (pathToCheck === child) return true;
21
- });
22
- };
23
- let repoRootCache = null;
24
- const rule = createRule({
25
- create(context) {
26
- return { "Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.value=repository][value.type=JSONObjectExpression]"(node) {
27
- const directoryProperty = findPropertyWithKeyValue(node.value.properties, "directory");
28
- if (directoryProperty?.value.type !== "JSONLiteral" || typeof directoryProperty.value.value !== "string") return;
29
- const directoryValue = directoryProperty.value.value;
30
- const fileDirectory = path.normalize(path.dirname(context.filename));
31
- let repositoryRoot;
32
- if (repoRootCache && fileDirectory.startsWith(repoRootCache)) repositoryRoot = repoRootCache;
33
- else {
34
- repositoryRoot = findRootSync(fileDirectory);
35
- if (repositoryRoot) repoRootCache = path.normalize(repositoryRoot);
36
- }
37
- if (repositoryRoot) {
38
- const expected = path.relative(repositoryRoot, fileDirectory).replaceAll(path.sep, sep);
39
- if (expected !== directoryValue) context.report({
40
- messageId: "mismatched",
41
- node: directoryProperty.value,
42
- suggest: [{
43
- data: { expected },
44
- fix(fixer) {
45
- return fixer.replaceText(directoryProperty.value, `"${expected}"`);
46
- },
47
- messageId: "replace"
48
- }]
49
- });
50
- } else if (!pathEndsWith(fileDirectory, path.normalize(directoryValue))) context.report({
51
- messageId: "mismatched",
52
- node: directoryProperty.value
53
- });
54
- } };
55
- },
56
- meta: {
57
- docs: {
58
- category: "Best Practices",
59
- description: "Enforce that if repository directory is specified, it matches the path to the package.json file",
60
- recommended: true
61
- },
62
- hasSuggestions: true,
63
- messages: {
64
- mismatched: "Directory does not match package.json directory.",
65
- replace: "Replace with '{{ expected }}'."
66
- },
67
- schema: [],
68
- type: "suggestion"
69
- },
70
- name: "valid-repository-directory"
71
- });
72
- //#endregion
73
- export { rule };
@@ -1,8 +0,0 @@
1
- import { JSONNode } from "jsonc-eslint-parser";
2
-
3
- //#region src/types/estree.d.ts
4
- declare module 'estree' {
5
- interface NodeMap {
6
- JSONNode: JSONNode;
7
- }
8
- }
@@ -1,48 +0,0 @@
1
- import { PackageJsonRuleModule } from "../createRule.mjs";
2
-
3
- //#region src/utils/createSimpleRequirePropertyRule.d.ts
4
- interface CreateRequirePropertyRuleOptions {
5
- /**
6
- * The category for this rule.
7
- */
8
- category?: 'Publishable' | (string & {});
9
- /** The value to use when fixing a violation when this property is missing */
10
- fixValue?: unknown;
11
- /**
12
- * The default value of `ignorePrivate` rule option.
13
- */
14
- ignorePrivateDefault?: boolean;
15
- /**
16
- * Whether the rule should be included in the recommended config.
17
- */
18
- isRecommended?: boolean;
19
- }
20
- /**
21
- * Given a top-level property name, create a rule that requires that property to be present.
22
- * Optionally, include it in the recommended config.
23
- * Note: this will only create a basic require rule, with no options. If you need
24
- * to create a more complex rule, create it in its own file.
25
- */
26
- declare const createSimpleRequirePropertyRule: (propertyName: string, {
27
- category,
28
- fixValue,
29
- ignorePrivateDefault,
30
- isRecommended
31
- }?: CreateRequirePropertyRuleOptions) => {
32
- rule: PackageJsonRuleModule<[] | [({
33
- ignorePrivate: boolean;
34
- } | undefined)?], [] | [{
35
- readonly additionalProperties: false;
36
- readonly properties: {
37
- readonly ignorePrivate: {
38
- readonly default: boolean;
39
- readonly description: "Determines if this rule should be enforced when the package's `private` property is `true`.";
40
- readonly type: "boolean";
41
- };
42
- };
43
- readonly type: "object";
44
- }]>;
45
- ruleName: string;
46
- };
47
- //#endregion
48
- export { CreateRequirePropertyRuleOptions, createSimpleRequirePropertyRule };
@@ -1,59 +0,0 @@
1
- import { createRule } from "../createRule.mjs";
2
- import { isJSONStringLiteral } from "./predicates.mjs";
3
- //#region src/utils/createSimpleRequirePropertyRule.ts
4
- /**
5
- * Given a top-level property name, create a rule that requires that property to be present.
6
- * Optionally, include it in the recommended config.
7
- * Note: this will only create a basic require rule, with no options. If you need
8
- * to create a more complex rule, create it in its own file.
9
- */
10
- const createSimpleRequirePropertyRule = (propertyName, { category, fixValue, ignorePrivateDefault = false, isRecommended } = {}) => {
11
- const ruleName = `require-${propertyName}`;
12
- return {
13
- rule: createRule({
14
- create(context) {
15
- const enforceForPrivate = context.settings.packageJson?.enforceForPrivate;
16
- const ignorePrivate = context.options[0]?.ignorePrivate ?? (typeof enforceForPrivate === "boolean" ? !enforceForPrivate : ignorePrivateDefault);
17
- return { "Program > JSONExpressionStatement > JSONObjectExpression"(node) {
18
- if (ignorePrivate && node.properties.some((property) => isJSONStringLiteral(property.key) && property.key.value === "private" && property.value.type === "JSONLiteral" && property.value.value === true)) return;
19
- if (node.properties.every((property) => !(isJSONStringLiteral(property.key) && property.key.value === propertyName))) context.report({
20
- data: { property: propertyName },
21
- fix: fixValue === void 0 ? void 0 : function* (fixer) {
22
- yield fixer.insertTextAfterRange([0, 1], `\n "${propertyName}": ${JSON.stringify(fixValue)}`);
23
- yield node.properties.length > 0 ? fixer.insertTextAfterRange([0, 1], ",") : fixer.insertTextAfterRange([0, 1], "\n");
24
- },
25
- loc: {
26
- column: 0,
27
- line: 1
28
- },
29
- messageId: "missing"
30
- });
31
- } };
32
- },
33
- meta: {
34
- docs: {
35
- category,
36
- description: `Requires the \`${propertyName}\` property to be present.`,
37
- recommended: isRecommended,
38
- ruleGroup: "require-properties"
39
- },
40
- fixable: fixValue === void 0 ? void 0 : "code",
41
- messages: { missing: "Property '{{property}}' is required." },
42
- schema: propertyName === "private" ? [] : [{
43
- additionalProperties: false,
44
- properties: { ignorePrivate: {
45
- default: ignorePrivateDefault,
46
- description: "Determines if this rule should be enforced when the package's `private` property is `true`.",
47
- type: "boolean"
48
- } },
49
- type: "object"
50
- }],
51
- type: "suggestion"
52
- },
53
- name: ruleName
54
- }),
55
- ruleName
56
- };
57
- };
58
- //#endregion
59
- export { createSimpleRequirePropertyRule };
@@ -1,17 +0,0 @@
1
- import { PackageJsonRuleModule } from "../createRule.mjs";
2
- import { Result } from "package-json-validator";
3
-
4
- //#region src/utils/createSimpleValidPropertyRule.d.ts
5
- type ValidationFunction = (value: unknown) => Result;
6
- /**
7
- * Given a top-level property name, and a validation function, create a rule that validates the property using the validation function.
8
- * These rules will always be included in the recommended config.
9
- * Note: this will only create a basic validation rule, with no options. If you need
10
- * to create a more complex rule, create it in its own file.
11
- */
12
- declare const createSimpleValidPropertyRule: (propertyName: string, validationFunction: ValidationFunction, aliases?: string[]) => {
13
- rule: PackageJsonRuleModule<[], []>;
14
- ruleName: string;
15
- };
16
- //#endregion
17
- export { ValidationFunction, createSimpleValidPropertyRule };
@@ -1,57 +0,0 @@
1
- import { createRule } from "../createRule.mjs";
2
- //#region src/utils/createSimpleValidPropertyRule.ts
3
- /**
4
- * Given a top-level property name, and a validation function, create a rule that validates the property using the validation function.
5
- * These rules will always be included in the recommended config.
6
- * Note: this will only create a basic validation rule, with no options. If you need
7
- * to create a more complex rule, create it in its own file.
8
- */
9
- const createSimpleValidPropertyRule = (propertyName, validationFunction, aliases = []) => {
10
- const ruleName = `valid-${propertyName}`;
11
- const propertyNames = [propertyName, ...aliases];
12
- return {
13
- rule: createRule({
14
- create(context) {
15
- const reportIssues = (result, node) => {
16
- if (result.errorMessages.length === 0) return;
17
- if (result.issues.length) for (const issue of result.issues) context.report({
18
- data: { error: issue.message },
19
- messageId: "validationError",
20
- node
21
- });
22
- const childrenWithIssues = result.childResults.filter((childResult) => childResult.errorMessages.length);
23
- if (node.type === "JSONObjectExpression" && childrenWithIssues.length) for (const childResult of childrenWithIssues) {
24
- const childNode = node.properties[childResult.index];
25
- reportIssues(childResult, childNode.value);
26
- }
27
- else if (node.type === "JSONArrayExpression" && childrenWithIssues.length) for (const childResult of childrenWithIssues) {
28
- const childNode = node.elements[childResult.index];
29
- if (childNode) reportIssues(childResult, childNode);
30
- }
31
- };
32
- return propertyNames.reduce((acc, name) => {
33
- acc[`Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.value=${name}]`] = (node) => {
34
- const valueNode = node.value;
35
- reportIssues(validationFunction(JSON.parse(context.sourceCode.getText(valueNode))), valueNode);
36
- };
37
- return acc;
38
- }, {});
39
- },
40
- meta: {
41
- docs: {
42
- category: "Best Practices",
43
- description: `Enforce that the \`${propertyName}\`${aliases.length ? ` (also ${aliases.map((alias) => `\`${alias}\``).join(", ")})` : ""} property is valid.`,
44
- recommended: true,
45
- ruleGroup: "valid-properties"
46
- },
47
- messages: { validationError: `Invalid ${propertyName}: {{ error }}` },
48
- schema: [],
49
- type: "problem"
50
- },
51
- name: ruleName
52
- }),
53
- ruleName
54
- };
55
- };
56
- //#endregion
57
- export { createSimpleValidPropertyRule };
@@ -1,10 +0,0 @@
1
- import { AST } from "jsonc-eslint-parser";
2
-
3
- //#region src/utils/findPropertyWithKeyValue.d.ts
4
- type JSONPropertyWithKeyAndValue<Value extends string> = AST.JSONProperty & {
5
- key: AST.JSONStringLiteral;
6
- value: Value;
7
- };
8
- declare function findPropertyWithKeyValue<Value extends string>(properties: AST.JSONProperty[], value: Value): JSONPropertyWithKeyAndValue<Value> | undefined;
9
- //#endregion
10
- export { JSONPropertyWithKeyAndValue, findPropertyWithKeyValue };
@@ -1,6 +0,0 @@
1
- //#region src/utils/findPropertyWithKeyValue.ts
2
- function findPropertyWithKeyValue(properties, value) {
3
- return properties.find((property) => property.key.type === "JSONLiteral" && property.key.value === value);
4
- }
5
- //#endregion
6
- export { findPropertyWithKeyValue };
@@ -1,9 +0,0 @@
1
- //#region src/utils/formatErrors.d.ts
2
- /**
3
- * Formats an array of error messages into a single string.
4
- * When there is more than one error, the errors will be formatted as a list,
5
- * starting on a new line.
6
- */
7
- declare const formatErrors: (errors: string[]) => string;
8
- //#endregion
9
- export { formatErrors };
@@ -1,12 +0,0 @@
1
- //#region src/utils/formatErrors.ts
2
- /**
3
- * Formats an array of error messages into a single string.
4
- * When there is more than one error, the errors will be formatted as a list,
5
- * starting on a new line.
6
- */
7
- const formatErrors = (errors) => {
8
- if (errors.length === 0) return "";
9
- return errors.length > 1 ? ["", ...errors].join("\n - ") : errors[0];
10
- };
11
- //#endregion
12
- export { formatErrors };
@@ -1,4 +0,0 @@
1
- //#region src/utils/isPackageJson.d.ts
2
- declare const isPackageJson: (filePath: string) => boolean;
3
- //#endregion
4
- export { isPackageJson };
@@ -1,4 +0,0 @@
1
- //#region src/utils/isPackageJson.ts
2
- const isPackageJson = (filePath) => /(?:^|[/\\])package.json$/.test(filePath);
3
- //#endregion
4
- export { isPackageJson };
@@ -1,7 +0,0 @@
1
- import { AST } from "jsonc-eslint-parser";
2
-
3
- //#region src/utils/predicates.d.ts
4
- declare function isJSONStringLiteral(node: AST.JSONNode): node is AST.JSONStringLiteral;
5
- declare function isNotNullish<T extends NonNullable<unknown>>(value: null | T | undefined): value is T;
6
- //#endregion
7
- export { isJSONStringLiteral, isNotNullish };
@@ -1,9 +0,0 @@
1
- //#region src/utils/predicates.ts
2
- function isJSONStringLiteral(node) {
3
- return node.type === "JSONLiteral" && typeof node.value === "string";
4
- }
5
- function isNotNullish(value) {
6
- return value !== null && value !== void 0;
7
- }
8
- //#endregion
9
- export { isJSONStringLiteral, isNotNullish };