eslint-plugin-package-json 0.47.0 → 0.47.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/CHANGELOG.md +8 -2
- package/README.md +3 -3
- package/lib/plugin.js +2 -12
- package/lib/rules/no-empty-fields.js +14 -6
- package/lib/rules/require-properties.js +2 -2
- package/lib/rules/valid-properties.d.ts +9 -0
- package/lib/rules/valid-properties.js +48 -0
- package/lib/utils/{createRequirePropertyRule.d.ts → createSimpleRequirePropertyRule.d.ts} +4 -2
- package/lib/utils/{createRequirePropertyRule.js → createSimpleRequirePropertyRule.js} +2 -2
- package/lib/utils/createSimpleValidPropertyRule.d.ts +18 -0
- package/lib/utils/createSimpleValidPropertyRule.js +43 -0
- package/package.json +2 -2
- package/lib/rules/valid-author.d.ts +0 -11
- package/lib/rules/valid-author.js +0 -39
- package/lib/rules/valid-bundleDependencies.d.ts +0 -11
- package/lib/rules/valid-bundleDependencies.js +0 -43
- package/lib/rules/valid-config.d.ts +0 -11
- package/lib/rules/valid-config.js +0 -40
- package/lib/rules/valid-license.d.ts +0 -11
- package/lib/rules/valid-license.js +0 -40
- package/lib/rules/valid-scripts.d.ts +0 -11
- package/lib/rules/valid-scripts.js +0 -40
- package/lib/rules/valid-type.d.ts +0 -11
- package/lib/rules/valid-type.js +0 -40
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## [0.47.1](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/compare/v0.47.0...v0.47.1) (2025-07-30)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* **no-empty-fields:** don't throw error on empty object ([#1190](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/1190)) ([8a9ba8a](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commit/8a9ba8acb1d68fd1040a008dfdb185b6908284a2)), closes [#1188](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/1188)
|
|
4
9
|
|
|
10
|
+
# [0.47.0](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/compare/v0.46.0...v0.47.0) (2025-07-25)
|
|
5
11
|
|
|
6
12
|
### Features
|
|
7
13
|
|
|
8
|
-
|
|
14
|
+
- **no-empty-fields:** Add `ignoreProperties` option ([#1186](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/1186)) ([91e7156](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commit/91e7156d9f4569e8fee6f1124c4c1bb18ffdfbe0)), closes [#1182](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/1182)
|
|
9
15
|
|
|
10
16
|
# [0.46.0](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/compare/v0.45.2...v0.46.0) (2025-07-24)
|
|
11
17
|
|
package/README.md
CHANGED
|
@@ -137,9 +137,9 @@ The default settings don't conflict, and Prettier plugins can quickly fix up ord
|
|
|
137
137
|
| [restrict-dependency-ranges](docs/rules/restrict-dependency-ranges.md) | Restricts the range of dependencies to allow or disallow specific types of ranges. | | | 💡 | |
|
|
138
138
|
| [sort-collections](docs/rules/sort-collections.md) | Dependencies, scripts, and configuration values must be declared in alphabetical order. | ✔️ ✅ | 🔧 | | |
|
|
139
139
|
| [unique-dependencies](docs/rules/unique-dependencies.md) | Checks a dependency isn't specified more than once (i.e. in `dependencies` and `devDependencies`) | ✔️ ✅ | | 💡 | |
|
|
140
|
-
| [valid-author](docs/rules/valid-author.md) | Enforce that the author
|
|
140
|
+
| [valid-author](docs/rules/valid-author.md) | Enforce that the `author` property is valid. | ✔️ ✅ | | | |
|
|
141
141
|
| [valid-bin](docs/rules/valid-bin.md) | Enforce that the `bin` property is valid. | ✔️ ✅ | | 💡 | |
|
|
142
|
-
| [valid-bundleDependencies](docs/rules/valid-bundleDependencies.md) | Enforce that the `bundleDependencies` (
|
|
142
|
+
| [valid-bundleDependencies](docs/rules/valid-bundleDependencies.md) | Enforce that the `bundleDependencies` (also: `bundledDependencies`) property is valid. | ✔️ ✅ | | | |
|
|
143
143
|
| [valid-config](docs/rules/valid-config.md) | Enforce that the `config` property is valid. | ✔️ ✅ | | | |
|
|
144
144
|
| [valid-license](docs/rules/valid-license.md) | Enforce that the `license` property is valid. | ✔️ ✅ | | | |
|
|
145
145
|
| [valid-local-dependency](docs/rules/valid-local-dependency.md) | Checks existence of local dependencies in the package.json | | | | ❌ |
|
|
@@ -194,7 +194,7 @@ Thanks! 🗂
|
|
|
194
194
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/andreww2012"><img src="https://avatars.githubusercontent.com/u/6554045?v=4?s=100" width="100px;" alt="Andrew Kazakov"/><br /><sub><b>Andrew Kazakov</b></sub></a><br /><a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues?q=author%3Aandreww2012" title="Bug reports">🐛</a> <a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commits?author=andreww2012" title="Code">💻</a> <a href="#ideas-andreww2012" title="Ideas, Planning, & Feedback">🤔</a></td>
|
|
195
195
|
<td align="center" valign="top" width="14.28%"><a href="http://technotes.khitrenovich.com/"><img src="https://avatars.githubusercontent.com/u/3424762?v=4?s=100" width="100px;" alt="Anton Khitrenovich"/><br /><sub><b>Anton Khitrenovich</b></sub></a><br /><a href="#ideas-khitrenovich" title="Ideas, Planning, & Feedback">🤔</a></td>
|
|
196
196
|
<td align="center" valign="top" width="14.28%"><a href="https://azat.io"><img src="https://avatars.githubusercontent.com/u/5698350?v=4?s=100" width="100px;" alt="Azat S."/><br /><sub><b>Azat S.</b></sub></a><br /><a href="#ideas-azat-io" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commits?author=azat-io" title="Code">💻</a></td>
|
|
197
|
-
<td align="center" valign="top" width="14.28%"><a href="https://github.com/anomiex"><img src="https://avatars.githubusercontent.com/u/1030580?v=4?s=100" width="100px;" alt="Brad Jorsch"/><br /><sub><b>Brad Jorsch</b></sub></a><br /><a href="#ideas-anomiex" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues?q=author%3Aanomiex" title="Bug reports">🐛</a></td>
|
|
197
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/anomiex"><img src="https://avatars.githubusercontent.com/u/1030580?v=4?s=100" width="100px;" alt="Brad Jorsch"/><br /><sub><b>Brad Jorsch</b></sub></a><br /><a href="#ideas-anomiex" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues?q=author%3Aanomiex" title="Bug reports">🐛</a> <a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commits?author=anomiex" title="Code">💻</a></td>
|
|
198
198
|
<td align="center" valign="top" width="14.28%"><a href="http://www.curtisjewell.dev/"><img src="https://avatars.githubusercontent.com/u/67483?v=4?s=100" width="100px;" alt="Curtis Jewell"/><br /><sub><b>Curtis Jewell</b></sub></a><br /><a href="#ideas-csjewell" title="Ideas, Planning, & Feedback">🤔</a></td>
|
|
199
199
|
</tr>
|
|
200
200
|
<tr>
|
package/lib/plugin.js
CHANGED
|
@@ -8,17 +8,12 @@ import { rules as requireRules } from "./rules/require-properties.js";
|
|
|
8
8
|
import { rule as restrictDependencyRanges } from "./rules/restrict-dependency-ranges.js";
|
|
9
9
|
import { rule as sortCollections } from "./rules/sort-collections.js";
|
|
10
10
|
import { rule as uniqueDependencies } from "./rules/unique-dependencies.js";
|
|
11
|
-
import { rule as validAuthor } from "./rules/valid-author.js";
|
|
12
11
|
import { rule as validBin } from "./rules/valid-bin.js";
|
|
13
|
-
import { rule as validBundleDependencies } from "./rules/valid-bundleDependencies.js";
|
|
14
|
-
import { rule as validConfig } from "./rules/valid-config.js";
|
|
15
|
-
import { rule as validLicense } from "./rules/valid-license.js";
|
|
16
12
|
import { rule as validLocalDependency } from "./rules/valid-local-dependency.js";
|
|
17
13
|
import { rule as validName } from "./rules/valid-name.js";
|
|
18
14
|
import { rule as validPackageDefinition } from "./rules/valid-package-definition.js";
|
|
15
|
+
import { rules as basicValidRules } from "./rules/valid-properties.js";
|
|
19
16
|
import { rule as validRepositoryDirectory } from "./rules/valid-repository-directory.js";
|
|
20
|
-
import { rule as validScripts } from "./rules/valid-scripts.js";
|
|
21
|
-
import { rule as validType } from "./rules/valid-type.js";
|
|
22
17
|
import { rule as validVersion } from "./rules/valid-version.js";
|
|
23
18
|
const require2 = createRequire(import.meta.url);
|
|
24
19
|
const { name, version } = require2("../package.json");
|
|
@@ -31,17 +26,12 @@ const rules = {
|
|
|
31
26
|
"restrict-dependency-ranges": restrictDependencyRanges,
|
|
32
27
|
"sort-collections": sortCollections,
|
|
33
28
|
"unique-dependencies": uniqueDependencies,
|
|
34
|
-
|
|
29
|
+
...basicValidRules,
|
|
35
30
|
"valid-bin": validBin,
|
|
36
|
-
"valid-bundleDependencies": validBundleDependencies,
|
|
37
|
-
"valid-config": validConfig,
|
|
38
|
-
"valid-license": validLicense,
|
|
39
31
|
"valid-local-dependency": validLocalDependency,
|
|
40
32
|
"valid-name": validName,
|
|
41
33
|
"valid-package-definition": validPackageDefinition,
|
|
42
34
|
"valid-repository-directory": validRepositoryDirectory,
|
|
43
|
-
"valid-scripts": validScripts,
|
|
44
|
-
"valid-type": validType,
|
|
45
35
|
"valid-version": validVersion
|
|
46
36
|
};
|
|
47
37
|
const baseRecommendedRules = {
|
|
@@ -52,29 +52,37 @@ const report = (context, node) => {
|
|
|
52
52
|
const getNode = (node) => {
|
|
53
53
|
return node.parent.type === "JSONProperty" ? node.parent : node;
|
|
54
54
|
};
|
|
55
|
-
const
|
|
55
|
+
const getTopLevelProperty = (node) => {
|
|
56
56
|
let n = node;
|
|
57
57
|
while (n.parent.parent?.parent?.type !== void 0 && n.parent.parent.parent.type !== "Program") {
|
|
58
58
|
n = n.parent;
|
|
59
59
|
}
|
|
60
|
-
return n.key
|
|
60
|
+
return n.type === "JSONProperty" ? n.key : void 0;
|
|
61
61
|
};
|
|
62
62
|
const rule = createRule({
|
|
63
63
|
create(context) {
|
|
64
64
|
const ignoreProperties = context.options[0]?.ignoreProperties ?? [];
|
|
65
65
|
return {
|
|
66
66
|
JSONArrayExpression(node) {
|
|
67
|
+
const topLevelProperty = getTopLevelProperty(node);
|
|
68
|
+
if (!topLevelProperty) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
67
71
|
if (!node.elements.length) {
|
|
68
|
-
const
|
|
69
|
-
if (!ignoreProperties.includes(
|
|
72
|
+
const topLevelPropertyName = topLevelProperty.value;
|
|
73
|
+
if (!ignoreProperties.includes(topLevelPropertyName)) {
|
|
70
74
|
report(context, getNode(node));
|
|
71
75
|
}
|
|
72
76
|
}
|
|
73
77
|
},
|
|
74
78
|
JSONObjectExpression(node) {
|
|
79
|
+
const topLevelProperty = getTopLevelProperty(node);
|
|
80
|
+
if (!topLevelProperty) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
75
83
|
if (!node.properties.length) {
|
|
76
|
-
const
|
|
77
|
-
if (!ignoreProperties.includes(
|
|
84
|
+
const topLevelPropertyName = topLevelProperty.value;
|
|
85
|
+
if (!ignoreProperties.includes(topLevelPropertyName)) {
|
|
78
86
|
report(context, getNode(node));
|
|
79
87
|
}
|
|
80
88
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createSimpleRequirePropertyRule } from "../utils/createSimpleRequirePropertyRule.js";
|
|
2
2
|
const properties = [
|
|
3
3
|
["author", false],
|
|
4
4
|
["description", true],
|
|
@@ -13,7 +13,7 @@ const properties = [
|
|
|
13
13
|
];
|
|
14
14
|
const rules = properties.reduce(
|
|
15
15
|
(acc, [propertyName, isRecommended]) => {
|
|
16
|
-
acc[`require-${propertyName}`] =
|
|
16
|
+
acc[`require-${propertyName}`] = createSimpleRequirePropertyRule(
|
|
17
17
|
propertyName,
|
|
18
18
|
isRecommended
|
|
19
19
|
);
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
validateAuthor,
|
|
3
|
+
validateBundleDependencies,
|
|
4
|
+
validateConfig,
|
|
5
|
+
validateLicense,
|
|
6
|
+
validateScripts,
|
|
7
|
+
validateType
|
|
8
|
+
} from "package-json-validator";
|
|
9
|
+
import {
|
|
10
|
+
createSimpleValidPropertyRule
|
|
11
|
+
} from "../utils/createSimpleValidPropertyRule.js";
|
|
12
|
+
const properties = [
|
|
13
|
+
["author", validateAuthor],
|
|
14
|
+
[
|
|
15
|
+
"bundleDependencies",
|
|
16
|
+
{
|
|
17
|
+
aliases: ["bundledDependencies"],
|
|
18
|
+
validator: validateBundleDependencies
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
["config", validateConfig],
|
|
22
|
+
["license", validateLicense],
|
|
23
|
+
["scripts", validateScripts],
|
|
24
|
+
["type", validateType]
|
|
25
|
+
// TODO: More to come!
|
|
26
|
+
];
|
|
27
|
+
const rules = properties.reduce(
|
|
28
|
+
(acc, [propertyName, validationFunctionOrOptions]) => {
|
|
29
|
+
let validationFunction;
|
|
30
|
+
let aliases = [];
|
|
31
|
+
if (typeof validationFunctionOrOptions === "object") {
|
|
32
|
+
validationFunction = validationFunctionOrOptions.validator;
|
|
33
|
+
aliases = validationFunctionOrOptions.aliases;
|
|
34
|
+
} else {
|
|
35
|
+
validationFunction = validationFunctionOrOptions;
|
|
36
|
+
}
|
|
37
|
+
acc[`valid-${propertyName}`] = createSimpleValidPropertyRule(
|
|
38
|
+
propertyName,
|
|
39
|
+
validationFunction,
|
|
40
|
+
aliases
|
|
41
|
+
);
|
|
42
|
+
return acc;
|
|
43
|
+
},
|
|
44
|
+
{}
|
|
45
|
+
);
|
|
46
|
+
export {
|
|
47
|
+
rules
|
|
48
|
+
};
|
|
@@ -6,10 +6,12 @@ import 'estree';
|
|
|
6
6
|
/**
|
|
7
7
|
* Given a top-level property name, create a rule that requires that property to be present.
|
|
8
8
|
* Optionally, include it in the recommended config.
|
|
9
|
+
* Note: this will only create a basic require rule, with no options. If you need
|
|
10
|
+
* to create a more complex rule, create it in its own file.
|
|
9
11
|
*/
|
|
10
|
-
declare const
|
|
12
|
+
declare const createSimpleRequirePropertyRule: (propertyName: string, isRecommended?: boolean) => {
|
|
11
13
|
create(context: PackageJsonRuleContext<unknown[]>): jsonc_eslint_parser.RuleListener;
|
|
12
14
|
meta: eslint.Rule.RuleMetaData;
|
|
13
15
|
};
|
|
14
16
|
|
|
15
|
-
export {
|
|
17
|
+
export { createSimpleRequirePropertyRule };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRule } from "../createRule.js";
|
|
2
2
|
import { isJSONStringLiteral } from "./predicates.js";
|
|
3
|
-
const
|
|
3
|
+
const createSimpleRequirePropertyRule = (propertyName, isRecommended = false) => {
|
|
4
4
|
return createRule({
|
|
5
5
|
create(context) {
|
|
6
6
|
return {
|
|
@@ -31,5 +31,5 @@ const createRequirePropertyRule = (propertyName, isRecommended = false) => {
|
|
|
31
31
|
});
|
|
32
32
|
};
|
|
33
33
|
export {
|
|
34
|
-
|
|
34
|
+
createSimpleRequirePropertyRule
|
|
35
35
|
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as eslint from 'eslint';
|
|
2
|
+
import * as jsonc_eslint_parser from 'jsonc-eslint-parser';
|
|
3
|
+
import { PackageJsonRuleContext } from '../createRule.js';
|
|
4
|
+
import 'estree';
|
|
5
|
+
|
|
6
|
+
type ValidationFunction = (value: unknown) => string[];
|
|
7
|
+
/**
|
|
8
|
+
* Given a top-level property name, and a validation function, create a rule that validates the property using the validation function.
|
|
9
|
+
* These rules will always be included in the recommended config.
|
|
10
|
+
* Note: this will only create a basic validation rule, with no options. If you need
|
|
11
|
+
* to create a more complex rule, create it in its own file.
|
|
12
|
+
*/
|
|
13
|
+
declare const createSimpleValidPropertyRule: (propertyName: string, validationFunction: ValidationFunction, aliases?: string[]) => {
|
|
14
|
+
create(context: PackageJsonRuleContext<unknown[]>): jsonc_eslint_parser.RuleListener;
|
|
15
|
+
meta: eslint.Rule.RuleMetaData;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { type ValidationFunction, createSimpleValidPropertyRule };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { createRule } from "../createRule.js";
|
|
2
|
+
import { formatErrors } from "./formatErrors.js";
|
|
3
|
+
const createSimpleValidPropertyRule = (propertyName, validationFunction, aliases = []) => {
|
|
4
|
+
const propertyNames = [propertyName, ...aliases];
|
|
5
|
+
return createRule({
|
|
6
|
+
create(context) {
|
|
7
|
+
return propertyNames.reduce((acc, name) => {
|
|
8
|
+
acc[`Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.value=${name}]`] = (node) => {
|
|
9
|
+
const valueNode = node.value;
|
|
10
|
+
const value = JSON.parse(
|
|
11
|
+
context.sourceCode.getText(valueNode)
|
|
12
|
+
);
|
|
13
|
+
const errors = validationFunction(value);
|
|
14
|
+
if (errors.length) {
|
|
15
|
+
context.report({
|
|
16
|
+
data: {
|
|
17
|
+
errors: formatErrors(errors)
|
|
18
|
+
},
|
|
19
|
+
messageId: "validationError",
|
|
20
|
+
node: valueNode
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
return acc;
|
|
25
|
+
}, {});
|
|
26
|
+
},
|
|
27
|
+
meta: {
|
|
28
|
+
docs: {
|
|
29
|
+
category: "Best Practices",
|
|
30
|
+
description: `Enforce that the \`${propertyName}\`${aliases.length ? ` (also: ${aliases.map((alias) => `\`${alias}\``).join(", ")})` : ""} property is valid.`,
|
|
31
|
+
recommended: true
|
|
32
|
+
},
|
|
33
|
+
messages: {
|
|
34
|
+
validationError: `Invalid ${propertyName}: {{ errors }}`
|
|
35
|
+
},
|
|
36
|
+
schema: [],
|
|
37
|
+
type: "problem"
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
export {
|
|
42
|
+
createSimpleValidPropertyRule
|
|
43
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-package-json",
|
|
3
|
-
"version": "0.47.
|
|
3
|
+
"version": "0.47.1",
|
|
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": {
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"sentences-per-line": "0.3.0",
|
|
95
95
|
"tsup": "8.5.0",
|
|
96
96
|
"typescript": "5.8.2",
|
|
97
|
-
"typescript-eslint": "8.
|
|
97
|
+
"typescript-eslint": "8.38.0",
|
|
98
98
|
"vitest": "3.2.0"
|
|
99
99
|
},
|
|
100
100
|
"peerDependencies": {
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import * as eslint from 'eslint';
|
|
2
|
-
import * as jsonc_eslint_parser from 'jsonc-eslint-parser';
|
|
3
|
-
import { PackageJsonRuleContext } from '../createRule.js';
|
|
4
|
-
import 'estree';
|
|
5
|
-
|
|
6
|
-
declare const rule: {
|
|
7
|
-
create(context: PackageJsonRuleContext<unknown[]>): jsonc_eslint_parser.RuleListener;
|
|
8
|
-
meta: eslint.Rule.RuleMetaData;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export { rule };
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { validateAuthor } from "package-json-validator";
|
|
2
|
-
import { createRule } from "../createRule.js";
|
|
3
|
-
import { formatErrors } from "../utils/formatErrors.js";
|
|
4
|
-
const rule = createRule({
|
|
5
|
-
create(context) {
|
|
6
|
-
return {
|
|
7
|
-
"Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.value=author]"(node) {
|
|
8
|
-
const authorValue = JSON.parse(
|
|
9
|
-
context.sourceCode.getText(node.value)
|
|
10
|
-
);
|
|
11
|
-
const errors = validateAuthor(authorValue);
|
|
12
|
-
if (errors.length > 0) {
|
|
13
|
-
context.report({
|
|
14
|
-
data: {
|
|
15
|
-
errors: formatErrors(errors)
|
|
16
|
-
},
|
|
17
|
-
messageId: "invalid",
|
|
18
|
-
node: node.value
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
},
|
|
24
|
-
meta: {
|
|
25
|
-
docs: {
|
|
26
|
-
category: "Best Practices",
|
|
27
|
-
description: "Enforce that the author field is a valid npm author specification",
|
|
28
|
-
recommended: true
|
|
29
|
-
},
|
|
30
|
-
messages: {
|
|
31
|
-
invalid: "Invalid author: {{ errors }}"
|
|
32
|
-
},
|
|
33
|
-
schema: [],
|
|
34
|
-
type: "problem"
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
export {
|
|
38
|
-
rule
|
|
39
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import * as eslint from 'eslint';
|
|
2
|
-
import * as jsonc_eslint_parser from 'jsonc-eslint-parser';
|
|
3
|
-
import { PackageJsonRuleContext } from '../createRule.js';
|
|
4
|
-
import 'estree';
|
|
5
|
-
|
|
6
|
-
declare const rule: {
|
|
7
|
-
create(context: PackageJsonRuleContext<unknown[]>): jsonc_eslint_parser.RuleListener;
|
|
8
|
-
meta: eslint.Rule.RuleMetaData;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export { rule };
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { validateBundleDependencies } from "package-json-validator";
|
|
2
|
-
import { createRule } from "../createRule.js";
|
|
3
|
-
import { formatErrors } from "../utils/formatErrors.js";
|
|
4
|
-
const rule = createRule({
|
|
5
|
-
create(context) {
|
|
6
|
-
const checkBundleDependencies = (node) => {
|
|
7
|
-
const bundleDependenciesValueNode = node.value;
|
|
8
|
-
const bundleDependenciesValue = JSON.parse(
|
|
9
|
-
context.sourceCode.getText(bundleDependenciesValueNode)
|
|
10
|
-
);
|
|
11
|
-
const errors = validateBundleDependencies(bundleDependenciesValue);
|
|
12
|
-
if (errors.length) {
|
|
13
|
-
context.report({
|
|
14
|
-
data: {
|
|
15
|
-
errors: formatErrors(errors),
|
|
16
|
-
property: node.key.value
|
|
17
|
-
},
|
|
18
|
-
messageId: "validationError",
|
|
19
|
-
node: bundleDependenciesValueNode
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
return {
|
|
24
|
-
"Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.value=bundledDependencies]": checkBundleDependencies,
|
|
25
|
-
"Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.value=bundleDependencies]": checkBundleDependencies
|
|
26
|
-
};
|
|
27
|
-
},
|
|
28
|
-
meta: {
|
|
29
|
-
docs: {
|
|
30
|
-
category: "Best Practices",
|
|
31
|
-
description: "Enforce that the `bundleDependencies` (or `bundledDependencies`) property is valid.",
|
|
32
|
-
recommended: true
|
|
33
|
-
},
|
|
34
|
-
messages: {
|
|
35
|
-
validationError: "Invalid {{ property }}: {{ errors }}"
|
|
36
|
-
},
|
|
37
|
-
schema: [],
|
|
38
|
-
type: "problem"
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
export {
|
|
42
|
-
rule
|
|
43
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import * as eslint from 'eslint';
|
|
2
|
-
import * as jsonc_eslint_parser from 'jsonc-eslint-parser';
|
|
3
|
-
import { PackageJsonRuleContext } from '../createRule.js';
|
|
4
|
-
import 'estree';
|
|
5
|
-
|
|
6
|
-
declare const rule: {
|
|
7
|
-
create(context: PackageJsonRuleContext<unknown[]>): jsonc_eslint_parser.RuleListener;
|
|
8
|
-
meta: eslint.Rule.RuleMetaData;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export { rule };
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { validateConfig } from "package-json-validator";
|
|
2
|
-
import { createRule } from "../createRule.js";
|
|
3
|
-
import { formatErrors } from "../utils/formatErrors.js";
|
|
4
|
-
const rule = createRule({
|
|
5
|
-
create(context) {
|
|
6
|
-
return {
|
|
7
|
-
"Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.value=config]"(node) {
|
|
8
|
-
const valueNode = node.value;
|
|
9
|
-
const value = JSON.parse(
|
|
10
|
-
context.sourceCode.getText(valueNode)
|
|
11
|
-
);
|
|
12
|
-
const errors = validateConfig(value);
|
|
13
|
-
if (errors.length) {
|
|
14
|
-
context.report({
|
|
15
|
-
data: {
|
|
16
|
-
errors: formatErrors(errors)
|
|
17
|
-
},
|
|
18
|
-
messageId: "validationError",
|
|
19
|
-
node: valueNode
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
},
|
|
25
|
-
meta: {
|
|
26
|
-
docs: {
|
|
27
|
-
category: "Best Practices",
|
|
28
|
-
description: "Enforce that the `config` property is valid.",
|
|
29
|
-
recommended: true
|
|
30
|
-
},
|
|
31
|
-
messages: {
|
|
32
|
-
validationError: "Invalid config: {{ errors }}"
|
|
33
|
-
},
|
|
34
|
-
schema: [],
|
|
35
|
-
type: "problem"
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
export {
|
|
39
|
-
rule
|
|
40
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import * as eslint from 'eslint';
|
|
2
|
-
import * as jsonc_eslint_parser from 'jsonc-eslint-parser';
|
|
3
|
-
import { PackageJsonRuleContext } from '../createRule.js';
|
|
4
|
-
import 'estree';
|
|
5
|
-
|
|
6
|
-
declare const rule: {
|
|
7
|
-
create(context: PackageJsonRuleContext<unknown[]>): jsonc_eslint_parser.RuleListener;
|
|
8
|
-
meta: eslint.Rule.RuleMetaData;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export { rule };
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { validateLicense } from "package-json-validator";
|
|
2
|
-
import { createRule } from "../createRule.js";
|
|
3
|
-
import { formatErrors } from "../utils/formatErrors.js";
|
|
4
|
-
const rule = createRule({
|
|
5
|
-
create(context) {
|
|
6
|
-
return {
|
|
7
|
-
"Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.value=license]"(node) {
|
|
8
|
-
const valueNode = node.value;
|
|
9
|
-
const value = JSON.parse(
|
|
10
|
-
context.sourceCode.getText(valueNode)
|
|
11
|
-
);
|
|
12
|
-
const errors = validateLicense(value);
|
|
13
|
-
if (errors.length) {
|
|
14
|
-
context.report({
|
|
15
|
-
data: {
|
|
16
|
-
errors: formatErrors(errors)
|
|
17
|
-
},
|
|
18
|
-
messageId: "validationError",
|
|
19
|
-
node: valueNode
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
},
|
|
25
|
-
meta: {
|
|
26
|
-
docs: {
|
|
27
|
-
category: "Best Practices",
|
|
28
|
-
description: "Enforce that the `license` property is valid.",
|
|
29
|
-
recommended: true
|
|
30
|
-
},
|
|
31
|
-
messages: {
|
|
32
|
-
validationError: "Invalid license: {{ errors }}"
|
|
33
|
-
},
|
|
34
|
-
schema: [],
|
|
35
|
-
type: "problem"
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
export {
|
|
39
|
-
rule
|
|
40
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import * as eslint from 'eslint';
|
|
2
|
-
import * as jsonc_eslint_parser from 'jsonc-eslint-parser';
|
|
3
|
-
import { PackageJsonRuleContext } from '../createRule.js';
|
|
4
|
-
import 'estree';
|
|
5
|
-
|
|
6
|
-
declare const rule: {
|
|
7
|
-
create(context: PackageJsonRuleContext<unknown[]>): jsonc_eslint_parser.RuleListener;
|
|
8
|
-
meta: eslint.Rule.RuleMetaData;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export { rule };
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { validateScripts } from "package-json-validator";
|
|
2
|
-
import { createRule } from "../createRule.js";
|
|
3
|
-
import { formatErrors } from "../utils/formatErrors.js";
|
|
4
|
-
const rule = createRule({
|
|
5
|
-
create(context) {
|
|
6
|
-
return {
|
|
7
|
-
"Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.value=scripts]"(node) {
|
|
8
|
-
const scriptValueNode = node.value;
|
|
9
|
-
const scriptValue = JSON.parse(
|
|
10
|
-
context.sourceCode.getText(scriptValueNode)
|
|
11
|
-
);
|
|
12
|
-
const errors = validateScripts(scriptValue);
|
|
13
|
-
if (errors.length) {
|
|
14
|
-
context.report({
|
|
15
|
-
data: {
|
|
16
|
-
errors: formatErrors(errors)
|
|
17
|
-
},
|
|
18
|
-
messageId: "validationError",
|
|
19
|
-
node: scriptValueNode
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
},
|
|
25
|
-
meta: {
|
|
26
|
-
docs: {
|
|
27
|
-
category: "Best Practices",
|
|
28
|
-
description: "Enforce that the `scripts` property is valid.",
|
|
29
|
-
recommended: true
|
|
30
|
-
},
|
|
31
|
-
messages: {
|
|
32
|
-
validationError: "Invalid scripts: {{ errors }}"
|
|
33
|
-
},
|
|
34
|
-
schema: [],
|
|
35
|
-
type: "problem"
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
export {
|
|
39
|
-
rule
|
|
40
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import * as eslint from 'eslint';
|
|
2
|
-
import * as jsonc_eslint_parser from 'jsonc-eslint-parser';
|
|
3
|
-
import { PackageJsonRuleContext } from '../createRule.js';
|
|
4
|
-
import 'estree';
|
|
5
|
-
|
|
6
|
-
declare const rule: {
|
|
7
|
-
create(context: PackageJsonRuleContext<unknown[]>): jsonc_eslint_parser.RuleListener;
|
|
8
|
-
meta: eslint.Rule.RuleMetaData;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export { rule };
|
package/lib/rules/valid-type.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { validateType } from "package-json-validator";
|
|
2
|
-
import { createRule } from "../createRule.js";
|
|
3
|
-
import { formatErrors } from "../utils/formatErrors.js";
|
|
4
|
-
const rule = createRule({
|
|
5
|
-
create(context) {
|
|
6
|
-
return {
|
|
7
|
-
"Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.value=type]"(node) {
|
|
8
|
-
const typeValueNode = node.value;
|
|
9
|
-
const typeValue = JSON.parse(
|
|
10
|
-
context.sourceCode.getText(typeValueNode)
|
|
11
|
-
);
|
|
12
|
-
const errors = validateType(typeValue);
|
|
13
|
-
if (errors.length) {
|
|
14
|
-
context.report({
|
|
15
|
-
data: {
|
|
16
|
-
errors: formatErrors(errors)
|
|
17
|
-
},
|
|
18
|
-
messageId: "validationError",
|
|
19
|
-
node: typeValueNode
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
},
|
|
25
|
-
meta: {
|
|
26
|
-
docs: {
|
|
27
|
-
category: "Best Practices",
|
|
28
|
-
description: "Enforce that the `type` property is valid.",
|
|
29
|
-
recommended: true
|
|
30
|
-
},
|
|
31
|
-
messages: {
|
|
32
|
-
validationError: "Invalid type: {{ errors }}"
|
|
33
|
-
},
|
|
34
|
-
schema: [],
|
|
35
|
-
type: "problem"
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
export {
|
|
39
|
-
rule
|
|
40
|
-
};
|