eslint-plugin-package-json 0.52.0 → 0.53.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -2
- package/lib/createRule.d.ts +28 -28
- package/lib/createRule.js +18 -12
- package/lib/index.d.ts +33 -35
- package/lib/index.js +6 -6
- package/lib/plugin.d.ts +33 -34
- package/lib/plugin.js +62 -80
- package/lib/rules/no-empty-fields.d.ts +6 -11
- package/lib/rules/no-empty-fields.js +80 -112
- package/lib/rules/no-redundant-files.d.ts +5 -10
- package/lib/rules/no-redundant-files.js +93 -136
- package/lib/rules/order-properties.d.ts +6 -11
- package/lib/rules/order-properties.js +92 -116
- package/lib/rules/repository-shorthand.d.ts +6 -11
- package/lib/rules/repository-shorthand.js +79 -112
- package/lib/rules/require-properties.d.ts +7 -12
- package/lib/rules/require-properties.js +31 -27
- package/lib/rules/restrict-dependency-ranges.d.ts +9 -14
- package/lib/rules/restrict-dependency-ranges.js +137 -189
- package/lib/rules/sort-collections.d.ts +5 -10
- package/lib/rules/sort-collections.js +71 -124
- package/lib/rules/unique-dependencies.d.ts +5 -10
- package/lib/rules/unique-dependencies.js +58 -82
- package/lib/rules/valid-bin.d.ts +6 -11
- package/lib/rules/valid-bin.js +59 -78
- package/lib/rules/valid-local-dependency.d.ts +5 -10
- package/lib/rules/valid-local-dependency.js +49 -57
- package/lib/rules/valid-name.d.ts +5 -10
- package/lib/rules/valid-name.js +41 -48
- package/lib/rules/valid-package-definition.d.ts +6 -11
- package/lib/rules/valid-package-definition.js +41 -50
- package/lib/rules/valid-properties.d.ts +7 -7
- package/lib/rules/valid-properties.js +33 -55
- package/lib/rules/valid-repository-directory.d.ts +5 -10
- package/lib/rules/valid-repository-directory.js +65 -80
- package/lib/rules/valid-version.d.ts +5 -10
- package/lib/rules/valid-version.js +35 -36
- package/lib/types/estree.d.ts +8 -0
- package/lib/utils/createSimpleRequirePropertyRule.d.ts +19 -18
- package/lib/utils/createSimpleRequirePropertyRule.js +48 -53
- package/lib/utils/createSimpleValidPropertyRule.d.ts +6 -8
- package/lib/utils/createSimpleValidPropertyRule.js +45 -39
- package/lib/utils/findPropertyWithKeyValue.d.ts +6 -5
- package/lib/utils/findPropertyWithKeyValue.js +5 -6
- package/lib/utils/formatErrors.d.ts +3 -2
- package/lib/utils/formatErrors.js +11 -7
- package/lib/utils/isPackageJson.d.ts +3 -2
- package/lib/utils/isPackageJson.js +4 -3
- package/lib/utils/predicates.d.ts +4 -3
- package/lib/utils/predicates.js +6 -6
- package/package.json +8 -8
- package/lib/tests/rules/ruleTester.d.ts +0 -15
- package/lib/tests/rules/ruleTester.js +0 -25
- package/lib/types/estree.d.d.ts +0 -7
- package/lib/types/estree.d.js +0 -0
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as jsonc_eslint_parser from 'jsonc-eslint-parser';
|
|
3
|
-
import { PackageJsonRuleContext } from '../createRule.js';
|
|
4
|
-
import 'estree';
|
|
1
|
+
import { PackageJsonRuleModule } from "../createRule.js";
|
|
5
2
|
|
|
3
|
+
//#region src/utils/createSimpleValidPropertyRule.d.ts
|
|
6
4
|
type ValidationFunction = (value: unknown) => string[];
|
|
7
5
|
/**
|
|
8
6
|
* Given a top-level property name, and a validation function, create a rule that validates the property using the validation function.
|
|
@@ -11,8 +9,8 @@ type ValidationFunction = (value: unknown) => string[];
|
|
|
11
9
|
* to create a more complex rule, create it in its own file.
|
|
12
10
|
*/
|
|
13
11
|
declare const createSimpleValidPropertyRule: (propertyName: string, validationFunction: ValidationFunction, aliases?: string[]) => {
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
rule: PackageJsonRuleModule<unknown[]>;
|
|
13
|
+
ruleName: string;
|
|
16
14
|
};
|
|
17
|
-
|
|
18
|
-
export {
|
|
15
|
+
//#endregion
|
|
16
|
+
export { ValidationFunction, createSimpleValidPropertyRule };
|
|
@@ -1,43 +1,49 @@
|
|
|
1
1
|
import { createRule } from "../createRule.js";
|
|
2
2
|
import { formatErrors } from "./formatErrors.js";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/createSimpleValidPropertyRule.ts
|
|
5
|
+
/**
|
|
6
|
+
* Given a top-level property name, and a validation function, create a rule that validates the property using the validation function.
|
|
7
|
+
* These rules will always be included in the recommended config.
|
|
8
|
+
* Note: this will only create a basic validation rule, with no options. If you need
|
|
9
|
+
* to create a more complex rule, create it in its own file.
|
|
10
|
+
*/
|
|
3
11
|
const createSimpleValidPropertyRule = (propertyName, validationFunction, aliases = []) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
export {
|
|
42
|
-
createSimpleValidPropertyRule
|
|
12
|
+
const ruleName = `valid-${propertyName}`;
|
|
13
|
+
const propertyNames = [propertyName, ...aliases];
|
|
14
|
+
const rule = createRule({
|
|
15
|
+
create(context) {
|
|
16
|
+
return propertyNames.reduce((acc, name) => {
|
|
17
|
+
acc[`Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.value=${name}]`] = (node) => {
|
|
18
|
+
const valueNode = node.value;
|
|
19
|
+
const value = JSON.parse(context.sourceCode.getText(valueNode));
|
|
20
|
+
const errors = validationFunction(value);
|
|
21
|
+
if (errors.length) context.report({
|
|
22
|
+
data: { errors: formatErrors(errors) },
|
|
23
|
+
messageId: "validationError",
|
|
24
|
+
node: valueNode
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
return acc;
|
|
28
|
+
}, {});
|
|
29
|
+
},
|
|
30
|
+
meta: {
|
|
31
|
+
docs: {
|
|
32
|
+
category: "Best Practices",
|
|
33
|
+
description: `Enforce that the \`${propertyName}\`${aliases.length ? ` (also: ${aliases.map((alias) => `\`${alias}\``).join(", ")})` : ""} property is valid.`,
|
|
34
|
+
recommended: true
|
|
35
|
+
},
|
|
36
|
+
messages: { validationError: `Invalid ${propertyName}: {{ errors }}` },
|
|
37
|
+
schema: [],
|
|
38
|
+
type: "problem"
|
|
39
|
+
},
|
|
40
|
+
name: ruleName
|
|
41
|
+
});
|
|
42
|
+
return {
|
|
43
|
+
rule,
|
|
44
|
+
ruleName
|
|
45
|
+
};
|
|
43
46
|
};
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
export { createSimpleValidPropertyRule };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { AST } from
|
|
1
|
+
import { AST } from "jsonc-eslint-parser";
|
|
2
2
|
|
|
3
|
+
//#region src/utils/findPropertyWithKeyValue.d.ts
|
|
3
4
|
type JSONPropertyWithKeyAndValue<Value extends string> = AST.JSONProperty & {
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
key: AST.JSONStringLiteral;
|
|
6
|
+
value: Value;
|
|
6
7
|
};
|
|
7
8
|
declare function findPropertyWithKeyValue<Value extends string>(properties: AST.JSONProperty[], value: Value): JSONPropertyWithKeyAndValue<Value> | undefined;
|
|
8
|
-
|
|
9
|
-
export {
|
|
9
|
+
//#endregion
|
|
10
|
+
export { JSONPropertyWithKeyAndValue, findPropertyWithKeyValue };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
//#region src/utils/findPropertyWithKeyValue.ts
|
|
1
2
|
function findPropertyWithKeyValue(properties, value) {
|
|
2
|
-
|
|
3
|
-
(property) => property.key.type === "JSONLiteral" && property.key.value === value
|
|
4
|
-
);
|
|
3
|
+
return properties.find((property) => property.key.type === "JSONLiteral" && property.key.value === value);
|
|
5
4
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
5
|
+
|
|
6
|
+
//#endregion
|
|
7
|
+
export { findPropertyWithKeyValue };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
//#region src/utils/formatErrors.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Formats an array of error messages into a single string.
|
|
3
4
|
* When there is more than one error, the errors will be formatted as a list,
|
|
4
5
|
* starting on a new line.
|
|
5
6
|
*/
|
|
6
7
|
declare const formatErrors: (errors: string[]) => string;
|
|
7
|
-
|
|
8
|
-
export { formatErrors };
|
|
8
|
+
//#endregion
|
|
9
|
+
export { formatErrors };
|
|
@@ -1,9 +1,13 @@
|
|
|
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
|
+
*/
|
|
1
7
|
const formatErrors = (errors) => {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
return errors.length > 1 ? ["", ...errors].join("\n - ") : errors[0];
|
|
6
|
-
};
|
|
7
|
-
export {
|
|
8
|
-
formatErrors
|
|
8
|
+
if (errors.length === 0) return "";
|
|
9
|
+
return errors.length > 1 ? ["", ...errors].join("\n - ") : errors[0];
|
|
9
10
|
};
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { formatErrors };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { AST } from
|
|
1
|
+
import { AST } from "jsonc-eslint-parser";
|
|
2
2
|
|
|
3
|
+
//#region src/utils/predicates.d.ts
|
|
3
4
|
declare function isJSONStringLiteral(node: AST.JSONNode): node is AST.JSONStringLiteral;
|
|
4
5
|
declare function isNotNullish<T extends NonNullable<unknown>>(value: null | T | undefined): value is T;
|
|
5
|
-
|
|
6
|
-
export { isJSONStringLiteral, isNotNullish };
|
|
6
|
+
//#endregion
|
|
7
|
+
export { isJSONStringLiteral, isNotNullish };
|
package/lib/utils/predicates.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
//#region src/utils/predicates.ts
|
|
1
2
|
function isJSONStringLiteral(node) {
|
|
2
|
-
|
|
3
|
+
return node.type === "JSONLiteral" && typeof node.value === "string";
|
|
3
4
|
}
|
|
4
5
|
function isNotNullish(value) {
|
|
5
|
-
|
|
6
|
+
return value !== null && value !== void 0;
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
export { isJSONStringLiteral, isNotNullish };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-package-json",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.53.0",
|
|
4
4
|
"description": "Rules for consistent, readable, and valid package.json files. 🗂️",
|
|
5
5
|
"homepage": "https://github.com/JoshuaKGoldberg/eslint-plugin-package-json#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"lib/"
|
|
29
29
|
],
|
|
30
30
|
"scripts": {
|
|
31
|
-
"build": "
|
|
31
|
+
"build": "tsdown",
|
|
32
32
|
"build:docs": "pnpm build --no-dts && eslint-doc-generator",
|
|
33
33
|
"format": "prettier .",
|
|
34
34
|
"lint": "eslint . --max-warnings 0",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"*": "prettier --ignore-unknown --write"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@altano/repository-tools": "^2.0.
|
|
47
|
+
"@altano/repository-tools": "^2.0.1",
|
|
48
48
|
"change-case": "^5.4.4",
|
|
49
49
|
"detect-indent": "^7.0.1",
|
|
50
50
|
"detect-newline": "^4.0.1",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"package-json-validator": "~0.27.0",
|
|
53
53
|
"semver": "^7.5.4",
|
|
54
54
|
"sort-object-keys": "^1.1.3",
|
|
55
|
-
"sort-package-json": "^3.
|
|
56
|
-
"validate-npm-package-name": "^6.0.
|
|
55
|
+
"sort-package-json": "^3.3.0",
|
|
56
|
+
"validate-npm-package-name": "^6.0.2"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@eslint-community/eslint-plugin-eslint-comments": "4.5.0",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"create-typescript-app": "2.46.1",
|
|
72
72
|
"eslint": "9.32.0",
|
|
73
73
|
"eslint-doc-generator": "2.2.0",
|
|
74
|
-
"eslint-plugin-eslint-plugin": "
|
|
74
|
+
"eslint-plugin-eslint-plugin": "7.0.0",
|
|
75
75
|
"eslint-plugin-jsdoc": "52.0.0",
|
|
76
76
|
"eslint-plugin-jsonc": "2.20.0",
|
|
77
77
|
"eslint-plugin-markdown": "5.1.0",
|
|
@@ -92,9 +92,9 @@
|
|
|
92
92
|
"prettier-plugin-sh": "0.18.0",
|
|
93
93
|
"release-it": "19.0.1",
|
|
94
94
|
"sentences-per-line": "0.3.0",
|
|
95
|
-
"
|
|
95
|
+
"tsdown": "0.13.3",
|
|
96
96
|
"typescript": "5.9.2",
|
|
97
|
-
"typescript-eslint": "8.
|
|
97
|
+
"typescript-eslint": "8.39.0",
|
|
98
98
|
"vitest": "3.2.0"
|
|
99
99
|
},
|
|
100
100
|
"peerDependencies": {
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { RuleTester } from 'eslint';
|
|
2
|
-
import { PackageJsonRuleModule } from '../../createRule.js';
|
|
3
|
-
import 'estree';
|
|
4
|
-
import 'jsonc-eslint-parser';
|
|
5
|
-
|
|
6
|
-
type JsonRuleTester = RuleTester & {
|
|
7
|
-
run: JsonRuleTesterRun;
|
|
8
|
-
};
|
|
9
|
-
type JsonRuleTesterRun = (name: string, rule: PackageJsonRuleModule, tests: {
|
|
10
|
-
invalid?: RuleTester.InvalidTestCase[] | undefined;
|
|
11
|
-
valid?: (RuleTester.ValidTestCase | string)[] | undefined;
|
|
12
|
-
}) => void;
|
|
13
|
-
declare const ruleTester: JsonRuleTester;
|
|
14
|
-
|
|
15
|
-
export { type JsonRuleTester, type JsonRuleTesterRun, ruleTester };
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { RuleTester } from "eslint";
|
|
2
|
-
import jsoncESLintParser from "jsonc-eslint-parser";
|
|
3
|
-
import * as vitest from "vitest";
|
|
4
|
-
RuleTester.describe = vitest.describe;
|
|
5
|
-
RuleTester.it = vitest.it;
|
|
6
|
-
RuleTester.itOnly = vitest.it.only;
|
|
7
|
-
const ruleTester = new RuleTester({
|
|
8
|
-
languageOptions: { parser: jsoncESLintParser }
|
|
9
|
-
});
|
|
10
|
-
const originalRun = ruleTester.run;
|
|
11
|
-
ruleTester.run = (name, rule, tests) => {
|
|
12
|
-
originalRun.call(ruleTester, name, rule, {
|
|
13
|
-
invalid: tests.invalid?.map((test) => ({
|
|
14
|
-
filename: "package.json",
|
|
15
|
-
...test
|
|
16
|
-
})),
|
|
17
|
-
valid: tests.valid?.map((test) => ({
|
|
18
|
-
filename: "package.json",
|
|
19
|
-
...typeof test === "string" ? { code: test } : { ...test }
|
|
20
|
-
}))
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
export {
|
|
24
|
-
ruleTester
|
|
25
|
-
};
|
package/lib/types/estree.d.d.ts
DELETED
package/lib/types/estree.d.js
DELETED
|
File without changes
|