eslint-plugin-package-json 0.3.2 → 0.4.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 +77 -26
- package/lib/createRule.d.mts +33 -0
- package/lib/createRule.d.ts +18 -15
- package/lib/createRule.js +37 -13
- package/lib/createRule.js.map +1 -0
- package/lib/createRule.mjs +16 -0
- package/lib/createRule.mjs.map +1 -0
- package/lib/index.d.mts +34 -0
- package/lib/index.d.ts +24 -31
- package/lib/index.js +53 -17
- package/lib/index.js.map +1 -0
- package/lib/index.mjs +22 -0
- package/lib/index.mjs.map +1 -0
- package/lib/rules/order-properties.d.mts +15 -0
- package/lib/rules/order-properties.d.ts +13 -4
- package/lib/rules/order-properties.js +124 -104
- package/lib/rules/order-properties.js.map +1 -0
- package/lib/rules/order-properties.mjs +100 -0
- package/lib/rules/order-properties.mjs.map +1 -0
- package/lib/rules/sort-collections.d.mts +12 -0
- package/lib/rules/sort-collections.d.ts +10 -4
- package/lib/rules/sort-collections.js +90 -61
- package/lib/rules/sort-collections.js.map +1 -0
- package/lib/rules/sort-collections.mjs +75 -0
- package/lib/rules/sort-collections.mjs.map +1 -0
- package/lib/rules/valid-local-dependency.d.mts +11 -0
- package/lib/rules/valid-local-dependency.d.ts +9 -4
- package/lib/rules/valid-local-dependency.js +83 -52
- package/lib/rules/valid-local-dependency.js.map +1 -0
- package/lib/rules/valid-local-dependency.mjs +58 -0
- package/lib/rules/valid-local-dependency.mjs.map +1 -0
- package/lib/rules/valid-package-def.d.mts +11 -0
- package/lib/rules/valid-package-def.d.ts +9 -4
- package/lib/rules/valid-package-def.js +54 -30
- package/lib/rules/valid-package-def.js.map +1 -0
- package/lib/rules/valid-package-def.mjs +38 -0
- package/lib/rules/valid-package-def.mjs.map +1 -0
- package/lib/tests/rules/ruleTester.d.mts +14 -0
- package/lib/tests/rules/ruleTester.d.ts +9 -5
- package/lib/tests/rules/ruleTester.js +40 -5
- package/lib/tests/rules/ruleTester.js.map +1 -0
- package/lib/tests/rules/ruleTester.mjs +8 -0
- package/lib/tests/rules/ruleTester.mjs.map +1 -0
- package/package.json +110 -52
- package/.editorconfig +0 -13
- package/.eslintrc +0 -11
- package/.github/actions/prepare/action.yml +0 -12
- package/.github/workflows/format.yml +0 -15
- package/.github/workflows/lint-eslint-docs.yml +0 -16
- package/.github/workflows/lint.yml +0 -15
- package/.github/workflows/test.yml +0 -15
- package/.github/workflows/tsc.yml +0 -15
- package/.vscode/extensions.json +0 -3
- package/.vscode/launch.json +0 -16
- package/.vscode/settings.json +0 -4
- package/docs/rules/order-properties.md +0 -95
- package/docs/rules/sort-collections.md +0 -87
- package/docs/rules/valid-local-dependency.md +0 -23
- package/docs/rules/valid-package-def.md +0 -55
- package/lib/createRule.d.ts.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/rules/order-properties.d.ts.map +0 -1
- package/lib/rules/sort-collections.d.ts.map +0 -1
- package/lib/rules/valid-local-dependency.d.ts.map +0 -1
- package/lib/rules/valid-package-def.d.ts.map +0 -1
- package/lib/tests/rules/order-properties.test.d.ts +0 -2
- package/lib/tests/rules/order-properties.test.d.ts.map +0 -1
- package/lib/tests/rules/order-properties.test.js +0 -223
- package/lib/tests/rules/ruleTester.d.ts.map +0 -1
- package/lib/tests/rules/sort-collections.test.d.ts +0 -2
- package/lib/tests/rules/sort-collections.test.d.ts.map +0 -1
- package/lib/tests/rules/sort-collections.test.js +0 -64
- package/lib/tests/rules/valid-local-dependency.test.d.ts +0 -2
- package/lib/tests/rules/valid-local-dependency.test.d.ts.map +0 -1
- package/lib/tests/rules/valid-local-dependency.test.js +0 -232
- package/lib/tests/rules/valid-package-def.test.d.ts +0 -2
- package/lib/tests/rules/valid-package-def.test.d.ts.map +0 -1
- package/lib/tests/rules/valid-package-def.test.js +0 -65
- package/prettier.config.js +0 -7
- package/src/createRule.ts +0 -49
- package/src/index.ts +0 -17
- package/src/rules/order-properties.ts +0 -122
- package/src/rules/sort-collections.ts +0 -96
- package/src/rules/valid-local-dependency.ts +0 -73
- package/src/rules/valid-package-def.ts +0 -45
- package/src/tests/__fixtures__/invalid-top-level-property-order/package.json +0 -13
- package/src/tests/__fixtures__/unalphabetized-collections/package.json +0 -16
- package/src/tests/__fixtures__/valid-local-dependency/gotcha/package.json/gotcha/package.json +0 -16
- package/src/tests/__fixtures__/valid-local-dependency/package.json +0 -16
- package/src/tests/globalSetup.js +0 -7
- package/src/tests/rules/order-properties.test.ts +0 -223
- package/src/tests/rules/ruleTester.ts +0 -17
- package/src/tests/rules/sort-collections.test.ts +0 -62
- package/src/tests/rules/valid-local-dependency.test.ts +0 -244
- package/src/tests/rules/valid-package-def.test.ts +0 -65
- package/tsconfig.json +0 -13
- package/vitest.config.ts +0 -15
package/README.md
CHANGED
|
@@ -1,17 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Rules for
|
|
4
|
-
|
|
5
|
-
>
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
<h1 align="center">eslint-plugin-package-json</h1>
|
|
2
|
+
|
|
3
|
+
<p align="center">Rules for consistent, readable, and valid package.json files. 🗂️</p>
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a href="#contributors" target="_blank">
|
|
7
|
+
<!-- prettier-ignore-start -->
|
|
8
|
+
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
9
|
+
<img alt="All Contributors: 8 👪" src="https://img.shields.io/badge/all_contributors-8_👪-21bb42.svg" />
|
|
10
|
+
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
11
|
+
<!-- prettier-ignore-end -->
|
|
12
|
+
</a>
|
|
13
|
+
<a href="https://codecov.io/gh/JoshuaKGoldberg/eslint-plugin-package-json" target="_blank">
|
|
14
|
+
<img alt="Codecov Test Coverage" src="https://codecov.io/gh/JoshuaKGoldberg/eslint-plugin-package-json/branch/main/graph/badge.svg"/>
|
|
15
|
+
</a>
|
|
16
|
+
<a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/blob/main/.github/CODE_OF_CONDUCT.md" target="_blank">
|
|
17
|
+
<img alt="Contributor Covenant" src="https://img.shields.io/badge/code_of_conduct-enforced-21bb42" />
|
|
18
|
+
</a>
|
|
19
|
+
<a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/blob/main/LICENSE.md" target="_blank">
|
|
20
|
+
<img alt="License: MIT" src="https://img.shields.io/github/license/JoshuaKGoldberg/eslint-plugin-package-json?color=21bb42">
|
|
21
|
+
</a>
|
|
22
|
+
<img alt="Style: Prettier" src="https://img.shields.io/badge/style-prettier-21bb42.svg" />
|
|
23
|
+
<img alt="TypeScript: Strict" src="https://img.shields.io/badge/typescript-strict-21bb42.svg" />
|
|
24
|
+
<img alt="npm package version" src="https://img.shields.io/npm/v/eslint-plugin-package-json?color=21bb42" />
|
|
25
|
+
</p>
|
|
8
26
|
|
|
9
27
|
## Installation
|
|
10
28
|
|
|
11
29
|
You'll first need to install [ESLint](http://eslint.org) >=8 and `eslint-plugin-package-json`:
|
|
12
30
|
|
|
13
31
|
```shell
|
|
14
|
-
|
|
32
|
+
npm install eslint eslint-plugin-package-json jsonc-eslint-parser --save-dev
|
|
15
33
|
```
|
|
16
34
|
|
|
17
35
|
**Note:** If you installed ESLint globally (using the `-g` flag) then you must also install `eslint-plugin-package-json` globally.
|
|
@@ -22,14 +40,14 @@ Add an override to your ESLint configuration file that specifies this plugin, [`
|
|
|
22
40
|
|
|
23
41
|
```js
|
|
24
42
|
module.exports = {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
43
|
+
overrides: [
|
|
44
|
+
{
|
|
45
|
+
extends: ["plugin:package-json/recommended"],
|
|
46
|
+
files: ["package.json"],
|
|
47
|
+
parser: "jsonc-eslint-parser",
|
|
48
|
+
plugins: ["package-json"],
|
|
49
|
+
},
|
|
50
|
+
],
|
|
33
51
|
};
|
|
34
52
|
```
|
|
35
53
|
|
|
@@ -37,21 +55,22 @@ Or, individually configure the rules you want to use under the rules section.
|
|
|
37
55
|
|
|
38
56
|
```js
|
|
39
57
|
module.exports = {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
58
|
+
overrides: [
|
|
59
|
+
{
|
|
60
|
+
files: ["package.json"],
|
|
61
|
+
parser: "jsonc-eslint-parser",
|
|
62
|
+
plugins: ["package-json"],
|
|
63
|
+
rules: {
|
|
64
|
+
"package-json/valid-package-def": "error",
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
],
|
|
50
68
|
};
|
|
51
69
|
```
|
|
52
70
|
|
|
53
71
|
## Supported Rules
|
|
54
72
|
|
|
73
|
+
<!-- prettier-ignore-start -->
|
|
55
74
|
<!-- begin auto-generated rules list -->
|
|
56
75
|
|
|
57
76
|
🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).
|
|
@@ -64,9 +83,41 @@ module.exports = {
|
|
|
64
83
|
| [valid-package-def](docs/rules/valid-package-def.md) | Enforce that package.json has all properties required by NPM spec | |
|
|
65
84
|
|
|
66
85
|
<!-- end auto-generated rules list -->
|
|
86
|
+
<!-- prettier-ignore-end -->
|
|
67
87
|
|
|
68
88
|
These rules only run on `package.json` files; they will ignore all other files being linted. They lint `package.json` files at project root, and in any subfolder of the project, making this plugin great for monorepos.
|
|
69
89
|
|
|
90
|
+
## Contributors
|
|
91
|
+
|
|
92
|
+
<!-- spellchecker: disable -->
|
|
93
|
+
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
|
94
|
+
<!-- prettier-ignore-start -->
|
|
95
|
+
<!-- markdownlint-disable -->
|
|
96
|
+
<table>
|
|
97
|
+
<tbody>
|
|
98
|
+
<tr>
|
|
99
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Zamiell"><img src="https://avatars.githubusercontent.com/u/5511220?v=4?s=100" width="100px;" alt="James"/><br /><sub><b>James</b></sub></a><br /><a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commits?author=Zamiell" title="Code">💻</a></td>
|
|
100
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/zetlen"><img src="https://avatars.githubusercontent.com/u/1643758?v=4?s=100" width="100px;" alt="James Zetlen"/><br /><sub><b>James Zetlen</b></sub></a><br /><a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commits?author=zetlen" title="Code">💻</a> <a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues?q=author%3Azetlen" title="Bug reports">🐛</a> <a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commits?author=zetlen" title="Documentation">📖</a> <a href="#infra-zetlen" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#maintenance-zetlen" title="Maintenance">🚧</a> <a href="#tool-zetlen" title="Tools">🔧</a></td>
|
|
101
|
+
<td align="center" valign="top" width="14.28%"><a href="https://piranna.github.io/"><img src="https://avatars.githubusercontent.com/u/532414?v=4?s=100" width="100px;" alt="Jesús Leganés-Combarro"/><br /><sub><b>Jesús Leganés-Combarro</b></sub></a><br /><a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commits?author=piranna" title="Code">💻</a></td>
|
|
102
|
+
<td align="center" valign="top" width="14.28%"><a href="http://www.joshuakgoldberg.com/"><img src="https://avatars.githubusercontent.com/u/3335181?v=4?s=100" width="100px;" alt="Josh Goldberg ✨"/><br /><sub><b>Josh Goldberg ✨</b></sub></a><br /><a href="#tool-JoshuaKGoldberg" title="Tools">🔧</a> <a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues?q=author%3AJoshuaKGoldberg" title="Bug reports">🐛</a> <a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commits?author=JoshuaKGoldberg" title="Code">💻</a> <a href="#infra-JoshuaKGoldberg" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commits?author=JoshuaKGoldberg" title="Documentation">📖</a> <a href="#maintenance-JoshuaKGoldberg" title="Maintenance">🚧</a></td>
|
|
103
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/kendallgassner"><img src="https://avatars.githubusercontent.com/u/15275462?v=4?s=100" width="100px;" alt="Kendall Gassner"/><br /><sub><b>Kendall Gassner</b></sub></a><br /><a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commits?author=kendallgassner" title="Code">💻</a> <a href="#maintenance-kendallgassner" title="Maintenance">🚧</a></td>
|
|
104
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/nschonni"><img src="https://avatars.githubusercontent.com/u/1297909?v=4?s=100" width="100px;" alt="Nick Schonning"/><br /><sub><b>Nick Schonning</b></sub></a><br /><a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commits?author=nschonni" title="Code">💻</a></td>
|
|
105
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/sirugh"><img src="https://avatars.githubusercontent.com/u/1278869?v=4?s=100" width="100px;" alt="Stephen"/><br /><sub><b>Stephen</b></sub></a><br /><a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commits?author=sirugh" title="Code">💻</a></td>
|
|
106
|
+
</tr>
|
|
107
|
+
<tr>
|
|
108
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/b3rnhard"><img src="https://avatars.githubusercontent.com/u/10774404?v=4?s=100" width="100px;" alt="b3rnhard"/><br /><sub><b>b3rnhard</b></sub></a><br /><a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues?q=author%3Ab3rnhard" title="Bug reports">🐛</a></td>
|
|
109
|
+
</tr>
|
|
110
|
+
</tbody>
|
|
111
|
+
</table>
|
|
112
|
+
|
|
113
|
+
<!-- markdownlint-restore -->
|
|
114
|
+
<!-- prettier-ignore-end -->
|
|
115
|
+
|
|
116
|
+
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
|
117
|
+
<!-- spellchecker: enable -->
|
|
118
|
+
|
|
70
119
|
## Appreciation
|
|
71
120
|
|
|
72
121
|
Many thanks to [@zetlen](https://github.com/zetlen) for creating the initial version and core infrastructure of this package! 💖
|
|
122
|
+
|
|
123
|
+
> 💙 This package was templated with [create-typescript-app](https://github.com/JoshuaKGoldberg/create-typescript-app).
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as ESTree from 'estree';
|
|
2
|
+
import { AST as AST$1, SourceCode, Rule } from 'eslint';
|
|
3
|
+
import { AST, RuleListener } from 'jsonc-eslint-parser';
|
|
4
|
+
|
|
5
|
+
type JsonAstBodyProperty = AST.JSONProperty & {
|
|
6
|
+
value: string;
|
|
7
|
+
};
|
|
8
|
+
type JsonAstBodyExpression = ESTree.Expression & {
|
|
9
|
+
properties: JsonAstBodyProperty[];
|
|
10
|
+
};
|
|
11
|
+
interface JsonAstBodyStatement extends ESTree.ExpressionStatement {
|
|
12
|
+
expression: JsonAstBodyExpression;
|
|
13
|
+
}
|
|
14
|
+
interface PackageJsonAst extends AST$1.Program {
|
|
15
|
+
body: [JsonAstBodyStatement];
|
|
16
|
+
}
|
|
17
|
+
interface PackageJsonSourceCode extends SourceCode {
|
|
18
|
+
ast: PackageJsonAst;
|
|
19
|
+
}
|
|
20
|
+
interface PackageJsonRuleContext<Options extends unknown[] = unknown[]> extends Rule.RuleContext {
|
|
21
|
+
options: Options;
|
|
22
|
+
sourceCode: PackageJsonSourceCode;
|
|
23
|
+
}
|
|
24
|
+
interface PackageJsonRuleModule<Options extends unknown[] = unknown[]> {
|
|
25
|
+
create(context: PackageJsonRuleContext<Options>): RuleListener;
|
|
26
|
+
meta: Rule.RuleMetaData;
|
|
27
|
+
}
|
|
28
|
+
declare function createRule<Options extends unknown[]>(rule: PackageJsonRuleModule<Options>): {
|
|
29
|
+
create(context: PackageJsonRuleContext<Options>): RuleListener;
|
|
30
|
+
meta: Rule.RuleMetaData;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export { type JsonAstBodyExpression, type JsonAstBodyProperty, type JsonAstBodyStatement, type PackageJsonAst, type PackageJsonRuleContext, type PackageJsonRuleModule, type PackageJsonSourceCode, createRule };
|
package/lib/createRule.d.ts
CHANGED
|
@@ -1,30 +1,33 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { AST as
|
|
3
|
-
import
|
|
4
|
-
|
|
1
|
+
import * as ESTree from 'estree';
|
|
2
|
+
import { AST as AST$1, SourceCode, Rule } from 'eslint';
|
|
3
|
+
import { AST, RuleListener } from 'jsonc-eslint-parser';
|
|
4
|
+
|
|
5
|
+
type JsonAstBodyProperty = AST.JSONProperty & {
|
|
5
6
|
value: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
7
|
+
};
|
|
8
|
+
type JsonAstBodyExpression = ESTree.Expression & {
|
|
8
9
|
properties: JsonAstBodyProperty[];
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
+
interface JsonAstBodyStatement extends ESTree.ExpressionStatement {
|
|
11
12
|
expression: JsonAstBodyExpression;
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
+
interface PackageJsonAst extends AST$1.Program {
|
|
14
15
|
body: [JsonAstBodyStatement];
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
+
interface PackageJsonSourceCode extends SourceCode {
|
|
17
18
|
ast: PackageJsonAst;
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
+
interface PackageJsonRuleContext<Options extends unknown[] = unknown[]> extends Rule.RuleContext {
|
|
21
|
+
options: Options;
|
|
20
22
|
sourceCode: PackageJsonSourceCode;
|
|
21
23
|
}
|
|
22
|
-
|
|
24
|
+
interface PackageJsonRuleModule<Options extends unknown[] = unknown[]> {
|
|
25
|
+
create(context: PackageJsonRuleContext<Options>): RuleListener;
|
|
23
26
|
meta: Rule.RuleMetaData;
|
|
24
|
-
create(context: PackageJsonRuleContext): RuleListener;
|
|
25
27
|
}
|
|
26
|
-
|
|
27
|
-
create(context: PackageJsonRuleContext): RuleListener;
|
|
28
|
+
declare function createRule<Options extends unknown[]>(rule: PackageJsonRuleModule<Options>): {
|
|
29
|
+
create(context: PackageJsonRuleContext<Options>): RuleListener;
|
|
28
30
|
meta: Rule.RuleMetaData;
|
|
29
31
|
};
|
|
30
|
-
|
|
32
|
+
|
|
33
|
+
export { type JsonAstBodyExpression, type JsonAstBodyProperty, type JsonAstBodyStatement, type PackageJsonAst, type PackageJsonRuleContext, type PackageJsonRuleModule, type PackageJsonSourceCode, createRule };
|
package/lib/createRule.js
CHANGED
|
@@ -1,16 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
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 createRule_exports = {};
|
|
20
|
+
__export(createRule_exports, {
|
|
21
|
+
createRule: () => createRule
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(createRule_exports);
|
|
24
|
+
const isPackageJson = (filePath) => filePath.endsWith("/package.json") || filePath === "package.json";
|
|
5
25
|
function createRule(rule) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
26
|
+
return {
|
|
27
|
+
...rule,
|
|
28
|
+
create(context) {
|
|
29
|
+
if (!isPackageJson(context.filename)) {
|
|
30
|
+
return {};
|
|
31
|
+
}
|
|
32
|
+
return rule.create(context);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
15
35
|
}
|
|
16
|
-
|
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
+
0 && (module.exports = {
|
|
38
|
+
createRule
|
|
39
|
+
});
|
|
40
|
+
//# sourceMappingURL=createRule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/createRule.ts"],"sourcesContent":["import type * as ESTree from \"estree\";\n\nimport { AST, Rule, SourceCode } from \"eslint\";\nimport { AST as JsonAST, RuleListener } from \"jsonc-eslint-parser\";\n\nconst isPackageJson = (filePath: string) =>\n\tfilePath.endsWith(\"/package.json\") || filePath === \"package.json\";\n\nexport type JsonAstBodyProperty = JsonAST.JSONProperty & {\n\tvalue: string;\n};\n\nexport type JsonAstBodyExpression = ESTree.Expression & {\n\tproperties: JsonAstBodyProperty[];\n};\n\nexport interface JsonAstBodyStatement extends ESTree.ExpressionStatement {\n\texpression: JsonAstBodyExpression;\n}\n\nexport interface PackageJsonAst extends AST.Program {\n\tbody: [JsonAstBodyStatement];\n}\n\nexport interface PackageJsonSourceCode extends SourceCode {\n\tast: PackageJsonAst;\n}\n\nexport interface PackageJsonRuleContext<Options extends unknown[] = unknown[]>\n\textends Rule.RuleContext {\n\toptions: Options;\n\tsourceCode: PackageJsonSourceCode;\n}\n\nexport interface PackageJsonRuleModule<Options extends unknown[] = unknown[]> {\n\tcreate(context: PackageJsonRuleContext<Options>): RuleListener;\n\tmeta: Rule.RuleMetaData;\n}\n\nexport function createRule<Options extends unknown[]>(\n\trule: PackageJsonRuleModule<Options>,\n) {\n\treturn {\n\t\t...rule,\n\t\tcreate(context: PackageJsonRuleContext<Options>) {\n\t\t\tif (!isPackageJson(context.filename)) {\n\t\t\t\treturn {};\n\t\t\t}\n\n\t\t\treturn rule.create(context);\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,MAAM,gBAAgB,CAAC,aACtB,SAAS,SAAS,eAAe,KAAK,aAAa;AAiC7C,SAAS,WACf,MACC;AACD,SAAO;AAAA,IACN,GAAG;AAAA,IACH,OAAO,SAA0C;AAChD,UAAI,CAAC,cAAc,QAAQ,QAAQ,GAAG;AACrC,eAAO,CAAC;AAAA,MACT;AAEA,aAAO,KAAK,OAAO,OAAO;AAAA,IAC3B;AAAA,EACD;AACD;","names":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const isPackageJson = (filePath) => filePath.endsWith("/package.json") || filePath === "package.json";
|
|
2
|
+
function createRule(rule) {
|
|
3
|
+
return {
|
|
4
|
+
...rule,
|
|
5
|
+
create(context) {
|
|
6
|
+
if (!isPackageJson(context.filename)) {
|
|
7
|
+
return {};
|
|
8
|
+
}
|
|
9
|
+
return rule.create(context);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
createRule
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=createRule.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/createRule.ts"],"sourcesContent":["import type * as ESTree from \"estree\";\n\nimport { AST, Rule, SourceCode } from \"eslint\";\nimport { AST as JsonAST, RuleListener } from \"jsonc-eslint-parser\";\n\nconst isPackageJson = (filePath: string) =>\n\tfilePath.endsWith(\"/package.json\") || filePath === \"package.json\";\n\nexport type JsonAstBodyProperty = JsonAST.JSONProperty & {\n\tvalue: string;\n};\n\nexport type JsonAstBodyExpression = ESTree.Expression & {\n\tproperties: JsonAstBodyProperty[];\n};\n\nexport interface JsonAstBodyStatement extends ESTree.ExpressionStatement {\n\texpression: JsonAstBodyExpression;\n}\n\nexport interface PackageJsonAst extends AST.Program {\n\tbody: [JsonAstBodyStatement];\n}\n\nexport interface PackageJsonSourceCode extends SourceCode {\n\tast: PackageJsonAst;\n}\n\nexport interface PackageJsonRuleContext<Options extends unknown[] = unknown[]>\n\textends Rule.RuleContext {\n\toptions: Options;\n\tsourceCode: PackageJsonSourceCode;\n}\n\nexport interface PackageJsonRuleModule<Options extends unknown[] = unknown[]> {\n\tcreate(context: PackageJsonRuleContext<Options>): RuleListener;\n\tmeta: Rule.RuleMetaData;\n}\n\nexport function createRule<Options extends unknown[]>(\n\trule: PackageJsonRuleModule<Options>,\n) {\n\treturn {\n\t\t...rule,\n\t\tcreate(context: PackageJsonRuleContext<Options>) {\n\t\t\tif (!isPackageJson(context.filename)) {\n\t\t\t\treturn {};\n\t\t\t}\n\n\t\t\treturn rule.create(context);\n\t\t},\n\t};\n}\n"],"mappings":"AAKA,MAAM,gBAAgB,CAAC,aACtB,SAAS,SAAS,eAAe,KAAK,aAAa;AAiC7C,SAAS,WACf,MACC;AACD,SAAO;AAAA,IACN,GAAG;AAAA,IACH,OAAO,SAA0C;AAChD,UAAI,CAAC,cAAc,QAAQ,QAAQ,GAAG;AACrC,eAAO,CAAC;AAAA,MACT;AAEA,aAAO,KAAK,OAAO,OAAO;AAAA,IAC3B;AAAA,EACD;AACD;","names":[]}
|
package/lib/index.d.mts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
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 rules: {
|
|
7
|
+
"order-properties": {
|
|
8
|
+
create(context: PackageJsonRuleContext<[({
|
|
9
|
+
order: "legacy" | "sort-package-json";
|
|
10
|
+
} | undefined)?]>): jsonc_eslint_parser.RuleListener;
|
|
11
|
+
meta: eslint.Rule.RuleMetaData;
|
|
12
|
+
};
|
|
13
|
+
"sort-collections": {
|
|
14
|
+
create(context: PackageJsonRuleContext<string[]>): jsonc_eslint_parser.RuleListener;
|
|
15
|
+
meta: eslint.Rule.RuleMetaData;
|
|
16
|
+
};
|
|
17
|
+
"valid-local-dependency": {
|
|
18
|
+
create(context: PackageJsonRuleContext<unknown[]>): jsonc_eslint_parser.RuleListener;
|
|
19
|
+
meta: eslint.Rule.RuleMetaData;
|
|
20
|
+
};
|
|
21
|
+
"valid-package-def": {
|
|
22
|
+
create(context: PackageJsonRuleContext<unknown[]>): jsonc_eslint_parser.RuleListener;
|
|
23
|
+
meta: eslint.Rule.RuleMetaData;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
declare const configs: {
|
|
27
|
+
recommended: {
|
|
28
|
+
rules: {
|
|
29
|
+
[k: string]: "error";
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export { configs, rules };
|
package/lib/index.d.ts
CHANGED
|
@@ -1,41 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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 rules: {
|
|
7
|
+
"order-properties": {
|
|
8
|
+
create(context: PackageJsonRuleContext<[({
|
|
9
|
+
order: "legacy" | "sort-package-json";
|
|
10
|
+
} | undefined)?]>): jsonc_eslint_parser.RuleListener;
|
|
11
|
+
meta: eslint.Rule.RuleMetaData;
|
|
5
12
|
};
|
|
6
|
-
|
|
7
|
-
create(context:
|
|
8
|
-
meta:
|
|
13
|
+
"sort-collections": {
|
|
14
|
+
create(context: PackageJsonRuleContext<string[]>): jsonc_eslint_parser.RuleListener;
|
|
15
|
+
meta: eslint.Rule.RuleMetaData;
|
|
9
16
|
};
|
|
10
|
-
|
|
11
|
-
create(context:
|
|
12
|
-
meta:
|
|
17
|
+
"valid-local-dependency": {
|
|
18
|
+
create(context: PackageJsonRuleContext<unknown[]>): jsonc_eslint_parser.RuleListener;
|
|
19
|
+
meta: eslint.Rule.RuleMetaData;
|
|
13
20
|
};
|
|
14
|
-
|
|
15
|
-
create(context:
|
|
16
|
-
meta:
|
|
21
|
+
"valid-package-def": {
|
|
22
|
+
create(context: PackageJsonRuleContext<unknown[]>): jsonc_eslint_parser.RuleListener;
|
|
23
|
+
meta: eslint.Rule.RuleMetaData;
|
|
17
24
|
};
|
|
18
25
|
};
|
|
19
|
-
|
|
26
|
+
declare const configs: {
|
|
20
27
|
recommended: {
|
|
21
28
|
rules: {
|
|
22
|
-
|
|
23
|
-
create(context: import("./createRule").PackageJsonRuleContext): import("jsonc-eslint-parser").RuleListener;
|
|
24
|
-
meta: import("eslint").Rule.RuleMetaData;
|
|
25
|
-
};
|
|
26
|
-
'sort-collections': {
|
|
27
|
-
create(context: import("./createRule").PackageJsonRuleContext): import("jsonc-eslint-parser").RuleListener;
|
|
28
|
-
meta: import("eslint").Rule.RuleMetaData;
|
|
29
|
-
};
|
|
30
|
-
'valid-local-dependency': {
|
|
31
|
-
create(context: import("./createRule").PackageJsonRuleContext): import("jsonc-eslint-parser").RuleListener;
|
|
32
|
-
meta: import("eslint").Rule.RuleMetaData;
|
|
33
|
-
};
|
|
34
|
-
'valid-package-def': {
|
|
35
|
-
create(context: import("./createRule").PackageJsonRuleContext): import("jsonc-eslint-parser").RuleListener;
|
|
36
|
-
meta: import("eslint").Rule.RuleMetaData;
|
|
37
|
-
};
|
|
29
|
+
[k: string]: "error";
|
|
38
30
|
};
|
|
39
31
|
};
|
|
40
32
|
};
|
|
41
|
-
|
|
33
|
+
|
|
34
|
+
export { configs, rules };
|
package/lib/index.js
CHANGED
|
@@ -1,21 +1,57 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
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 });
|
|
4
11
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
'order-properties': order_properties_1.default,
|
|
13
|
-
'sort-collections': sort_collections_1.default,
|
|
14
|
-
'valid-local-dependency': valid_local_dependency_1.default,
|
|
15
|
-
'valid-package-def': valid_package_def_1.default
|
|
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;
|
|
16
19
|
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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 src_exports = {};
|
|
30
|
+
__export(src_exports, {
|
|
31
|
+
configs: () => configs,
|
|
32
|
+
rules: () => rules
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(src_exports);
|
|
35
|
+
var import_order_properties = __toESM(require("./rules/order-properties.js"));
|
|
36
|
+
var import_sort_collections = __toESM(require("./rules/sort-collections.js"));
|
|
37
|
+
var import_valid_local_dependency = __toESM(require("./rules/valid-local-dependency.js"));
|
|
38
|
+
var import_valid_package_def = __toESM(require("./rules/valid-package-def.js"));
|
|
39
|
+
const rules = {
|
|
40
|
+
"order-properties": import_order_properties.default,
|
|
41
|
+
"sort-collections": import_sort_collections.default,
|
|
42
|
+
"valid-local-dependency": import_valid_local_dependency.default,
|
|
43
|
+
"valid-package-def": import_valid_package_def.default
|
|
21
44
|
};
|
|
45
|
+
const configs = {
|
|
46
|
+
recommended: {
|
|
47
|
+
rules: Object.fromEntries(
|
|
48
|
+
Object.entries(rules).filter(([, rule]) => rule.meta.docs?.recommended).map(([name]) => ["package-json/" + name, "error"])
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
53
|
+
0 && (module.exports = {
|
|
54
|
+
configs,
|
|
55
|
+
rules
|
|
56
|
+
});
|
|
57
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import orderProperties from \"./rules/order-properties.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\"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,8BAA4B;AAC5B,oCAAiC;AACjC,+BAA4B;AAErB,MAAM,QAAQ;AAAA,EACpB,oBAAoB,wBAAAA;AAAA,EACpB,oBAAoB,wBAAAC;AAAA,EACpB,0BAA0B,8BAAAC;AAAA,EAC1B,qBAAqB,yBAAAC;AACtB;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","sortCollections","validLocalDependency","validPackageDef"]}
|
package/lib/index.mjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import orderProperties from "./rules/order-properties.js";
|
|
2
|
+
import sortCollections from "./rules/sort-collections.js";
|
|
3
|
+
import validLocalDependency from "./rules/valid-local-dependency.js";
|
|
4
|
+
import validPackageDef from "./rules/valid-package-def.js";
|
|
5
|
+
const rules = {
|
|
6
|
+
"order-properties": orderProperties,
|
|
7
|
+
"sort-collections": sortCollections,
|
|
8
|
+
"valid-local-dependency": validLocalDependency,
|
|
9
|
+
"valid-package-def": validPackageDef
|
|
10
|
+
};
|
|
11
|
+
const configs = {
|
|
12
|
+
recommended: {
|
|
13
|
+
rules: Object.fromEntries(
|
|
14
|
+
Object.entries(rules).filter(([, rule]) => rule.meta.docs?.recommended).map(([name]) => ["package-json/" + name, "error"])
|
|
15
|
+
)
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
export {
|
|
19
|
+
configs,
|
|
20
|
+
rules
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import orderProperties from \"./rules/order-properties.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\"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,qBAAqB;AAC5B,OAAO,0BAA0B;AACjC,OAAO,qBAAqB;AAErB,MAAM,QAAQ;AAAA,EACpB,oBAAoB;AAAA,EACpB,oBAAoB;AAAA,EACpB,0BAA0B;AAAA,EAC1B,qBAAqB;AACtB;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":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
type Order = "legacy" | "sort-package-json";
|
|
7
|
+
type Options = [{
|
|
8
|
+
order: Order;
|
|
9
|
+
}?];
|
|
10
|
+
declare const _default: {
|
|
11
|
+
create(context: PackageJsonRuleContext<Options>): jsonc_eslint_parser.RuleListener;
|
|
12
|
+
meta: eslint.Rule.RuleMetaData;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { _default as default };
|
|
@@ -1,6 +1,15 @@
|
|
|
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 Order = "legacy" | "sort-package-json";
|
|
7
|
+
type Options = [{
|
|
8
|
+
order: Order;
|
|
9
|
+
}?];
|
|
1
10
|
declare const _default: {
|
|
2
|
-
create(context:
|
|
3
|
-
meta:
|
|
11
|
+
create(context: PackageJsonRuleContext<Options>): jsonc_eslint_parser.RuleListener;
|
|
12
|
+
meta: eslint.Rule.RuleMetaData;
|
|
4
13
|
};
|
|
5
|
-
|
|
6
|
-
|
|
14
|
+
|
|
15
|
+
export { _default as default };
|