eslint-plugin-package-json 0.3.0 → 0.3.2
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/.github/actions/prepare/action.yml +12 -0
- package/.github/workflows/format.yml +15 -0
- package/.github/workflows/lint-eslint-docs.yml +16 -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 +19 -7
- package/docs/rules/order-properties.md +5 -1
- package/docs/rules/sort-collections.md +5 -1
- package/docs/rules/valid-local-dependency.md +3 -5
- package/docs/rules/valid-package-def.md +3 -5
- package/lib/createRule.d.ts +30 -0
- package/lib/createRule.d.ts.map +1 -0
- package/lib/createRule.js +5 -6
- package/lib/index.d.ts +41 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +19 -17
- package/lib/rules/order-properties.d.ts +6 -0
- package/lib/rules/order-properties.d.ts.map +1 -0
- package/lib/rules/order-properties.js +31 -35
- package/lib/rules/sort-collections.d.ts +6 -0
- package/lib/rules/sort-collections.d.ts.map +1 -0
- package/lib/rules/sort-collections.js +22 -42
- 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-local-dependency.js +29 -48
- package/lib/rules/valid-package-def.d.ts +6 -0
- package/lib/rules/valid-package-def.d.ts.map +1 -0
- package/lib/rules/valid-package-def.js +13 -28
- 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 +223 -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 +17 -16
- package/src/createRule.ts +49 -0
- package/src/index.ts +17 -0
- package/src/rules/order-properties.ts +122 -0
- package/src/rules/sort-collections.ts +96 -0
- package/src/rules/valid-local-dependency.ts +73 -0
- package/src/rules/valid-package-def.ts +45 -0
- package/src/tests/globalSetup.js +7 -0
- package/{tests/lib/rules/order-properties.js → src/tests/rules/order-properties.test.ts} +5 -16
- package/src/tests/rules/ruleTester.ts +17 -0
- package/{tests/lib/rules/sort-collections.js → src/tests/rules/sort-collections.test.ts} +2 -8
- package/{tests/lib/rules/valid-local-dependency.js → src/tests/rules/valid-local-dependency.test.ts} +33 -45
- package/{tests/lib/rules/valid-package-def.js → src/tests/rules/valid-package-def.test.ts} +2 -12
- package/tsconfig.json +13 -0
- package/vitest.config.ts +15 -0
- package/tests/lib/rules/ruleTester.js +0 -7
- /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
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
- run: npm run lint:eslint-docs
|
|
9
|
+
|
|
10
|
+
name: Lint ESLint Docs
|
|
11
|
+
|
|
12
|
+
on:
|
|
13
|
+
pull_request: ~
|
|
14
|
+
push:
|
|
15
|
+
branches:
|
|
16
|
+
- main
|
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,12 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
Rules for valid, consistent, and readable package.json files
|
|
4
4
|
|
|
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
|
+
|
|
5
9
|
## Installation
|
|
6
10
|
|
|
7
11
|
You'll first need to install [ESLint](http://eslint.org) >=8 and `eslint-plugin-package-json`:
|
|
8
12
|
|
|
9
13
|
```shell
|
|
10
|
-
$ npm install eslint eslint-plugin-package-json --save-dev
|
|
14
|
+
$ npm install eslint eslint-plugin-package-json jsonc-eslint-parser --save-dev
|
|
11
15
|
```
|
|
12
16
|
|
|
13
17
|
**Note:** If you installed ESLint globally (using the `-g` flag) then you must also install `eslint-plugin-package-json` globally.
|
|
@@ -22,7 +26,7 @@ module.exports = {
|
|
|
22
26
|
{
|
|
23
27
|
extends: ['plugin:package-json/recommended'],
|
|
24
28
|
files: ['package.json'],
|
|
25
|
-
parser: 'jsonc-eslint-parser'
|
|
29
|
+
parser: 'jsonc-eslint-parser',
|
|
26
30
|
plugins: ['package-json']
|
|
27
31
|
}
|
|
28
32
|
]
|
|
@@ -36,7 +40,7 @@ module.exports = {
|
|
|
36
40
|
overrides: [
|
|
37
41
|
{
|
|
38
42
|
files: ['package.json'],
|
|
39
|
-
parser: 'jsonc-eslint-parser'
|
|
43
|
+
parser: 'jsonc-eslint-parser',
|
|
40
44
|
plugins: ['package-json'],
|
|
41
45
|
rules: {
|
|
42
46
|
'package-json/valid-package-def': 'error'
|
|
@@ -48,10 +52,18 @@ module.exports = {
|
|
|
48
52
|
|
|
49
53
|
## Supported Rules
|
|
50
54
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
<!-- begin auto-generated rules list -->
|
|
56
|
+
|
|
57
|
+
🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).
|
|
58
|
+
|
|
59
|
+
| Name | Description | 🔧 |
|
|
60
|
+
| :------------------------------------------------------------- | :-------------------------------------------------------------------------------------- | :- |
|
|
61
|
+
| [order-properties](docs/rules/order-properties.md) | Package properties must be declared in standard order | 🔧 |
|
|
62
|
+
| [sort-collections](docs/rules/sort-collections.md) | Dependencies, scripts, and configuration values must be declared in alphabetical order. | 🔧 |
|
|
63
|
+
| [valid-local-dependency](docs/rules/valid-local-dependency.md) | Checks existence of local dependencies in the package.json | |
|
|
64
|
+
| [valid-package-def](docs/rules/valid-package-def.md) | Enforce that package.json has all properties required by NPM spec | |
|
|
65
|
+
|
|
66
|
+
<!-- end auto-generated rules list -->
|
|
55
67
|
|
|
56
68
|
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.
|
|
57
69
|
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
# Package properties must be declared in standard order (order-properties)
|
|
1
|
+
# Package properties must be declared in standard order (`package-json/order-properties`)
|
|
2
|
+
|
|
3
|
+
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
|
|
4
|
+
|
|
5
|
+
<!-- end auto-generated rule header -->
|
|
2
6
|
|
|
3
7
|
A conventional order exists for `package.json` top-level properties. NPM does
|
|
4
8
|
not enforce this order, but for consistency and readability, this rule can
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
# Dependencies, scripts, and configuration values must be declared in alphabetical order
|
|
1
|
+
# Dependencies, scripts, and configuration values must be declared in alphabetical order (`package-json/sort-collections`)
|
|
2
|
+
|
|
3
|
+
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
|
|
4
|
+
|
|
5
|
+
<!-- end auto-generated rule header -->
|
|
2
6
|
|
|
3
7
|
Whenever NPM changes package dependencies through `npm install`, it lexically sorts (that is, alphabetizes by package name) all dependencies in `package.json`. Nevertheless, sometimes a developer will manually update `package.json` and leave dependencies out of order, leading to "noise" in changesets when a later change re-sorts the packages. This rule aims to keep the dependency collections sorted in every commit.
|
|
4
8
|
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Checks existence of local dependencies in the package.json (`package-json/valid-local-dependency`)
|
|
2
|
+
|
|
3
|
+
<!-- end auto-generated rule header -->
|
|
2
4
|
|
|
3
5
|
## Rule Details
|
|
4
6
|
|
|
@@ -19,7 +21,3 @@ Examples of **correct** code for this rule:
|
|
|
19
21
|
"some-package": "link:../folder",
|
|
20
22
|
}
|
|
21
23
|
```
|
|
22
|
-
|
|
23
|
-
### Options
|
|
24
|
-
|
|
25
|
-
This rule has no options.
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
# Enforce that package.json has all properties required by NPM spec (valid-package-def)
|
|
1
|
+
# Enforce that package.json has all properties required by NPM spec (`package-json/valid-package-def`)
|
|
2
|
+
|
|
3
|
+
<!-- end auto-generated rule header -->
|
|
2
4
|
|
|
3
5
|
NPM issues warnings after install if the `package.json` has a missing or
|
|
4
6
|
invalid required property. This rule uses [`package-json-validator`][pjv] to
|
|
@@ -43,10 +45,6 @@ Examples of **correct** code for this rule:
|
|
|
43
45
|
}
|
|
44
46
|
```
|
|
45
47
|
|
|
46
|
-
### Options
|
|
47
|
-
|
|
48
|
-
This rule has no options.
|
|
49
|
-
|
|
50
48
|
## When Not To Use It
|
|
51
49
|
|
|
52
50
|
NPM may complain, but it works perfectly with many package files that do not
|
|
@@ -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/createRule.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createRule = void 0;
|
|
4
|
+
const isPackageJson = (filePath) => filePath.endsWith('/package.json') || filePath === 'package.json';
|
|
4
5
|
function createRule(rule) {
|
|
5
6
|
return {
|
|
6
7
|
...rule,
|
|
@@ -8,10 +9,8 @@ function createRule(rule) {
|
|
|
8
9
|
if (!isPackageJson(context.filename)) {
|
|
9
10
|
return {};
|
|
10
11
|
}
|
|
11
|
-
|
|
12
12
|
return rule.create(context);
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
module.exports.createRule = createRule;
|
|
16
|
+
exports.createRule = createRule;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export declare const rules: {
|
|
2
|
+
'order-properties': {
|
|
3
|
+
create(context: import("./createRule").PackageJsonRuleContext): import("jsonc-eslint-parser").RuleListener;
|
|
4
|
+
meta: import("eslint").Rule.RuleMetaData;
|
|
5
|
+
};
|
|
6
|
+
'sort-collections': {
|
|
7
|
+
create(context: import("./createRule").PackageJsonRuleContext): import("jsonc-eslint-parser").RuleListener;
|
|
8
|
+
meta: import("eslint").Rule.RuleMetaData;
|
|
9
|
+
};
|
|
10
|
+
'valid-local-dependency': {
|
|
11
|
+
create(context: import("./createRule").PackageJsonRuleContext): import("jsonc-eslint-parser").RuleListener;
|
|
12
|
+
meta: import("eslint").Rule.RuleMetaData;
|
|
13
|
+
};
|
|
14
|
+
'valid-package-def': {
|
|
15
|
+
create(context: import("./createRule").PackageJsonRuleContext): import("jsonc-eslint-parser").RuleListener;
|
|
16
|
+
meta: import("eslint").Rule.RuleMetaData;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export declare const configs: {
|
|
20
|
+
recommended: {
|
|
21
|
+
rules: {
|
|
22
|
+
'order-properties': {
|
|
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
|
+
};
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;CAKjB,CAAC;AAEF,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;CAInB,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
+
exports.configs = exports.rules = void 0;
|
|
7
|
+
const order_properties_1 = __importDefault(require("./rules/order-properties"));
|
|
8
|
+
const sort_collections_1 = __importDefault(require("./rules/sort-collections"));
|
|
9
|
+
const valid_local_dependency_1 = __importDefault(require("./rules/valid-local-dependency"));
|
|
10
|
+
const valid_package_def_1 = __importDefault(require("./rules/valid-package-def"));
|
|
11
|
+
exports.rules = {
|
|
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
|
|
16
|
+
};
|
|
17
|
+
exports.configs = {
|
|
18
|
+
recommended: {
|
|
19
|
+
rules: exports.rules
|
|
18
20
|
}
|
|
19
21
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order-properties.d.ts","sourceRoot":"","sources":["../../src/rules/order-properties.ts"],"names":[],"mappings":";;;;AAmCA,wBAsFG"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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_package_json_1 = __importDefault(require("sort-package-json"));
|
|
7
|
+
const createRule_js_1 = require("../createRule.js");
|
|
9
8
|
const standardOrderLegacy = [
|
|
10
9
|
'name',
|
|
11
10
|
'version',
|
|
@@ -36,12 +35,10 @@ const standardOrderLegacy = [
|
|
|
36
35
|
'os',
|
|
37
36
|
'cpu'
|
|
38
37
|
];
|
|
39
|
-
|
|
40
|
-
module.exports = createRule({
|
|
38
|
+
exports.default = (0, createRule_js_1.createRule)({
|
|
41
39
|
meta: {
|
|
42
40
|
docs: {
|
|
43
|
-
description:
|
|
44
|
-
'Package properties must be declared in standard order',
|
|
41
|
+
description: 'Package properties must be declared in standard order',
|
|
45
42
|
category: 'Best Practices',
|
|
46
43
|
recommended: true
|
|
47
44
|
},
|
|
@@ -68,41 +65,40 @@ module.exports = createRule({
|
|
|
68
65
|
}
|
|
69
66
|
]
|
|
70
67
|
},
|
|
71
|
-
|
|
72
68
|
create(context) {
|
|
73
69
|
return {
|
|
74
70
|
'Program:exit'() {
|
|
75
71
|
const { ast, text } = context.sourceCode;
|
|
76
|
-
|
|
77
72
|
const options = context.options[0] || { order: 'legacy' };
|
|
78
|
-
const requiredOrder =
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
: {
|
|
87
|
-
sortOrder: requiredOrder
|
|
88
|
-
}
|
|
89
|
-
);
|
|
73
|
+
const requiredOrder = options.order === 'legacy'
|
|
74
|
+
? standardOrderLegacy
|
|
75
|
+
: options.order;
|
|
76
|
+
const orderedSource = (0, sort_package_json_1.default)(JSON.parse(text), requiredOrder === 'sort-package-json'
|
|
77
|
+
? undefined
|
|
78
|
+
: {
|
|
79
|
+
sortOrder: requiredOrder
|
|
80
|
+
});
|
|
90
81
|
const orderedKeys = Object.keys(orderedSource);
|
|
91
|
-
|
|
92
82
|
const { properties } = ast.body[0].expression;
|
|
93
|
-
|
|
83
|
+
// console.log({ orderedSource });
|
|
94
84
|
for (let i = 0; i < properties.length; i += 1) {
|
|
85
|
+
// console.log(
|
|
86
|
+
// properties.map(p => p.value),
|
|
87
|
+
// 'vs',
|
|
88
|
+
// orderedKeys
|
|
89
|
+
// );
|
|
95
90
|
if (properties[i].value !== orderedKeys[i]) {
|
|
91
|
+
// console.log(
|
|
92
|
+
// 'JOSH SAYS HI',
|
|
93
|
+
// properties[i].value.value,
|
|
94
|
+
// orderedKeys[i]
|
|
95
|
+
// );
|
|
96
96
|
context.report({
|
|
97
97
|
node: context.sourceCode.ast,
|
|
98
|
-
message:
|
|
99
|
-
'Package top-level properties are not ordered in the npm standard way. Run the ESLint auto-fixer to correct.',
|
|
98
|
+
message: 'Package top-level properties are not ordered in the npm standard way. Run the ESLint auto-fixer to correct.',
|
|
100
99
|
fix(fixer) {
|
|
101
|
-
return fixer.replaceText(
|
|
102
|
-
|
|
103
|
-
JSON.stringify(orderedSource, null, 2) +
|
|
104
|
-
`\n`
|
|
105
|
-
);
|
|
100
|
+
return fixer.replaceText(context.sourceCode.ast, JSON.stringify(orderedSource, null, 2) +
|
|
101
|
+
`\n`);
|
|
106
102
|
}
|
|
107
103
|
});
|
|
108
104
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sort-collections.d.ts","sourceRoot":"","sources":["../../src/rules/sort-collections.ts"],"names":[],"mappings":";;;;AAaA,wBAkFG"}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
//------------------------------------------------------------------------------
|
|
6
|
-
// Rule Definition
|
|
7
|
-
//------------------------------------------------------------------------------
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const createRule_js_1 = require("../createRule.js");
|
|
8
4
|
const defaultCollections = [
|
|
9
5
|
'scripts',
|
|
10
6
|
'devDependencies',
|
|
@@ -12,11 +8,10 @@ const defaultCollections = [
|
|
|
12
8
|
'peerDependencies',
|
|
13
9
|
'config'
|
|
14
10
|
];
|
|
15
|
-
|
|
11
|
+
exports.default = (0, createRule_js_1.createRule)({
|
|
16
12
|
meta: {
|
|
17
13
|
docs: {
|
|
18
|
-
description:
|
|
19
|
-
'Dependencies, scripts, and configuration values must be declared in alphabetical order.',
|
|
14
|
+
description: 'Dependencies, scripts, and configuration values must be declared in alphabetical order.',
|
|
20
15
|
category: 'Best Practices',
|
|
21
16
|
recommended: true
|
|
22
17
|
},
|
|
@@ -30,51 +25,36 @@ module.exports = createRule({
|
|
|
30
25
|
}
|
|
31
26
|
]
|
|
32
27
|
},
|
|
33
|
-
|
|
34
28
|
create(context) {
|
|
35
29
|
const toSort = context.options[0] || defaultCollections;
|
|
36
30
|
return {
|
|
37
31
|
'JSONProperty:exit'(node) {
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
toSort.includes(
|
|
42
|
-
) {
|
|
32
|
+
const { key, value } = node;
|
|
33
|
+
const collection = value;
|
|
34
|
+
if (collection.type === 'JSONObjectExpression' &&
|
|
35
|
+
toSort.includes(key.value)) {
|
|
43
36
|
const currentOrder = collection.properties;
|
|
44
37
|
const desiredOrder = currentOrder
|
|
45
38
|
.slice()
|
|
46
|
-
.sort((a, b) =>
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
) {
|
|
39
|
+
.sort((a, b) => a.key.value >
|
|
40
|
+
b.key.value
|
|
41
|
+
? 1
|
|
42
|
+
: -1);
|
|
43
|
+
if (currentOrder.some((property, i) => desiredOrder[i] !== property)) {
|
|
52
44
|
context.report({
|
|
53
|
-
node,
|
|
45
|
+
node: node,
|
|
54
46
|
loc: collection.loc,
|
|
55
47
|
message: 'Package {{ key }} are not alphabetized',
|
|
56
48
|
data: {
|
|
57
|
-
key:
|
|
49
|
+
key: key.value
|
|
58
50
|
},
|
|
59
51
|
fix(fixer) {
|
|
60
|
-
return fixer.replaceText(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
] = JSON.parse(
|
|
67
|
-
context
|
|
68
|
-
.getSourceCode()
|
|
69
|
-
.getText(property.value)
|
|
70
|
-
);
|
|
71
|
-
return out;
|
|
72
|
-
}, {}),
|
|
73
|
-
null,
|
|
74
|
-
2
|
|
75
|
-
)
|
|
76
|
-
.split('\n')
|
|
77
|
-
.join('\n ') // nest indents
|
|
52
|
+
return fixer.replaceText(collection, JSON.stringify(desiredOrder.reduce((out, property) => {
|
|
53
|
+
out[property.key.value] = JSON.parse(context.sourceCode.getText(property.value));
|
|
54
|
+
return out;
|
|
55
|
+
}, {}), null, 2)
|
|
56
|
+
.split('\n')
|
|
57
|
+
.join('\n ') // nest indents
|
|
78
58
|
);
|
|
79
59
|
}
|
|
80
60
|
});
|
|
@@ -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"}
|