eslint-plugin-package-json 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc +1 -1
- package/.github/actions/prepare/action.yml +12 -0
- package/.github/workflows/format.yml +15 -0
- package/.github/workflows/lint.yml +15 -0
- package/.github/workflows/test.yml +1 -4
- package/.github/workflows/tsc.yml +15 -0
- package/.vscode/extensions.json +3 -0
- package/.vscode/launch.json +14 -15
- package/.vscode/settings.json +4 -0
- package/README.md +33 -30
- package/lib/createRule.d.ts +30 -0
- package/lib/createRule.d.ts.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/rules/order-properties.d.ts +6 -0
- package/lib/rules/order-properties.d.ts.map +1 -0
- package/lib/rules/sort-collections.d.ts +6 -0
- package/lib/rules/sort-collections.d.ts.map +1 -0
- package/lib/rules/valid-local-dependency.d.ts +6 -0
- package/lib/rules/valid-local-dependency.d.ts.map +1 -0
- package/lib/rules/valid-package-def.d.ts +6 -0
- package/lib/rules/valid-package-def.d.ts.map +1 -0
- package/lib/tests/rules/order-properties.test.d.ts +2 -0
- package/lib/tests/rules/order-properties.test.d.ts.map +1 -0
- package/lib/tests/rules/order-properties.test.js +232 -0
- package/lib/tests/rules/ruleTester.d.ts +10 -0
- package/lib/tests/rules/ruleTester.d.ts.map +1 -0
- package/lib/tests/rules/ruleTester.js +7 -0
- package/lib/tests/rules/sort-collections.test.d.ts +2 -0
- package/lib/tests/rules/sort-collections.test.d.ts.map +1 -0
- package/lib/tests/rules/sort-collections.test.js +64 -0
- package/lib/tests/rules/valid-local-dependency.test.d.ts +2 -0
- package/lib/tests/rules/valid-local-dependency.test.d.ts.map +1 -0
- package/lib/tests/rules/valid-local-dependency.test.js +232 -0
- package/lib/tests/rules/valid-package-def.test.d.ts +2 -0
- package/lib/tests/rules/valid-package-def.test.d.ts.map +1 -0
- package/lib/tests/rules/valid-package-def.test.js +65 -0
- package/package.json +49 -51
- package/src/createRule.ts +49 -0
- package/src/index.ts +19 -0
- package/src/rules/order-properties.ts +122 -0
- package/{lib/rules/sort-collections.js → src/rules/sort-collections.ts} +32 -24
- package/{lib/rules/valid-local-dependency.js → src/rules/valid-local-dependency.ts} +15 -27
- package/src/rules/valid-package-def.ts +45 -0
- package/src/tests/globalSetup.js +7 -0
- package/src/tests/rules/order-properties.test.ts +223 -0
- package/src/tests/rules/ruleTester.ts +17 -0
- package/{tests/lib/rules/sort-collections.js → src/tests/rules/sort-collections.test.ts} +13 -20
- package/{tests/lib/rules/valid-local-dependency.js → src/tests/rules/valid-local-dependency.test.ts} +51 -64
- package/{tests/lib/rules/valid-package-def.js → src/tests/rules/valid-package-def.test.ts} +6 -17
- package/tsconfig.json +13 -0
- package/vitest.config.ts +15 -0
- package/lib/index.js +0 -34
- package/lib/processors/PackageJsonProcessor.js +0 -63
- package/lib/rules/order-properties.js +0 -124
- package/lib/rules/valid-package-def.js +0 -61
- package/tests/lib/index.js +0 -157
- package/tests/lib/processors/PackageJsonProcessor.js +0 -159
- package/tests/lib/rules/order-properties.js +0 -234
- /package/{tests/lib → src/tests}/__fixtures__/invalid-top-level-property-order/package.json +0 -0
- /package/{tests/lib → src/tests}/__fixtures__/unalphabetized-collections/package.json +0 -0
- /package/{tests/lib → src/tests}/__fixtures__/valid-local-dependency/gotcha/package.json/gotcha/package.json +0 -0
- /package/{tests/lib → src/tests}/__fixtures__/valid-local-dependency/package.json +0 -0
package/.eslintrc
CHANGED
package/.vscode/launch.json
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
]
|
|
2
|
+
"configurations": [
|
|
3
|
+
{
|
|
4
|
+
"args": ["run", "${relativeFile}"],
|
|
5
|
+
"autoAttachChildProcesses": true,
|
|
6
|
+
"console": "integratedTerminal",
|
|
7
|
+
"name": "Debug Current Test File",
|
|
8
|
+
"program": "${workspaceRoot}/node_modules/vitest/vitest.mjs",
|
|
9
|
+
"request": "launch",
|
|
10
|
+
"skipFiles": ["<node_internals>/**", "**/node_modules/**"],
|
|
11
|
+
"smartStep": true,
|
|
12
|
+
"type": "node"
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"version": "0.2.0"
|
|
17
16
|
}
|
package/README.md
CHANGED
|
@@ -2,49 +2,52 @@
|
|
|
2
2
|
|
|
3
3
|
Rules for valid, consistent, and readable package.json files
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
> ⚠️ This README.md is for the `0.3.x` versions of this package.
|
|
6
|
+
> Those versions are tagged as `beta` on npm.
|
|
7
|
+
> For 0.2.x, see [the latest 0.2.x README.md](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/tree/a1c3bf76fb1a55e85f071051be55dc06ebb47c8b).
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
$ npm i eslint --save-dev
|
|
11
|
-
```
|
|
9
|
+
## Installation
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
You'll first need to install [ESLint](http://eslint.org) >=8 and `eslint-plugin-package-json`:
|
|
14
12
|
|
|
15
|
-
```
|
|
16
|
-
$ npm install eslint-plugin-package-json --save-dev
|
|
13
|
+
```shell
|
|
14
|
+
$ npm install eslint eslint-plugin-package-json jsonc-eslint-parser --save-dev
|
|
17
15
|
```
|
|
18
16
|
|
|
19
17
|
**Note:** If you installed ESLint globally (using the `-g` flag) then you must also install `eslint-plugin-package-json` globally.
|
|
20
18
|
|
|
21
19
|
## Usage
|
|
22
20
|
|
|
23
|
-
Add
|
|
24
|
-
|
|
25
|
-
```
|
|
26
|
-
{
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"plugins": ["package-json"]
|
|
37
|
-
}
|
|
21
|
+
Add an override to your ESLint configuration file that specifies this plugin, [`jsonc-eslint-parser`](https://github.com/ota-meshi/jsonc-eslint-parser) and its recommended rules for your `package.json` file:
|
|
22
|
+
|
|
23
|
+
```js
|
|
24
|
+
module.exports = {
|
|
25
|
+
overrides: [
|
|
26
|
+
{
|
|
27
|
+
extends: ['plugin:package-json/recommended'],
|
|
28
|
+
files: ['package.json'],
|
|
29
|
+
parser: 'jsonc-eslint-parser',
|
|
30
|
+
plugins: ['package-json']
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
};
|
|
38
34
|
```
|
|
39
35
|
|
|
40
36
|
Or, individually configure the rules you want to use under the rules section.
|
|
41
37
|
|
|
42
|
-
```
|
|
43
|
-
{
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
38
|
+
```js
|
|
39
|
+
module.exports = {
|
|
40
|
+
overrides: [
|
|
41
|
+
{
|
|
42
|
+
files: ['package.json'],
|
|
43
|
+
parser: 'jsonc-eslint-parser',
|
|
44
|
+
plugins: ['package-json'],
|
|
45
|
+
rules: {
|
|
46
|
+
'package-json/valid-package-def': 'error'
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
};
|
|
48
51
|
```
|
|
49
52
|
|
|
50
53
|
## Supported Rules
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AST, Rule, SourceCode } from 'eslint';
|
|
2
|
+
import { AST as JsonAST, RuleListener } from "jsonc-eslint-parser";
|
|
3
|
+
import type * as ESTree from 'estree';
|
|
4
|
+
export type JsonAstBodyProperty = (JsonAST.JSONProperty & {
|
|
5
|
+
value: string;
|
|
6
|
+
});
|
|
7
|
+
export type JsonAstBodyExpression = ESTree.Expression & {
|
|
8
|
+
properties: JsonAstBodyProperty[];
|
|
9
|
+
};
|
|
10
|
+
export interface JsonAstBodyStatement extends ESTree.ExpressionStatement {
|
|
11
|
+
expression: JsonAstBodyExpression;
|
|
12
|
+
}
|
|
13
|
+
export interface PackageJsonAst extends AST.Program {
|
|
14
|
+
body: [JsonAstBodyStatement];
|
|
15
|
+
}
|
|
16
|
+
export interface PackageJsonSourceCode extends SourceCode {
|
|
17
|
+
ast: PackageJsonAst;
|
|
18
|
+
}
|
|
19
|
+
export interface PackageJsonRuleContext extends Rule.RuleContext {
|
|
20
|
+
sourceCode: PackageJsonSourceCode;
|
|
21
|
+
}
|
|
22
|
+
export interface PackageJsonRuleModule {
|
|
23
|
+
meta: Rule.RuleMetaData;
|
|
24
|
+
create(context: PackageJsonRuleContext): RuleListener;
|
|
25
|
+
}
|
|
26
|
+
export declare function createRule(rule: PackageJsonRuleModule): {
|
|
27
|
+
create(context: PackageJsonRuleContext): RuleListener;
|
|
28
|
+
meta: Rule.RuleMetaData;
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=createRule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createRule.d.ts","sourceRoot":"","sources":["../src/createRule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EAAE,GAAG,IAAI,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClE,OAAO,KAAK,KAAK,MAAM,MAAM,QAAQ,CAAC;AAKtC,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,CAAC,YAAY,GAAG;IACtD,KAAK,EAAE,MAAM,CAAC;CACjB,CAAC,CAAC;AAEH,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC,UAAU,GAAG;IACpD,UAAU,EAAE,mBAAmB,EAAE,CAAC;CACrC,CAAC;AAEF,MAAM,WAAW,oBAAqB,SAAQ,MAAM,CAAC,mBAAmB;IACpE,UAAU,EAAE,qBAAqB,CAAA;CACpC;AAED,MAAM,WAAW,cAAe,SAAQ,GAAG,CAAC,OAAO;IAC/C,IAAI,EAAE,CAAC,oBAAoB,CAAC,CAAA;CAC/B;AAED,MAAM,WAAW,qBAAsB,SAAQ,UAAU;IACrD,GAAG,EAAE,cAAc,CAAC;CACvB;AAED,MAAM,WAAW,sBAAuB,SAAQ,IAAI,CAAC,WAAW;IAC5D,UAAU,EAAE,qBAAqB,CAAC;CACrC;AAED,MAAM,WAAW,qBAAqB;IAClC,IAAI,EAAE,IAAI,CAAC,YAAY,CAAC;IACxB,MAAM,CAAC,OAAO,EAAE,sBAAsB,GAAG,YAAY,CAAC;CACvD;AAGH,wBAAgB,UAAU,CAAC,IAAI,EAAE,qBAAqB;oBAG9B,sBAAsB;;EAQ7C"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order-properties.d.ts","sourceRoot":"","sources":["../../src/rules/order-properties.ts"],"names":[],"mappings":";;;;AAmCA,wBA0EG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sort-collections.d.ts","sourceRoot":"","sources":["../../src/rules/sort-collections.ts"],"names":[],"mappings":";;;;AAaA,wBAkFG"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
create(context: import("../createRule.js").PackageJsonRuleContext): import("jsonc-eslint-parser").RuleListener;
|
|
3
|
+
meta: import("eslint").Rule.RuleMetaData;
|
|
4
|
+
};
|
|
5
|
+
export default _default;
|
|
6
|
+
//# sourceMappingURL=valid-local-dependency.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"valid-local-dependency.d.ts","sourceRoot":"","sources":["../../src/rules/valid-local-dependency.ts"],"names":[],"mappings":";;;;AAQA,wBAgEG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"valid-package-def.d.ts","sourceRoot":"","sources":["../../src/rules/valid-package-def.ts"],"names":[],"mappings":";;;;AAgBA,wBA4BG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order-properties.test.d.ts","sourceRoot":"","sources":["../../../src/tests/rules/order-properties.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const order_properties_1 = __importDefault(require("../../rules/order-properties"));
|
|
7
|
+
const ruleTester_1 = require("./ruleTester");
|
|
8
|
+
ruleTester_1.ruleTester.run('order-properties', order_properties_1.default, {
|
|
9
|
+
invalid: [
|
|
10
|
+
{
|
|
11
|
+
only: true,
|
|
12
|
+
code: `{
|
|
13
|
+
"name": "invalid-top-level-property-order",
|
|
14
|
+
"scripts": {
|
|
15
|
+
"test": "tape"
|
|
16
|
+
},
|
|
17
|
+
"version": "1.0.0",
|
|
18
|
+
"description": "npm made me this way",
|
|
19
|
+
"main": "index.js",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/fake/github.git"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
`,
|
|
26
|
+
errors: [
|
|
27
|
+
{
|
|
28
|
+
message: 'Package top-level properties are not ordered in the npm standard way. Run the ESLint auto-fixer to correct.'
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
filename: 'package.json',
|
|
32
|
+
output: `{
|
|
33
|
+
"name": "invalid-top-level-property-order",
|
|
34
|
+
"version": "1.0.0",
|
|
35
|
+
"description": "npm made me this way",
|
|
36
|
+
"main": "index.js",
|
|
37
|
+
"scripts": {
|
|
38
|
+
"test": "tape"
|
|
39
|
+
},
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/fake/github.git"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
`
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
only: true,
|
|
49
|
+
code: `{
|
|
50
|
+
"name": "invalid-top-level-property-order",
|
|
51
|
+
"scripts": {
|
|
52
|
+
"test": "tape"
|
|
53
|
+
},
|
|
54
|
+
"version": "1.0.0",
|
|
55
|
+
"description": "npm made me this way",
|
|
56
|
+
"main": "index.js",
|
|
57
|
+
"repository": {
|
|
58
|
+
"type": "git",
|
|
59
|
+
"url": "git+https://github.com/fake/github.git"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
`,
|
|
63
|
+
errors: [
|
|
64
|
+
{
|
|
65
|
+
message: 'Package top-level properties are not ordered in the npm standard way. Run the ESLint auto-fixer to correct.'
|
|
66
|
+
}
|
|
67
|
+
],
|
|
68
|
+
filename: 'package.json',
|
|
69
|
+
options: [{ order: 'legacy' }],
|
|
70
|
+
output: `{
|
|
71
|
+
"name": "invalid-top-level-property-order",
|
|
72
|
+
"version": "1.0.0",
|
|
73
|
+
"description": "npm made me this way",
|
|
74
|
+
"main": "index.js",
|
|
75
|
+
"scripts": {
|
|
76
|
+
"test": "tape"
|
|
77
|
+
},
|
|
78
|
+
"repository": {
|
|
79
|
+
"type": "git",
|
|
80
|
+
"url": "git+https://github.com/fake/github.git"
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
`
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
only: true,
|
|
87
|
+
code: `{
|
|
88
|
+
"name": "invalid-top-level-property-order",
|
|
89
|
+
"scripts": {
|
|
90
|
+
"test": "tape"
|
|
91
|
+
},
|
|
92
|
+
"version": "1.0.0",
|
|
93
|
+
"description": "npm made me this way",
|
|
94
|
+
"main": "index.js",
|
|
95
|
+
"repository": {
|
|
96
|
+
"type": "git",
|
|
97
|
+
"url": "git+https://github.com/fake/github.git"
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
`,
|
|
101
|
+
errors: [
|
|
102
|
+
{
|
|
103
|
+
message: 'Package top-level properties are not ordered in the npm standard way. Run the ESLint auto-fixer to correct.'
|
|
104
|
+
}
|
|
105
|
+
],
|
|
106
|
+
filename: 'package.json',
|
|
107
|
+
options: [{ order: 'sort-package-json' }],
|
|
108
|
+
output: `{
|
|
109
|
+
"name": "invalid-top-level-property-order",
|
|
110
|
+
"version": "1.0.0",
|
|
111
|
+
"description": "npm made me this way",
|
|
112
|
+
"repository": {
|
|
113
|
+
"type": "git",
|
|
114
|
+
"url": "git+https://github.com/fake/github.git"
|
|
115
|
+
},
|
|
116
|
+
"main": "index.js",
|
|
117
|
+
"scripts": {
|
|
118
|
+
"test": "tape"
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
`
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
only: true,
|
|
125
|
+
code: `{
|
|
126
|
+
"name": "invalid-top-level-property-order",
|
|
127
|
+
"scripts": {
|
|
128
|
+
"test": "tape"
|
|
129
|
+
},
|
|
130
|
+
"version": "1.0.0",
|
|
131
|
+
"description": "npm made me this way",
|
|
132
|
+
"main": "index.js",
|
|
133
|
+
"repository": {
|
|
134
|
+
"type": "git",
|
|
135
|
+
"url": "git+https://github.com/fake/github.git"
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
`,
|
|
139
|
+
errors: [
|
|
140
|
+
{
|
|
141
|
+
message: 'Package top-level properties are not ordered in the npm standard way. Run the ESLint auto-fixer to correct.'
|
|
142
|
+
}
|
|
143
|
+
],
|
|
144
|
+
filename: 'package.json',
|
|
145
|
+
options: [{ order: ['version', 'name', 'repository'] }],
|
|
146
|
+
output: `{
|
|
147
|
+
"version": "1.0.0",
|
|
148
|
+
"name": "invalid-top-level-property-order",
|
|
149
|
+
"repository": {
|
|
150
|
+
"type": "git",
|
|
151
|
+
"url": "git+https://github.com/fake/github.git"
|
|
152
|
+
},
|
|
153
|
+
"description": "npm made me this way",
|
|
154
|
+
"main": "index.js",
|
|
155
|
+
"scripts": {
|
|
156
|
+
"test": "tape"
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
`
|
|
160
|
+
}
|
|
161
|
+
],
|
|
162
|
+
valid: [
|
|
163
|
+
{
|
|
164
|
+
code: `{
|
|
165
|
+
"name": "treat-yo-self",
|
|
166
|
+
"version": "1.1.1",
|
|
167
|
+
"description": "Once a year.",
|
|
168
|
+
"keywords": [
|
|
169
|
+
"modern",
|
|
170
|
+
"master"
|
|
171
|
+
]
|
|
172
|
+
}`,
|
|
173
|
+
filename: 'package.json'
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
code: `{
|
|
177
|
+
"name": "treat-yo-self",
|
|
178
|
+
"version": "0.1.0",
|
|
179
|
+
"private": true,
|
|
180
|
+
"description": "Once a year.",
|
|
181
|
+
"keywords": [
|
|
182
|
+
"modern",
|
|
183
|
+
"master"
|
|
184
|
+
]
|
|
185
|
+
}
|
|
186
|
+
`
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
code: `{
|
|
190
|
+
"version": "1.1.1",
|
|
191
|
+
"name": "treat-yo-self",
|
|
192
|
+
"description": "Once a year.",
|
|
193
|
+
"keywords": [
|
|
194
|
+
"modern",
|
|
195
|
+
"master"
|
|
196
|
+
]
|
|
197
|
+
}
|
|
198
|
+
`,
|
|
199
|
+
options: [{ order: ['version', 'name'] }]
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
code: `{
|
|
203
|
+
"name": "treat-yo-self",
|
|
204
|
+
"version": "1.1.1",
|
|
205
|
+
"description": "Once a year.",
|
|
206
|
+
"keywords": [
|
|
207
|
+
"modern",
|
|
208
|
+
"master"
|
|
209
|
+
],
|
|
210
|
+
"exports": {
|
|
211
|
+
"import": "./index.js",
|
|
212
|
+
"require": "./index.js"
|
|
213
|
+
},
|
|
214
|
+
"main": "index.js"
|
|
215
|
+
}`,
|
|
216
|
+
options: [{ order: 'sort-package-json' }]
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
code: `{
|
|
220
|
+
"name": "treat-yo-self",
|
|
221
|
+
"version": "1.1.1",
|
|
222
|
+
"description": "Once a year.",
|
|
223
|
+
"main": "index.js",
|
|
224
|
+
"exports": {
|
|
225
|
+
"import": "./index.js",
|
|
226
|
+
"require": "./index.js"
|
|
227
|
+
}
|
|
228
|
+
}`,
|
|
229
|
+
options: [{ order: 'legacy' }]
|
|
230
|
+
}
|
|
231
|
+
]
|
|
232
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { RuleTester } from 'eslint';
|
|
2
|
+
import { PackageJsonRuleModule } from '../../createRule';
|
|
3
|
+
export type JsonRuleTester = RuleTester & {
|
|
4
|
+
run: (name: string, rule: PackageJsonRuleModule, tests: {
|
|
5
|
+
valid?: Array<string | RuleTester.ValidTestCase> | undefined;
|
|
6
|
+
invalid?: RuleTester.InvalidTestCase[] | undefined;
|
|
7
|
+
}) => void;
|
|
8
|
+
};
|
|
9
|
+
export declare const ruleTester: JsonRuleTester;
|
|
10
|
+
//# sourceMappingURL=ruleTester.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ruleTester.d.ts","sourceRoot":"","sources":["../../../src/tests/rules/ruleTester.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG;IACtC,GAAG,EAAE,CACD,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,qBAAqB,EAC3B,KAAK,EAAE;QACH,KAAK,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,UAAU,CAAC,aAAa,CAAC,GAAG,SAAS,CAAC;QAC7D,OAAO,CAAC,EAAE,UAAU,CAAC,eAAe,EAAE,GAAG,SAAS,CAAC;KACtD,KACA,IAAI,CAAC;CACb,CAAC;AAEF,eAAO,MAAM,UAAU,gBAEH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sort-collections.test.d.ts","sourceRoot":"","sources":["../../../src/tests/rules/sort-collections.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const sort_collections_1 = __importDefault(require("../../rules/sort-collections"));
|
|
7
|
+
const ruleTester_js_1 = require("./ruleTester.js");
|
|
8
|
+
//------------------------------------------------------------------------------
|
|
9
|
+
// Tests
|
|
10
|
+
//------------------------------------------------------------------------------
|
|
11
|
+
ruleTester_js_1.ruleTester.run('sort-collections', sort_collections_1.default, {
|
|
12
|
+
valid: [
|
|
13
|
+
{
|
|
14
|
+
code: `{
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "webpack",
|
|
17
|
+
"watch": "webpack-dev-server"
|
|
18
|
+
}
|
|
19
|
+
}`,
|
|
20
|
+
filename: 'package.json'
|
|
21
|
+
},
|
|
22
|
+
// ignore if custom include rule
|
|
23
|
+
{
|
|
24
|
+
code: `{
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "webpack",
|
|
27
|
+
"watch": "webpack-dev-server"
|
|
28
|
+
}
|
|
29
|
+
}`,
|
|
30
|
+
filename: 'package.json',
|
|
31
|
+
options: [['devDependencies']]
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
code: `{
|
|
35
|
+
"scripts": { "watch": "out of order...", "build": "but okay" }
|
|
36
|
+
}`,
|
|
37
|
+
filename: 'not-a-package.json',
|
|
38
|
+
options: [['devDependencies']]
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
invalid: [
|
|
42
|
+
{
|
|
43
|
+
code: `{
|
|
44
|
+
"scripts": {
|
|
45
|
+
"watch": "webpack-dev-server",
|
|
46
|
+
"build": "webpack"
|
|
47
|
+
}
|
|
48
|
+
}`,
|
|
49
|
+
filename: 'package.json',
|
|
50
|
+
errors: [
|
|
51
|
+
{
|
|
52
|
+
message: 'Package scripts are not alphabetized',
|
|
53
|
+
type: 'JSONProperty'
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
output: `{
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "webpack",
|
|
59
|
+
"watch": "webpack-dev-server"
|
|
60
|
+
}
|
|
61
|
+
}`
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"valid-local-dependency.test.d.ts","sourceRoot":"","sources":["../../../src/tests/rules/valid-local-dependency.test.ts"],"names":[],"mappings":""}
|