eslint-plugin-package-json 0.6.0 → 0.8.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/README.md +21 -12
- package/lib/index.d.mts +8 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +5 -1
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +5 -1
- package/lib/index.mjs.map +1 -1
- package/lib/rules/prefer-repository-shorthand.js +4 -8
- package/lib/rules/prefer-repository-shorthand.js.map +1 -1
- package/lib/rules/prefer-repository-shorthand.mjs +4 -8
- package/lib/rules/prefer-repository-shorthand.mjs.map +1 -1
- package/lib/rules/unique-dependencies.d.mts +11 -0
- package/lib/rules/unique-dependencies.d.ts +11 -0
- package/lib/rules/unique-dependencies.js +109 -0
- package/lib/rules/unique-dependencies.js.map +1 -0
- package/lib/rules/unique-dependencies.mjs +89 -0
- package/lib/rules/unique-dependencies.mjs.map +1 -0
- package/lib/rules/valid-local-dependency.js.map +1 -1
- package/lib/rules/valid-local-dependency.mjs.map +1 -1
- package/lib/rules/valid-package-def.js.map +1 -1
- package/lib/rules/valid-package-def.mjs.map +1 -1
- package/lib/rules/valid-repository-directory.d.mts +11 -0
- package/lib/rules/valid-repository-directory.d.ts +11 -0
- package/lib/rules/valid-repository-directory.js +83 -0
- package/lib/rules/valid-repository-directory.js.map +1 -0
- package/lib/rules/valid-repository-directory.mjs +53 -0
- package/lib/rules/valid-repository-directory.mjs.map +1 -0
- package/lib/utils/findPropertyWithKeyValue.d.mts +9 -0
- package/lib/utils/findPropertyWithKeyValue.d.ts +9 -0
- package/lib/utils/findPropertyWithKeyValue.js +33 -0
- package/lib/utils/findPropertyWithKeyValue.js.map +1 -0
- package/lib/utils/findPropertyWithKeyValue.mjs +9 -0
- package/lib/utils/findPropertyWithKeyValue.mjs.map +1 -0
- package/lib/utils/predicates.d.mts +6 -0
- package/lib/utils/predicates.d.ts +6 -0
- package/lib/utils/predicates.js +36 -0
- package/lib/utils/predicates.js.map +1 -0
- package/lib/utils/predicates.mjs +11 -0
- package/lib/utils/predicates.mjs.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,8 +14,7 @@
|
|
|
14
14
|
<a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/blob/main/.github/CODE_OF_CONDUCT.md" target="_blank"><img alt="Contributor Covenant" src="https://img.shields.io/badge/code_of_conduct-enforced-21bb42" /></a>
|
|
15
15
|
<a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/blob/main/LICENSE.md" target="_blank"><img alt="License: MIT" src="https://img.shields.io/github/license/JoshuaKGoldberg/eslint-plugin-package-json?color=21bb42"></a>
|
|
16
16
|
<img alt="Style: Prettier" src="https://img.shields.io/badge/style-prettier-21bb42.svg" />
|
|
17
|
-
<img alt="
|
|
18
|
-
<img alt="npm package version" src="https://img.shields.io/npm/v/eslint-plugin-package-json?color=21bb42" />
|
|
17
|
+
<a href="https://www.npmjs.com/package/eslint-plugin-package-json"><img alt="npm package version" src="https://img.shields.io/npm/v/eslint-plugin-package-json?color=21bb42" /></a>
|
|
19
18
|
</p>
|
|
20
19
|
|
|
21
20
|
## Installation
|
|
@@ -62,6 +61,12 @@ module.exports = {
|
|
|
62
61
|
};
|
|
63
62
|
```
|
|
64
63
|
|
|
64
|
+
### Usage Alongside Prettier
|
|
65
|
+
|
|
66
|
+
**[`prettier-plugin-packagejson`](https://github.com/matzkoh/prettier-plugin-packagejson)** is a [Prettier plugin](https://prettier.io/docs/en/plugins) that enforces the same `package.json` keys ordering as the [`order-properties`](docs/rules/order-properties.md) and [sort-collections](docs/rules/sort-collections.md) rules with default options.
|
|
67
|
+
We recommend using both the Prettier plugin and `extends: ["plugin:package-json/recommended"]`.
|
|
68
|
+
The default settings don't conflict, and Prettier plugins can quickly fix up ordering in your editor on save and/or as a Git hook.
|
|
69
|
+
|
|
65
70
|
## Supported Rules
|
|
66
71
|
|
|
67
72
|
<!-- prettier-ignore-start -->
|
|
@@ -69,20 +74,24 @@ module.exports = {
|
|
|
69
74
|
|
|
70
75
|
💼 Configurations enabled in.\
|
|
71
76
|
✅ Set in the `recommended` configuration.\
|
|
72
|
-
🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix)
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
|
76
|
-
|
|
|
77
|
-
| [
|
|
78
|
-
| [
|
|
79
|
-
| [
|
|
80
|
-
| [
|
|
77
|
+
🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).\
|
|
78
|
+
💡 Manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
|
|
79
|
+
|
|
80
|
+
| Name | Description | 💼 | 🔧 | 💡 |
|
|
81
|
+
| :----------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------- | :- | :- | :- |
|
|
82
|
+
| [order-properties](docs/rules/order-properties.md) | Package properties must be declared in standard order | ✅ | 🔧 | |
|
|
83
|
+
| [prefer-repository-shorthand](docs/rules/prefer-repository-shorthand.md) | Enforce shorthand declaration for GitHub repository. | ✅ | 🔧 | |
|
|
84
|
+
| [sort-collections](docs/rules/sort-collections.md) | Dependencies, scripts, and configuration values must be declared in alphabetical order. | ✅ | 🔧 | |
|
|
85
|
+
| [unique-dependencies](docs/rules/unique-dependencies.md) | Enforce that if repository directory is specified, it matches the path to the package.json file | ✅ | | 💡 |
|
|
86
|
+
| [valid-local-dependency](docs/rules/valid-local-dependency.md) | Checks existence of local dependencies in the package.json | ✅ | | |
|
|
87
|
+
| [valid-package-def](docs/rules/valid-package-def.md) | Enforce that package.json has all properties required by the npm spec | ✅ | | |
|
|
88
|
+
| [valid-repository-directory](docs/rules/valid-repository-directory.md) | Enforce that if repository directory is specified, it matches the path to the package.json file | ✅ | | 💡 |
|
|
81
89
|
|
|
82
90
|
<!-- end auto-generated rules list -->
|
|
83
91
|
<!-- prettier-ignore-end -->
|
|
84
92
|
|
|
85
|
-
These rules only run on `package.json` files; they will ignore all other files being linted.
|
|
93
|
+
These rules only run on `package.json` files; they will ignore all other files being linted.
|
|
94
|
+
They can lint `package.json` files at project root and in any subfolder of the project, making this plugin great for monorepos.
|
|
86
95
|
|
|
87
96
|
## Contributors
|
|
88
97
|
|
package/lib/index.d.mts
CHANGED
|
@@ -18,6 +18,10 @@ declare const rules: {
|
|
|
18
18
|
create(context: PackageJsonRuleContext<string[]>): jsonc_eslint_parser.RuleListener;
|
|
19
19
|
meta: eslint.Rule.RuleMetaData;
|
|
20
20
|
};
|
|
21
|
+
"unique-dependencies": {
|
|
22
|
+
create(context: PackageJsonRuleContext<unknown[]>): jsonc_eslint_parser.RuleListener;
|
|
23
|
+
meta: eslint.Rule.RuleMetaData;
|
|
24
|
+
};
|
|
21
25
|
"valid-local-dependency": {
|
|
22
26
|
create(context: PackageJsonRuleContext<unknown[]>): jsonc_eslint_parser.RuleListener;
|
|
23
27
|
meta: eslint.Rule.RuleMetaData;
|
|
@@ -26,6 +30,10 @@ declare const rules: {
|
|
|
26
30
|
create(context: PackageJsonRuleContext<unknown[]>): jsonc_eslint_parser.RuleListener;
|
|
27
31
|
meta: eslint.Rule.RuleMetaData;
|
|
28
32
|
};
|
|
33
|
+
"valid-repository-directory": {
|
|
34
|
+
create(context: PackageJsonRuleContext<unknown[]>): jsonc_eslint_parser.RuleListener;
|
|
35
|
+
meta: eslint.Rule.RuleMetaData;
|
|
36
|
+
};
|
|
29
37
|
};
|
|
30
38
|
declare const configs: {
|
|
31
39
|
recommended: {
|
package/lib/index.d.ts
CHANGED
|
@@ -18,6 +18,10 @@ declare const rules: {
|
|
|
18
18
|
create(context: PackageJsonRuleContext<string[]>): jsonc_eslint_parser.RuleListener;
|
|
19
19
|
meta: eslint.Rule.RuleMetaData;
|
|
20
20
|
};
|
|
21
|
+
"unique-dependencies": {
|
|
22
|
+
create(context: PackageJsonRuleContext<unknown[]>): jsonc_eslint_parser.RuleListener;
|
|
23
|
+
meta: eslint.Rule.RuleMetaData;
|
|
24
|
+
};
|
|
21
25
|
"valid-local-dependency": {
|
|
22
26
|
create(context: PackageJsonRuleContext<unknown[]>): jsonc_eslint_parser.RuleListener;
|
|
23
27
|
meta: eslint.Rule.RuleMetaData;
|
|
@@ -26,6 +30,10 @@ declare const rules: {
|
|
|
26
30
|
create(context: PackageJsonRuleContext<unknown[]>): jsonc_eslint_parser.RuleListener;
|
|
27
31
|
meta: eslint.Rule.RuleMetaData;
|
|
28
32
|
};
|
|
33
|
+
"valid-repository-directory": {
|
|
34
|
+
create(context: PackageJsonRuleContext<unknown[]>): jsonc_eslint_parser.RuleListener;
|
|
35
|
+
meta: eslint.Rule.RuleMetaData;
|
|
36
|
+
};
|
|
29
37
|
};
|
|
30
38
|
declare const configs: {
|
|
31
39
|
recommended: {
|
package/lib/index.js
CHANGED
|
@@ -35,14 +35,18 @@ module.exports = __toCommonJS(src_exports);
|
|
|
35
35
|
var import_order_properties = __toESM(require("./rules/order-properties.js"));
|
|
36
36
|
var import_prefer_repository_shorthand = __toESM(require("./rules/prefer-repository-shorthand.js"));
|
|
37
37
|
var import_sort_collections = __toESM(require("./rules/sort-collections.js"));
|
|
38
|
+
var import_unique_dependencies = __toESM(require("./rules/unique-dependencies.js"));
|
|
38
39
|
var import_valid_local_dependency = __toESM(require("./rules/valid-local-dependency.js"));
|
|
39
40
|
var import_valid_package_def = __toESM(require("./rules/valid-package-def.js"));
|
|
41
|
+
var import_valid_repository_directory = __toESM(require("./rules/valid-repository-directory.js"));
|
|
40
42
|
const rules = {
|
|
41
43
|
"order-properties": import_order_properties.default,
|
|
42
44
|
"prefer-repository-shorthand": import_prefer_repository_shorthand.default,
|
|
43
45
|
"sort-collections": import_sort_collections.default,
|
|
46
|
+
"unique-dependencies": import_unique_dependencies.default,
|
|
44
47
|
"valid-local-dependency": import_valid_local_dependency.default,
|
|
45
|
-
"valid-package-def": import_valid_package_def.default
|
|
48
|
+
"valid-package-def": import_valid_package_def.default,
|
|
49
|
+
"valid-repository-directory": import_valid_repository_directory.default
|
|
46
50
|
};
|
|
47
51
|
const configs = {
|
|
48
52
|
recommended: {
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import orderProperties from \"./rules/order-properties.js\";\nimport preferRepositoryShorthand from \"./rules/prefer-repository-shorthand.js\";\nimport sortCollections from \"./rules/sort-collections.js\";\nimport validLocalDependency from \"./rules/valid-local-dependency.js\";\nimport validPackageDef from \"./rules/valid-package-def.js\";\n\nexport const rules = {\n\t\"order-properties\": orderProperties,\n\t\"prefer-repository-shorthand\": preferRepositoryShorthand,\n\t\"sort-collections\": sortCollections,\n\t\"valid-local-dependency\": validLocalDependency,\n\t\"valid-package-def\": validPackageDef,\n};\n\nexport const configs = {\n\trecommended: {\n\t\trules: Object.fromEntries(\n\t\t\tObject.entries(rules)\n\t\t\t\t.filter(([, rule]) => rule.meta.docs?.recommended)\n\t\t\t\t.map(([name]) => [\"package-json/\" + name, \"error\" as const]),\n\t\t),\n\t},\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAA4B;AAC5B,yCAAsC;AACtC,8BAA4B;AAC5B,oCAAiC;AACjC,+BAA4B;
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import orderProperties from \"./rules/order-properties.js\";\nimport preferRepositoryShorthand from \"./rules/prefer-repository-shorthand.js\";\nimport sortCollections from \"./rules/sort-collections.js\";\nimport uniqueDependencies from \"./rules/unique-dependencies.js\";\nimport validLocalDependency from \"./rules/valid-local-dependency.js\";\nimport validPackageDef from \"./rules/valid-package-def.js\";\nimport validRepositoryDirectory from \"./rules/valid-repository-directory.js\";\n\nexport const rules = {\n\t\"order-properties\": orderProperties,\n\t\"prefer-repository-shorthand\": preferRepositoryShorthand,\n\t\"sort-collections\": sortCollections,\n\t\"unique-dependencies\": uniqueDependencies,\n\t\"valid-local-dependency\": validLocalDependency,\n\t\"valid-package-def\": validPackageDef,\n\t\"valid-repository-directory\": validRepositoryDirectory,\n};\n\nexport const configs = {\n\trecommended: {\n\t\trules: Object.fromEntries(\n\t\t\tObject.entries(rules)\n\t\t\t\t.filter(([, rule]) => rule.meta.docs?.recommended)\n\t\t\t\t.map(([name]) => [\"package-json/\" + name, \"error\" as const]),\n\t\t),\n\t},\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAA4B;AAC5B,yCAAsC;AACtC,8BAA4B;AAC5B,iCAA+B;AAC/B,oCAAiC;AACjC,+BAA4B;AAC5B,wCAAqC;AAE9B,MAAM,QAAQ;AAAA,EACpB,oBAAoB,wBAAAA;AAAA,EACpB,+BAA+B,mCAAAC;AAAA,EAC/B,oBAAoB,wBAAAC;AAAA,EACpB,uBAAuB,2BAAAC;AAAA,EACvB,0BAA0B,8BAAAC;AAAA,EAC1B,qBAAqB,yBAAAC;AAAA,EACrB,8BAA8B,kCAAAC;AAC/B;AAEO,MAAM,UAAU;AAAA,EACtB,aAAa;AAAA,IACZ,OAAO,OAAO;AAAA,MACb,OAAO,QAAQ,KAAK,EAClB,OAAO,CAAC,CAAC,EAAE,IAAI,MAAM,KAAK,KAAK,MAAM,WAAW,EAChD,IAAI,CAAC,CAAC,IAAI,MAAM,CAAC,kBAAkB,MAAM,OAAgB,CAAC;AAAA,IAC7D;AAAA,EACD;AACD;","names":["orderProperties","preferRepositoryShorthand","sortCollections","uniqueDependencies","validLocalDependency","validPackageDef","validRepositoryDirectory"]}
|
package/lib/index.mjs
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import orderProperties from "./rules/order-properties.js";
|
|
2
2
|
import preferRepositoryShorthand from "./rules/prefer-repository-shorthand.js";
|
|
3
3
|
import sortCollections from "./rules/sort-collections.js";
|
|
4
|
+
import uniqueDependencies from "./rules/unique-dependencies.js";
|
|
4
5
|
import validLocalDependency from "./rules/valid-local-dependency.js";
|
|
5
6
|
import validPackageDef from "./rules/valid-package-def.js";
|
|
7
|
+
import validRepositoryDirectory from "./rules/valid-repository-directory.js";
|
|
6
8
|
const rules = {
|
|
7
9
|
"order-properties": orderProperties,
|
|
8
10
|
"prefer-repository-shorthand": preferRepositoryShorthand,
|
|
9
11
|
"sort-collections": sortCollections,
|
|
12
|
+
"unique-dependencies": uniqueDependencies,
|
|
10
13
|
"valid-local-dependency": validLocalDependency,
|
|
11
|
-
"valid-package-def": validPackageDef
|
|
14
|
+
"valid-package-def": validPackageDef,
|
|
15
|
+
"valid-repository-directory": validRepositoryDirectory
|
|
12
16
|
};
|
|
13
17
|
const configs = {
|
|
14
18
|
recommended: {
|
package/lib/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import orderProperties from \"./rules/order-properties.js\";\nimport preferRepositoryShorthand from \"./rules/prefer-repository-shorthand.js\";\nimport sortCollections from \"./rules/sort-collections.js\";\nimport validLocalDependency from \"./rules/valid-local-dependency.js\";\nimport validPackageDef from \"./rules/valid-package-def.js\";\n\nexport const rules = {\n\t\"order-properties\": orderProperties,\n\t\"prefer-repository-shorthand\": preferRepositoryShorthand,\n\t\"sort-collections\": sortCollections,\n\t\"valid-local-dependency\": validLocalDependency,\n\t\"valid-package-def\": validPackageDef,\n};\n\nexport const configs = {\n\trecommended: {\n\t\trules: Object.fromEntries(\n\t\t\tObject.entries(rules)\n\t\t\t\t.filter(([, rule]) => rule.meta.docs?.recommended)\n\t\t\t\t.map(([name]) => [\"package-json/\" + name, \"error\" as const]),\n\t\t),\n\t},\n};\n"],"mappings":"AAAA,OAAO,qBAAqB;AAC5B,OAAO,+BAA+B;AACtC,OAAO,qBAAqB;AAC5B,OAAO,0BAA0B;AACjC,OAAO,qBAAqB;
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import orderProperties from \"./rules/order-properties.js\";\nimport preferRepositoryShorthand from \"./rules/prefer-repository-shorthand.js\";\nimport sortCollections from \"./rules/sort-collections.js\";\nimport uniqueDependencies from \"./rules/unique-dependencies.js\";\nimport validLocalDependency from \"./rules/valid-local-dependency.js\";\nimport validPackageDef from \"./rules/valid-package-def.js\";\nimport validRepositoryDirectory from \"./rules/valid-repository-directory.js\";\n\nexport const rules = {\n\t\"order-properties\": orderProperties,\n\t\"prefer-repository-shorthand\": preferRepositoryShorthand,\n\t\"sort-collections\": sortCollections,\n\t\"unique-dependencies\": uniqueDependencies,\n\t\"valid-local-dependency\": validLocalDependency,\n\t\"valid-package-def\": validPackageDef,\n\t\"valid-repository-directory\": validRepositoryDirectory,\n};\n\nexport const configs = {\n\trecommended: {\n\t\trules: Object.fromEntries(\n\t\t\tObject.entries(rules)\n\t\t\t\t.filter(([, rule]) => rule.meta.docs?.recommended)\n\t\t\t\t.map(([name]) => [\"package-json/\" + name, \"error\" as const]),\n\t\t),\n\t},\n};\n"],"mappings":"AAAA,OAAO,qBAAqB;AAC5B,OAAO,+BAA+B;AACtC,OAAO,qBAAqB;AAC5B,OAAO,wBAAwB;AAC/B,OAAO,0BAA0B;AACjC,OAAO,qBAAqB;AAC5B,OAAO,8BAA8B;AAE9B,MAAM,QAAQ;AAAA,EACpB,oBAAoB;AAAA,EACpB,+BAA+B;AAAA,EAC/B,oBAAoB;AAAA,EACpB,uBAAuB;AAAA,EACvB,0BAA0B;AAAA,EAC1B,qBAAqB;AAAA,EACrB,8BAA8B;AAC/B;AAEO,MAAM,UAAU;AAAA,EACtB,aAAa;AAAA,IACZ,OAAO,OAAO;AAAA,MACb,OAAO,QAAQ,KAAK,EAClB,OAAO,CAAC,CAAC,EAAE,IAAI,MAAM,KAAK,KAAK,MAAM,WAAW,EAChD,IAAI,CAAC,CAAC,IAAI,MAAM,CAAC,kBAAkB,MAAM,OAAgB,CAAC;AAAA,IAC7D;AAAA,EACD;AACD;","names":[]}
|
|
@@ -22,14 +22,10 @@ __export(prefer_repository_shorthand_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(prefer_repository_shorthand_exports);
|
|
24
24
|
var import_createRule = require("../createRule.js");
|
|
25
|
+
var import_findPropertyWithKeyValue = require("../utils/findPropertyWithKeyValue.js");
|
|
25
26
|
const githubUrlRegex = /^(?:git\+)?(?:ssh:\/\/git@|http?s:\/\/)?(?:www\.)?github\.com\//;
|
|
26
27
|
const isGitHubUrl = (url) => githubUrlRegex.test(url);
|
|
27
28
|
const cleanGitHubUrl = (url) => url.replace(githubUrlRegex, "").replace(/\.git$/, "");
|
|
28
|
-
function findJSONLiteralWithValue(properties, value) {
|
|
29
|
-
return properties.find(
|
|
30
|
-
(property) => property.key.type === "JSONLiteral" && property.key.value === value
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
29
|
var prefer_repository_shorthand_default = (0, import_createRule.createRule)({
|
|
34
30
|
create(context) {
|
|
35
31
|
return {
|
|
@@ -39,17 +35,17 @@ var prefer_repository_shorthand_default = (0, import_createRule.createRule)({
|
|
|
39
35
|
}
|
|
40
36
|
if (node.value.type === "JSONObjectExpression") {
|
|
41
37
|
const { properties } = node.value;
|
|
42
|
-
if (
|
|
38
|
+
if ((0, import_findPropertyWithKeyValue.findPropertyWithKeyValue)(properties, "directory")) {
|
|
43
39
|
return;
|
|
44
40
|
}
|
|
45
|
-
const typeProperty =
|
|
41
|
+
const typeProperty = (0, import_findPropertyWithKeyValue.findPropertyWithKeyValue)(
|
|
46
42
|
properties,
|
|
47
43
|
"type"
|
|
48
44
|
);
|
|
49
45
|
if (typeProperty?.value.type !== "JSONLiteral" || typeProperty.value.value !== "git") {
|
|
50
46
|
return;
|
|
51
47
|
}
|
|
52
|
-
const urlProperty =
|
|
48
|
+
const urlProperty = (0, import_findPropertyWithKeyValue.findPropertyWithKeyValue)(
|
|
53
49
|
properties,
|
|
54
50
|
"url"
|
|
55
51
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/rules/prefer-repository-shorthand.ts"],"sourcesContent":["import type ESTree from \"estree\";\nimport
|
|
1
|
+
{"version":3,"sources":["../../src/rules/prefer-repository-shorthand.ts"],"sourcesContent":["import type ESTree from \"estree\";\n\nimport { createRule } from \"../createRule.js\";\nimport { findPropertyWithKeyValue } from \"../utils/findPropertyWithKeyValue.js\";\n\nconst githubUrlRegex =\n\t/^(?:git\\+)?(?:ssh:\\/\\/git@|http?s:\\/\\/)?(?:www\\.)?github\\.com\\//;\n\nconst isGitHubUrl = (url: string) => githubUrlRegex.test(url);\n\nconst cleanGitHubUrl = (url: string) =>\n\turl.replace(githubUrlRegex, \"\").replace(/\\.git$/, \"\");\n\nexport default createRule({\n\tcreate(context) {\n\t\treturn {\n\t\t\tJSONProperty(node) {\n\t\t\t\tif (\n\t\t\t\t\tnode.key.type !== \"JSONLiteral\" ||\n\t\t\t\t\tnode.key.value !== \"repository\" ||\n\t\t\t\t\tnode.parent.parent.parent.type !== \"Program\"\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (node.value.type === \"JSONObjectExpression\") {\n\t\t\t\t\tconst { properties } = node.value;\n\n\t\t\t\t\tif (findPropertyWithKeyValue(properties, \"directory\")) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst typeProperty = findPropertyWithKeyValue(\n\t\t\t\t\t\tproperties,\n\t\t\t\t\t\t\"type\",\n\t\t\t\t\t);\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypeProperty?.value.type !== \"JSONLiteral\" ||\n\t\t\t\t\t\ttypeProperty.value.value !== \"git\"\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst urlProperty = findPropertyWithKeyValue(\n\t\t\t\t\t\tproperties,\n\t\t\t\t\t\t\"url\",\n\t\t\t\t\t);\n\t\t\t\t\tif (\n\t\t\t\t\t\turlProperty?.value.type !== \"JSONLiteral\" ||\n\t\t\t\t\t\ttypeof urlProperty.value.value !== \"string\" ||\n\t\t\t\t\t\t!isGitHubUrl(urlProperty.value.value)\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst url = urlProperty.value.value;\n\n\t\t\t\t\tcontext.report({\n\t\t\t\t\t\tfix(fixer) {\n\t\t\t\t\t\t\treturn fixer.replaceText(\n\t\t\t\t\t\t\t\tnode.value as unknown as ESTree.Node,\n\t\t\t\t\t\t\t\tJSON.stringify(cleanGitHubUrl(url)),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t},\n\t\t\t\t\t\tmessageId: \"preferShorthand\",\n\t\t\t\t\t\tnode: node.value as unknown as ESTree.Node,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tif (node.value.type === \"JSONLiteral\") {\n\t\t\t\t\tconst { value } = node.value;\n\t\t\t\t\tif (typeof value === \"string\" && isGitHubUrl(value)) {\n\t\t\t\t\t\tcontext.report({\n\t\t\t\t\t\t\tfix(fixer) {\n\t\t\t\t\t\t\t\treturn fixer.replaceText(\n\t\t\t\t\t\t\t\t\tnode.value as unknown as ESTree.Node,\n\t\t\t\t\t\t\t\t\tJSON.stringify(cleanGitHubUrl(value)),\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tmessageId: \"preferShorthand\",\n\t\t\t\t\t\t\tnode: node.value as unknown as ESTree.Node,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t},\n\n\tmeta: {\n\t\tdocs: {\n\t\t\tcategory: \"Best Practices\",\n\t\t\tdescription: \"Enforce shorthand declaration for GitHub repository.\",\n\t\t\trecommended: true,\n\t\t},\n\t\tfixable: \"code\",\n\t\tmessages: {\n\t\t\tpreferShorthand:\n\t\t\t\t\"Prefer a shorthand locator for a GitHub repository.\",\n\t\t},\n\t},\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,wBAA2B;AAC3B,sCAAyC;AAEzC,MAAM,iBACL;AAED,MAAM,cAAc,CAAC,QAAgB,eAAe,KAAK,GAAG;AAE5D,MAAM,iBAAiB,CAAC,QACvB,IAAI,QAAQ,gBAAgB,EAAE,EAAE,QAAQ,UAAU,EAAE;AAErD,IAAO,0CAAQ,8BAAW;AAAA,EACzB,OAAO,SAAS;AACf,WAAO;AAAA,MACN,aAAa,MAAM;AAClB,YACC,KAAK,IAAI,SAAS,iBAClB,KAAK,IAAI,UAAU,gBACnB,KAAK,OAAO,OAAO,OAAO,SAAS,WAClC;AACD;AAAA,QACD;AAEA,YAAI,KAAK,MAAM,SAAS,wBAAwB;AAC/C,gBAAM,EAAE,WAAW,IAAI,KAAK;AAE5B,kBAAI,0DAAyB,YAAY,WAAW,GAAG;AACtD;AAAA,UACD;AAEA,gBAAM,mBAAe;AAAA,YACpB;AAAA,YACA;AAAA,UACD;AACA,cACC,cAAc,MAAM,SAAS,iBAC7B,aAAa,MAAM,UAAU,OAC5B;AACD;AAAA,UACD;AAEA,gBAAM,kBAAc;AAAA,YACnB;AAAA,YACA;AAAA,UACD;AACA,cACC,aAAa,MAAM,SAAS,iBAC5B,OAAO,YAAY,MAAM,UAAU,YACnC,CAAC,YAAY,YAAY,MAAM,KAAK,GACnC;AACD;AAAA,UACD;AAEA,gBAAM,MAAM,YAAY,MAAM;AAE9B,kBAAQ,OAAO;AAAA,YACd,IAAI,OAAO;AACV,qBAAO,MAAM;AAAA,gBACZ,KAAK;AAAA,gBACL,KAAK,UAAU,eAAe,GAAG,CAAC;AAAA,cACnC;AAAA,YACD;AAAA,YACA,WAAW;AAAA,YACX,MAAM,KAAK;AAAA,UACZ,CAAC;AAAA,QACF;AAEA,YAAI,KAAK,MAAM,SAAS,eAAe;AACtC,gBAAM,EAAE,MAAM,IAAI,KAAK;AACvB,cAAI,OAAO,UAAU,YAAY,YAAY,KAAK,GAAG;AACpD,oBAAQ,OAAO;AAAA,cACd,IAAI,OAAO;AACV,uBAAO,MAAM;AAAA,kBACZ,KAAK;AAAA,kBACL,KAAK,UAAU,eAAe,KAAK,CAAC;AAAA,gBACrC;AAAA,cACD;AAAA,cACA,WAAW;AAAA,cACX,MAAM,KAAK;AAAA,YACZ,CAAC;AAAA,UACF;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAAA,EAEA,MAAM;AAAA,IACL,MAAM;AAAA,MACL,UAAU;AAAA,MACV,aAAa;AAAA,MACb,aAAa;AAAA,IACd;AAAA,IACA,SAAS;AAAA,IACT,UAAU;AAAA,MACT,iBACC;AAAA,IACF;AAAA,EACD;AACD,CAAC;","names":[]}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import { createRule } from "../createRule.js";
|
|
2
|
+
import { findPropertyWithKeyValue } from "../utils/findPropertyWithKeyValue.js";
|
|
2
3
|
const githubUrlRegex = /^(?:git\+)?(?:ssh:\/\/git@|http?s:\/\/)?(?:www\.)?github\.com\//;
|
|
3
4
|
const isGitHubUrl = (url) => githubUrlRegex.test(url);
|
|
4
5
|
const cleanGitHubUrl = (url) => url.replace(githubUrlRegex, "").replace(/\.git$/, "");
|
|
5
|
-
function findJSONLiteralWithValue(properties, value) {
|
|
6
|
-
return properties.find(
|
|
7
|
-
(property) => property.key.type === "JSONLiteral" && property.key.value === value
|
|
8
|
-
);
|
|
9
|
-
}
|
|
10
6
|
var prefer_repository_shorthand_default = createRule({
|
|
11
7
|
create(context) {
|
|
12
8
|
return {
|
|
@@ -16,17 +12,17 @@ var prefer_repository_shorthand_default = createRule({
|
|
|
16
12
|
}
|
|
17
13
|
if (node.value.type === "JSONObjectExpression") {
|
|
18
14
|
const { properties } = node.value;
|
|
19
|
-
if (
|
|
15
|
+
if (findPropertyWithKeyValue(properties, "directory")) {
|
|
20
16
|
return;
|
|
21
17
|
}
|
|
22
|
-
const typeProperty =
|
|
18
|
+
const typeProperty = findPropertyWithKeyValue(
|
|
23
19
|
properties,
|
|
24
20
|
"type"
|
|
25
21
|
);
|
|
26
22
|
if (typeProperty?.value.type !== "JSONLiteral" || typeProperty.value.value !== "git") {
|
|
27
23
|
return;
|
|
28
24
|
}
|
|
29
|
-
const urlProperty =
|
|
25
|
+
const urlProperty = findPropertyWithKeyValue(
|
|
30
26
|
properties,
|
|
31
27
|
"url"
|
|
32
28
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/rules/prefer-repository-shorthand.ts"],"sourcesContent":["import type ESTree from \"estree\";\nimport
|
|
1
|
+
{"version":3,"sources":["../../src/rules/prefer-repository-shorthand.ts"],"sourcesContent":["import type ESTree from \"estree\";\n\nimport { createRule } from \"../createRule.js\";\nimport { findPropertyWithKeyValue } from \"../utils/findPropertyWithKeyValue.js\";\n\nconst githubUrlRegex =\n\t/^(?:git\\+)?(?:ssh:\\/\\/git@|http?s:\\/\\/)?(?:www\\.)?github\\.com\\//;\n\nconst isGitHubUrl = (url: string) => githubUrlRegex.test(url);\n\nconst cleanGitHubUrl = (url: string) =>\n\turl.replace(githubUrlRegex, \"\").replace(/\\.git$/, \"\");\n\nexport default createRule({\n\tcreate(context) {\n\t\treturn {\n\t\t\tJSONProperty(node) {\n\t\t\t\tif (\n\t\t\t\t\tnode.key.type !== \"JSONLiteral\" ||\n\t\t\t\t\tnode.key.value !== \"repository\" ||\n\t\t\t\t\tnode.parent.parent.parent.type !== \"Program\"\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (node.value.type === \"JSONObjectExpression\") {\n\t\t\t\t\tconst { properties } = node.value;\n\n\t\t\t\t\tif (findPropertyWithKeyValue(properties, \"directory\")) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst typeProperty = findPropertyWithKeyValue(\n\t\t\t\t\t\tproperties,\n\t\t\t\t\t\t\"type\",\n\t\t\t\t\t);\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypeProperty?.value.type !== \"JSONLiteral\" ||\n\t\t\t\t\t\ttypeProperty.value.value !== \"git\"\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst urlProperty = findPropertyWithKeyValue(\n\t\t\t\t\t\tproperties,\n\t\t\t\t\t\t\"url\",\n\t\t\t\t\t);\n\t\t\t\t\tif (\n\t\t\t\t\t\turlProperty?.value.type !== \"JSONLiteral\" ||\n\t\t\t\t\t\ttypeof urlProperty.value.value !== \"string\" ||\n\t\t\t\t\t\t!isGitHubUrl(urlProperty.value.value)\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst url = urlProperty.value.value;\n\n\t\t\t\t\tcontext.report({\n\t\t\t\t\t\tfix(fixer) {\n\t\t\t\t\t\t\treturn fixer.replaceText(\n\t\t\t\t\t\t\t\tnode.value as unknown as ESTree.Node,\n\t\t\t\t\t\t\t\tJSON.stringify(cleanGitHubUrl(url)),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t},\n\t\t\t\t\t\tmessageId: \"preferShorthand\",\n\t\t\t\t\t\tnode: node.value as unknown as ESTree.Node,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tif (node.value.type === \"JSONLiteral\") {\n\t\t\t\t\tconst { value } = node.value;\n\t\t\t\t\tif (typeof value === \"string\" && isGitHubUrl(value)) {\n\t\t\t\t\t\tcontext.report({\n\t\t\t\t\t\t\tfix(fixer) {\n\t\t\t\t\t\t\t\treturn fixer.replaceText(\n\t\t\t\t\t\t\t\t\tnode.value as unknown as ESTree.Node,\n\t\t\t\t\t\t\t\t\tJSON.stringify(cleanGitHubUrl(value)),\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tmessageId: \"preferShorthand\",\n\t\t\t\t\t\t\tnode: node.value as unknown as ESTree.Node,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t},\n\n\tmeta: {\n\t\tdocs: {\n\t\t\tcategory: \"Best Practices\",\n\t\t\tdescription: \"Enforce shorthand declaration for GitHub repository.\",\n\t\t\trecommended: true,\n\t\t},\n\t\tfixable: \"code\",\n\t\tmessages: {\n\t\t\tpreferShorthand:\n\t\t\t\t\"Prefer a shorthand locator for a GitHub repository.\",\n\t\t},\n\t},\n});\n"],"mappings":"AAEA,SAAS,kBAAkB;AAC3B,SAAS,gCAAgC;AAEzC,MAAM,iBACL;AAED,MAAM,cAAc,CAAC,QAAgB,eAAe,KAAK,GAAG;AAE5D,MAAM,iBAAiB,CAAC,QACvB,IAAI,QAAQ,gBAAgB,EAAE,EAAE,QAAQ,UAAU,EAAE;AAErD,IAAO,sCAAQ,WAAW;AAAA,EACzB,OAAO,SAAS;AACf,WAAO;AAAA,MACN,aAAa,MAAM;AAClB,YACC,KAAK,IAAI,SAAS,iBAClB,KAAK,IAAI,UAAU,gBACnB,KAAK,OAAO,OAAO,OAAO,SAAS,WAClC;AACD;AAAA,QACD;AAEA,YAAI,KAAK,MAAM,SAAS,wBAAwB;AAC/C,gBAAM,EAAE,WAAW,IAAI,KAAK;AAE5B,cAAI,yBAAyB,YAAY,WAAW,GAAG;AACtD;AAAA,UACD;AAEA,gBAAM,eAAe;AAAA,YACpB;AAAA,YACA;AAAA,UACD;AACA,cACC,cAAc,MAAM,SAAS,iBAC7B,aAAa,MAAM,UAAU,OAC5B;AACD;AAAA,UACD;AAEA,gBAAM,cAAc;AAAA,YACnB;AAAA,YACA;AAAA,UACD;AACA,cACC,aAAa,MAAM,SAAS,iBAC5B,OAAO,YAAY,MAAM,UAAU,YACnC,CAAC,YAAY,YAAY,MAAM,KAAK,GACnC;AACD;AAAA,UACD;AAEA,gBAAM,MAAM,YAAY,MAAM;AAE9B,kBAAQ,OAAO;AAAA,YACd,IAAI,OAAO;AACV,qBAAO,MAAM;AAAA,gBACZ,KAAK;AAAA,gBACL,KAAK,UAAU,eAAe,GAAG,CAAC;AAAA,cACnC;AAAA,YACD;AAAA,YACA,WAAW;AAAA,YACX,MAAM,KAAK;AAAA,UACZ,CAAC;AAAA,QACF;AAEA,YAAI,KAAK,MAAM,SAAS,eAAe;AACtC,gBAAM,EAAE,MAAM,IAAI,KAAK;AACvB,cAAI,OAAO,UAAU,YAAY,YAAY,KAAK,GAAG;AACpD,oBAAQ,OAAO;AAAA,cACd,IAAI,OAAO;AACV,uBAAO,MAAM;AAAA,kBACZ,KAAK;AAAA,kBACL,KAAK,UAAU,eAAe,KAAK,CAAC;AAAA,gBACrC;AAAA,cACD;AAAA,cACA,WAAW;AAAA,cACX,MAAM,KAAK;AAAA,YACZ,CAAC;AAAA,UACF;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAAA,EAEA,MAAM;AAAA,IACL,MAAM;AAAA,MACL,UAAU;AAAA,MACV,aAAa;AAAA,MACb,aAAa;AAAA,IACd;AAAA,IACA,SAAS;AAAA,IACT,UAAU;AAAA,MACT,iBACC;AAAA,IACF;AAAA,EACD;AACD,CAAC;","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as eslint from 'eslint';
|
|
2
|
+
import * as jsonc_eslint_parser from 'jsonc-eslint-parser';
|
|
3
|
+
import { PackageJsonRuleContext } from '../createRule.mjs';
|
|
4
|
+
import 'estree';
|
|
5
|
+
|
|
6
|
+
declare const _default: {
|
|
7
|
+
create(context: PackageJsonRuleContext<unknown[]>): jsonc_eslint_parser.RuleListener;
|
|
8
|
+
meta: eslint.Rule.RuleMetaData;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { _default as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
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 _default: {
|
|
7
|
+
create(context: PackageJsonRuleContext<unknown[]>): jsonc_eslint_parser.RuleListener;
|
|
8
|
+
meta: eslint.Rule.RuleMetaData;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { _default as default };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var unique_dependencies_exports = {};
|
|
20
|
+
__export(unique_dependencies_exports, {
|
|
21
|
+
default: () => unique_dependencies_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(unique_dependencies_exports);
|
|
24
|
+
var import_createRule = require("../createRule.js");
|
|
25
|
+
var import_predicates = require("../utils/predicates.js");
|
|
26
|
+
const dependencyPropertyNames = /* @__PURE__ */ new Set([
|
|
27
|
+
"bundleDependencies",
|
|
28
|
+
"bundledDependencies",
|
|
29
|
+
"dependencies",
|
|
30
|
+
"devDependencies",
|
|
31
|
+
"optionalDependencies",
|
|
32
|
+
"peerDependencies",
|
|
33
|
+
"overrides"
|
|
34
|
+
]);
|
|
35
|
+
var unique_dependencies_default = (0, import_createRule.createRule)({
|
|
36
|
+
create(context) {
|
|
37
|
+
function check(elements, getNodeToRemove) {
|
|
38
|
+
const seen = /* @__PURE__ */ new Set();
|
|
39
|
+
for (const element of elements.filter(import_predicates.isNotNullish).filter(import_predicates.isJSONStringLiteral).reverse()) {
|
|
40
|
+
if (seen.has(element.value)) {
|
|
41
|
+
report(element);
|
|
42
|
+
} else {
|
|
43
|
+
seen.add(element.value);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function report(node) {
|
|
47
|
+
context.report({
|
|
48
|
+
messageId: "overridden",
|
|
49
|
+
node,
|
|
50
|
+
suggest: [
|
|
51
|
+
{
|
|
52
|
+
fix(fixer) {
|
|
53
|
+
const removal = getNodeToRemove(node);
|
|
54
|
+
return [
|
|
55
|
+
fixer.remove(removal),
|
|
56
|
+
fixer.remove(
|
|
57
|
+
// A listing that's overridden can't be last,
|
|
58
|
+
// so we're guaranteed there's a comma after.
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
60
|
+
context.sourceCode.getTokenAfter(
|
|
61
|
+
removal
|
|
62
|
+
)
|
|
63
|
+
)
|
|
64
|
+
];
|
|
65
|
+
},
|
|
66
|
+
messageId: "remove"
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
"Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.type=JSONLiteral]"(node) {
|
|
74
|
+
if (!dependencyPropertyNames.has(node.key.value)) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
switch (node.value.type) {
|
|
78
|
+
case "JSONArrayExpression":
|
|
79
|
+
check(
|
|
80
|
+
node.value.elements,
|
|
81
|
+
(element) => element
|
|
82
|
+
);
|
|
83
|
+
break;
|
|
84
|
+
case "JSONObjectExpression":
|
|
85
|
+
check(
|
|
86
|
+
node.value.properties.map(
|
|
87
|
+
(property) => property.key
|
|
88
|
+
),
|
|
89
|
+
(property) => property.parent
|
|
90
|
+
);
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
},
|
|
96
|
+
meta: {
|
|
97
|
+
docs: {
|
|
98
|
+
category: "Best Practices",
|
|
99
|
+
description: "Enforce that if repository directory is specified, it matches the path to the package.json file",
|
|
100
|
+
recommended: true
|
|
101
|
+
},
|
|
102
|
+
hasSuggestions: true,
|
|
103
|
+
messages: {
|
|
104
|
+
overridden: "Package name is overridden by a duplicate listing later on.",
|
|
105
|
+
remove: "Remove this redundant dependency listing."
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
//# sourceMappingURL=unique-dependencies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/rules/unique-dependencies.ts"],"sourcesContent":["import type { AST as JsonAST } from \"jsonc-eslint-parser\";\n\nimport * as ESTree from \"estree\";\n\nimport { createRule } from \"../createRule.js\";\nimport { isJSONStringLiteral, isNotNullish } from \"../utils/predicates.js\";\n\nconst dependencyPropertyNames = new Set([\n\t\"bundleDependencies\",\n\t\"bundledDependencies\",\n\t\"dependencies\",\n\t\"devDependencies\",\n\t\"optionalDependencies\",\n\t\"peerDependencies\",\n\t\"overrides\",\n]);\n\nexport default createRule({\n\tcreate(context) {\n\t\tfunction check(\n\t\t\telements: (JsonAST.JSONNode | null)[],\n\t\t\tgetNodeToRemove: (element: JsonAST.JSONNode) => ESTree.Node,\n\t\t) {\n\t\t\tconst seen = new Set();\n\n\t\t\tfor (const element of elements\n\t\t\t\t.filter(isNotNullish)\n\t\t\t\t.filter(isJSONStringLiteral)\n\t\t\t\t.reverse()) {\n\t\t\t\tif (seen.has(element.value)) {\n\t\t\t\t\treport(element);\n\t\t\t\t} else {\n\t\t\t\t\tseen.add(element.value);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction report(node: JsonAST.JSONNode) {\n\t\t\t\tcontext.report({\n\t\t\t\t\tmessageId: \"overridden\",\n\t\t\t\t\tnode: node as unknown as ESTree.Node,\n\t\t\t\t\tsuggest: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tfix(fixer) {\n\t\t\t\t\t\t\t\tconst removal = getNodeToRemove(node);\n\t\t\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\t\t\tfixer.remove(removal),\n\t\t\t\t\t\t\t\t\tfixer.remove(\n\t\t\t\t\t\t\t\t\t\t// A listing that's overridden can't be last,\n\t\t\t\t\t\t\t\t\t\t// so we're guaranteed there's a comma after.\n\t\t\t\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\t\t\t\t\t\tcontext.sourceCode.getTokenAfter(\n\t\t\t\t\t\t\t\t\t\t\tremoval,\n\t\t\t\t\t\t\t\t\t\t)!,\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tmessageId: \"remove\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\t\"Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.type=JSONLiteral]\"(\n\t\t\t\tnode: JsonAST.JSONProperty & {\n\t\t\t\t\tkey: JsonAST.JSONStringLiteral;\n\t\t\t\t},\n\t\t\t) {\n\t\t\t\tif (!dependencyPropertyNames.has(node.key.value)) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tswitch (node.value.type) {\n\t\t\t\t\tcase \"JSONArrayExpression\":\n\t\t\t\t\t\tcheck(\n\t\t\t\t\t\t\tnode.value.elements,\n\t\t\t\t\t\t\t(element) => element as unknown as ESTree.Node,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"JSONObjectExpression\":\n\t\t\t\t\t\tcheck(\n\t\t\t\t\t\t\tnode.value.properties.map(\n\t\t\t\t\t\t\t\t(property) => property.key,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t(property) =>\n\t\t\t\t\t\t\t\tproperty.parent as unknown as ESTree.Node,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t},\n\n\tmeta: {\n\t\tdocs: {\n\t\t\tcategory: \"Best Practices\",\n\t\t\tdescription:\n\t\t\t\t\"Enforce that if repository directory is specified, it matches the path to the package.json file\",\n\t\t\trecommended: true,\n\t\t},\n\t\thasSuggestions: true,\n\t\tmessages: {\n\t\t\toverridden:\n\t\t\t\t\"Package name is overridden by a duplicate listing later on.\",\n\t\t\tremove: \"Remove this redundant dependency listing.\",\n\t\t},\n\t},\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,wBAA2B;AAC3B,wBAAkD;AAElD,MAAM,0BAA0B,oBAAI,IAAI;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,CAAC;AAED,IAAO,kCAAQ,8BAAW;AAAA,EACzB,OAAO,SAAS;AACf,aAAS,MACR,UACA,iBACC;AACD,YAAM,OAAO,oBAAI,IAAI;AAErB,iBAAW,WAAW,SACpB,OAAO,8BAAY,EACnB,OAAO,qCAAmB,EAC1B,QAAQ,GAAG;AACZ,YAAI,KAAK,IAAI,QAAQ,KAAK,GAAG;AAC5B,iBAAO,OAAO;AAAA,QACf,OAAO;AACN,eAAK,IAAI,QAAQ,KAAK;AAAA,QACvB;AAAA,MACD;AAEA,eAAS,OAAO,MAAwB;AACvC,gBAAQ,OAAO;AAAA,UACd,WAAW;AAAA,UACX;AAAA,UACA,SAAS;AAAA,YACR;AAAA,cACC,IAAI,OAAO;AACV,sBAAM,UAAU,gBAAgB,IAAI;AACpC,uBAAO;AAAA,kBACN,MAAM,OAAO,OAAO;AAAA,kBACpB,MAAM;AAAA;AAAA;AAAA;AAAA,oBAIL,QAAQ,WAAW;AAAA,sBAClB;AAAA,oBACD;AAAA,kBACD;AAAA,gBACD;AAAA,cACD;AAAA,cACA,WAAW;AAAA,YACZ;AAAA,UACD;AAAA,QACD,CAAC;AAAA,MACF;AAAA,IACD;AAEA,WAAO;AAAA,MACN,gGACC,MAGC;AACD,YAAI,CAAC,wBAAwB,IAAI,KAAK,IAAI,KAAK,GAAG;AACjD;AAAA,QACD;AAEA,gBAAQ,KAAK,MAAM,MAAM;AAAA,UACxB,KAAK;AACJ;AAAA,cACC,KAAK,MAAM;AAAA,cACX,CAAC,YAAY;AAAA,YACd;AACA;AAAA,UACD,KAAK;AACJ;AAAA,cACC,KAAK,MAAM,WAAW;AAAA,gBACrB,CAAC,aAAa,SAAS;AAAA,cACxB;AAAA,cACA,CAAC,aACA,SAAS;AAAA,YACX;AACA;AAAA,QACF;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAAA,EAEA,MAAM;AAAA,IACL,MAAM;AAAA,MACL,UAAU;AAAA,MACV,aACC;AAAA,MACD,aAAa;AAAA,IACd;AAAA,IACA,gBAAgB;AAAA,IAChB,UAAU;AAAA,MACT,YACC;AAAA,MACD,QAAQ;AAAA,IACT;AAAA,EACD;AACD,CAAC;","names":[]}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { createRule } from "../createRule.js";
|
|
2
|
+
import { isJSONStringLiteral, isNotNullish } from "../utils/predicates.js";
|
|
3
|
+
const dependencyPropertyNames = /* @__PURE__ */ new Set([
|
|
4
|
+
"bundleDependencies",
|
|
5
|
+
"bundledDependencies",
|
|
6
|
+
"dependencies",
|
|
7
|
+
"devDependencies",
|
|
8
|
+
"optionalDependencies",
|
|
9
|
+
"peerDependencies",
|
|
10
|
+
"overrides"
|
|
11
|
+
]);
|
|
12
|
+
var unique_dependencies_default = createRule({
|
|
13
|
+
create(context) {
|
|
14
|
+
function check(elements, getNodeToRemove) {
|
|
15
|
+
const seen = /* @__PURE__ */ new Set();
|
|
16
|
+
for (const element of elements.filter(isNotNullish).filter(isJSONStringLiteral).reverse()) {
|
|
17
|
+
if (seen.has(element.value)) {
|
|
18
|
+
report(element);
|
|
19
|
+
} else {
|
|
20
|
+
seen.add(element.value);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function report(node) {
|
|
24
|
+
context.report({
|
|
25
|
+
messageId: "overridden",
|
|
26
|
+
node,
|
|
27
|
+
suggest: [
|
|
28
|
+
{
|
|
29
|
+
fix(fixer) {
|
|
30
|
+
const removal = getNodeToRemove(node);
|
|
31
|
+
return [
|
|
32
|
+
fixer.remove(removal),
|
|
33
|
+
fixer.remove(
|
|
34
|
+
// A listing that's overridden can't be last,
|
|
35
|
+
// so we're guaranteed there's a comma after.
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
37
|
+
context.sourceCode.getTokenAfter(
|
|
38
|
+
removal
|
|
39
|
+
)
|
|
40
|
+
)
|
|
41
|
+
];
|
|
42
|
+
},
|
|
43
|
+
messageId: "remove"
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
"Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.type=JSONLiteral]"(node) {
|
|
51
|
+
if (!dependencyPropertyNames.has(node.key.value)) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
switch (node.value.type) {
|
|
55
|
+
case "JSONArrayExpression":
|
|
56
|
+
check(
|
|
57
|
+
node.value.elements,
|
|
58
|
+
(element) => element
|
|
59
|
+
);
|
|
60
|
+
break;
|
|
61
|
+
case "JSONObjectExpression":
|
|
62
|
+
check(
|
|
63
|
+
node.value.properties.map(
|
|
64
|
+
(property) => property.key
|
|
65
|
+
),
|
|
66
|
+
(property) => property.parent
|
|
67
|
+
);
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
meta: {
|
|
74
|
+
docs: {
|
|
75
|
+
category: "Best Practices",
|
|
76
|
+
description: "Enforce that if repository directory is specified, it matches the path to the package.json file",
|
|
77
|
+
recommended: true
|
|
78
|
+
},
|
|
79
|
+
hasSuggestions: true,
|
|
80
|
+
messages: {
|
|
81
|
+
overridden: "Package name is overridden by a duplicate listing later on.",
|
|
82
|
+
remove: "Remove this redundant dependency listing."
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
export {
|
|
87
|
+
unique_dependencies_default as default
|
|
88
|
+
};
|
|
89
|
+
//# sourceMappingURL=unique-dependencies.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/rules/unique-dependencies.ts"],"sourcesContent":["import type { AST as JsonAST } from \"jsonc-eslint-parser\";\n\nimport * as ESTree from \"estree\";\n\nimport { createRule } from \"../createRule.js\";\nimport { isJSONStringLiteral, isNotNullish } from \"../utils/predicates.js\";\n\nconst dependencyPropertyNames = new Set([\n\t\"bundleDependencies\",\n\t\"bundledDependencies\",\n\t\"dependencies\",\n\t\"devDependencies\",\n\t\"optionalDependencies\",\n\t\"peerDependencies\",\n\t\"overrides\",\n]);\n\nexport default createRule({\n\tcreate(context) {\n\t\tfunction check(\n\t\t\telements: (JsonAST.JSONNode | null)[],\n\t\t\tgetNodeToRemove: (element: JsonAST.JSONNode) => ESTree.Node,\n\t\t) {\n\t\t\tconst seen = new Set();\n\n\t\t\tfor (const element of elements\n\t\t\t\t.filter(isNotNullish)\n\t\t\t\t.filter(isJSONStringLiteral)\n\t\t\t\t.reverse()) {\n\t\t\t\tif (seen.has(element.value)) {\n\t\t\t\t\treport(element);\n\t\t\t\t} else {\n\t\t\t\t\tseen.add(element.value);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction report(node: JsonAST.JSONNode) {\n\t\t\t\tcontext.report({\n\t\t\t\t\tmessageId: \"overridden\",\n\t\t\t\t\tnode: node as unknown as ESTree.Node,\n\t\t\t\t\tsuggest: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tfix(fixer) {\n\t\t\t\t\t\t\t\tconst removal = getNodeToRemove(node);\n\t\t\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\t\t\tfixer.remove(removal),\n\t\t\t\t\t\t\t\t\tfixer.remove(\n\t\t\t\t\t\t\t\t\t\t// A listing that's overridden can't be last,\n\t\t\t\t\t\t\t\t\t\t// so we're guaranteed there's a comma after.\n\t\t\t\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\t\t\t\t\t\tcontext.sourceCode.getTokenAfter(\n\t\t\t\t\t\t\t\t\t\t\tremoval,\n\t\t\t\t\t\t\t\t\t\t)!,\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tmessageId: \"remove\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\t\"Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.type=JSONLiteral]\"(\n\t\t\t\tnode: JsonAST.JSONProperty & {\n\t\t\t\t\tkey: JsonAST.JSONStringLiteral;\n\t\t\t\t},\n\t\t\t) {\n\t\t\t\tif (!dependencyPropertyNames.has(node.key.value)) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tswitch (node.value.type) {\n\t\t\t\t\tcase \"JSONArrayExpression\":\n\t\t\t\t\t\tcheck(\n\t\t\t\t\t\t\tnode.value.elements,\n\t\t\t\t\t\t\t(element) => element as unknown as ESTree.Node,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"JSONObjectExpression\":\n\t\t\t\t\t\tcheck(\n\t\t\t\t\t\t\tnode.value.properties.map(\n\t\t\t\t\t\t\t\t(property) => property.key,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t(property) =>\n\t\t\t\t\t\t\t\tproperty.parent as unknown as ESTree.Node,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t},\n\n\tmeta: {\n\t\tdocs: {\n\t\t\tcategory: \"Best Practices\",\n\t\t\tdescription:\n\t\t\t\t\"Enforce that if repository directory is specified, it matches the path to the package.json file\",\n\t\t\trecommended: true,\n\t\t},\n\t\thasSuggestions: true,\n\t\tmessages: {\n\t\t\toverridden:\n\t\t\t\t\"Package name is overridden by a duplicate listing later on.\",\n\t\t\tremove: \"Remove this redundant dependency listing.\",\n\t\t},\n\t},\n});\n"],"mappings":"AAIA,SAAS,kBAAkB;AAC3B,SAAS,qBAAqB,oBAAoB;AAElD,MAAM,0BAA0B,oBAAI,IAAI;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,CAAC;AAED,IAAO,8BAAQ,WAAW;AAAA,EACzB,OAAO,SAAS;AACf,aAAS,MACR,UACA,iBACC;AACD,YAAM,OAAO,oBAAI,IAAI;AAErB,iBAAW,WAAW,SACpB,OAAO,YAAY,EACnB,OAAO,mBAAmB,EAC1B,QAAQ,GAAG;AACZ,YAAI,KAAK,IAAI,QAAQ,KAAK,GAAG;AAC5B,iBAAO,OAAO;AAAA,QACf,OAAO;AACN,eAAK,IAAI,QAAQ,KAAK;AAAA,QACvB;AAAA,MACD;AAEA,eAAS,OAAO,MAAwB;AACvC,gBAAQ,OAAO;AAAA,UACd,WAAW;AAAA,UACX;AAAA,UACA,SAAS;AAAA,YACR;AAAA,cACC,IAAI,OAAO;AACV,sBAAM,UAAU,gBAAgB,IAAI;AACpC,uBAAO;AAAA,kBACN,MAAM,OAAO,OAAO;AAAA,kBACpB,MAAM;AAAA;AAAA;AAAA;AAAA,oBAIL,QAAQ,WAAW;AAAA,sBAClB;AAAA,oBACD;AAAA,kBACD;AAAA,gBACD;AAAA,cACD;AAAA,cACA,WAAW;AAAA,YACZ;AAAA,UACD;AAAA,QACD,CAAC;AAAA,MACF;AAAA,IACD;AAEA,WAAO;AAAA,MACN,gGACC,MAGC;AACD,YAAI,CAAC,wBAAwB,IAAI,KAAK,IAAI,KAAK,GAAG;AACjD;AAAA,QACD;AAEA,gBAAQ,KAAK,MAAM,MAAM;AAAA,UACxB,KAAK;AACJ;AAAA,cACC,KAAK,MAAM;AAAA,cACX,CAAC,YAAY;AAAA,YACd;AACA;AAAA,UACD,KAAK;AACJ;AAAA,cACC,KAAK,MAAM,WAAW;AAAA,gBACrB,CAAC,aAAa,SAAS;AAAA,cACxB;AAAA,cACA,CAAC,aACA,SAAS;AAAA,YACX;AACA;AAAA,QACF;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAAA,EAEA,MAAM;AAAA,IACL,MAAM;AAAA,MACL,UAAU;AAAA,MACV,aACC;AAAA,MACD,aAAa;AAAA,IACd;AAAA,IACA,gBAAgB;AAAA,IAChB,UAAU;AAAA,MACT,YACC;AAAA,MACD,QAAQ;AAAA,IACT;AAAA,EACD;AACD,CAAC;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/rules/valid-local-dependency.ts"],"sourcesContent":["import path from \"path\";\n\nimport { createRule } from \"../createRule.js\";\n\
|
|
1
|
+
{"version":3,"sources":["../../src/rules/valid-local-dependency.ts"],"sourcesContent":["import path from \"path\";\n\nimport { createRule } from \"../createRule.js\";\n\nexport default createRule({\n\tcreate(context) {\n\t\treturn {\n\t\t\t\"Program:exit\"() {\n\t\t\t\tconst original = JSON.parse(context.sourceCode.text) as Record<\n\t\t\t\t\tstring,\n\t\t\t\t\tunknown\n\t\t\t\t>;\n\t\t\t\tconst { dependencies, devDependencies, peerDependencies } =\n\t\t\t\t\toriginal;\n\n\t\t\t\tconst depObjs = [\n\t\t\t\t\tObject.entries(dependencies ?? {}),\n\t\t\t\t\tObject.entries(peerDependencies ?? {}),\n\t\t\t\t\tObject.entries(devDependencies ?? {}),\n\t\t\t\t] as [string, string][][];\n\n\t\t\t\tdepObjs.forEach((obj) => {\n\t\t\t\t\tobj.forEach(([key, value]) => {\n\t\t\t\t\t\tconst response = (localPath: RegExp | string) => {\n\t\t\t\t\t\t\tconst filePath = path.join(\n\t\t\t\t\t\t\t\tcontext.filename.replace(/package\\.json/g, \"/\"),\n\t\t\t\t\t\t\t\tvalue.replace(new RegExp(localPath, \"g\"), \"\"),\n\t\t\t\t\t\t\t\t\"/package.json\",\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tif (!require.resolve(filePath)) {\n\t\t\t\t\t\t\t\t\tcontext.report({\n\t\t\t\t\t\t\t\t\t\tmessage: `The package ${key} does not exist given the specified path: ${value}.`,\n\t\t\t\t\t\t\t\t\t\tnode: context.sourceCode.ast,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\tcontext.report({\n\t\t\t\t\t\t\t\t\tmessage: `The package ${key} does not exist given the specified path: ${value}.`,\n\t\t\t\t\t\t\t\t\tnode: context.sourceCode.ast,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tif (value.startsWith(\"link:\")) {\n\t\t\t\t\t\t\tresponse(\"link:\");\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (value.startsWith(\"file:\")) {\n\t\t\t\t\t\t\tresponse(\"file:\");\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t},\n\t\t};\n\t},\n\n\tmeta: {\n\t\tdocs: {\n\t\t\tcategory: \"Best Practices\",\n\t\t\tdescription:\n\t\t\t\t\"Checks existence of local dependencies in the package.json\",\n\t\t\trecommended: true,\n\t\t},\n\t},\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiB;AAEjB,wBAA2B;AAE3B,IAAO,qCAAQ,8BAAW;AAAA,EACzB,OAAO,SAAS;AACf,WAAO;AAAA,MACN,iBAAiB;AAChB,cAAM,WAAW,KAAK,MAAM,QAAQ,WAAW,IAAI;AAInD,cAAM,EAAE,cAAc,iBAAiB,iBAAiB,IACvD;AAED,cAAM,UAAU;AAAA,UACf,OAAO,QAAQ,gBAAgB,CAAC,CAAC;AAAA,UACjC,OAAO,QAAQ,oBAAoB,CAAC,CAAC;AAAA,UACrC,OAAO,QAAQ,mBAAmB,CAAC,CAAC;AAAA,QACrC;AAEA,gBAAQ,QAAQ,CAAC,QAAQ;AACxB,cAAI,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AAC7B,kBAAM,WAAW,CAAC,cAA+B;AAChD,oBAAM,WAAW,YAAAA,QAAK;AAAA,gBACrB,QAAQ,SAAS,QAAQ,kBAAkB,GAAG;AAAA,gBAC9C,MAAM,QAAQ,IAAI,OAAO,WAAW,GAAG,GAAG,EAAE;AAAA,gBAC5C;AAAA,cACD;AAEA,kBAAI;AACH,oBAAI,CAAC,QAAQ,QAAQ,QAAQ,GAAG;AAC/B,0BAAQ,OAAO;AAAA,oBACd,SAAS,eAAe,GAAG,6CAA6C,KAAK;AAAA,oBAC7E,MAAM,QAAQ,WAAW;AAAA,kBAC1B,CAAC;AAAA,gBACF;AAAA,cACD,QAAQ;AACP,wBAAQ,OAAO;AAAA,kBACd,SAAS,eAAe,GAAG,6CAA6C,KAAK;AAAA,kBAC7E,MAAM,QAAQ,WAAW;AAAA,gBAC1B,CAAC;AAAA,cACF;AAAA,YACD;AAEA,gBAAI,MAAM,WAAW,OAAO,GAAG;AAC9B,uBAAS,OAAO;AAAA,YACjB;AAEA,gBAAI,MAAM,WAAW,OAAO,GAAG;AAC9B,uBAAS,OAAO;AAAA,YACjB;AAAA,UACD,CAAC;AAAA,QACF,CAAC;AAAA,MACF;AAAA,IACD;AAAA,EACD;AAAA,EAEA,MAAM;AAAA,IACL,MAAM;AAAA,MACL,UAAU;AAAA,MACV,aACC;AAAA,MACD,aAAa;AAAA,IACd;AAAA,EACD;AACD,CAAC;","names":["path"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/rules/valid-local-dependency.ts"],"sourcesContent":["import path from \"path\";\n\nimport { createRule } from \"../createRule.js\";\n\
|
|
1
|
+
{"version":3,"sources":["../../src/rules/valid-local-dependency.ts"],"sourcesContent":["import path from \"path\";\n\nimport { createRule } from \"../createRule.js\";\n\nexport default createRule({\n\tcreate(context) {\n\t\treturn {\n\t\t\t\"Program:exit\"() {\n\t\t\t\tconst original = JSON.parse(context.sourceCode.text) as Record<\n\t\t\t\t\tstring,\n\t\t\t\t\tunknown\n\t\t\t\t>;\n\t\t\t\tconst { dependencies, devDependencies, peerDependencies } =\n\t\t\t\t\toriginal;\n\n\t\t\t\tconst depObjs = [\n\t\t\t\t\tObject.entries(dependencies ?? {}),\n\t\t\t\t\tObject.entries(peerDependencies ?? {}),\n\t\t\t\t\tObject.entries(devDependencies ?? {}),\n\t\t\t\t] as [string, string][][];\n\n\t\t\t\tdepObjs.forEach((obj) => {\n\t\t\t\t\tobj.forEach(([key, value]) => {\n\t\t\t\t\t\tconst response = (localPath: RegExp | string) => {\n\t\t\t\t\t\t\tconst filePath = path.join(\n\t\t\t\t\t\t\t\tcontext.filename.replace(/package\\.json/g, \"/\"),\n\t\t\t\t\t\t\t\tvalue.replace(new RegExp(localPath, \"g\"), \"\"),\n\t\t\t\t\t\t\t\t\"/package.json\",\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tif (!require.resolve(filePath)) {\n\t\t\t\t\t\t\t\t\tcontext.report({\n\t\t\t\t\t\t\t\t\t\tmessage: `The package ${key} does not exist given the specified path: ${value}.`,\n\t\t\t\t\t\t\t\t\t\tnode: context.sourceCode.ast,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\tcontext.report({\n\t\t\t\t\t\t\t\t\tmessage: `The package ${key} does not exist given the specified path: ${value}.`,\n\t\t\t\t\t\t\t\t\tnode: context.sourceCode.ast,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tif (value.startsWith(\"link:\")) {\n\t\t\t\t\t\t\tresponse(\"link:\");\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (value.startsWith(\"file:\")) {\n\t\t\t\t\t\t\tresponse(\"file:\");\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t},\n\t\t};\n\t},\n\n\tmeta: {\n\t\tdocs: {\n\t\t\tcategory: \"Best Practices\",\n\t\t\tdescription:\n\t\t\t\t\"Checks existence of local dependencies in the package.json\",\n\t\t\trecommended: true,\n\t\t},\n\t},\n});\n"],"mappings":"AAAA,OAAO,UAAU;AAEjB,SAAS,kBAAkB;AAE3B,IAAO,iCAAQ,WAAW;AAAA,EACzB,OAAO,SAAS;AACf,WAAO;AAAA,MACN,iBAAiB;AAChB,cAAM,WAAW,KAAK,MAAM,QAAQ,WAAW,IAAI;AAInD,cAAM,EAAE,cAAc,iBAAiB,iBAAiB,IACvD;AAED,cAAM,UAAU;AAAA,UACf,OAAO,QAAQ,gBAAgB,CAAC,CAAC;AAAA,UACjC,OAAO,QAAQ,oBAAoB,CAAC,CAAC;AAAA,UACrC,OAAO,QAAQ,mBAAmB,CAAC,CAAC;AAAA,QACrC;AAEA,gBAAQ,QAAQ,CAAC,QAAQ;AACxB,cAAI,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AAC7B,kBAAM,WAAW,CAAC,cAA+B;AAChD,oBAAM,WAAW,KAAK;AAAA,gBACrB,QAAQ,SAAS,QAAQ,kBAAkB,GAAG;AAAA,gBAC9C,MAAM,QAAQ,IAAI,OAAO,WAAW,GAAG,GAAG,EAAE;AAAA,gBAC5C;AAAA,cACD;AAEA,kBAAI;AACH,oBAAI,CAAC,QAAQ,QAAQ,QAAQ,GAAG;AAC/B,0BAAQ,OAAO;AAAA,oBACd,SAAS,eAAe,GAAG,6CAA6C,KAAK;AAAA,oBAC7E,MAAM,QAAQ,WAAW;AAAA,kBAC1B,CAAC;AAAA,gBACF;AAAA,cACD,QAAQ;AACP,wBAAQ,OAAO;AAAA,kBACd,SAAS,eAAe,GAAG,6CAA6C,KAAK;AAAA,kBAC7E,MAAM,QAAQ,WAAW;AAAA,gBAC1B,CAAC;AAAA,cACF;AAAA,YACD;AAEA,gBAAI,MAAM,WAAW,OAAO,GAAG;AAC9B,uBAAS,OAAO;AAAA,YACjB;AAEA,gBAAI,MAAM,WAAW,OAAO,GAAG;AAC9B,uBAAS,OAAO;AAAA,YACjB;AAAA,UACD,CAAC;AAAA,QACF,CAAC;AAAA,MACF;AAAA,IACD;AAAA,EACD;AAAA,EAEA,MAAM;AAAA,IACL,MAAM;AAAA,MACL,UAAU;AAAA,MACV,aACC;AAAA,MACD,aAAa;AAAA,IACd;AAAA,EACD;AACD,CAAC;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/rules/valid-package-def.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../src/rules/valid-package-def.ts"],"sourcesContent":["import { PJV as PackageValidator } from \"package-json-validator\";\n\nimport { createRule } from \"../createRule.js\";\n\n// package-json-validator does not correctly recognize shorthand for repositories and alternate dependency statements, so we discard those values.\n// it also enforces a stricter code for npm than is really appropriate,\n// so we disable some other errors here.\nconst unusedErrorPatterns = [\n\t/^Url not valid/i,\n\t/^Invalid version range for .+?: file:/i,\n\t/^author field should have name/i,\n];\n\nconst isUsableError = (errorText: string) =>\n\tunusedErrorPatterns.every((pattern) => !pattern.test(errorText));\n\nexport default createRule({\n\tcreate(context) {\n\t\treturn {\n\t\t\t\"Program:exit\"() {\n\t\t\t\tconst validation = PackageValidator.validate(\n\t\t\t\t\tcontext.sourceCode.text,\n\t\t\t\t) as PackageValidator.ValidationSuccessResult;\n\n\t\t\t\tvalidation.errors?.filter(isUsableError).forEach((message) => {\n\t\t\t\t\tif (message) {\n\t\t\t\t\t\tcontext.report({\n\t\t\t\t\t\t\tmessage,\n\t\t\t\t\t\t\tnode: context.sourceCode.ast,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t},\n\t\t};\n\t},\n\n\tmeta: {\n\t\tdocs: {\n\t\t\tcategory: \"Best Practices\",\n\t\t\tdescription:\n\t\t\t\t\"Enforce that package.json has all properties required by the npm spec\",\n\t\t\trecommended: true,\n\t\t},\n\t},\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oCAAwC;AAExC,wBAA2B;AAK3B,MAAM,sBAAsB;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AACD;AAEA,MAAM,gBAAgB,CAAC,cACtB,oBAAoB,MAAM,CAAC,YAAY,CAAC,QAAQ,KAAK,SAAS,CAAC;AAEhE,IAAO,gCAAQ,8BAAW;AAAA,EACzB,OAAO,SAAS;AACf,WAAO;AAAA,MACN,iBAAiB;AAChB,cAAM,aAAa,8BAAAA,IAAiB;AAAA,UACnC,QAAQ,WAAW;AAAA,QACpB;AAEA,mBAAW,QAAQ,OAAO,aAAa,EAAE,QAAQ,CAAC,YAAY;AAC7D,cAAI,SAAS;AACZ,oBAAQ,OAAO;AAAA,cACd;AAAA,cACA,MAAM,QAAQ,WAAW;AAAA,YAC1B,CAAC;AAAA,UACF;AAAA,QACD,CAAC;AAAA,MACF;AAAA,IACD;AAAA,EACD;AAAA,EAEA,MAAM;AAAA,IACL,MAAM;AAAA,MACL,UAAU;AAAA,MACV,aACC;AAAA,MACD,aAAa;AAAA,IACd;AAAA,EACD;AACD,CAAC;","names":["PackageValidator"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/rules/valid-package-def.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../src/rules/valid-package-def.ts"],"sourcesContent":["import { PJV as PackageValidator } from \"package-json-validator\";\n\nimport { createRule } from \"../createRule.js\";\n\n// package-json-validator does not correctly recognize shorthand for repositories and alternate dependency statements, so we discard those values.\n// it also enforces a stricter code for npm than is really appropriate,\n// so we disable some other errors here.\nconst unusedErrorPatterns = [\n\t/^Url not valid/i,\n\t/^Invalid version range for .+?: file:/i,\n\t/^author field should have name/i,\n];\n\nconst isUsableError = (errorText: string) =>\n\tunusedErrorPatterns.every((pattern) => !pattern.test(errorText));\n\nexport default createRule({\n\tcreate(context) {\n\t\treturn {\n\t\t\t\"Program:exit\"() {\n\t\t\t\tconst validation = PackageValidator.validate(\n\t\t\t\t\tcontext.sourceCode.text,\n\t\t\t\t) as PackageValidator.ValidationSuccessResult;\n\n\t\t\t\tvalidation.errors?.filter(isUsableError).forEach((message) => {\n\t\t\t\t\tif (message) {\n\t\t\t\t\t\tcontext.report({\n\t\t\t\t\t\t\tmessage,\n\t\t\t\t\t\t\tnode: context.sourceCode.ast,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t},\n\t\t};\n\t},\n\n\tmeta: {\n\t\tdocs: {\n\t\t\tcategory: \"Best Practices\",\n\t\t\tdescription:\n\t\t\t\t\"Enforce that package.json has all properties required by the npm spec\",\n\t\t\trecommended: true,\n\t\t},\n\t},\n});\n"],"mappings":"AAAA,SAAS,OAAO,wBAAwB;AAExC,SAAS,kBAAkB;AAK3B,MAAM,sBAAsB;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AACD;AAEA,MAAM,gBAAgB,CAAC,cACtB,oBAAoB,MAAM,CAAC,YAAY,CAAC,QAAQ,KAAK,SAAS,CAAC;AAEhE,IAAO,4BAAQ,WAAW;AAAA,EACzB,OAAO,SAAS;AACf,WAAO;AAAA,MACN,iBAAiB;AAChB,cAAM,aAAa,iBAAiB;AAAA,UACnC,QAAQ,WAAW;AAAA,QACpB;AAEA,mBAAW,QAAQ,OAAO,aAAa,EAAE,QAAQ,CAAC,YAAY;AAC7D,cAAI,SAAS;AACZ,oBAAQ,OAAO;AAAA,cACd;AAAA,cACA,MAAM,QAAQ,WAAW;AAAA,YAC1B,CAAC;AAAA,UACF;AAAA,QACD,CAAC;AAAA,MACF;AAAA,IACD;AAAA,EACD;AAAA,EAEA,MAAM;AAAA,IACL,MAAM;AAAA,MACL,UAAU;AAAA,MACV,aACC;AAAA,MACD,aAAa;AAAA,IACd;AAAA,EACD;AACD,CAAC;","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as eslint from 'eslint';
|
|
2
|
+
import * as jsonc_eslint_parser from 'jsonc-eslint-parser';
|
|
3
|
+
import { PackageJsonRuleContext } from '../createRule.mjs';
|
|
4
|
+
import 'estree';
|
|
5
|
+
|
|
6
|
+
declare const _default: {
|
|
7
|
+
create(context: PackageJsonRuleContext<unknown[]>): jsonc_eslint_parser.RuleListener;
|
|
8
|
+
meta: eslint.Rule.RuleMetaData;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { _default as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
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 _default: {
|
|
7
|
+
create(context: PackageJsonRuleContext<unknown[]>): jsonc_eslint_parser.RuleListener;
|
|
8
|
+
meta: eslint.Rule.RuleMetaData;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { _default as default };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var valid_repository_directory_exports = {};
|
|
30
|
+
__export(valid_repository_directory_exports, {
|
|
31
|
+
default: () => valid_repository_directory_default
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(valid_repository_directory_exports);
|
|
34
|
+
var path = __toESM(require("node:path"));
|
|
35
|
+
var import_createRule = require("../createRule.js");
|
|
36
|
+
var import_findPropertyWithKeyValue = require("../utils/findPropertyWithKeyValue.js");
|
|
37
|
+
var valid_repository_directory_default = (0, import_createRule.createRule)({
|
|
38
|
+
create(context) {
|
|
39
|
+
return {
|
|
40
|
+
"Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.value=repository][value.type=JSONObjectExpression]"(node) {
|
|
41
|
+
const directoryProperty = (0, import_findPropertyWithKeyValue.findPropertyWithKeyValue)(
|
|
42
|
+
node.value.properties,
|
|
43
|
+
"directory"
|
|
44
|
+
);
|
|
45
|
+
if (directoryProperty?.value.type !== "JSONLiteral" || typeof directoryProperty.value.value !== "string") {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const directoryValue = directoryProperty.value.value;
|
|
49
|
+
const expected = path.normalize(path.dirname(context.filename));
|
|
50
|
+
if (path.normalize(directoryValue) !== expected) {
|
|
51
|
+
context.report({
|
|
52
|
+
messageId: "mismatched",
|
|
53
|
+
node: directoryProperty.value,
|
|
54
|
+
suggest: [
|
|
55
|
+
{
|
|
56
|
+
fix(fixer) {
|
|
57
|
+
return fixer.replaceText(
|
|
58
|
+
directoryProperty.value,
|
|
59
|
+
`"${expected}"`
|
|
60
|
+
);
|
|
61
|
+
},
|
|
62
|
+
messageId: "replace"
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
meta: {
|
|
71
|
+
docs: {
|
|
72
|
+
category: "Best Practices",
|
|
73
|
+
description: "Enforce that if repository directory is specified, it matches the path to the package.json file",
|
|
74
|
+
recommended: true
|
|
75
|
+
},
|
|
76
|
+
hasSuggestions: true,
|
|
77
|
+
messages: {
|
|
78
|
+
mismatched: "Directory does not match package.json directory.",
|
|
79
|
+
replace: "Replace with '{{ expected }}'."
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
//# sourceMappingURL=valid-repository-directory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/rules/valid-repository-directory.ts"],"sourcesContent":["import type { AST as JsonAST } from \"jsonc-eslint-parser\";\n\nimport * as ESTree from \"estree\";\nimport * as path from \"node:path\";\n\nimport { createRule } from \"../createRule.js\";\nimport { findPropertyWithKeyValue } from \"../utils/findPropertyWithKeyValue.js\";\n\nexport default createRule({\n\tcreate(context) {\n\t\treturn {\n\t\t\t\"Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.value=repository][value.type=JSONObjectExpression]\"(\n\t\t\t\tnode: JsonAST.JSONProperty & {\n\t\t\t\t\tvalue: JsonAST.JSONObjectExpression;\n\t\t\t\t},\n\t\t\t) {\n\t\t\t\tconst directoryProperty = findPropertyWithKeyValue(\n\t\t\t\t\tnode.value.properties,\n\t\t\t\t\t\"directory\",\n\t\t\t\t);\n\t\t\t\tif (\n\t\t\t\t\tdirectoryProperty?.value.type !== \"JSONLiteral\" ||\n\t\t\t\t\ttypeof directoryProperty.value.value !== \"string\"\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst directoryValue = directoryProperty.value.value;\n\t\t\t\tconst expected = path.normalize(path.dirname(context.filename));\n\n\t\t\t\tif (path.normalize(directoryValue) !== expected) {\n\t\t\t\t\tcontext.report({\n\t\t\t\t\t\tmessageId: \"mismatched\",\n\t\t\t\t\t\tnode: directoryProperty.value as unknown as ESTree.Node,\n\t\t\t\t\t\tsuggest: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tfix(fixer) {\n\t\t\t\t\t\t\t\t\treturn fixer.replaceText(\n\t\t\t\t\t\t\t\t\t\tdirectoryProperty.value as unknown as ESTree.Node,\n\t\t\t\t\t\t\t\t\t\t`\"${expected}\"`,\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tmessageId: \"replace\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t},\n\n\tmeta: {\n\t\tdocs: {\n\t\t\tcategory: \"Best Practices\",\n\t\t\tdescription:\n\t\t\t\t\"Enforce that if repository directory is specified, it matches the path to the package.json file\",\n\t\t\trecommended: true,\n\t\t},\n\t\thasSuggestions: true,\n\t\tmessages: {\n\t\t\tmismatched: \"Directory does not match package.json directory.\",\n\t\t\treplace: \"Replace with '{{ expected }}'.\",\n\t\t},\n\t},\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,WAAsB;AAEtB,wBAA2B;AAC3B,sCAAyC;AAEzC,IAAO,yCAAQ,8BAAW;AAAA,EACzB,OAAO,SAAS;AACf,WAAO;AAAA,MACN,iIACC,MAGC;AACD,cAAM,wBAAoB;AAAA,UACzB,KAAK,MAAM;AAAA,UACX;AAAA,QACD;AACA,YACC,mBAAmB,MAAM,SAAS,iBAClC,OAAO,kBAAkB,MAAM,UAAU,UACxC;AACD;AAAA,QACD;AAEA,cAAM,iBAAiB,kBAAkB,MAAM;AAC/C,cAAM,WAAW,KAAK,UAAU,KAAK,QAAQ,QAAQ,QAAQ,CAAC;AAE9D,YAAI,KAAK,UAAU,cAAc,MAAM,UAAU;AAChD,kBAAQ,OAAO;AAAA,YACd,WAAW;AAAA,YACX,MAAM,kBAAkB;AAAA,YACxB,SAAS;AAAA,cACR;AAAA,gBACC,IAAI,OAAO;AACV,yBAAO,MAAM;AAAA,oBACZ,kBAAkB;AAAA,oBAClB,IAAI,QAAQ;AAAA,kBACb;AAAA,gBACD;AAAA,gBACA,WAAW;AAAA,cACZ;AAAA,YACD;AAAA,UACD,CAAC;AAAA,QACF;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAAA,EAEA,MAAM;AAAA,IACL,MAAM;AAAA,MACL,UAAU;AAAA,MACV,aACC;AAAA,MACD,aAAa;AAAA,IACd;AAAA,IACA,gBAAgB;AAAA,IAChB,UAAU;AAAA,MACT,YAAY;AAAA,MACZ,SAAS;AAAA,IACV;AAAA,EACD;AACD,CAAC;","names":[]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
import { createRule } from "../createRule.js";
|
|
3
|
+
import { findPropertyWithKeyValue } from "../utils/findPropertyWithKeyValue.js";
|
|
4
|
+
var valid_repository_directory_default = createRule({
|
|
5
|
+
create(context) {
|
|
6
|
+
return {
|
|
7
|
+
"Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.value=repository][value.type=JSONObjectExpression]"(node) {
|
|
8
|
+
const directoryProperty = findPropertyWithKeyValue(
|
|
9
|
+
node.value.properties,
|
|
10
|
+
"directory"
|
|
11
|
+
);
|
|
12
|
+
if (directoryProperty?.value.type !== "JSONLiteral" || typeof directoryProperty.value.value !== "string") {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const directoryValue = directoryProperty.value.value;
|
|
16
|
+
const expected = path.normalize(path.dirname(context.filename));
|
|
17
|
+
if (path.normalize(directoryValue) !== expected) {
|
|
18
|
+
context.report({
|
|
19
|
+
messageId: "mismatched",
|
|
20
|
+
node: directoryProperty.value,
|
|
21
|
+
suggest: [
|
|
22
|
+
{
|
|
23
|
+
fix(fixer) {
|
|
24
|
+
return fixer.replaceText(
|
|
25
|
+
directoryProperty.value,
|
|
26
|
+
`"${expected}"`
|
|
27
|
+
);
|
|
28
|
+
},
|
|
29
|
+
messageId: "replace"
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
meta: {
|
|
38
|
+
docs: {
|
|
39
|
+
category: "Best Practices",
|
|
40
|
+
description: "Enforce that if repository directory is specified, it matches the path to the package.json file",
|
|
41
|
+
recommended: true
|
|
42
|
+
},
|
|
43
|
+
hasSuggestions: true,
|
|
44
|
+
messages: {
|
|
45
|
+
mismatched: "Directory does not match package.json directory.",
|
|
46
|
+
replace: "Replace with '{{ expected }}'."
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
export {
|
|
51
|
+
valid_repository_directory_default as default
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=valid-repository-directory.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/rules/valid-repository-directory.ts"],"sourcesContent":["import type { AST as JsonAST } from \"jsonc-eslint-parser\";\n\nimport * as ESTree from \"estree\";\nimport * as path from \"node:path\";\n\nimport { createRule } from \"../createRule.js\";\nimport { findPropertyWithKeyValue } from \"../utils/findPropertyWithKeyValue.js\";\n\nexport default createRule({\n\tcreate(context) {\n\t\treturn {\n\t\t\t\"Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.value=repository][value.type=JSONObjectExpression]\"(\n\t\t\t\tnode: JsonAST.JSONProperty & {\n\t\t\t\t\tvalue: JsonAST.JSONObjectExpression;\n\t\t\t\t},\n\t\t\t) {\n\t\t\t\tconst directoryProperty = findPropertyWithKeyValue(\n\t\t\t\t\tnode.value.properties,\n\t\t\t\t\t\"directory\",\n\t\t\t\t);\n\t\t\t\tif (\n\t\t\t\t\tdirectoryProperty?.value.type !== \"JSONLiteral\" ||\n\t\t\t\t\ttypeof directoryProperty.value.value !== \"string\"\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst directoryValue = directoryProperty.value.value;\n\t\t\t\tconst expected = path.normalize(path.dirname(context.filename));\n\n\t\t\t\tif (path.normalize(directoryValue) !== expected) {\n\t\t\t\t\tcontext.report({\n\t\t\t\t\t\tmessageId: \"mismatched\",\n\t\t\t\t\t\tnode: directoryProperty.value as unknown as ESTree.Node,\n\t\t\t\t\t\tsuggest: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tfix(fixer) {\n\t\t\t\t\t\t\t\t\treturn fixer.replaceText(\n\t\t\t\t\t\t\t\t\t\tdirectoryProperty.value as unknown as ESTree.Node,\n\t\t\t\t\t\t\t\t\t\t`\"${expected}\"`,\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tmessageId: \"replace\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t},\n\n\tmeta: {\n\t\tdocs: {\n\t\t\tcategory: \"Best Practices\",\n\t\t\tdescription:\n\t\t\t\t\"Enforce that if repository directory is specified, it matches the path to the package.json file\",\n\t\t\trecommended: true,\n\t\t},\n\t\thasSuggestions: true,\n\t\tmessages: {\n\t\t\tmismatched: \"Directory does not match package.json directory.\",\n\t\t\treplace: \"Replace with '{{ expected }}'.\",\n\t\t},\n\t},\n});\n"],"mappings":"AAGA,YAAY,UAAU;AAEtB,SAAS,kBAAkB;AAC3B,SAAS,gCAAgC;AAEzC,IAAO,qCAAQ,WAAW;AAAA,EACzB,OAAO,SAAS;AACf,WAAO;AAAA,MACN,iIACC,MAGC;AACD,cAAM,oBAAoB;AAAA,UACzB,KAAK,MAAM;AAAA,UACX;AAAA,QACD;AACA,YACC,mBAAmB,MAAM,SAAS,iBAClC,OAAO,kBAAkB,MAAM,UAAU,UACxC;AACD;AAAA,QACD;AAEA,cAAM,iBAAiB,kBAAkB,MAAM;AAC/C,cAAM,WAAW,KAAK,UAAU,KAAK,QAAQ,QAAQ,QAAQ,CAAC;AAE9D,YAAI,KAAK,UAAU,cAAc,MAAM,UAAU;AAChD,kBAAQ,OAAO;AAAA,YACd,WAAW;AAAA,YACX,MAAM,kBAAkB;AAAA,YACxB,SAAS;AAAA,cACR;AAAA,gBACC,IAAI,OAAO;AACV,yBAAO,MAAM;AAAA,oBACZ,kBAAkB;AAAA,oBAClB,IAAI,QAAQ;AAAA,kBACb;AAAA,gBACD;AAAA,gBACA,WAAW;AAAA,cACZ;AAAA,YACD;AAAA,UACD,CAAC;AAAA,QACF;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAAA,EAEA,MAAM;AAAA,IACL,MAAM;AAAA,MACL,UAAU;AAAA,MACV,aACC;AAAA,MACD,aAAa;AAAA,IACd;AAAA,IACA,gBAAgB;AAAA,IAChB,UAAU;AAAA,MACT,YAAY;AAAA,MACZ,SAAS;AAAA,IACV;AAAA,EACD;AACD,CAAC;","names":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AST } from 'jsonc-eslint-parser';
|
|
2
|
+
|
|
3
|
+
type JSONPropertyWithKeyAndValue<Value extends string> = AST.JSONProperty & {
|
|
4
|
+
key: AST.JSONStringLiteral;
|
|
5
|
+
value: Value;
|
|
6
|
+
};
|
|
7
|
+
declare function findPropertyWithKeyValue<Value extends string>(properties: AST.JSONProperty[], value: Value): JSONPropertyWithKeyAndValue<Value> | undefined;
|
|
8
|
+
|
|
9
|
+
export { type JSONPropertyWithKeyAndValue, findPropertyWithKeyValue };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AST } from 'jsonc-eslint-parser';
|
|
2
|
+
|
|
3
|
+
type JSONPropertyWithKeyAndValue<Value extends string> = AST.JSONProperty & {
|
|
4
|
+
key: AST.JSONStringLiteral;
|
|
5
|
+
value: Value;
|
|
6
|
+
};
|
|
7
|
+
declare function findPropertyWithKeyValue<Value extends string>(properties: AST.JSONProperty[], value: Value): JSONPropertyWithKeyAndValue<Value> | undefined;
|
|
8
|
+
|
|
9
|
+
export { type JSONPropertyWithKeyAndValue, findPropertyWithKeyValue };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var findPropertyWithKeyValue_exports = {};
|
|
20
|
+
__export(findPropertyWithKeyValue_exports, {
|
|
21
|
+
findPropertyWithKeyValue: () => findPropertyWithKeyValue
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(findPropertyWithKeyValue_exports);
|
|
24
|
+
function findPropertyWithKeyValue(properties, value) {
|
|
25
|
+
return properties.find(
|
|
26
|
+
(property) => property.key.type === "JSONLiteral" && property.key.value === value
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
findPropertyWithKeyValue
|
|
32
|
+
});
|
|
33
|
+
//# sourceMappingURL=findPropertyWithKeyValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/findPropertyWithKeyValue.ts"],"sourcesContent":["import type { AST as JsonAST } from \"jsonc-eslint-parser\";\n\nexport type JSONPropertyWithKeyAndValue<Value extends string> =\n\tJsonAST.JSONProperty & {\n\t\tkey: JsonAST.JSONStringLiteral;\n\t\tvalue: Value;\n\t};\n\nexport function findPropertyWithKeyValue<Value extends string>(\n\tproperties: JsonAST.JSONProperty[],\n\tvalue: Value,\n) {\n\treturn properties.find(\n\t\t(property): property is JSONPropertyWithKeyAndValue<Value> =>\n\t\t\tproperty.key.type === \"JSONLiteral\" && property.key.value === value,\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQO,SAAS,yBACf,YACA,OACC;AACD,SAAO,WAAW;AAAA,IACjB,CAAC,aACA,SAAS,IAAI,SAAS,iBAAiB,SAAS,IAAI,UAAU;AAAA,EAChE;AACD;","names":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
function findPropertyWithKeyValue(properties, value) {
|
|
2
|
+
return properties.find(
|
|
3
|
+
(property) => property.key.type === "JSONLiteral" && property.key.value === value
|
|
4
|
+
);
|
|
5
|
+
}
|
|
6
|
+
export {
|
|
7
|
+
findPropertyWithKeyValue
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=findPropertyWithKeyValue.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/findPropertyWithKeyValue.ts"],"sourcesContent":["import type { AST as JsonAST } from \"jsonc-eslint-parser\";\n\nexport type JSONPropertyWithKeyAndValue<Value extends string> =\n\tJsonAST.JSONProperty & {\n\t\tkey: JsonAST.JSONStringLiteral;\n\t\tvalue: Value;\n\t};\n\nexport function findPropertyWithKeyValue<Value extends string>(\n\tproperties: JsonAST.JSONProperty[],\n\tvalue: Value,\n) {\n\treturn properties.find(\n\t\t(property): property is JSONPropertyWithKeyAndValue<Value> =>\n\t\t\tproperty.key.type === \"JSONLiteral\" && property.key.value === value,\n\t);\n}\n"],"mappings":"AAQO,SAAS,yBACf,YACA,OACC;AACD,SAAO,WAAW;AAAA,IACjB,CAAC,aACA,SAAS,IAAI,SAAS,iBAAiB,SAAS,IAAI,UAAU;AAAA,EAChE;AACD;","names":[]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AST } from 'jsonc-eslint-parser';
|
|
2
|
+
|
|
3
|
+
declare function isNotNullish<T extends NonNullable<unknown>>(value: T | null | undefined): value is T;
|
|
4
|
+
declare function isJSONStringLiteral(node: AST.JSONNode): node is AST.JSONStringLiteral;
|
|
5
|
+
|
|
6
|
+
export { isJSONStringLiteral, isNotNullish };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AST } from 'jsonc-eslint-parser';
|
|
2
|
+
|
|
3
|
+
declare function isNotNullish<T extends NonNullable<unknown>>(value: T | null | undefined): value is T;
|
|
4
|
+
declare function isJSONStringLiteral(node: AST.JSONNode): node is AST.JSONStringLiteral;
|
|
5
|
+
|
|
6
|
+
export { isJSONStringLiteral, isNotNullish };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var predicates_exports = {};
|
|
20
|
+
__export(predicates_exports, {
|
|
21
|
+
isJSONStringLiteral: () => isJSONStringLiteral,
|
|
22
|
+
isNotNullish: () => isNotNullish
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(predicates_exports);
|
|
25
|
+
function isNotNullish(value) {
|
|
26
|
+
return value !== null && value !== void 0;
|
|
27
|
+
}
|
|
28
|
+
function isJSONStringLiteral(node) {
|
|
29
|
+
return node.type === "JSONLiteral" && typeof node.value === "string";
|
|
30
|
+
}
|
|
31
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
+
0 && (module.exports = {
|
|
33
|
+
isJSONStringLiteral,
|
|
34
|
+
isNotNullish
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=predicates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/predicates.ts"],"sourcesContent":["import type { AST as JsonAST } from \"jsonc-eslint-parser\";\n\nexport function isNotNullish<T extends NonNullable<unknown>>(\n\tvalue: T | null | undefined,\n): value is T {\n\treturn value !== null && value !== undefined;\n}\n\nexport function isJSONStringLiteral(\n\tnode: JsonAST.JSONNode,\n): node is JsonAST.JSONStringLiteral {\n\treturn node.type === \"JSONLiteral\" && typeof node.value === \"string\";\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,SAAS,aACf,OACa;AACb,SAAO,UAAU,QAAQ,UAAU;AACpC;AAEO,SAAS,oBACf,MACoC;AACpC,SAAO,KAAK,SAAS,iBAAiB,OAAO,KAAK,UAAU;AAC7D;","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
function isNotNullish(value) {
|
|
2
|
+
return value !== null && value !== void 0;
|
|
3
|
+
}
|
|
4
|
+
function isJSONStringLiteral(node) {
|
|
5
|
+
return node.type === "JSONLiteral" && typeof node.value === "string";
|
|
6
|
+
}
|
|
7
|
+
export {
|
|
8
|
+
isJSONStringLiteral,
|
|
9
|
+
isNotNullish
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=predicates.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/predicates.ts"],"sourcesContent":["import type { AST as JsonAST } from \"jsonc-eslint-parser\";\n\nexport function isNotNullish<T extends NonNullable<unknown>>(\n\tvalue: T | null | undefined,\n): value is T {\n\treturn value !== null && value !== undefined;\n}\n\nexport function isJSONStringLiteral(\n\tnode: JsonAST.JSONNode,\n): node is JsonAST.JSONStringLiteral {\n\treturn node.type === \"JSONLiteral\" && typeof node.value === \"string\";\n}\n"],"mappings":"AAEO,SAAS,aACf,OACa;AACb,SAAO,UAAU,QAAQ,UAAU;AACpC;AAEO,SAAS,oBACf,MACoC;AACpC,SAAO,KAAK,SAAS,iBAAiB,OAAO,KAAK,UAAU;AAC7D;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-package-json",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.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": {
|