eslint-plugin-package-json 1.5.0 → 1.6.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.
Files changed (156) hide show
  1. package/README.md +107 -106
  2. package/{lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/definitions/jsonSchema.d.mts → dist/createRule-29pC9RoP.d.mts} +49 -4
  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-C-Z8sf5g.mjs +1737 -0
  8. package/package.json +33 -27
  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/@types_estree@1.0.8/node_modules/@types/estree/index.d.mts +0 -438
  16. 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
  17. 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
  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 -93
  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 -100
  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 -74
  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 -87
  128. package/lib/rules/valid-author.d.mts +0 -6
  129. package/lib/rules/valid-author.mjs +0 -59
  130. package/lib/rules/valid-peerDependenciesMeta-relationship.d.mts +0 -6
  131. package/lib/rules/valid-peerDependenciesMeta-relationship.mjs +0 -50
  132. package/lib/rules/valid-properties.d.mts +0 -9
  133. package/lib/rules/valid-properties.mjs +0 -57
  134. package/lib/rules/valid-repository-directory.d.mts +0 -6
  135. package/lib/rules/valid-repository-directory.mjs +0 -73
  136. package/lib/types/estree.d.mts +0 -8
  137. package/lib/utils/createSimpleRequirePropertyRule.d.mts +0 -48
  138. package/lib/utils/createSimpleRequirePropertyRule.mjs +0 -62
  139. package/lib/utils/createSimpleValidPropertyRule.d.mts +0 -17
  140. package/lib/utils/createSimpleValidPropertyRule.mjs +0 -57
  141. package/lib/utils/findPropertyWithKeyValue.d.mts +0 -10
  142. package/lib/utils/findPropertyWithKeyValue.mjs +0 -6
  143. package/lib/utils/formatErrors.d.mts +0 -9
  144. package/lib/utils/formatErrors.mjs +0 -12
  145. package/lib/utils/git/getGitAuthor.d.mts +0 -8
  146. package/lib/utils/git/getGitAuthor.mjs +0 -29
  147. package/lib/utils/git/index.d.mts +0 -2
  148. package/lib/utils/git/index.mjs +0 -2
  149. package/lib/utils/predicates/index.d.mts +0 -4
  150. package/lib/utils/predicates/index.mjs +0 -4
  151. package/lib/utils/predicates/isJSONStringLiteral.d.mts +0 -6
  152. package/lib/utils/predicates/isJSONStringLiteral.mjs +0 -6
  153. package/lib/utils/predicates/isNotNullish.d.mts +0 -4
  154. package/lib/utils/predicates/isNotNullish.mjs +0 -6
  155. package/lib/utils/predicates/isPackageJson.d.mts +0 -4
  156. package/lib/utils/predicates/isPackageJson.mjs +0 -4
@@ -1,6 +0,0 @@
1
- import { PackageJsonRuleModule } from "../createRule.mjs";
2
-
3
- //#region src/rules/no-redundant-publishConfig.d.ts
4
- declare const rule: PackageJsonRuleModule<[], []>;
5
- //#endregion
6
- export { rule };
@@ -1,50 +0,0 @@
1
- import { isJSONStringLiteral } from "../utils/predicates/isJSONStringLiteral.mjs";
2
- import { createRule } from "../createRule.mjs";
3
- import { fixRemoveObjectProperty } from "eslint-fix-utils";
4
- //#region src/rules/no-redundant-publishConfig.ts
5
- const rule = createRule({
6
- create(context) {
7
- let packageName;
8
- let publishConfigAccessProperty;
9
- return {
10
- "Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.value=name]"(node) {
11
- if (isJSONStringLiteral(node.value)) packageName = node.value.value;
12
- },
13
- "Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.value=publishConfig]"(node) {
14
- if (node.value.type !== "JSONObjectExpression") return;
15
- for (const property of node.value.properties) if (isJSONStringLiteral(property.key) && property.key.value === "access") {
16
- publishConfigAccessProperty = property;
17
- break;
18
- }
19
- },
20
- "Program:exit"() {
21
- if (!packageName || !publishConfigAccessProperty) return;
22
- if (!packageName.startsWith("@")) context.report({
23
- messageId: "redundantAccess",
24
- node: publishConfigAccessProperty,
25
- suggest: [{
26
- fix: fixRemoveObjectProperty(context, publishConfigAccessProperty),
27
- messageId: "removeAccess"
28
- }]
29
- });
30
- }
31
- };
32
- },
33
- meta: {
34
- docs: {
35
- category: "Best Practices",
36
- description: "Warns when publishConfig.access is used in unscoped packages.",
37
- recommended: true
38
- },
39
- hasSuggestions: true,
40
- messages: {
41
- redundantAccess: "'publishConfig.access' is redundant for unscoped packages - they are always public.",
42
- removeAccess: "Remove the redundant 'access' field."
43
- },
44
- schema: [],
45
- type: "suggestion"
46
- },
47
- name: "no-redundant-publishConfig"
48
- });
49
- //#endregion
50
- export { rule };
@@ -1,25 +0,0 @@
1
- import { PackageJsonRuleModule } from "../createRule.mjs";
2
-
3
- //#region src/rules/order-properties.d.ts
4
- declare const rule: PackageJsonRuleModule<[({
5
- order?: "sort-package-json" | string[] | undefined;
6
- } | undefined)?], [{
7
- readonly additionalProperties: false;
8
- readonly properties: {
9
- readonly order: {
10
- readonly anyOf: readonly [{
11
- readonly enum: readonly ["sort-package-json"];
12
- readonly type: readonly ["string"];
13
- }, {
14
- readonly items: {
15
- readonly type: readonly ["string"];
16
- };
17
- readonly type: readonly ["array"];
18
- }];
19
- readonly description: "Specifies the sorting order of top-level properties.";
20
- };
21
- };
22
- readonly type: "object";
23
- }]>;
24
- //#endregion
25
- export { rule };
@@ -1,64 +0,0 @@
1
- import { createRule } from "../createRule.mjs";
2
- import detectIndent from "detect-indent";
3
- import { detectNewlineGraceful } from "detect-newline";
4
- import sortObjectKeys from "sort-object-keys";
5
- import { sortOrder } from "sort-package-json";
6
- //#region src/rules/order-properties.ts
7
- const rule = createRule({
8
- create(context) {
9
- return { "Program:exit"() {
10
- const { ast, text } = context.sourceCode;
11
- const { order = "sort-package-json" } = context.options[0] ?? {};
12
- const requiredOrder = order === "sort-package-json" ? sortOrder : order;
13
- const json = JSON.parse(text);
14
- const orderedNonStandardKeys = Object.keys(json).filter((key) => !requiredOrder.includes(key)).sort();
15
- const orderedSource = sortObjectKeys(json, [...requiredOrder, ...orderedNonStandardKeys]);
16
- const orderedKeys = Object.keys(orderedSource);
17
- const { properties } = ast.body[0].expression;
18
- for (let i = 0; i < properties.length; i += 1) {
19
- const { value } = properties[i].key;
20
- if (value === orderedKeys[i]) continue;
21
- context.report({
22
- data: { property: value },
23
- fix(fixer) {
24
- const { indent, type } = detectIndent(text);
25
- const endCharacters = text.endsWith("\n") ? "\n" : "";
26
- const newline = detectNewlineGraceful(text);
27
- let result = JSON.stringify(orderedSource, null, type === "tab" ? " " : indent) + endCharacters;
28
- if (newline === "\r\n") result = result.replace(/\n/g, newline);
29
- return fixer.replaceText(context.sourceCode.ast, result);
30
- },
31
- loc: properties[i].loc,
32
- messageId: "incorrectOrder"
33
- });
34
- }
35
- } };
36
- },
37
- meta: {
38
- defaultOptions: [{ order: "sort-package-json" }],
39
- docs: {
40
- category: "Stylistic",
41
- description: "Enforces that package properties are declared in a consistent order."
42
- },
43
- fixable: "code",
44
- messages: { incorrectOrder: "Top-level property `{{property}}` is not ordered in the standard way." },
45
- schema: [{
46
- additionalProperties: false,
47
- properties: { order: {
48
- anyOf: [{
49
- enum: ["sort-package-json"],
50
- type: ["string"]
51
- }, {
52
- items: { type: ["string"] },
53
- type: ["array"]
54
- }],
55
- description: "Specifies the sorting order of top-level properties."
56
- } },
57
- type: "object"
58
- }],
59
- type: "layout"
60
- },
61
- name: "order-properties"
62
- });
63
- //#endregion
64
- export { rule };
@@ -1,18 +0,0 @@
1
- import { PackageJsonRuleModule } from "../createRule.mjs";
2
-
3
- //#region src/rules/repository-shorthand.d.ts
4
- declare const rule: PackageJsonRuleModule<[({
5
- form?: "object" | "shorthand" | undefined;
6
- } | undefined)?], [{
7
- readonly additionalProperties: false;
8
- readonly properties: {
9
- readonly form: {
10
- readonly description: "Specifies which repository form to enforce.";
11
- readonly enum: readonly ["object", "shorthand"];
12
- readonly type: readonly ["string"];
13
- };
14
- };
15
- readonly type: "object";
16
- }]>;
17
- //#endregion
18
- export { rule };
@@ -1,111 +0,0 @@
1
- import { isJSONStringLiteral } from "../utils/predicates/isJSONStringLiteral.mjs";
2
- import { createRule } from "../createRule.mjs";
3
- import { findPropertyWithKeyValue } from "../utils/findPropertyWithKeyValue.mjs";
4
- //#region src/rules/repository-shorthand.ts
5
- const providerRegexes = {
6
- bitbucket: /^(?:git\+)?(?:ssh:\/\/git@|http?s:\/\/)?(?:www\.)?bitbucket\.org\//,
7
- gist: /^(?:git\+)?(?:ssh:\/\/git@|http?s:\/\/)?(?:www\.)?gist\.github\.com\//,
8
- github: /^(?:git\+)?(?:ssh:\/\/git@|http?s:\/\/)?(?:www\.)?github\.com\//,
9
- gitlab: /^(?:git\+)?(?:ssh:\/\/git@|http?s:\/\/)?(?:www\.)?gitlab\.com\//
10
- };
11
- const providerUrls = {
12
- bitbucket: "https://bitbucket.org/",
13
- gist: "https://gist.github.com/",
14
- github: "https://github.com/",
15
- gitlab: "https://gitlab.com/"
16
- };
17
- const providers = Object.keys(providerRegexes);
18
- const isProvider = (value) => value in providerRegexes;
19
- const cleanUrl = (url, provider) => url.replace(providerRegexes[provider], "").replace(/\.git$/, "");
20
- const getProviderFromUrl = (url) => {
21
- return providers.find((provider) => providerRegexes[provider].test(url));
22
- };
23
- const createShorthand = (url, provider) => {
24
- return `${provider}:${cleanUrl(url, provider)}`;
25
- };
26
- const createUrl = (shorthand) => {
27
- if (shorthand.includes(":")) {
28
- const [provider, repo] = shorthand.split(":");
29
- if (isProvider(provider)) return `${providerUrls[provider]}${repo}`;
30
- }
31
- return `${providerUrls.github}${shorthand}`;
32
- };
33
- const rule = createRule({
34
- create(context) {
35
- const [{ form = "object" } = {}] = context.options;
36
- function validateRepositoryForObject(node) {
37
- if (isJSONStringLiteral(node.value)) context.report({
38
- fix(fixer) {
39
- if (!isJSONStringLiteral(node.value) || node.value.value.split("/").filter(Boolean).length !== 2) return null;
40
- return fixer.replaceText(node.value, JSON.stringify({
41
- type: "git",
42
- url: createUrl(node.value.value)
43
- }, null, 2));
44
- },
45
- messageId: "preferObject",
46
- node: node.value
47
- });
48
- }
49
- function validateRepositoryForShorthand(node) {
50
- if (isJSONStringLiteral(node.value)) {
51
- const { value } = node.value;
52
- const provider = getProviderFromUrl(value);
53
- if (provider) context.report({
54
- fix(fixer) {
55
- return fixer.replaceText(node.value, JSON.stringify(createShorthand(value, provider)));
56
- },
57
- messageId: "preferShorthand",
58
- node: node.value
59
- });
60
- return;
61
- }
62
- if (node.value.type !== "JSONObjectExpression") return;
63
- const { properties } = node.value;
64
- if (findPropertyWithKeyValue(properties, "directory")) return;
65
- const typeProperty = findPropertyWithKeyValue(properties, "type");
66
- if (typeProperty?.value.type !== "JSONLiteral" || typeProperty.value.value !== "git") return;
67
- const urlProperty = findPropertyWithKeyValue(properties, "url");
68
- if (urlProperty?.value.type !== "JSONLiteral" || typeof urlProperty.value.value !== "string") return;
69
- const url = urlProperty.value.value;
70
- const provider = getProviderFromUrl(url);
71
- if (provider) context.report({
72
- fix(fixer) {
73
- return fixer.replaceText(node.value, JSON.stringify(createShorthand(url, provider)));
74
- },
75
- messageId: "preferShorthand",
76
- node: node.value
77
- });
78
- }
79
- return { JSONProperty(node) {
80
- if (node.key.type !== "JSONLiteral" || node.key.value !== "repository" || node.parent.parent.parent.type !== "Program") return;
81
- if (form === "shorthand") validateRepositoryForShorthand(node);
82
- else validateRepositoryForObject(node);
83
- } };
84
- },
85
- meta: {
86
- defaultOptions: [{ form: "object" }],
87
- docs: {
88
- category: "Best Practices",
89
- description: "Enforce either object or shorthand declaration for repository.",
90
- recommended: true
91
- },
92
- fixable: "code",
93
- messages: {
94
- preferObject: "Prefer an object locator for a repository.",
95
- preferShorthand: "Prefer a shorthand locator for a supported repository provider."
96
- },
97
- schema: [{
98
- additionalProperties: false,
99
- properties: { form: {
100
- description: "Specifies which repository form to enforce.",
101
- enum: ["object", "shorthand"],
102
- type: ["string"]
103
- } },
104
- type: "object"
105
- }],
106
- type: "suggestion"
107
- },
108
- name: "repository-shorthand"
109
- });
110
- //#endregion
111
- export { rule };
@@ -1,22 +0,0 @@
1
- import { PackageJsonRuleModule } from "../createRule.mjs";
2
-
3
- //#region src/rules/require-attribution.d.ts
4
- declare const rule: PackageJsonRuleModule<[({
5
- ignorePrivate?: boolean | undefined;
6
- preferContributorsOnly?: boolean | undefined;
7
- } | undefined)?], [{
8
- readonly additionalProperties: false;
9
- readonly properties: {
10
- readonly ignorePrivate: {
11
- readonly description: "Skip attribution requirements for packages with `\"private\": true`.";
12
- readonly type: "boolean";
13
- };
14
- readonly preferContributorsOnly: {
15
- readonly description: "Require that only `contributors` is present, and `author` is not defined.";
16
- readonly type: "boolean";
17
- };
18
- };
19
- readonly type: "object";
20
- }]>;
21
- //#endregion
22
- export { rule };
@@ -1,91 +0,0 @@
1
- import { createRule } from "../createRule.mjs";
2
- import { fixRemoveObjectProperty } from "eslint-fix-utils";
3
- //#region src/rules/require-attribution.ts
4
- const rule = createRule({
5
- create(context) {
6
- const preferContributorsOnly = context.options[0]?.preferContributorsOnly ?? false;
7
- const ignorePrivate = context.options[0]?.ignorePrivate ?? true;
8
- let authorPropertyNode;
9
- let contributorsPropertyNode;
10
- let isPrivatePackage = false;
11
- return {
12
- "Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.value=author]"(node) {
13
- authorPropertyNode = node;
14
- },
15
- "Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.value=contributors]"(node) {
16
- contributorsPropertyNode = node;
17
- const contributorsValue = node.value;
18
- if (contributorsValue.type !== "JSONArrayExpression" || contributorsValue.elements.every((element) => !element)) context.report({
19
- messageId: "noContributors",
20
- node
21
- });
22
- },
23
- "Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.value=private]"(node) {
24
- if (node.value.type === "JSONLiteral" && node.value.value === true) isPrivatePackage = true;
25
- },
26
- "Program:exit"() {
27
- if (ignorePrivate && isPrivatePackage) return;
28
- if (preferContributorsOnly) {
29
- if (authorPropertyNode) context.report({
30
- messageId: "contributorsOnly",
31
- node: authorPropertyNode,
32
- suggest: [{
33
- fix: fixRemoveObjectProperty(context, authorPropertyNode),
34
- messageId: "removeAuthor"
35
- }]
36
- });
37
- if (!contributorsPropertyNode) context.report({
38
- loc: {
39
- column: 0,
40
- line: 1
41
- },
42
- messageId: "missingContributor"
43
- });
44
- } else if (!authorPropertyNode && !contributorsPropertyNode) context.report({
45
- loc: {
46
- column: 0,
47
- line: 1
48
- },
49
- messageId: "missing"
50
- });
51
- }
52
- };
53
- },
54
- meta: {
55
- defaultOptions: [{
56
- ignorePrivate: true,
57
- preferContributorsOnly: false
58
- }],
59
- docs: {
60
- category: "Best Practices",
61
- description: "Ensures that proper attribution is included, requiring that either `author` or `contributors` is defined, and that if `contributors` is present, it should include at least one contributor.",
62
- recommended: true
63
- },
64
- hasSuggestions: true,
65
- messages: {
66
- contributorsOnly: "Only `contributors` should be defined for attribution.",
67
- missing: "Property attribution is required. Either `author` or `contributors` should be defined.",
68
- missingContributor: "Property attribution is required. `contributors` should be defined.",
69
- noContributors: "At least one contributor should be defined.",
70
- removeAuthor: "Remove `author`."
71
- },
72
- schema: [{
73
- additionalProperties: false,
74
- properties: {
75
- ignorePrivate: {
76
- description: "Skip attribution requirements for packages with `\"private\": true`.",
77
- type: "boolean"
78
- },
79
- preferContributorsOnly: {
80
- description: "Require that only `contributors` is present, and `author` is not defined.",
81
- type: "boolean"
82
- }
83
- },
84
- type: "object"
85
- }],
86
- type: "suggestion"
87
- },
88
- name: "require-attribution"
89
- });
90
- //#endregion
91
- export { rule };
@@ -1,22 +0,0 @@
1
- import { PackageJsonRuleModule } from "../createRule.mjs";
2
- import { CreateRequirePropertyRuleOptions } from "../utils/createSimpleRequirePropertyRule.mjs";
3
-
4
- //#region src/rules/require-properties.d.ts
5
- declare const propertyConfig: [name: string, options?: CreateRequirePropertyRuleOptions][];
6
- declare const rules: {
7
- [k: string]: PackageJsonRuleModule<[] | [({
8
- ignorePrivate: boolean;
9
- } | undefined)?], [] | [{
10
- readonly additionalProperties: false;
11
- readonly properties: {
12
- readonly ignorePrivate: {
13
- readonly default: boolean;
14
- readonly description: "Determines if this rule should be enforced when the package's `private` property is `true`.";
15
- readonly type: "boolean";
16
- };
17
- };
18
- readonly type: "object";
19
- }]>;
20
- };
21
- //#endregion
22
- export { propertyConfig, rules };
@@ -1,74 +0,0 @@
1
- import { createSimpleRequirePropertyRule } from "../utils/createSimpleRequirePropertyRule.mjs";
2
- import { getGitAuthor } from "../utils/git/getGitAuthor.mjs";
3
- //#region src/rules/require-properties.ts
4
- const propertyConfig = [
5
- ["author", { fixValue: getGitAuthor }],
6
- ["bin"],
7
- ["browser"],
8
- ["bugs", { ignorePrivateDefault: true }],
9
- ["bundleDependencies"],
10
- ["config"],
11
- ["contributors"],
12
- ["cpu"],
13
- ["dependencies"],
14
- ["description", { isRecommended: true }],
15
- ["devDependencies"],
16
- ["devEngines"],
17
- ["directories"],
18
- ["engines"],
19
- ["exports", {
20
- ignorePrivateDefault: true,
21
- isRecommended: true
22
- }],
23
- ["files", {
24
- ignorePrivateDefault: true,
25
- isRecommended: true
26
- }],
27
- ["funding"],
28
- ["gypfile"],
29
- ["homepage", { ignorePrivateDefault: true }],
30
- ["keywords", { ignorePrivateDefault: true }],
31
- ["libc"],
32
- ["license", {
33
- ignorePrivateDefault: true,
34
- isRecommended: true
35
- }],
36
- ["main"],
37
- ["man"],
38
- ["module"],
39
- ["name", {
40
- ignorePrivateDefault: true,
41
- isRecommended: true
42
- }],
43
- ["optionalDependencies"],
44
- ["os"],
45
- ["packageManager"],
46
- ["peerDependencies"],
47
- ["peerDependenciesMeta"],
48
- ["private", { fixValue: false }],
49
- ["publishConfig", { ignorePrivateDefault: true }],
50
- ["repository", {
51
- ignorePrivateDefault: true,
52
- isRecommended: true
53
- }],
54
- ["scripts"],
55
- ["sideEffects", {
56
- ignorePrivateDefault: true,
57
- isRecommended: true
58
- }],
59
- ["type", {
60
- fixValue: "commonjs",
61
- isRecommended: true
62
- }],
63
- ["types"],
64
- ["version", {
65
- ignorePrivateDefault: true,
66
- isRecommended: true
67
- }]
68
- ];
69
- const rules = Object.fromEntries(propertyConfig.map(([propertyName, options]) => {
70
- const { rule, ruleName } = createSimpleRequirePropertyRule(propertyName, options);
71
- return [ruleName, rule];
72
- }));
73
- //#endregion
74
- export { propertyConfig, rules };
@@ -1,92 +0,0 @@
1
- import { PackageJsonRuleModule } from "../createRule.mjs";
2
-
3
- //#region src/rules/restrict-dependency-ranges.d.ts
4
- declare const rule: PackageJsonRuleModule<[({
5
- forDependencyTypes?: string[] | undefined;
6
- forPackages?: string[] | undefined;
7
- forVersions?: string | undefined;
8
- rangeType: "caret" | "pin" | "tilde" | ("caret" | "pin" | "tilde")[];
9
- } | {
10
- forDependencyTypes?: string[] | undefined;
11
- forPackages?: string[] | undefined;
12
- forVersions?: string | undefined;
13
- rangeType: "caret" | "pin" | "tilde" | ("caret" | "pin" | "tilde")[];
14
- }[] | undefined)?], [{
15
- readonly oneOf: readonly [{
16
- readonly additionalProperties: false;
17
- readonly properties: {
18
- readonly forDependencyTypes: {
19
- readonly description: "Apply a range type restriction for an entire group of dependencies by which type of dependencies they belong to.";
20
- readonly items: {
21
- readonly enum: string[];
22
- };
23
- readonly type: "array";
24
- };
25
- readonly forPackages: {
26
- readonly description: "The exact name of a package, or a regex pattern used to match a group of packages by name.";
27
- readonly items: {
28
- readonly type: "string";
29
- };
30
- readonly type: "array";
31
- };
32
- readonly forVersions: {
33
- readonly description: "Apply a restriction to a specific semver range.";
34
- readonly type: "string";
35
- };
36
- readonly rangeType: {
37
- readonly 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).";
38
- readonly oneOf: readonly [{
39
- readonly enum: readonly ["caret", "pin", "tilde"];
40
- }, {
41
- readonly items: {
42
- readonly enum: readonly ["caret", "pin", "tilde"];
43
- };
44
- readonly type: "array";
45
- }];
46
- };
47
- };
48
- readonly required: readonly ["rangeType"];
49
- readonly type: "object";
50
- }, {
51
- readonly description: "Array of configuration options, specifying range requirements.";
52
- readonly items: {
53
- readonly additionalProperties: false;
54
- readonly properties: {
55
- readonly forDependencyTypes: {
56
- readonly description: "Apply a range type restriction for an entire group of dependencies by which type of dependencies they belong to.";
57
- readonly items: {
58
- readonly enum: string[];
59
- };
60
- readonly type: "array";
61
- };
62
- readonly forPackages: {
63
- readonly description: "The exact name of a package, or a regex pattern used to match a group of packages by name.";
64
- readonly items: {
65
- readonly type: "string";
66
- };
67
- readonly type: "array";
68
- };
69
- readonly forVersions: {
70
- readonly description: "Apply a restriction to a specific semver range.";
71
- readonly type: "string";
72
- };
73
- readonly rangeType: {
74
- readonly 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).";
75
- readonly oneOf: readonly [{
76
- readonly enum: readonly ["caret", "pin", "tilde"];
77
- }, {
78
- readonly items: {
79
- readonly enum: readonly ["caret", "pin", "tilde"];
80
- };
81
- readonly type: "array";
82
- }];
83
- };
84
- };
85
- readonly required: readonly ["rangeType"];
86
- readonly type: "object";
87
- };
88
- readonly type: "array";
89
- }];
90
- }]>;
91
- //#endregion
92
- export { rule };