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.
- package/README.md +107 -106
- 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
- package/dist/experimental/index.d.mts +68 -0
- package/{lib/experimental/plugin.mjs → dist/experimental/index.mjs} +10 -5
- package/dist/index.d.mts +99 -0
- package/{lib → dist}/index.mjs +1 -1
- package/dist/plugin-C-Z8sf5g.mjs +1737 -0
- package/package.json +33 -27
- package/lib/createRule.d.mts +0 -59
- package/lib/createRule.mjs +0 -24
- package/lib/experimental/index.d.mts +0 -34
- package/lib/experimental/index.mjs +0 -7
- package/lib/experimental/plugin.d.mts +0 -40
- package/lib/index.d.mts +0 -49
- package/lib/node_modules/.pnpm/@types_estree@1.0.8/node_modules/@types/estree/index.d.mts +0 -438
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/any.d.mts +0 -20
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/array.d.mts +0 -28
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/const.d.mts +0 -25
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/enum.d.mts +0 -25
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/exclusion/any.d.mts +0 -16
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/exclusion/array.d.mts +0 -20
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/exclusion/const.d.mts +0 -28
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/exclusion/enum.d.mts +0 -23
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/exclusion/index.d.mts +0 -24
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/exclusion/object.d.mts +0 -44
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/exclusion/primitive.d.mts +0 -16
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/exclusion/tuple.d.mts +0 -43
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/exclusion/union.d.mts +0 -13
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/exclusion/utils.d.mts +0 -35
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/intersection/any.d.mts +0 -23
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/intersection/array.d.mts +0 -24
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/intersection/const.d.mts +0 -34
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/intersection/enum.d.mts +0 -26
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/intersection/index.d.mts +0 -24
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/intersection/object.d.mts +0 -25
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/intersection/primitive.d.mts +0 -23
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/intersection/tuple.d.mts +0 -26
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/intersection/union.d.mts +0 -17
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/intersection/utils.d.mts +0 -10
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/never.d.mts +0 -9
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/object.d.mts +0 -49
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/primitive.d.mts +0 -26
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/resolve.d.mts +0 -22
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/tuple.d.mts +0 -36
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/type.d.mts +0 -18
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/union.d.mts +0 -23
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/utils.d.mts +0 -7
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/and.d.mts +0 -4
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/extends.d.mts +0 -7
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/if.d.mts +0 -4
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/intersectUnion.d.mts +0 -4
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/isNever.d.mts +0 -4
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/merge.d.mts +0 -6
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/not.d.mts +0 -4
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/or.d.mts +0 -4
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/prettify.d.mts +0 -6
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/tail.d.mts +0 -4
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/unionLast.d.mts +0 -6
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/unionPop.d.mts +0 -6
- package/lib/plugin.d.mts +0 -56
- package/lib/plugin.mjs +0 -93
- package/lib/rules/bin-name-casing.d.mts +0 -6
- package/lib/rules/bin-name-casing.mjs +0 -41
- package/lib/rules/exports-subpaths-style.d.mts +0 -18
- package/lib/rules/exports-subpaths-style.mjs +0 -71
- package/lib/rules/no-empty-fields.d.mts +0 -20
- package/lib/rules/no-empty-fields.mjs +0 -90
- package/lib/rules/no-local-dependencies.d.mts +0 -17
- package/lib/rules/no-local-dependencies.mjs +0 -47
- package/lib/rules/no-redundant-files.d.mts +0 -6
- package/lib/rules/no-redundant-files.mjs +0 -100
- package/lib/rules/no-redundant-publishConfig.d.mts +0 -6
- package/lib/rules/no-redundant-publishConfig.mjs +0 -50
- package/lib/rules/order-properties.d.mts +0 -25
- package/lib/rules/order-properties.mjs +0 -64
- package/lib/rules/repository-shorthand.d.mts +0 -18
- package/lib/rules/repository-shorthand.mjs +0 -111
- package/lib/rules/require-attribution.d.mts +0 -22
- package/lib/rules/require-attribution.mjs +0 -91
- package/lib/rules/require-properties.d.mts +0 -22
- package/lib/rules/require-properties.mjs +0 -74
- package/lib/rules/restrict-dependency-ranges.d.mts +0 -92
- package/lib/rules/restrict-dependency-ranges.mjs +0 -147
- package/lib/rules/restrict-private-properties.d.mts +0 -20
- package/lib/rules/restrict-private-properties.mjs +0 -53
- package/lib/rules/restrict-top-level-properties.d.mts +0 -39
- package/lib/rules/restrict-top-level-properties.mjs +0 -73
- package/lib/rules/scripts-name-casing.d.mts +0 -6
- package/lib/rules/scripts-name-casing.mjs +0 -44
- package/lib/rules/sort-collections.d.mts +0 -35
- package/lib/rules/sort-collections.mjs +0 -111
- package/lib/rules/specify-peers-locally.d.mts +0 -6
- package/lib/rules/specify-peers-locally.mjs +0 -63
- package/lib/rules/unique-dependencies.d.mts +0 -6
- package/lib/rules/unique-dependencies.mjs +0 -87
- package/lib/rules/valid-author.d.mts +0 -6
- package/lib/rules/valid-author.mjs +0 -59
- package/lib/rules/valid-peerDependenciesMeta-relationship.d.mts +0 -6
- package/lib/rules/valid-peerDependenciesMeta-relationship.mjs +0 -50
- package/lib/rules/valid-properties.d.mts +0 -9
- package/lib/rules/valid-properties.mjs +0 -57
- package/lib/rules/valid-repository-directory.d.mts +0 -6
- package/lib/rules/valid-repository-directory.mjs +0 -73
- package/lib/types/estree.d.mts +0 -8
- package/lib/utils/createSimpleRequirePropertyRule.d.mts +0 -48
- package/lib/utils/createSimpleRequirePropertyRule.mjs +0 -62
- package/lib/utils/createSimpleValidPropertyRule.d.mts +0 -17
- package/lib/utils/createSimpleValidPropertyRule.mjs +0 -57
- package/lib/utils/findPropertyWithKeyValue.d.mts +0 -10
- package/lib/utils/findPropertyWithKeyValue.mjs +0 -6
- package/lib/utils/formatErrors.d.mts +0 -9
- package/lib/utils/formatErrors.mjs +0 -12
- package/lib/utils/git/getGitAuthor.d.mts +0 -8
- package/lib/utils/git/getGitAuthor.mjs +0 -29
- package/lib/utils/git/index.d.mts +0 -2
- package/lib/utils/git/index.mjs +0 -2
- package/lib/utils/predicates/index.d.mts +0 -4
- package/lib/utils/predicates/index.mjs +0 -4
- package/lib/utils/predicates/isJSONStringLiteral.d.mts +0 -6
- package/lib/utils/predicates/isJSONStringLiteral.mjs +0 -6
- package/lib/utils/predicates/isNotNullish.d.mts +0 -4
- package/lib/utils/predicates/isNotNullish.mjs +0 -6
- package/lib/utils/predicates/isPackageJson.d.mts +0 -4
- package/lib/utils/predicates/isPackageJson.mjs +0 -4
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { isJSONStringLiteral } from "../utils/predicates/isJSONStringLiteral.mjs";
|
|
2
|
-
import { createRule } from "../createRule.mjs";
|
|
3
|
-
import semver from "semver";
|
|
4
|
-
//#region src/rules/restrict-dependency-ranges.ts
|
|
5
|
-
const DEPENDENCY_TYPES = [
|
|
6
|
-
"dependencies",
|
|
7
|
-
"devDependencies",
|
|
8
|
-
"optionalDependencies",
|
|
9
|
-
"peerDependencies"
|
|
10
|
-
];
|
|
11
|
-
const RANGE_TYPES = [
|
|
12
|
-
"caret",
|
|
13
|
-
"pin",
|
|
14
|
-
"tilde"
|
|
15
|
-
];
|
|
16
|
-
const schemaOptions = {
|
|
17
|
-
additionalProperties: false,
|
|
18
|
-
properties: {
|
|
19
|
-
forDependencyTypes: {
|
|
20
|
-
description: "Apply a range type restriction for an entire group of dependencies by which type of dependencies they belong to.",
|
|
21
|
-
items: { enum: DEPENDENCY_TYPES },
|
|
22
|
-
type: "array"
|
|
23
|
-
},
|
|
24
|
-
forPackages: {
|
|
25
|
-
description: "The exact name of a package, or a regex pattern used to match a group of packages by name.",
|
|
26
|
-
items: { type: "string" },
|
|
27
|
-
type: "array"
|
|
28
|
-
},
|
|
29
|
-
forVersions: {
|
|
30
|
-
description: "Apply a restriction to a specific semver range.",
|
|
31
|
-
type: "string"
|
|
32
|
-
},
|
|
33
|
-
rangeType: {
|
|
34
|
-
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).",
|
|
35
|
-
oneOf: [{ enum: RANGE_TYPES }, {
|
|
36
|
-
items: { enum: RANGE_TYPES },
|
|
37
|
-
type: "array"
|
|
38
|
-
}]
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
required: ["rangeType"],
|
|
42
|
-
type: "object"
|
|
43
|
-
};
|
|
44
|
-
const SYMBOLS = {
|
|
45
|
-
caret: "^",
|
|
46
|
-
pin: "",
|
|
47
|
-
tilde: "~"
|
|
48
|
-
};
|
|
49
|
-
/**
|
|
50
|
-
* Given the original version, update it to use the correct range type.
|
|
51
|
-
*/
|
|
52
|
-
const changeVersionRange = (version, rangeType) => {
|
|
53
|
-
if (/^workspace:[~^*]$/.test(version)) switch (rangeType) {
|
|
54
|
-
case "caret": return "workspace:^";
|
|
55
|
-
case "pin": return "workspace:*";
|
|
56
|
-
default: return "workspace:~";
|
|
57
|
-
}
|
|
58
|
-
return version.replace(/^(workspace:)?(\^|~|<=?|>=?)?/, `$1${SYMBOLS[rangeType]}`);
|
|
59
|
-
};
|
|
60
|
-
/**
|
|
61
|
-
* Check if the version is in a form that this rule supports.
|
|
62
|
-
*/
|
|
63
|
-
const isVersionSupported = (version) => {
|
|
64
|
-
if (/^workspace:[*^~]$/.test(version)) return true;
|
|
65
|
-
const rawVersion = version.replace(/^workspace:/, "");
|
|
66
|
-
return !!semver.validRange(rawVersion);
|
|
67
|
-
};
|
|
68
|
-
const capitalize = (str) => {
|
|
69
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
70
|
-
};
|
|
71
|
-
const rule = createRule({
|
|
72
|
-
create(context) {
|
|
73
|
-
if (!context.options[0]) return {};
|
|
74
|
-
const optionsArray = (Array.isArray(context.options[0]) ? context.options[0].toReversed() : [context.options[0]]).map((option) => ({
|
|
75
|
-
...option,
|
|
76
|
-
forPackages: option.forPackages?.map((pattern) => new RegExp(pattern)),
|
|
77
|
-
rangeTypes: Array.isArray(option.rangeType) ? option.rangeType : [option.rangeType]
|
|
78
|
-
}));
|
|
79
|
-
return { "Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.type=JSONLiteral][value.type=JSONObjectExpression]"(node) {
|
|
80
|
-
const dependencyType = node.key.value;
|
|
81
|
-
if (!DEPENDENCY_TYPES.includes(dependencyType)) return;
|
|
82
|
-
for (const property of node.value.properties) {
|
|
83
|
-
if (!isJSONStringLiteral(property.key) || !isJSONStringLiteral(property.value)) continue;
|
|
84
|
-
const name = property.key.value;
|
|
85
|
-
const version = property.value.value;
|
|
86
|
-
if (!isVersionSupported(version)) continue;
|
|
87
|
-
const isPinned = !!semver.parse(version) || version === "workspace:*";
|
|
88
|
-
const isTildeRange = !!semver.validRange(version) && version.startsWith("~") || version.startsWith("workspace:~");
|
|
89
|
-
const isCaretRange = !!semver.validRange(version) && version.startsWith("^") || version.startsWith("workspace:^");
|
|
90
|
-
for (const options of optionsArray) {
|
|
91
|
-
if (options.forDependencyTypes && !options.forDependencyTypes.includes(dependencyType)) continue;
|
|
92
|
-
if (options.forPackages) {
|
|
93
|
-
if (!options.forPackages.some((packageNameRegex) => packageNameRegex.test(name))) continue;
|
|
94
|
-
}
|
|
95
|
-
if (options.forVersions && (/^workspace:[^~*]?$/.test(version) || version !== "*" && !semver.satisfies(version.replace(/(?:workspace:)?[^~]?/, ""), options.forVersions))) continue;
|
|
96
|
-
const rangeTypes = options.rangeTypes;
|
|
97
|
-
if (version === "*") {
|
|
98
|
-
context.report({
|
|
99
|
-
data: { rangeTypes: rangeTypes.join(", ") },
|
|
100
|
-
messageId: "wrongRangeType",
|
|
101
|
-
node: property.value
|
|
102
|
-
});
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
if (!rangeTypes.some((rangeType) => {
|
|
106
|
-
switch (rangeType) {
|
|
107
|
-
case "caret": return isCaretRange;
|
|
108
|
-
case "pin": return isPinned;
|
|
109
|
-
case "tilde": return isTildeRange;
|
|
110
|
-
}
|
|
111
|
-
})) context.report({
|
|
112
|
-
data: { rangeTypes: rangeTypes.join(", ") },
|
|
113
|
-
messageId: "wrongRangeType",
|
|
114
|
-
node: property.value,
|
|
115
|
-
suggest: rangeTypes.map((rangeType) => ({
|
|
116
|
-
fix(fixer) {
|
|
117
|
-
return fixer.replaceText(property.value, `"${changeVersionRange(version, rangeType)}"`);
|
|
118
|
-
},
|
|
119
|
-
messageId: `changeTo${capitalize(rangeType)}`
|
|
120
|
-
}))
|
|
121
|
-
});
|
|
122
|
-
break;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
} };
|
|
126
|
-
},
|
|
127
|
-
meta: {
|
|
128
|
-
defaultOptions: [[]],
|
|
129
|
-
docs: { description: "Restricts the range of dependencies to allow or disallow specific types of ranges." },
|
|
130
|
-
hasSuggestions: true,
|
|
131
|
-
messages: {
|
|
132
|
-
changeToCaret: "Change to use a caret range.",
|
|
133
|
-
changeToPin: "Pin the version.",
|
|
134
|
-
changeToTilde: "Change to use a tilde range.",
|
|
135
|
-
wrongRangeType: "This dependency is using the wrong range type. Acceptable range type(s): {{rangeTypes}}"
|
|
136
|
-
},
|
|
137
|
-
schema: [{ oneOf: [schemaOptions, {
|
|
138
|
-
description: "Array of configuration options, specifying range requirements.",
|
|
139
|
-
items: schemaOptions,
|
|
140
|
-
type: "array"
|
|
141
|
-
}] }],
|
|
142
|
-
type: "suggestion"
|
|
143
|
-
},
|
|
144
|
-
name: "restrict-dependency-ranges"
|
|
145
|
-
});
|
|
146
|
-
//#endregion
|
|
147
|
-
export { rule };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { PackageJsonRuleModule } from "../createRule.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/rules/restrict-private-properties.d.ts
|
|
4
|
-
declare const rule: PackageJsonRuleModule<[({
|
|
5
|
-
blockedProperties?: string[] | undefined;
|
|
6
|
-
} | undefined)?], [{
|
|
7
|
-
readonly additionalProperties: false;
|
|
8
|
-
readonly properties: {
|
|
9
|
-
readonly blockedProperties: {
|
|
10
|
-
readonly description: "Array of property names to disallow in private packages.";
|
|
11
|
-
readonly items: {
|
|
12
|
-
readonly type: "string";
|
|
13
|
-
};
|
|
14
|
-
readonly type: "array";
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
readonly type: "object";
|
|
18
|
-
}]>;
|
|
19
|
-
//#endregion
|
|
20
|
-
export { rule };
|
|
@@ -1,53 +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/restrict-private-properties.ts
|
|
5
|
-
const defaultBlockedProperties = ["files", "publishConfig"];
|
|
6
|
-
const rule = createRule({
|
|
7
|
-
create(context) {
|
|
8
|
-
const blockedProperties = context.options[0]?.blockedProperties ?? defaultBlockedProperties;
|
|
9
|
-
return { "Program > JSONExpressionStatement > JSONObjectExpression"(node) {
|
|
10
|
-
if (node.properties.every((property) => !(isJSONStringLiteral(property.key) && property.key.value === "private" && property.value.type === "JSONLiteral" && property.value.value === true))) return;
|
|
11
|
-
for (const property of node.properties) if (isJSONStringLiteral(property.key) && blockedProperties.includes(property.key.value)) {
|
|
12
|
-
const isEmpty = property.value.type === "JSONArrayExpression" && property.value.elements.length === 0 || property.value.type === "JSONObjectExpression" && property.value.properties.length === 0;
|
|
13
|
-
context.report({
|
|
14
|
-
data: { property: property.key.value },
|
|
15
|
-
messageId: "unnecessaryProperty",
|
|
16
|
-
node: property,
|
|
17
|
-
...isEmpty ? { fix: fixRemoveObjectProperty(context, property) } : { suggest: [{
|
|
18
|
-
data: { property: property.key.value },
|
|
19
|
-
fix: fixRemoveObjectProperty(context, property),
|
|
20
|
-
messageId: "removePropertySuggestion"
|
|
21
|
-
}] }
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
} };
|
|
25
|
-
},
|
|
26
|
-
meta: {
|
|
27
|
-
defaultOptions: [{ blockedProperties: defaultBlockedProperties }],
|
|
28
|
-
docs: {
|
|
29
|
-
category: "Best Practices",
|
|
30
|
-
description: "Disallows unnecessary properties in private packages.",
|
|
31
|
-
recommended: false
|
|
32
|
-
},
|
|
33
|
-
fixable: "code",
|
|
34
|
-
hasSuggestions: true,
|
|
35
|
-
messages: {
|
|
36
|
-
removePropertySuggestion: "Remove the '{{ property }}' field.",
|
|
37
|
-
unnecessaryProperty: "The '{{ property }}' field is unnecessary in private packages and can be removed."
|
|
38
|
-
},
|
|
39
|
-
schema: [{
|
|
40
|
-
additionalProperties: false,
|
|
41
|
-
properties: { blockedProperties: {
|
|
42
|
-
description: "Array of property names to disallow in private packages.",
|
|
43
|
-
items: { type: "string" },
|
|
44
|
-
type: "array"
|
|
45
|
-
} },
|
|
46
|
-
type: "object"
|
|
47
|
-
}],
|
|
48
|
-
type: "suggestion"
|
|
49
|
-
},
|
|
50
|
-
name: "restrict-private-properties"
|
|
51
|
-
});
|
|
52
|
-
//#endregion
|
|
53
|
-
export { rule };
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { PackageJsonRuleModule } from "../createRule.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/rules/restrict-top-level-properties.d.ts
|
|
4
|
-
declare const rule: PackageJsonRuleModule<[({
|
|
5
|
-
ban?: (string | {
|
|
6
|
-
message?: string | undefined;
|
|
7
|
-
property: string;
|
|
8
|
-
})[] | undefined;
|
|
9
|
-
} | undefined)?], [{
|
|
10
|
-
readonly additionalProperties: false;
|
|
11
|
-
readonly properties: {
|
|
12
|
-
readonly ban: {
|
|
13
|
-
readonly description: "List of top-level properties to ban. Each entry can be a property name string or an object with a property name and an optional custom message.";
|
|
14
|
-
readonly items: {
|
|
15
|
-
readonly oneOf: readonly [{
|
|
16
|
-
readonly type: "string";
|
|
17
|
-
}, {
|
|
18
|
-
readonly additionalProperties: false;
|
|
19
|
-
readonly properties: {
|
|
20
|
-
readonly message: {
|
|
21
|
-
readonly description: "Custom message to append to the error report.";
|
|
22
|
-
readonly type: "string";
|
|
23
|
-
};
|
|
24
|
-
readonly property: {
|
|
25
|
-
readonly description: "The top-level property name to ban.";
|
|
26
|
-
readonly type: "string";
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
readonly required: readonly ["property"];
|
|
30
|
-
readonly type: "object";
|
|
31
|
-
}];
|
|
32
|
-
};
|
|
33
|
-
readonly type: "array";
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
readonly type: "object";
|
|
37
|
-
}]>;
|
|
38
|
-
//#endregion
|
|
39
|
-
export { rule };
|
|
@@ -1,73 +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/restrict-top-level-properties.ts
|
|
5
|
-
const rule = createRule({
|
|
6
|
-
create(context) {
|
|
7
|
-
const banList = Object.fromEntries(
|
|
8
|
-
/* v8 ignore next - not possible to cover due to presence of `defaultOptions` */
|
|
9
|
-
(context.options[0]?.ban ?? []).map((entry) => typeof entry === "string" ? [entry, ""] : [entry.property, entry.message ?? ""])
|
|
10
|
-
);
|
|
11
|
-
return { "Program > JSONExpressionStatement > JSONObjectExpression"(node) {
|
|
12
|
-
for (const property of node.properties) {
|
|
13
|
-
if (!isJSONStringLiteral(property.key)) continue;
|
|
14
|
-
const propertyName = property.key.value;
|
|
15
|
-
if (Object.hasOwn(banList, propertyName)) {
|
|
16
|
-
const customMessage = banList[propertyName];
|
|
17
|
-
context.report({
|
|
18
|
-
data: {
|
|
19
|
-
customMessage: customMessage ? `: ${customMessage}` : "",
|
|
20
|
-
property: propertyName
|
|
21
|
-
},
|
|
22
|
-
messageId: "bannedProperty",
|
|
23
|
-
node: property.key,
|
|
24
|
-
suggest: [{
|
|
25
|
-
fix: fixRemoveObjectProperty(context, property),
|
|
26
|
-
messageId: "removePropertySuggestion"
|
|
27
|
-
}]
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
} };
|
|
32
|
-
},
|
|
33
|
-
meta: {
|
|
34
|
-
defaultOptions: [{ ban: [] }],
|
|
35
|
-
docs: {
|
|
36
|
-
category: "Best Practices",
|
|
37
|
-
description: "Disallows specified top-level properties in package.json.",
|
|
38
|
-
recommended: false
|
|
39
|
-
},
|
|
40
|
-
hasSuggestions: true,
|
|
41
|
-
messages: {
|
|
42
|
-
bannedProperty: "The `{{ property }}` property is not allowed{{ customMessage }}",
|
|
43
|
-
removePropertySuggestion: "Remove the property."
|
|
44
|
-
},
|
|
45
|
-
schema: [{
|
|
46
|
-
additionalProperties: false,
|
|
47
|
-
properties: { ban: {
|
|
48
|
-
description: "List of top-level properties to ban. Each entry can be a property name string or an object with a property name and an optional custom message.",
|
|
49
|
-
items: { oneOf: [{ type: "string" }, {
|
|
50
|
-
additionalProperties: false,
|
|
51
|
-
properties: {
|
|
52
|
-
message: {
|
|
53
|
-
description: "Custom message to append to the error report.",
|
|
54
|
-
type: "string"
|
|
55
|
-
},
|
|
56
|
-
property: {
|
|
57
|
-
description: "The top-level property name to ban.",
|
|
58
|
-
type: "string"
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
required: ["property"],
|
|
62
|
-
type: "object"
|
|
63
|
-
}] },
|
|
64
|
-
type: "array"
|
|
65
|
-
} },
|
|
66
|
-
type: "object"
|
|
67
|
-
}],
|
|
68
|
-
type: "suggestion"
|
|
69
|
-
},
|
|
70
|
-
name: "restrict-top-level-properties"
|
|
71
|
-
});
|
|
72
|
-
//#endregion
|
|
73
|
-
export { rule };
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { createRule } from "../createRule.mjs";
|
|
2
|
-
import { kebabCase } from "change-case";
|
|
3
|
-
//#region src/rules/scripts-name-casing.ts
|
|
4
|
-
const BUILT_IN_SCRIPTS_IN_CAMEL_CASE = new Set(["prepublishOnly"]);
|
|
5
|
-
const rule = createRule({
|
|
6
|
-
create(context) {
|
|
7
|
-
return { "Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.value=scripts]"(node) {
|
|
8
|
-
if (node.value.type === "JSONObjectExpression") for (const property of node.value.properties) {
|
|
9
|
-
const keyNode = property.key;
|
|
10
|
-
const key = keyNode.value;
|
|
11
|
-
if (BUILT_IN_SCRIPTS_IN_CAMEL_CASE.has(key)) continue;
|
|
12
|
-
const kebabCaseKey = key.split(":").map((segment) => kebabCase(segment)).join(":");
|
|
13
|
-
if (kebabCaseKey !== key) context.report({
|
|
14
|
-
data: { property: key },
|
|
15
|
-
messageId: "invalidCase",
|
|
16
|
-
node: keyNode,
|
|
17
|
-
suggest: [{
|
|
18
|
-
data: { property: key },
|
|
19
|
-
fix: (fixer) => {
|
|
20
|
-
return fixer.replaceText(keyNode, JSON.stringify(kebabCaseKey));
|
|
21
|
-
},
|
|
22
|
-
messageId: "convertToKebabCase"
|
|
23
|
-
}]
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
} };
|
|
27
|
-
},
|
|
28
|
-
meta: {
|
|
29
|
-
docs: {
|
|
30
|
-
category: "Stylistic",
|
|
31
|
-
description: "Enforce that names for `scripts` are in kebab case (optionally separated by colons)."
|
|
32
|
-
},
|
|
33
|
-
hasSuggestions: true,
|
|
34
|
-
messages: {
|
|
35
|
-
convertToKebabCase: "Convert {{ property }} to kebab case.",
|
|
36
|
-
invalidCase: "Script name {{ property }} should be in kebab case."
|
|
37
|
-
},
|
|
38
|
-
schema: [],
|
|
39
|
-
type: "suggestion"
|
|
40
|
-
},
|
|
41
|
-
name: "scripts-name-casing"
|
|
42
|
-
});
|
|
43
|
-
//#endregion
|
|
44
|
-
export { rule };
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { PackageJsonRuleModule } from "../createRule.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/rules/sort-collections.d.ts
|
|
4
|
-
declare const rule: PackageJsonRuleModule<[((string | {
|
|
5
|
-
order: string[];
|
|
6
|
-
key: string;
|
|
7
|
-
})[] | undefined)?], [{
|
|
8
|
-
readonly description: "Array of package properties to require sorting. Provide a string to sort that collection lexicographically (lifecycle-aware for `scripts`), or an object to sort it by a specified order.";
|
|
9
|
-
readonly items: {
|
|
10
|
-
readonly anyOf: readonly [{
|
|
11
|
-
readonly type: "string";
|
|
12
|
-
}, {
|
|
13
|
-
readonly additionalProperties: false;
|
|
14
|
-
readonly properties: {
|
|
15
|
-
readonly key: {
|
|
16
|
-
readonly description: "The collection property to sort.";
|
|
17
|
-
readonly type: "string";
|
|
18
|
-
};
|
|
19
|
-
readonly order: {
|
|
20
|
-
readonly description: "The order to sort the collection by. Keys not listed are appended in lexicographical order.";
|
|
21
|
-
readonly items: {
|
|
22
|
-
readonly type: "string";
|
|
23
|
-
};
|
|
24
|
-
readonly type: "array";
|
|
25
|
-
readonly uniqueItems: true;
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
readonly required: readonly ["key", "order"];
|
|
29
|
-
readonly type: "object";
|
|
30
|
-
}];
|
|
31
|
-
};
|
|
32
|
-
readonly type: "array";
|
|
33
|
-
}]>;
|
|
34
|
-
//#endregion
|
|
35
|
-
export { rule };
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { createRule } from "../createRule.mjs";
|
|
2
|
-
import detectIndent from "detect-indent";
|
|
3
|
-
import { detectNewlineGraceful } from "detect-newline";
|
|
4
|
-
import sortPackageJson from "sort-package-json";
|
|
5
|
-
//#region src/rules/sort-collections.ts
|
|
6
|
-
const defaultCollections = new Set([
|
|
7
|
-
"config",
|
|
8
|
-
"dependencies",
|
|
9
|
-
"devDependencies",
|
|
10
|
-
"exports",
|
|
11
|
-
"optionalDependencies",
|
|
12
|
-
"overrides",
|
|
13
|
-
"peerDependencies",
|
|
14
|
-
"peerDependenciesMeta",
|
|
15
|
-
"scripts"
|
|
16
|
-
]);
|
|
17
|
-
const rule = createRule({
|
|
18
|
-
create(context) {
|
|
19
|
-
const toSort = new Map((context.options[0] ?? Array.from(defaultCollections)).map((entry) => typeof entry === "string" ? [entry, null] : [entry.key, entry.order]));
|
|
20
|
-
return { "JSONProperty:exit"(node) {
|
|
21
|
-
const { key: nodeKey, value: collection } = node;
|
|
22
|
-
if (nodeKey.type !== "JSONLiteral" || collection.type !== "JSONObjectExpression") return;
|
|
23
|
-
const keyPartsReversed = [nodeKey.value];
|
|
24
|
-
for (let currNode = node.parent; currNode; currNode = currNode.parent) if (currNode.type === "JSONProperty" && currNode.key.type === "JSONLiteral") keyPartsReversed.push(currNode.key.value);
|
|
25
|
-
else if (currNode.type === "JSONArrayExpression") return;
|
|
26
|
-
const key = keyPartsReversed.reverse().join(".");
|
|
27
|
-
const customOrder = toSort.get(key);
|
|
28
|
-
if (customOrder === void 0) return;
|
|
29
|
-
const currentOrder = collection.properties;
|
|
30
|
-
const isScripts = keyPartsReversed.at(-1) === "scripts";
|
|
31
|
-
let naturalCompare;
|
|
32
|
-
if (isScripts) {
|
|
33
|
-
const scriptsSource = context.sourceCode.getText(node);
|
|
34
|
-
const { scripts: sortedScripts } = sortPackageJson(JSON.parse(`{${scriptsSource}}`));
|
|
35
|
-
const lifecycleIndex = new Map(Object.keys(sortedScripts).map((k, i) => [k, i]));
|
|
36
|
-
naturalCompare = (a, b) => (lifecycleIndex.get(a) ?? 0) - (lifecycleIndex.get(b) ?? 0);
|
|
37
|
-
} else naturalCompare = (a, b) => a > b ? 1 : -1;
|
|
38
|
-
const orderIndex = new Map((customOrder ?? []).map((k, i) => [k, i]));
|
|
39
|
-
const rank = (k) => orderIndex.get(k) ?? orderIndex.size;
|
|
40
|
-
const desiredOrder = currentOrder.toSorted((a, b) => {
|
|
41
|
-
const aKey = a.key.value;
|
|
42
|
-
const bKey = b.key.value;
|
|
43
|
-
const ai = rank(aKey);
|
|
44
|
-
const bi = rank(bKey);
|
|
45
|
-
if (ai !== bi) return ai - bi;
|
|
46
|
-
return naturalCompare(aKey, bKey);
|
|
47
|
-
});
|
|
48
|
-
if (currentOrder.some((property, i) => desiredOrder[i] !== property)) context.report({
|
|
49
|
-
data: { key },
|
|
50
|
-
fix(fixer) {
|
|
51
|
-
const { text } = context.sourceCode;
|
|
52
|
-
const { indent, type } = detectIndent(text);
|
|
53
|
-
const newline = detectNewlineGraceful(text);
|
|
54
|
-
const indentUnit = type === "tab" ? " " : indent || " ";
|
|
55
|
-
const jsonLines = JSON.stringify(desiredOrder.reduce((out, property) => {
|
|
56
|
-
out[property.key.value] = JSON.parse(context.sourceCode.getText(property.value));
|
|
57
|
-
return out;
|
|
58
|
-
}, {}), null, indentUnit).split("\n");
|
|
59
|
-
const collectionStartLine = collection.loc.start.line;
|
|
60
|
-
const lineText = context.sourceCode.lines[collectionStartLine - 1];
|
|
61
|
-
const leadingWhitespaceMatch = /^\s*/.exec(lineText);
|
|
62
|
-
const leadingWhitespace = leadingWhitespaceMatch ? leadingWhitespaceMatch[0] : "";
|
|
63
|
-
const result = jsonLines.map((l, i) => i === 0 ? l : leadingWhitespace + l).join(newline);
|
|
64
|
-
return fixer.replaceText(collection, result);
|
|
65
|
-
},
|
|
66
|
-
loc: collection.loc,
|
|
67
|
-
messageId: customOrder ? "unsortedOrder" : isScripts ? "unsortedScripts" : "unsortedKeys",
|
|
68
|
-
node
|
|
69
|
-
});
|
|
70
|
-
} };
|
|
71
|
-
},
|
|
72
|
-
meta: {
|
|
73
|
-
defaultOptions: [Array.from(defaultCollections)],
|
|
74
|
-
docs: {
|
|
75
|
-
category: "Best Practices",
|
|
76
|
-
description: "Selected collections must be in a consistent order (lexicographical for most; lifecycle-aware for scripts).",
|
|
77
|
-
recommended: true
|
|
78
|
-
},
|
|
79
|
-
fixable: "code",
|
|
80
|
-
messages: {
|
|
81
|
-
unsortedKeys: "Entries in '{{ key }}' are not in lexicographical order",
|
|
82
|
-
unsortedOrder: "Entries in '{{ key }}' are not in the specified order",
|
|
83
|
-
unsortedScripts: "Entries in 'scripts' are not in lexicographical order and grouped by lifecycles"
|
|
84
|
-
},
|
|
85
|
-
schema: [{
|
|
86
|
-
description: "Array of package properties to require sorting. Provide a string to sort that collection lexicographically (lifecycle-aware for `scripts`), or an object to sort it by a specified order.",
|
|
87
|
-
items: { anyOf: [{ type: "string" }, {
|
|
88
|
-
additionalProperties: false,
|
|
89
|
-
properties: {
|
|
90
|
-
key: {
|
|
91
|
-
description: "The collection property to sort.",
|
|
92
|
-
type: "string"
|
|
93
|
-
},
|
|
94
|
-
order: {
|
|
95
|
-
description: "The order to sort the collection by. Keys not listed are appended in lexicographical order.",
|
|
96
|
-
items: { type: "string" },
|
|
97
|
-
type: "array",
|
|
98
|
-
uniqueItems: true
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
required: ["key", "order"],
|
|
102
|
-
type: "object"
|
|
103
|
-
}] },
|
|
104
|
-
type: "array"
|
|
105
|
-
}],
|
|
106
|
-
type: "layout"
|
|
107
|
-
},
|
|
108
|
-
name: "sort-collections"
|
|
109
|
-
});
|
|
110
|
-
//#endregion
|
|
111
|
-
export { rule };
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { isJSONStringLiteral } from "../utils/predicates/isJSONStringLiteral.mjs";
|
|
2
|
-
import { createRule } from "../createRule.mjs";
|
|
3
|
-
//#region src/rules/specify-peers-locally.ts
|
|
4
|
-
const rule = createRule({
|
|
5
|
-
create(context) {
|
|
6
|
-
const devDependencyNames = /* @__PURE__ */ new Set();
|
|
7
|
-
let devDependenciesObjectNode;
|
|
8
|
-
const peerDependencyMap = {};
|
|
9
|
-
return {
|
|
10
|
-
"Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.type=JSONLiteral][value.type=JSONObjectExpression][key.value=devDependencies]"(node) {
|
|
11
|
-
devDependenciesObjectNode = node.value;
|
|
12
|
-
for (const devDependencyPropertyNode of node.value.properties) {
|
|
13
|
-
const dependencyKey = devDependencyPropertyNode.key;
|
|
14
|
-
if (isJSONStringLiteral(dependencyKey)) devDependencyNames.add(dependencyKey.value);
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
"Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.type=JSONLiteral][value.type=JSONObjectExpression][key.value=peerDependencies]"(node) {
|
|
18
|
-
for (const peerDependencyPropertyNode of node.value.properties) {
|
|
19
|
-
const dependencyKey = peerDependencyPropertyNode.key;
|
|
20
|
-
if (isJSONStringLiteral(dependencyKey)) peerDependencyMap[dependencyKey.value] = peerDependencyPropertyNode;
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
"Program:exit"() {
|
|
24
|
-
for (const [peerDependencyName, peerDependencyNode] of Object.entries(peerDependencyMap)) if (!devDependencyNames.has(peerDependencyName)) {
|
|
25
|
-
const peerDependencyValue = peerDependencyNode.value;
|
|
26
|
-
context.report({
|
|
27
|
-
data: { name: peerDependencyName },
|
|
28
|
-
messageId: "devDependencyNotDefined",
|
|
29
|
-
node: peerDependencyNode,
|
|
30
|
-
suggest: devDependenciesObjectNode && isJSONStringLiteral(peerDependencyValue) ? [{
|
|
31
|
-
data: { name: peerDependencyName },
|
|
32
|
-
fix: (fixer) => {
|
|
33
|
-
const updatedDevDependencies = {
|
|
34
|
-
...JSON.parse(context.sourceCode.getText(devDependenciesObjectNode)),
|
|
35
|
-
[peerDependencyName]: peerDependencyValue.value
|
|
36
|
-
};
|
|
37
|
-
const sortedDevDependencies = Object.fromEntries(Object.entries(updatedDevDependencies).sort((a, b) => a[0] > b[0] ? 1 : -1));
|
|
38
|
-
return fixer.replaceText(devDependenciesObjectNode, JSON.stringify(sortedDevDependencies, null, 2).split("\n").join("\n "));
|
|
39
|
-
},
|
|
40
|
-
messageId: "addToDevDependencies"
|
|
41
|
-
}] : []
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
},
|
|
47
|
-
meta: {
|
|
48
|
-
docs: {
|
|
49
|
-
description: "Requires that all peer dependencies are also declared as dev dependencies",
|
|
50
|
-
recommended: true
|
|
51
|
-
},
|
|
52
|
-
hasSuggestions: true,
|
|
53
|
-
messages: {
|
|
54
|
-
addToDevDependencies: "Add \"{{ name }}\" to `devDependencies`",
|
|
55
|
-
devDependencyNotDefined: "Peer dependency \"{{ name }}\" is not also declared in `devDependencies`."
|
|
56
|
-
},
|
|
57
|
-
schema: [],
|
|
58
|
-
type: "problem"
|
|
59
|
-
},
|
|
60
|
-
name: "specify-peers-locally"
|
|
61
|
-
});
|
|
62
|
-
//#endregion
|
|
63
|
-
export { rule };
|