eslint-plugin-package-json 1.5.0 → 1.6.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/README.md +107 -106
- package/{lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/definitions/jsonSchema.d.mts → dist/createRule-29pC9RoP.d.mts} +49 -4
- package/dist/experimental/index.d.mts +68 -0
- package/{lib/experimental/plugin.mjs → dist/experimental/index.mjs} +10 -5
- package/dist/index.d.mts +99 -0
- package/{lib → dist}/index.mjs +1 -1
- package/dist/plugin-C-Z8sf5g.mjs +1737 -0
- package/package.json +33 -27
- package/lib/createRule.d.mts +0 -59
- package/lib/createRule.mjs +0 -24
- package/lib/experimental/index.d.mts +0 -34
- package/lib/experimental/index.mjs +0 -7
- package/lib/experimental/plugin.d.mts +0 -40
- package/lib/index.d.mts +0 -49
- package/lib/node_modules/.pnpm/@types_estree@1.0.8/node_modules/@types/estree/index.d.mts +0 -438
- package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/definitions/deserializationPattern.d.mts +0 -7
- package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/definitions/fromSchemaOptions.d.mts +0 -20
- package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/index.d.mts +0 -11
- package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-options.d.mts +0 -16
- package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/allOf.d.mts +0 -13
- package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/anyOf.d.mts +0 -14
- package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/array.d.mts +0 -58
- package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/const.d.mts +0 -14
- package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/deserialize.d.mts +0 -13
- package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/enum.d.mts +0 -14
- package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/ifThenElse.d.mts +0 -20
- package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/index.d.mts +0 -34
- package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/multipleTypes.d.mts +0 -14
- package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/not.d.mts +0 -20
- package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/nullable.d.mts +0 -14
- package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/object.d.mts +0 -34
- package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/oneOf.d.mts +0 -14
- package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/references/external.d.mts +0 -22
- package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/references/index.d.mts +0 -13
- package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/references/internal.d.mts +0 -8
- package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/references/utils.d.mts +0 -12
- package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/singleType.d.mts +0 -24
- package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/parse-schema/utils.d.mts +0 -20
- package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/type-utils/and.d.mts +0 -4
- package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/type-utils/extends.d.mts +0 -4
- package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/type-utils/get.d.mts +0 -4
- package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/type-utils/join.d.mts +0 -4
- package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/type-utils/not.d.mts +0 -4
- package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/type-utils/pop.d.mts +0 -4
- package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/type-utils/split.d.mts +0 -7
- package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/type-utils/tail.d.mts +0 -4
- package/lib/node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/type-utils/writable.d.mts +0 -4
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/any.d.mts +0 -20
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/array.d.mts +0 -28
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/const.d.mts +0 -25
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/enum.d.mts +0 -25
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/exclusion/any.d.mts +0 -16
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/exclusion/array.d.mts +0 -20
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/exclusion/const.d.mts +0 -28
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/exclusion/enum.d.mts +0 -23
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/exclusion/index.d.mts +0 -24
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/exclusion/object.d.mts +0 -44
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/exclusion/primitive.d.mts +0 -16
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/exclusion/tuple.d.mts +0 -43
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/exclusion/union.d.mts +0 -13
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/exclusion/utils.d.mts +0 -35
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/intersection/any.d.mts +0 -23
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/intersection/array.d.mts +0 -24
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/intersection/const.d.mts +0 -34
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/intersection/enum.d.mts +0 -26
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/intersection/index.d.mts +0 -24
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/intersection/object.d.mts +0 -25
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/intersection/primitive.d.mts +0 -23
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/intersection/tuple.d.mts +0 -26
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/intersection/union.d.mts +0 -17
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/intersection/utils.d.mts +0 -10
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/never.d.mts +0 -9
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/object.d.mts +0 -49
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/primitive.d.mts +0 -26
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/resolve.d.mts +0 -22
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/tuple.d.mts +0 -36
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/type.d.mts +0 -18
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/union.d.mts +0 -23
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/meta-types/utils.d.mts +0 -7
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/and.d.mts +0 -4
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/extends.d.mts +0 -7
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/if.d.mts +0 -4
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/intersectUnion.d.mts +0 -4
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/isNever.d.mts +0 -4
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/merge.d.mts +0 -6
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/not.d.mts +0 -4
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/or.d.mts +0 -4
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/prettify.d.mts +0 -6
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/tail.d.mts +0 -4
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/unionLast.d.mts +0 -6
- package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/unionPop.d.mts +0 -6
- package/lib/plugin.d.mts +0 -56
- package/lib/plugin.mjs +0 -93
- package/lib/rules/bin-name-casing.d.mts +0 -6
- package/lib/rules/bin-name-casing.mjs +0 -41
- package/lib/rules/exports-subpaths-style.d.mts +0 -18
- package/lib/rules/exports-subpaths-style.mjs +0 -71
- package/lib/rules/no-empty-fields.d.mts +0 -20
- package/lib/rules/no-empty-fields.mjs +0 -90
- package/lib/rules/no-local-dependencies.d.mts +0 -17
- package/lib/rules/no-local-dependencies.mjs +0 -47
- package/lib/rules/no-redundant-files.d.mts +0 -6
- package/lib/rules/no-redundant-files.mjs +0 -100
- package/lib/rules/no-redundant-publishConfig.d.mts +0 -6
- package/lib/rules/no-redundant-publishConfig.mjs +0 -50
- package/lib/rules/order-properties.d.mts +0 -25
- package/lib/rules/order-properties.mjs +0 -64
- package/lib/rules/repository-shorthand.d.mts +0 -18
- package/lib/rules/repository-shorthand.mjs +0 -111
- package/lib/rules/require-attribution.d.mts +0 -22
- package/lib/rules/require-attribution.mjs +0 -91
- package/lib/rules/require-properties.d.mts +0 -22
- package/lib/rules/require-properties.mjs +0 -74
- package/lib/rules/restrict-dependency-ranges.d.mts +0 -92
- package/lib/rules/restrict-dependency-ranges.mjs +0 -147
- package/lib/rules/restrict-private-properties.d.mts +0 -20
- package/lib/rules/restrict-private-properties.mjs +0 -53
- package/lib/rules/restrict-top-level-properties.d.mts +0 -39
- package/lib/rules/restrict-top-level-properties.mjs +0 -73
- package/lib/rules/scripts-name-casing.d.mts +0 -6
- package/lib/rules/scripts-name-casing.mjs +0 -44
- package/lib/rules/sort-collections.d.mts +0 -35
- package/lib/rules/sort-collections.mjs +0 -111
- package/lib/rules/specify-peers-locally.d.mts +0 -6
- package/lib/rules/specify-peers-locally.mjs +0 -63
- package/lib/rules/unique-dependencies.d.mts +0 -6
- package/lib/rules/unique-dependencies.mjs +0 -87
- package/lib/rules/valid-author.d.mts +0 -6
- package/lib/rules/valid-author.mjs +0 -59
- package/lib/rules/valid-peerDependenciesMeta-relationship.d.mts +0 -6
- package/lib/rules/valid-peerDependenciesMeta-relationship.mjs +0 -50
- package/lib/rules/valid-properties.d.mts +0 -9
- package/lib/rules/valid-properties.mjs +0 -57
- package/lib/rules/valid-repository-directory.d.mts +0 -6
- package/lib/rules/valid-repository-directory.mjs +0 -73
- package/lib/types/estree.d.mts +0 -8
- package/lib/utils/createSimpleRequirePropertyRule.d.mts +0 -48
- package/lib/utils/createSimpleRequirePropertyRule.mjs +0 -62
- package/lib/utils/createSimpleValidPropertyRule.d.mts +0 -17
- package/lib/utils/createSimpleValidPropertyRule.mjs +0 -57
- package/lib/utils/findPropertyWithKeyValue.d.mts +0 -10
- package/lib/utils/findPropertyWithKeyValue.mjs +0 -6
- package/lib/utils/formatErrors.d.mts +0 -9
- package/lib/utils/formatErrors.mjs +0 -12
- package/lib/utils/git/getGitAuthor.d.mts +0 -8
- package/lib/utils/git/getGitAuthor.mjs +0 -29
- package/lib/utils/git/index.d.mts +0 -2
- package/lib/utils/git/index.mjs +0 -2
- package/lib/utils/predicates/index.d.mts +0 -4
- package/lib/utils/predicates/index.mjs +0 -4
- package/lib/utils/predicates/isJSONStringLiteral.d.mts +0 -6
- package/lib/utils/predicates/isJSONStringLiteral.mjs +0 -6
- package/lib/utils/predicates/isNotNullish.d.mts +0 -4
- package/lib/utils/predicates/isNotNullish.mjs +0 -6
- package/lib/utils/predicates/isPackageJson.d.mts +0 -4
- package/lib/utils/predicates/isPackageJson.mjs +0 -4
package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/extends.d.mts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
//#region node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/extends.d.ts
|
|
2
|
-
declare type DoesExtend<TYPE_A, TYPE_B> = [TYPE_A] extends [TYPE_B] ? true : false;
|
|
3
|
-
declare type ArrayKeys = keyof [];
|
|
4
|
-
declare type IsObject<TYPE> = TYPE extends object ? ArrayKeys extends Extract<keyof TYPE, ArrayKeys> ? false : true : false;
|
|
5
|
-
declare type IsArray<TYPE> = TYPE extends object ? ArrayKeys extends Extract<keyof TYPE, ArrayKeys> ? true : false : false;
|
|
6
|
-
//#endregion
|
|
7
|
-
export { DoesExtend, IsArray, IsObject };
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
//#region node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/intersectUnion.d.ts
|
|
2
|
-
declare type IntersectUnion<UNION> = (UNION extends unknown ? (arg: UNION) => void : never) extends ((arg: infer INTERSECTION) => void) ? INTERSECTION : never;
|
|
3
|
-
//#endregion
|
|
4
|
-
export { IntersectUnion };
|
package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/merge.d.mts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { IsArray, IsObject } from "./extends.mjs";
|
|
2
|
-
|
|
3
|
-
//#region node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/merge.d.ts
|
|
4
|
-
declare type DeepMergeUnsafe<TYPE_A, TYPE_B> = IsObject<TYPE_A> extends true ? IsObject<TYPE_B> extends true ? { [KEY in keyof (TYPE_A & TYPE_B)]: KEY extends keyof TYPE_B ? KEY extends keyof TYPE_A ? DeepMergeUnsafe<TYPE_A[KEY], TYPE_B[KEY]> : TYPE_B[KEY] : KEY extends keyof TYPE_A ? TYPE_A[KEY] : never } : TYPE_B : IsArray<TYPE_A> extends true ? IsArray<TYPE_B> extends true ? TYPE_B extends unknown[] ? [...(TYPE_A extends unknown[] ? TYPE_A : never), TYPE_B] : never : TYPE_B : TYPE_B;
|
|
5
|
-
//#endregion
|
|
6
|
-
export { DeepMergeUnsafe };
|
package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/prettify.d.mts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { IsObject } from "./extends.mjs";
|
|
2
|
-
|
|
3
|
-
//#region node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/prettify.d.ts
|
|
4
|
-
declare type Prettify<TYPE> = IsObject<TYPE> extends true ? { [KEY in keyof TYPE]: KEY extends keyof TYPE ? TYPE[KEY] : never } : TYPE;
|
|
5
|
-
//#endregion
|
|
6
|
-
export { Prettify };
|
package/lib/node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/unionLast.d.mts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { IntersectUnion } from "./intersectUnion.mjs";
|
|
2
|
-
|
|
3
|
-
//#region node_modules/.pnpm/ts-algebra@2.0.0/node_modules/ts-algebra/lib/utils/unionLast.d.ts
|
|
4
|
-
declare type UnionLast<UNION> = IntersectUnion<UNION extends unknown ? (x: UNION) => void : never> extends ((x: infer LAST) => void) ? LAST : never;
|
|
5
|
-
//#endregion
|
|
6
|
-
export { UnionLast };
|
package/lib/plugin.d.mts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { JSONSchema } from "./node_modules/.pnpm/json-schema-to-ts@3.1.1/node_modules/json-schema-to-ts/lib/types/definitions/jsonSchema.mjs";
|
|
2
|
-
import { PackageJsonRuleModule } from "./createRule.mjs";
|
|
3
|
-
import * as parserJsonc from "jsonc-eslint-parser";
|
|
4
|
-
import { ESLint } from "eslint";
|
|
5
|
-
|
|
6
|
-
//#region src/plugin.d.ts
|
|
7
|
-
declare const plugin: {
|
|
8
|
-
configs: {
|
|
9
|
-
recommended: {
|
|
10
|
-
files: string[];
|
|
11
|
-
languageOptions: {
|
|
12
|
-
parser: typeof parserJsonc;
|
|
13
|
-
};
|
|
14
|
-
name: string;
|
|
15
|
-
plugins: {
|
|
16
|
-
readonly 'package-json': ESLint.Plugin;
|
|
17
|
-
};
|
|
18
|
-
rules: {
|
|
19
|
-
[k: string]: "error";
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
'recommended-publishable': {
|
|
23
|
-
files: string[];
|
|
24
|
-
languageOptions: {
|
|
25
|
-
parser: typeof parserJsonc;
|
|
26
|
-
};
|
|
27
|
-
name: string;
|
|
28
|
-
plugins: {
|
|
29
|
-
readonly 'package-json': ESLint.Plugin;
|
|
30
|
-
};
|
|
31
|
-
rules: {
|
|
32
|
-
[x: string]: "error";
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
stylistic: {
|
|
36
|
-
files: string[];
|
|
37
|
-
languageOptions: {
|
|
38
|
-
parser: typeof parserJsonc;
|
|
39
|
-
};
|
|
40
|
-
name: string;
|
|
41
|
-
plugins: {
|
|
42
|
-
readonly 'package-json': ESLint.Plugin;
|
|
43
|
-
};
|
|
44
|
-
rules: {
|
|
45
|
-
[k: string]: "error";
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
meta: {
|
|
50
|
-
name: string;
|
|
51
|
-
version: string;
|
|
52
|
-
};
|
|
53
|
-
rules: Record<string, PackageJsonRuleModule<unknown[], JSONSchema[]>>;
|
|
54
|
-
};
|
|
55
|
-
//#endregion
|
|
56
|
-
export { plugin };
|
package/lib/plugin.mjs
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { rule } from "./rules/bin-name-casing.mjs";
|
|
2
|
-
import { rule as rule$1 } from "./rules/exports-subpaths-style.mjs";
|
|
3
|
-
import { rule as rule$2 } from "./rules/no-empty-fields.mjs";
|
|
4
|
-
import { rule as rule$3 } from "./rules/no-local-dependencies.mjs";
|
|
5
|
-
import { rule as rule$4 } from "./rules/no-redundant-files.mjs";
|
|
6
|
-
import { rule as rule$5 } from "./rules/no-redundant-publishConfig.mjs";
|
|
7
|
-
import { rule as rule$6 } from "./rules/order-properties.mjs";
|
|
8
|
-
import { rule as rule$7 } from "./rules/repository-shorthand.mjs";
|
|
9
|
-
import { rule as rule$8 } from "./rules/require-attribution.mjs";
|
|
10
|
-
import { rules as rules$1 } from "./rules/require-properties.mjs";
|
|
11
|
-
import { rule as rule$9 } from "./rules/restrict-dependency-ranges.mjs";
|
|
12
|
-
import { rule as rule$10 } from "./rules/restrict-private-properties.mjs";
|
|
13
|
-
import { rule as rule$11 } from "./rules/restrict-top-level-properties.mjs";
|
|
14
|
-
import { rule as rule$12 } from "./rules/scripts-name-casing.mjs";
|
|
15
|
-
import { rule as rule$13 } from "./rules/sort-collections.mjs";
|
|
16
|
-
import { rule as rule$14 } from "./rules/specify-peers-locally.mjs";
|
|
17
|
-
import { rule as rule$15 } from "./rules/unique-dependencies.mjs";
|
|
18
|
-
import { rule as rule$16 } from "./rules/valid-author.mjs";
|
|
19
|
-
import { rule as rule$17 } from "./rules/valid-peerDependenciesMeta-relationship.mjs";
|
|
20
|
-
import { rules as rules$2 } from "./rules/valid-properties.mjs";
|
|
21
|
-
import { rule as rule$18 } from "./rules/valid-repository-directory.mjs";
|
|
22
|
-
import { createRequire } from "node:module";
|
|
23
|
-
import * as parserJsonc from "jsonc-eslint-parser";
|
|
24
|
-
//#region src/plugin.ts
|
|
25
|
-
const require = createRequire(import.meta.url);
|
|
26
|
-
const rules = {
|
|
27
|
-
"bin-name-casing": rule,
|
|
28
|
-
"exports-subpaths-style": rule$1,
|
|
29
|
-
"no-empty-fields": rule$2,
|
|
30
|
-
"no-local-dependencies": rule$3,
|
|
31
|
-
"no-redundant-files": rule$4,
|
|
32
|
-
"no-redundant-publishConfig": rule$5,
|
|
33
|
-
"order-properties": rule$6,
|
|
34
|
-
"require-attribution": rule$8,
|
|
35
|
-
...rules$1,
|
|
36
|
-
"repository-shorthand": rule$7,
|
|
37
|
-
"restrict-dependency-ranges": rule$9,
|
|
38
|
-
"restrict-private-properties": rule$10,
|
|
39
|
-
"restrict-top-level-properties": rule$11,
|
|
40
|
-
"scripts-name-casing": rule$12,
|
|
41
|
-
"sort-collections": rule$13,
|
|
42
|
-
"specify-peers-locally": rule$14,
|
|
43
|
-
"unique-dependencies": rule$15,
|
|
44
|
-
"valid-author": rule$16,
|
|
45
|
-
...rules$2,
|
|
46
|
-
"valid-peerDependenciesMeta-relationship": rule$17,
|
|
47
|
-
"valid-repository-directory": rule$18
|
|
48
|
-
};
|
|
49
|
-
const recommendedRules = { ...Object.fromEntries(Object.entries(rules).filter(([, rule]) => rule.meta.docs?.recommended).map(([name]) => ["package-json/" + name, "error"])) };
|
|
50
|
-
const recommendedPublishableRules = {
|
|
51
|
-
...recommendedRules,
|
|
52
|
-
...Object.fromEntries(Object.entries(rules).filter(([, rule]) => rule.meta.docs?.category === "Publishable").map(([name]) => ["package-json/" + name, "error"]))
|
|
53
|
-
};
|
|
54
|
-
const stylisticRules = { ...Object.fromEntries(Object.entries(rules).filter(([, rule]) => rule.meta.docs?.category === "Stylistic").map(([name]) => ["package-json/" + name, "error"])) };
|
|
55
|
-
const { name, version } = require("../package.json");
|
|
56
|
-
const plugin = {
|
|
57
|
-
configs: {
|
|
58
|
-
recommended: {
|
|
59
|
-
files: ["**/package.json"],
|
|
60
|
-
languageOptions: { parser: parserJsonc },
|
|
61
|
-
name: "package-json/recommended",
|
|
62
|
-
plugins: { get "package-json"() {
|
|
63
|
-
return plugin;
|
|
64
|
-
} },
|
|
65
|
-
rules: recommendedRules
|
|
66
|
-
},
|
|
67
|
-
"recommended-publishable": {
|
|
68
|
-
files: ["**/package.json"],
|
|
69
|
-
languageOptions: { parser: parserJsonc },
|
|
70
|
-
name: "package-json/recommended-publishable",
|
|
71
|
-
plugins: { get "package-json"() {
|
|
72
|
-
return plugin;
|
|
73
|
-
} },
|
|
74
|
-
rules: recommendedPublishableRules
|
|
75
|
-
},
|
|
76
|
-
stylistic: {
|
|
77
|
-
files: ["**/package.json"],
|
|
78
|
-
languageOptions: { parser: parserJsonc },
|
|
79
|
-
name: "package-json/stylistic",
|
|
80
|
-
plugins: { get "package-json"() {
|
|
81
|
-
return plugin;
|
|
82
|
-
} },
|
|
83
|
-
rules: stylisticRules
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
meta: {
|
|
87
|
-
name,
|
|
88
|
-
version
|
|
89
|
-
},
|
|
90
|
-
rules
|
|
91
|
-
};
|
|
92
|
-
//#endregion
|
|
93
|
-
export { plugin };
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { createRule } from "../createRule.mjs";
|
|
2
|
-
import { kebabCase } from "change-case";
|
|
3
|
-
//#region src/rules/bin-name-casing.ts
|
|
4
|
-
const rule = createRule({
|
|
5
|
-
create(context) {
|
|
6
|
-
return { "Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.value=bin]"(node) {
|
|
7
|
-
if (node.value.type === "JSONObjectExpression") for (const property of node.value.properties) {
|
|
8
|
-
const key = property.key;
|
|
9
|
-
const kebabCaseKey = kebabCase(key.value);
|
|
10
|
-
if (kebabCaseKey !== key.value) context.report({
|
|
11
|
-
data: { property: key.value },
|
|
12
|
-
messageId: "invalidCase",
|
|
13
|
-
node: key,
|
|
14
|
-
suggest: [{
|
|
15
|
-
data: { property: key.value },
|
|
16
|
-
fix: (fixer) => {
|
|
17
|
-
return fixer.replaceText(key, JSON.stringify(kebabCaseKey));
|
|
18
|
-
},
|
|
19
|
-
messageId: "convertToKebabCase"
|
|
20
|
-
}]
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
} };
|
|
24
|
-
},
|
|
25
|
-
meta: {
|
|
26
|
-
docs: {
|
|
27
|
-
category: "Stylistic",
|
|
28
|
-
description: "Enforce that names for bin properties are in kebab case."
|
|
29
|
-
},
|
|
30
|
-
hasSuggestions: true,
|
|
31
|
-
messages: {
|
|
32
|
-
convertToKebabCase: "Convert {{ property }} to kebab case.",
|
|
33
|
-
invalidCase: "Command name {{ property }} should be in kebab case."
|
|
34
|
-
},
|
|
35
|
-
schema: [],
|
|
36
|
-
type: "suggestion"
|
|
37
|
-
},
|
|
38
|
-
name: "bin-name-casing"
|
|
39
|
-
});
|
|
40
|
-
//#endregion
|
|
41
|
-
export { rule };
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { PackageJsonRuleModule } from "../createRule.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/rules/exports-subpaths-style.d.ts
|
|
4
|
-
declare const rule: PackageJsonRuleModule<[({
|
|
5
|
-
prefer?: "explicit" | "implicit" | undefined;
|
|
6
|
-
} | undefined)?], [{
|
|
7
|
-
readonly additionalProperties: false;
|
|
8
|
-
readonly properties: {
|
|
9
|
-
readonly prefer: {
|
|
10
|
-
readonly description: "Specifies which exports format to enforce.";
|
|
11
|
-
readonly enum: readonly ["implicit", "explicit"];
|
|
12
|
-
readonly type: "string";
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
readonly type: "object";
|
|
16
|
-
}]>;
|
|
17
|
-
//#endregion
|
|
18
|
-
export { rule };
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { isJSONStringLiteral } from "../utils/predicates/isJSONStringLiteral.mjs";
|
|
2
|
-
import { createRule } from "../createRule.mjs";
|
|
3
|
-
//#region src/rules/exports-subpaths-style.ts
|
|
4
|
-
function isImplicitFormat(node) {
|
|
5
|
-
if (node.type === "JSONLiteral") return true;
|
|
6
|
-
return node.properties.every((property) => !isJSONStringLiteral(property.key) || !property.key.value.startsWith("."));
|
|
7
|
-
}
|
|
8
|
-
const rule = createRule({
|
|
9
|
-
create(context) {
|
|
10
|
-
const [{ prefer = "explicit" } = {}] = context.options;
|
|
11
|
-
function validateForExplicit(node) {
|
|
12
|
-
const { value } = node;
|
|
13
|
-
if (value.type !== "JSONLiteral" && value.type !== "JSONObjectExpression" || !isImplicitFormat(value)) return;
|
|
14
|
-
context.report({
|
|
15
|
-
fix(fixer) {
|
|
16
|
-
const valueText = context.sourceCode.getText(value);
|
|
17
|
-
const fixedValue = JSON.stringify({ ".": JSON.parse(valueText) }, null, 2);
|
|
18
|
-
return fixer.replaceText(value, fixedValue);
|
|
19
|
-
},
|
|
20
|
-
messageId: "preferExplicit",
|
|
21
|
-
node: value
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
function validateForImplicit(node) {
|
|
25
|
-
const { value } = node;
|
|
26
|
-
if (value.type !== "JSONObjectExpression") return;
|
|
27
|
-
if (value.properties.length !== 1 || !isJSONStringLiteral(value.properties[0].key) || value.properties[0].key.value !== ".") return;
|
|
28
|
-
const dotProperty = value.properties[0];
|
|
29
|
-
context.report({
|
|
30
|
-
fix(fixer) {
|
|
31
|
-
const valueText = context.sourceCode.getText(dotProperty.value);
|
|
32
|
-
const fixedValue = JSON.stringify(JSON.parse(valueText), null, 2);
|
|
33
|
-
return fixer.replaceText(value, fixedValue);
|
|
34
|
-
},
|
|
35
|
-
messageId: "preferImplicit",
|
|
36
|
-
node: value
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
return { JSONProperty(node) {
|
|
40
|
-
if (node.key.type !== "JSONLiteral" || node.key.value !== "exports" || node.parent.parent.parent.type !== "Program") return;
|
|
41
|
-
if (prefer === "explicit") validateForExplicit(node);
|
|
42
|
-
else validateForImplicit(node);
|
|
43
|
-
} };
|
|
44
|
-
},
|
|
45
|
-
meta: {
|
|
46
|
-
defaultOptions: [{ prefer: "explicit" }],
|
|
47
|
-
docs: {
|
|
48
|
-
category: "Stylistic",
|
|
49
|
-
description: "Enforce consistent format for the exports field (implicit or explicit subpaths).",
|
|
50
|
-
recommended: false
|
|
51
|
-
},
|
|
52
|
-
fixable: "code",
|
|
53
|
-
messages: {
|
|
54
|
-
preferExplicit: "Prefer explicit subpaths format with \".\" key for single root export.",
|
|
55
|
-
preferImplicit: "Prefer implicit format without \".\" key for single root export."
|
|
56
|
-
},
|
|
57
|
-
schema: [{
|
|
58
|
-
additionalProperties: false,
|
|
59
|
-
properties: { prefer: {
|
|
60
|
-
description: "Specifies which exports format to enforce.",
|
|
61
|
-
enum: ["implicit", "explicit"],
|
|
62
|
-
type: "string"
|
|
63
|
-
} },
|
|
64
|
-
type: "object"
|
|
65
|
-
}],
|
|
66
|
-
type: "suggestion"
|
|
67
|
-
},
|
|
68
|
-
name: "exports-subpaths-style"
|
|
69
|
-
});
|
|
70
|
-
//#endregion
|
|
71
|
-
export { rule };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { PackageJsonRuleModule } from "../createRule.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/rules/no-empty-fields.d.ts
|
|
4
|
-
declare const rule: PackageJsonRuleModule<[({
|
|
5
|
-
ignoreProperties?: string[] | undefined;
|
|
6
|
-
} | undefined)?], [{
|
|
7
|
-
readonly additionalProperties: false;
|
|
8
|
-
readonly properties: {
|
|
9
|
-
readonly ignoreProperties: {
|
|
10
|
-
readonly description: "Array of top-level properties to ignore.";
|
|
11
|
-
readonly items: {
|
|
12
|
-
readonly type: "string";
|
|
13
|
-
};
|
|
14
|
-
readonly type: "array";
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
readonly type: "object";
|
|
18
|
-
}]>;
|
|
19
|
-
//#endregion
|
|
20
|
-
export { rule };
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { createRule } from "../createRule.mjs";
|
|
2
|
-
import { fixRemoveArrayElement, fixRemoveObjectProperty } from "eslint-fix-utils";
|
|
3
|
-
//#region src/rules/no-empty-fields.ts
|
|
4
|
-
const getDataAndMessageId = (node) => {
|
|
5
|
-
switch (node.type) {
|
|
6
|
-
case "JSONArrayExpression": return {
|
|
7
|
-
data: { expressionType: "array" },
|
|
8
|
-
messageId: "emptyExpression"
|
|
9
|
-
};
|
|
10
|
-
case "JSONObjectExpression": return {
|
|
11
|
-
data: { expressionType: "object" },
|
|
12
|
-
messageId: "emptyExpression"
|
|
13
|
-
};
|
|
14
|
-
case "JSONProperty": return {
|
|
15
|
-
data: { field: node.key.value },
|
|
16
|
-
messageId: "emptyFields"
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
const report = (context, node) => {
|
|
21
|
-
const { data, messageId } = getDataAndMessageId(node);
|
|
22
|
-
context.report({
|
|
23
|
-
data,
|
|
24
|
-
messageId,
|
|
25
|
-
node,
|
|
26
|
-
suggest: [{
|
|
27
|
-
fix: node.type === "JSONProperty" ? fixRemoveObjectProperty(context, node) : fixRemoveArrayElement(context, node, node.parent),
|
|
28
|
-
messageId: "remove"
|
|
29
|
-
}]
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
const getNode = (node) => {
|
|
33
|
-
return node.parent.type === "JSONProperty" ? node.parent : node;
|
|
34
|
-
};
|
|
35
|
-
const getTopLevelProperty = (node) => {
|
|
36
|
-
let n = node;
|
|
37
|
-
while (n.parent.parent?.parent?.type !== void 0 && n.parent.parent.parent.type !== "Program") n = n.parent;
|
|
38
|
-
return n.type === "JSONProperty" ? n.key : void 0;
|
|
39
|
-
};
|
|
40
|
-
const defaultIgnoreProperties = ["files"];
|
|
41
|
-
const rule = createRule({
|
|
42
|
-
create(context) {
|
|
43
|
-
const ignoreProperties = new Set(context.options[0]?.ignoreProperties ?? defaultIgnoreProperties);
|
|
44
|
-
return {
|
|
45
|
-
JSONArrayExpression(node) {
|
|
46
|
-
const topLevelProperty = getTopLevelProperty(node);
|
|
47
|
-
if (!topLevelProperty) return;
|
|
48
|
-
if (!node.elements.length) {
|
|
49
|
-
const topLevelPropertyName = topLevelProperty.value;
|
|
50
|
-
if (!ignoreProperties.has(topLevelPropertyName)) report(context, getNode(node));
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
JSONObjectExpression(node) {
|
|
54
|
-
const topLevelProperty = getTopLevelProperty(node);
|
|
55
|
-
if (!topLevelProperty) return;
|
|
56
|
-
if (!node.properties.length) {
|
|
57
|
-
const topLevelPropertyName = topLevelProperty.value;
|
|
58
|
-
if (!ignoreProperties.has(topLevelPropertyName)) report(context, getNode(node));
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
},
|
|
63
|
-
meta: {
|
|
64
|
-
defaultOptions: [{ ignoreProperties: defaultIgnoreProperties }],
|
|
65
|
-
docs: {
|
|
66
|
-
category: "Best Practices",
|
|
67
|
-
description: "Reports on unnecessary empty arrays and objects.",
|
|
68
|
-
recommended: true
|
|
69
|
-
},
|
|
70
|
-
hasSuggestions: true,
|
|
71
|
-
messages: {
|
|
72
|
-
emptyExpression: "This {{ expressionType }} does nothing and can be removed.",
|
|
73
|
-
emptyFields: "The field '{{ field }}' does nothing and can be removed.",
|
|
74
|
-
remove: "Remove this empty field."
|
|
75
|
-
},
|
|
76
|
-
schema: [{
|
|
77
|
-
additionalProperties: false,
|
|
78
|
-
properties: { ignoreProperties: {
|
|
79
|
-
description: "Array of top-level properties to ignore.",
|
|
80
|
-
items: { type: "string" },
|
|
81
|
-
type: "array"
|
|
82
|
-
} },
|
|
83
|
-
type: "object"
|
|
84
|
-
}],
|
|
85
|
-
type: "suggestion"
|
|
86
|
-
},
|
|
87
|
-
name: "no-empty-fields"
|
|
88
|
-
});
|
|
89
|
-
//#endregion
|
|
90
|
-
export { rule };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { PackageJsonRuleModule } from "../createRule.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/rules/no-local-dependencies.d.ts
|
|
4
|
-
declare const rule: PackageJsonRuleModule<[({
|
|
5
|
-
ignorePrivate?: boolean | undefined;
|
|
6
|
-
} | undefined)?], [{
|
|
7
|
-
readonly additionalProperties: false;
|
|
8
|
-
readonly properties: {
|
|
9
|
-
readonly ignorePrivate: {
|
|
10
|
-
readonly description: "Determines if this rule should be enforced when the package's `private` property is `true`.";
|
|
11
|
-
readonly type: "boolean";
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
readonly type: "object";
|
|
15
|
-
}]>;
|
|
16
|
-
//#endregion
|
|
17
|
-
export { rule };
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { isJSONStringLiteral } from "../utils/predicates/isJSONStringLiteral.mjs";
|
|
2
|
-
import { createRule } from "../createRule.mjs";
|
|
3
|
-
//#region src/rules/no-local-dependencies.ts
|
|
4
|
-
const isLocalDependency = (value) => value.startsWith("file:") || value.startsWith("link:") || value.startsWith("./") || value.startsWith("../") || value.startsWith(".\\") || value.startsWith("..\\");
|
|
5
|
-
const rule = createRule({
|
|
6
|
-
create(context) {
|
|
7
|
-
const ignorePrivate = context.options[0]?.ignorePrivate ?? true;
|
|
8
|
-
let isPrivate = false;
|
|
9
|
-
let dependencyNodes = [];
|
|
10
|
-
return {
|
|
11
|
-
"Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.type=JSONLiteral][value.type=JSONLiteral][key.value=private]"(node) {
|
|
12
|
-
if (node.value.value === true) isPrivate = true;
|
|
13
|
-
},
|
|
14
|
-
"Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.type=JSONLiteral][value.type=JSONObjectExpression][key.value=dependencies]"(node) {
|
|
15
|
-
dependencyNodes = node.value.properties;
|
|
16
|
-
},
|
|
17
|
-
"Program:exit"() {
|
|
18
|
-
if (ignorePrivate && isPrivate) return;
|
|
19
|
-
for (const dependencyPropertyNode of dependencyNodes) {
|
|
20
|
-
const dependencyValue = dependencyPropertyNode.value;
|
|
21
|
-
if (isJSONStringLiteral(dependencyValue) && isLocalDependency(dependencyValue.value)) context.report({
|
|
22
|
-
data: { name: dependencyValue.value },
|
|
23
|
-
messageId: "localDependencyFound",
|
|
24
|
-
node: dependencyValue
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
},
|
|
30
|
-
meta: {
|
|
31
|
-
defaultOptions: [{ ignorePrivate: true }],
|
|
32
|
-
docs: { description: "Requires that dependencies do not use local file paths, which will likely result in errors when installing from a registry." },
|
|
33
|
-
messages: { localDependencyFound: "Local dependency \"{{ name }}\" is not allowed." },
|
|
34
|
-
schema: [{
|
|
35
|
-
additionalProperties: false,
|
|
36
|
-
properties: { ignorePrivate: {
|
|
37
|
-
description: "Determines if this rule should be enforced when the package's `private` property is `true`.",
|
|
38
|
-
type: "boolean"
|
|
39
|
-
} },
|
|
40
|
-
type: "object"
|
|
41
|
-
}],
|
|
42
|
-
type: "problem"
|
|
43
|
-
},
|
|
44
|
-
name: "no-local-dependencies"
|
|
45
|
-
});
|
|
46
|
-
//#endregion
|
|
47
|
-
export { rule };
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { isJSONStringLiteral } from "../utils/predicates/isJSONStringLiteral.mjs";
|
|
2
|
-
import { isNotNullish } from "../utils/predicates/isNotNullish.mjs";
|
|
3
|
-
import { createRule } from "../createRule.mjs";
|
|
4
|
-
import { fixRemoveArrayElement } from "eslint-fix-utils";
|
|
5
|
-
//#region src/rules/no-redundant-files.ts
|
|
6
|
-
const defaultFiles = [
|
|
7
|
-
/^(\.\/)?LICEN(C|S)E(\.|$)/i,
|
|
8
|
-
/^(\.\/)?README(\.|$)/i,
|
|
9
|
-
/^(\.\/)?package\.json$/i
|
|
10
|
-
];
|
|
11
|
-
const wildcardsRegex = /[*?[\]{}]/;
|
|
12
|
-
const cachedRegex = /* @__PURE__ */ new Map();
|
|
13
|
-
const getCachedLocalFileRegex = (filename) => {
|
|
14
|
-
if (wildcardsRegex.test(filename)) return null;
|
|
15
|
-
const baseFilename = filename.replace("./", "");
|
|
16
|
-
let regex = cachedRegex.get(baseFilename);
|
|
17
|
-
if (regex) return regex;
|
|
18
|
-
else {
|
|
19
|
-
regex = new RegExp(`^(./)?${baseFilename}$`, "i");
|
|
20
|
-
cachedRegex.set(baseFilename, regex);
|
|
21
|
-
return regex;
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
const rule = createRule({
|
|
25
|
-
create(context) {
|
|
26
|
-
const entryCache = {
|
|
27
|
-
bin: [],
|
|
28
|
-
files: []
|
|
29
|
-
};
|
|
30
|
-
const report = (elements, index, messageId) => {
|
|
31
|
-
const element = elements[index];
|
|
32
|
-
if (isNotNullish(element) && isJSONStringLiteral(element)) context.report({
|
|
33
|
-
data: { file: element.value },
|
|
34
|
-
messageId,
|
|
35
|
-
node: element,
|
|
36
|
-
suggest: [{
|
|
37
|
-
fix: fixRemoveArrayElement(context, index, elements),
|
|
38
|
-
messageId: "remove"
|
|
39
|
-
}]
|
|
40
|
-
});
|
|
41
|
-
};
|
|
42
|
-
return {
|
|
43
|
-
"Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.value=bin]"(node) {
|
|
44
|
-
const binValue = node.value;
|
|
45
|
-
if (isJSONStringLiteral(binValue)) entryCache.bin.push(binValue.value);
|
|
46
|
-
else if (binValue.type === "JSONObjectExpression") {
|
|
47
|
-
for (const prop of binValue.properties) if (isJSONStringLiteral(prop.value)) entryCache.bin.push(prop.value.value);
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
"Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.value=files]"(node) {
|
|
51
|
-
if (node.value.type !== "JSONArrayExpression") return;
|
|
52
|
-
const seen = /* @__PURE__ */ new Set();
|
|
53
|
-
const elements = node.value.elements;
|
|
54
|
-
entryCache.files = elements;
|
|
55
|
-
for (const [index, element] of elements.entries()) if (isNotNullish(element) && isJSONStringLiteral(element)) {
|
|
56
|
-
if (seen.has(element.value)) report(elements, index, "duplicate");
|
|
57
|
-
else seen.add(element.value);
|
|
58
|
-
for (const defaultFile of defaultFiles) if (defaultFile.test(element.value)) report(elements, index, "unnecessaryDefault");
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
"Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.value=main]"(node) {
|
|
62
|
-
if (isJSONStringLiteral(node.value)) entryCache.main = node.value.value;
|
|
63
|
-
},
|
|
64
|
-
"Program:exit"() {
|
|
65
|
-
const files = entryCache.files;
|
|
66
|
-
if (files.length === 0) return;
|
|
67
|
-
const validations = [{
|
|
68
|
-
files: entryCache.main ? [entryCache.main] : [],
|
|
69
|
-
messageId: "unnecessaryMain"
|
|
70
|
-
}, {
|
|
71
|
-
files: entryCache.bin,
|
|
72
|
-
messageId: "unnecessaryBin"
|
|
73
|
-
}];
|
|
74
|
-
for (const validation of validations) for (const fileToCheck of validation.files) for (const [index, fileEntry] of files.entries()) if (isNotNullish(fileEntry) && isJSONStringLiteral(fileEntry)) {
|
|
75
|
-
if (getCachedLocalFileRegex(fileEntry.value)?.test(fileToCheck)) report(files, index, validation.messageId);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
},
|
|
80
|
-
meta: {
|
|
81
|
-
docs: {
|
|
82
|
-
category: "Best Practices",
|
|
83
|
-
description: "Prevents adding unnecessary / redundant files.",
|
|
84
|
-
recommended: true
|
|
85
|
-
},
|
|
86
|
-
hasSuggestions: true,
|
|
87
|
-
messages: {
|
|
88
|
-
duplicate: "Files has more than one entry for \"{{file}}\".",
|
|
89
|
-
remove: "Remove this redundant entry.",
|
|
90
|
-
unnecessaryBin: `Explicitly declaring "{{file}}" in "files" is unnecessary; it's included in "bin".`,
|
|
91
|
-
unnecessaryDefault: `Explicitly declaring "{{file}}" in "files" is unnecessary; it's included by default.`,
|
|
92
|
-
unnecessaryMain: `Explicitly declaring "{{file}}" in "files" is unnecessary; it's the "main" entry.`
|
|
93
|
-
},
|
|
94
|
-
schema: [],
|
|
95
|
-
type: "suggestion"
|
|
96
|
-
},
|
|
97
|
-
name: "no-redundant-files"
|
|
98
|
-
});
|
|
99
|
-
//#endregion
|
|
100
|
-
export { rule };
|