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.
Files changed (63) hide show
  1. package/.eslintrc +1 -1
  2. package/.github/actions/prepare/action.yml +12 -0
  3. package/.github/workflows/format.yml +15 -0
  4. package/.github/workflows/lint.yml +15 -0
  5. package/.github/workflows/test.yml +1 -4
  6. package/.github/workflows/tsc.yml +15 -0
  7. package/.vscode/extensions.json +3 -0
  8. package/.vscode/launch.json +14 -15
  9. package/.vscode/settings.json +4 -0
  10. package/README.md +33 -30
  11. package/lib/createRule.d.ts +30 -0
  12. package/lib/createRule.d.ts.map +1 -0
  13. package/lib/index.d.ts +2 -0
  14. package/lib/index.d.ts.map +1 -0
  15. package/lib/rules/order-properties.d.ts +6 -0
  16. package/lib/rules/order-properties.d.ts.map +1 -0
  17. package/lib/rules/sort-collections.d.ts +6 -0
  18. package/lib/rules/sort-collections.d.ts.map +1 -0
  19. package/lib/rules/valid-local-dependency.d.ts +6 -0
  20. package/lib/rules/valid-local-dependency.d.ts.map +1 -0
  21. package/lib/rules/valid-package-def.d.ts +6 -0
  22. package/lib/rules/valid-package-def.d.ts.map +1 -0
  23. package/lib/tests/rules/order-properties.test.d.ts +2 -0
  24. package/lib/tests/rules/order-properties.test.d.ts.map +1 -0
  25. package/lib/tests/rules/order-properties.test.js +232 -0
  26. package/lib/tests/rules/ruleTester.d.ts +10 -0
  27. package/lib/tests/rules/ruleTester.d.ts.map +1 -0
  28. package/lib/tests/rules/ruleTester.js +7 -0
  29. package/lib/tests/rules/sort-collections.test.d.ts +2 -0
  30. package/lib/tests/rules/sort-collections.test.d.ts.map +1 -0
  31. package/lib/tests/rules/sort-collections.test.js +64 -0
  32. package/lib/tests/rules/valid-local-dependency.test.d.ts +2 -0
  33. package/lib/tests/rules/valid-local-dependency.test.d.ts.map +1 -0
  34. package/lib/tests/rules/valid-local-dependency.test.js +232 -0
  35. package/lib/tests/rules/valid-package-def.test.d.ts +2 -0
  36. package/lib/tests/rules/valid-package-def.test.d.ts.map +1 -0
  37. package/lib/tests/rules/valid-package-def.test.js +65 -0
  38. package/package.json +49 -51
  39. package/src/createRule.ts +49 -0
  40. package/src/index.ts +19 -0
  41. package/src/rules/order-properties.ts +122 -0
  42. package/{lib/rules/sort-collections.js → src/rules/sort-collections.ts} +32 -24
  43. package/{lib/rules/valid-local-dependency.js → src/rules/valid-local-dependency.ts} +15 -27
  44. package/src/rules/valid-package-def.ts +45 -0
  45. package/src/tests/globalSetup.js +7 -0
  46. package/src/tests/rules/order-properties.test.ts +223 -0
  47. package/src/tests/rules/ruleTester.ts +17 -0
  48. package/{tests/lib/rules/sort-collections.js → src/tests/rules/sort-collections.test.ts} +13 -20
  49. package/{tests/lib/rules/valid-local-dependency.js → src/tests/rules/valid-local-dependency.test.ts} +51 -64
  50. package/{tests/lib/rules/valid-package-def.js → src/tests/rules/valid-package-def.test.ts} +6 -17
  51. package/tsconfig.json +13 -0
  52. package/vitest.config.ts +15 -0
  53. package/lib/index.js +0 -34
  54. package/lib/processors/PackageJsonProcessor.js +0 -63
  55. package/lib/rules/order-properties.js +0 -124
  56. package/lib/rules/valid-package-def.js +0 -61
  57. package/tests/lib/index.js +0 -157
  58. package/tests/lib/processors/PackageJsonProcessor.js +0 -159
  59. package/tests/lib/rules/order-properties.js +0 -234
  60. /package/{tests/lib → src/tests}/__fixtures__/invalid-top-level-property-order/package.json +0 -0
  61. /package/{tests/lib → src/tests}/__fixtures__/unalphabetized-collections/package.json +0 -0
  62. /package/{tests/lib → src/tests}/__fixtures__/valid-local-dependency/gotcha/package.json/gotcha/package.json +0 -0
  63. /package/{tests/lib → src/tests}/__fixtures__/valid-local-dependency/package.json +0 -0
package/.eslintrc CHANGED
@@ -5,7 +5,7 @@
5
5
  },
6
6
  "extends": ["eslint:recommended"],
7
7
  "parserOptions": {
8
- "ecmaVersion": 6,
8
+ "ecmaVersion": 2021,
9
9
  "sourceType": "module"
10
10
  }
11
11
  }
@@ -0,0 +1,12 @@
1
+ description: Prepares the repo for a typical CI job
2
+
3
+ name: Prepare
4
+
5
+ runs:
6
+ steps:
7
+ - uses: actions/setup-node@v4
8
+ with:
9
+ node-version: '18'
10
+ - run: npm ci
11
+ shell: bash
12
+ using: composite
@@ -0,0 +1,15 @@
1
+ jobs:
2
+ format:
3
+ runs-on: ubuntu-latest
4
+ steps:
5
+ - uses: actions/checkout@v4
6
+ - uses: ./.github/actions/prepare
7
+ - run: npm run format -- --check
8
+
9
+ name: Format
10
+
11
+ on:
12
+ pull_request: ~
13
+ push:
14
+ branches:
15
+ - main
@@ -0,0 +1,15 @@
1
+ jobs:
2
+ lint:
3
+ runs-on: ubuntu-latest
4
+ steps:
5
+ - uses: actions/checkout@v4
6
+ - uses: ./.github/actions/prepare
7
+ - run: npm run lint
8
+
9
+ name: Lint
10
+
11
+ on:
12
+ pull_request: ~
13
+ push:
14
+ branches:
15
+ - main
@@ -3,10 +3,7 @@ jobs:
3
3
  runs-on: ubuntu-latest
4
4
  steps:
5
5
  - uses: actions/checkout@v4
6
- - uses: actions/setup-node@v3
7
- with:
8
- node-version: 18
9
- - run: npm ci
6
+ - uses: ./.github/actions/prepare
10
7
  - run: npm run test
11
8
 
12
9
  name: Test
@@ -0,0 +1,15 @@
1
+ jobs:
2
+ tsc:
3
+ runs-on: ubuntu-latest
4
+ steps:
5
+ - uses: actions/checkout@v4
6
+ - uses: ./.github/actions/prepare
7
+ - run: npm run tsc
8
+
9
+ name: Type Check
10
+
11
+ on:
12
+ pull_request: ~
13
+ push:
14
+ branches:
15
+ - main
@@ -0,0 +1,3 @@
1
+ {
2
+ "recommendations": ["dbaeumer.vscode-eslint"]
3
+ }
@@ -1,17 +1,16 @@
1
1
  {
2
- // Use IntelliSense to learn about possible attributes.
3
- // Hover to view descriptions of existing attributes.
4
- // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
- "version": "0.2.0",
6
- "configurations": [
7
- {
8
- "type": "node",
9
- "request": "attach",
10
- "name": "Attach",
11
- "skipFiles": [
12
- "node-internals:*"
13
- ],
14
- "port": 9229
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
  }
@@ -0,0 +1,4 @@
1
+ {
2
+ "eslint.rules.customizations": [{ "rule": "*", "severity": "warn" }],
3
+ "typescript.tsdk": "node_modules/typescript/lib"
4
+ }
package/README.md CHANGED
@@ -2,49 +2,52 @@
2
2
 
3
3
  Rules for valid, consistent, and readable package.json files
4
4
 
5
- ## Installation
6
-
7
- You'll first need to install [ESLint](http://eslint.org):
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
- Next, install `eslint-plugin-package-json`:
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 `package-json` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:
24
-
25
- ```json
26
- {
27
- "plugins": ["package-json"]
28
- }
29
- ```
30
-
31
- Use the prepackaged config by adding an "extends" property, or appending to an existing "extends" property:
32
-
33
- ```json
34
- {
35
- "extends": ["eslint:recommended", "plugin:package-json/recommended"],
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
- ```json
43
- {
44
- "rules": {
45
- "package-json/rule-name": 2
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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
@@ -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=order-properties.d.ts.map
@@ -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,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=sort-collections.d.ts.map
@@ -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,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-package-def.d.ts.map
@@ -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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=order-properties.test.d.ts.map
@@ -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,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ruleTester = void 0;
4
+ const eslint_1 = require("eslint");
5
+ exports.ruleTester = new eslint_1.RuleTester({
6
+ parser: require.resolve('jsonc-eslint-parser')
7
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=sort-collections.test.d.ts.map
@@ -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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=valid-local-dependency.test.d.ts.map
@@ -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":""}