@checkdigit/eslint-plugin 6.8.0 → 6.9.0-PR.86-3a12

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "inputs": {
3
3
  "package.json": {
4
- "bytes": 3348,
4
+ "bytes": 2898,
5
5
  "imports": [],
6
6
  "format": "esm",
7
7
  "with": {
@@ -12193,6 +12193,27 @@
12193
12193
  ],
12194
12194
  "format": "cjs"
12195
12195
  },
12196
+ "src/no-duplicated-imports.ts": {
12197
+ "bytes": 4278,
12198
+ "imports": [
12199
+ {
12200
+ "path": "node_modules/@typescript-eslint/utils/dist/index.js",
12201
+ "kind": "import-statement",
12202
+ "original": "@typescript-eslint/utils"
12203
+ },
12204
+ {
12205
+ "path": "node:assert",
12206
+ "kind": "import-statement",
12207
+ "external": true
12208
+ },
12209
+ {
12210
+ "path": "src/get-documentation-url.ts",
12211
+ "kind": "import-statement",
12212
+ "original": "./get-documentation-url"
12213
+ }
12214
+ ],
12215
+ "format": "esm"
12216
+ },
12196
12217
  "src/library/ts-tree.ts": {
12197
12218
  "bytes": 2883,
12198
12219
  "imports": [
@@ -12241,6 +12262,22 @@
12241
12262
  ],
12242
12263
  "format": "esm"
12243
12264
  },
12265
+ "src/require-fixed-services-import.ts": {
12266
+ "bytes": 1467,
12267
+ "imports": [
12268
+ {
12269
+ "path": "node_modules/@typescript-eslint/utils/dist/index.js",
12270
+ "kind": "import-statement",
12271
+ "original": "@typescript-eslint/utils"
12272
+ },
12273
+ {
12274
+ "path": "src/get-documentation-url.ts",
12275
+ "kind": "import-statement",
12276
+ "original": "./get-documentation-url"
12277
+ }
12278
+ ],
12279
+ "format": "esm"
12280
+ },
12244
12281
  "src/require-resolve-full-response.ts": {
12245
12282
  "bytes": 7652,
12246
12283
  "imports": [
@@ -12334,13 +12371,18 @@
12334
12371
  "format": "esm"
12335
12372
  },
12336
12373
  "src/index.ts": {
12337
- "bytes": 3510,
12374
+ "bytes": 3990,
12338
12375
  "imports": [
12339
12376
  {
12340
12377
  "path": "src/invalid-json-stringify.ts",
12341
12378
  "kind": "import-statement",
12342
12379
  "original": "./invalid-json-stringify"
12343
12380
  },
12381
+ {
12382
+ "path": "src/no-duplicated-imports.ts",
12383
+ "kind": "import-statement",
12384
+ "original": "./no-duplicated-imports"
12385
+ },
12344
12386
  {
12345
12387
  "path": "src/agent/no-full-response.ts",
12346
12388
  "kind": "import-statement",
@@ -12351,6 +12393,11 @@
12351
12393
  "kind": "import-statement",
12352
12394
  "original": "./no-promise-instance-method"
12353
12395
  },
12396
+ {
12397
+ "path": "src/require-fixed-services-import.ts",
12398
+ "kind": "import-statement",
12399
+ "original": "./require-fixed-services-import"
12400
+ },
12354
12401
  {
12355
12402
  "path": "src/require-resolve-full-response.ts",
12356
12403
  "kind": "import-statement",
@@ -12918,6 +12965,11 @@
12918
12965
  "kind": "require-call",
12919
12966
  "external": true
12920
12967
  },
12968
+ {
12969
+ "path": "node:assert",
12970
+ "kind": "require-call",
12971
+ "external": true
12972
+ },
12921
12973
  {
12922
12974
  "path": "node:assert",
12923
12975
  "kind": "require-call",
@@ -15175,10 +15227,10 @@
15175
15227
  "bytesInOutput": 2215
15176
15228
  },
15177
15229
  "src/index.ts": {
15178
- "bytesInOutput": 2304
15230
+ "bytesInOutput": 2494
15179
15231
  },
15180
15232
  "package.json": {
15181
- "bytesInOutput": 3297
15233
+ "bytesInOutput": 2998
15182
15234
  },
15183
15235
  "src/get-documentation-url.ts": {
15184
15236
  "bytesInOutput": 146
@@ -15186,15 +15238,21 @@
15186
15238
  "src/invalid-json-stringify.ts": {
15187
15239
  "bytesInOutput": 2471
15188
15240
  },
15241
+ "src/no-duplicated-imports.ts": {
15242
+ "bytesInOutput": 3724
15243
+ },
15189
15244
  "src/library/ts-tree.ts": {
15190
- "bytesInOutput": 2070
15245
+ "bytesInOutput": 2078
15191
15246
  },
15192
15247
  "src/agent/no-full-response.ts": {
15193
- "bytesInOutput": 2000
15248
+ "bytesInOutput": 2006
15194
15249
  },
15195
15250
  "src/no-promise-instance-method.ts": {
15196
15251
  "bytesInOutput": 1275
15197
15252
  },
15253
+ "src/require-fixed-services-import.ts": {
15254
+ "bytesInOutput": 1254
15255
+ },
15198
15256
  "src/require-resolve-full-response.ts": {
15199
15257
  "bytesInOutput": 7354
15200
15258
  },
@@ -15229,7 +15287,7 @@
15229
15287
  "bytesInOutput": 3362
15230
15288
  }
15231
15289
  },
15232
- "bytes": 4233292
15290
+ "bytes": 4241869
15233
15291
  }
15234
15292
  }
15235
15293
  }
@@ -1,7 +1,11 @@
1
1
  // src/index.ts
2
2
  import invalidJsonStringify, { ruleId as invalidJsonStringifyRuleId } from "./invalid-json-stringify.mjs";
3
+ import noDuplicatedImports, { ruleId as noDuplicatedImportsRuleId } from "./no-duplicated-imports.mjs";
3
4
  import noFullResponse, { ruleId as noFullResponseRuleId } from "./agent/no-full-response.mjs";
4
5
  import noPromiseInstanceMethod, { ruleId as noPromiseInstanceMethodRuleId } from "./no-promise-instance-method.mjs";
6
+ import requireFixedServicesImport, {
7
+ ruleId as requireFixedServicesImportRuleId
8
+ } from "./require-fixed-services-import.mjs";
5
9
  import requireResolveFullResponse, {
6
10
  ruleId as requireResolveFullResponseRuleId
7
11
  } from "./require-resolve-full-response.mjs";
@@ -32,6 +36,8 @@ var src_default = {
32
36
  [noPromiseInstanceMethodRuleId]: noPromiseInstanceMethod,
33
37
  [noFullResponseRuleId]: noFullResponse,
34
38
  [requireResolveFullResponseRuleId]: requireResolveFullResponse,
39
+ [noDuplicatedImportsRuleId]: noDuplicatedImports,
40
+ [requireFixedServicesImportRuleId]: requireFixedServicesImport,
35
41
  [requireTypeOutOfTypeOnlyImportsRuleId]: requireTypeOutOfTypeOnlyImports
36
42
  },
37
43
  configs: {
@@ -50,6 +56,8 @@ var src_default = {
50
56
  [`@checkdigit/${noPromiseInstanceMethodRuleId}`]: "error",
51
57
  [`@checkdigit/${noFullResponseRuleId}`]: "error",
52
58
  [`@checkdigit/${requireResolveFullResponseRuleId}`]: "error",
59
+ [`@checkdigit/${noDuplicatedImportsRuleId}`]: "error",
60
+ [`@checkdigit/${requireFixedServicesImportRuleId}`]: "error",
53
61
  [`@checkdigit/${requireTypeOutOfTypeOnlyImportsRuleId}`]: "error"
54
62
  }
55
63
  },
@@ -73,4 +81,4 @@ var src_default = {
73
81
  export {
74
82
  src_default as default
75
83
  };
76
- //# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL2luZGV4LnRzIl0sCiAgIm1hcHBpbmdzIjogIjtBQVFBLE9BQU8sd0JBQXdCLFVBQVUsa0NBQWtDO0FBQzNFLE9BQU8sa0JBQWtCLFVBQVUsNEJBQTRCO0FBQy9ELE9BQU8sMkJBQTJCLFVBQVUscUNBQXFDO0FBQ2pGLE9BQU87QUFBQSxFQUNMLFVBQVU7QUFBQSxPQUNMO0FBQ1AsT0FBTztBQUFBLEVBQ0wsVUFBVTtBQUFBLE9BQ0w7QUFDUCxPQUFPLHFCQUFxQjtBQUM1QixPQUFPLG1CQUFtQjtBQUMxQixPQUFPLGtCQUFrQjtBQUN6QixPQUFPLFlBQVk7QUFDbkIsT0FBTyxzQkFBc0I7QUFDN0IsT0FBTywyQkFBMkI7QUFDbEMsT0FBTyxrQkFBa0I7QUFDekIsT0FBTyx5Q0FBeUM7QUFDaEQsT0FBTyx5QkFBeUI7QUFFaEMsSUFBTyxjQUFRO0FBQUEsRUFDYixPQUFPO0FBQUEsSUFDTCxxQkFBcUI7QUFBQSxJQUNyQixtQkFBbUI7QUFBQSxJQUNuQixXQUFXO0FBQUEsSUFDWCx5QkFBeUI7QUFBQSxJQUN6QixrQkFBa0I7QUFBQSxJQUNsQixzQkFBc0I7QUFBQSxJQUN0Qiw4QkFBOEI7QUFBQSxJQUM5QiwyQ0FBMkM7QUFBQSxJQUMzQywyQkFBMkI7QUFBQSxJQUMzQixDQUFDLDBCQ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UFxQztBQUFBLFFBQ3JDLGtDQUFrQztBQUFBLFFBQ2xDLDBDQUEwQztBQUFBLFFBQzFDLHVEQUF1RDtBQUFBLFFBQ3ZELHVDQUF1QztBQUFBLFFBQ3ZDLDhCQUE4QjtBQUFBLFFBQzlCLENBQUMsZUFBZSwwQkFBMEIsRUFBRSxHQUFHO0FBQUEsUUFDL0MsQ0FBQyxlQUFlLDZCQUE2QixFQUFFLEdBQUc7QUFBQSxNQUNwRDtBQUFBLElBQ0Y7QUFBQSxFQUNGO0FBQ0Y7IiwKICAibmFtZXMiOiBbXQp9Cg==
@@ -0,0 +1,87 @@
1
+ // src/no-duplicated-imports.ts
2
+ import { ESLintUtils, TSESTree } from "@typescript-eslint/utils";
3
+ import { strict as assert } from "node:assert";
4
+ import getDocumentationUrl from "./get-documentation-url.mjs";
5
+ var ruleId = "no-duplicated-imports";
6
+ var createRule = ESLintUtils.RuleCreator((name) => getDocumentationUrl(name));
7
+ var rule = createRule({
8
+ name: ruleId,
9
+ meta: {
10
+ type: "suggestion",
11
+ docs: {
12
+ description: 'Merge duplicated import statements with the same "from".'
13
+ },
14
+ messages: {
15
+ mergeDuplicatedImports: 'Merge duplicated import statements with the same "from".'
16
+ },
17
+ fixable: "code",
18
+ schema: []
19
+ },
20
+ defaultOptions: [],
21
+ create(context) {
22
+ const sourceCode = context.sourceCode;
23
+ const importDeclarations = /* @__PURE__ */ new Map();
24
+ return {
25
+ ImportDeclaration(node) {
26
+ const moduleName = node.source.value;
27
+ let declarations = importDeclarations.get(moduleName);
28
+ if (declarations === void 0) {
29
+ declarations = [];
30
+ importDeclarations.set(moduleName, declarations);
31
+ }
32
+ declarations.push(node);
33
+ },
34
+ "Program:exit"() {
35
+ for (const [moduleName, declarations] of importDeclarations.entries()) {
36
+ if (declarations.length <= 1) {
37
+ continue;
38
+ }
39
+ const firstDeclaration = declarations[0];
40
+ assert.ok(firstDeclaration);
41
+ const isAllTypeOnly = declarations.every(
42
+ (declaration) => declaration.importKind === "type" || declaration.specifiers.every(
43
+ (specifier) => specifier.type === TSESTree.AST_NODE_TYPES.ImportSpecifier && specifier.importKind === "type"
44
+ )
45
+ );
46
+ context.report({
47
+ messageId: "mergeDuplicatedImports",
48
+ node: firstDeclaration,
49
+ fix(fixer) {
50
+ const fixes = [];
51
+ const defaultSpecifier = declarations.flatMap(
52
+ (declaration) => declaration.specifiers.map(
53
+ (specifier) => specifier.type === TSESTree.AST_NODE_TYPES.ImportDefaultSpecifier ? specifier : void 0
54
+ )
55
+ ).filter(Boolean);
56
+ const defaultSpecifierText = defaultSpecifier[0] ? sourceCode.getText(defaultSpecifier[0]) : void 0;
57
+ const mergedSpecifiers = declarations.flatMap((declaration) => {
58
+ const isCurrentDeclarationTypeOnly = declaration.importKind === "type" || declaration.specifiers.every(
59
+ (specifier) => specifier.type === TSESTree.AST_NODE_TYPES.ImportSpecifier && specifier.importKind === "type"
60
+ );
61
+ return declaration.specifiers.filter((specifier) => specifier.type !== TSESTree.AST_NODE_TYPES.ImportDefaultSpecifier).map(
62
+ (specifier) => (
63
+ // eslint-disable-next-line no-nested-ternary
64
+ isAllTypeOnly ? sourceCode.getText(specifier).replace("type ", "") : isCurrentDeclarationTypeOnly ? `type ${sourceCode.getText(specifier)}` : sourceCode.getText(specifier)
65
+ )
66
+ );
67
+ });
68
+ const mergedSpecifiersText = `${isAllTypeOnly ? "type " : ""}{ ${mergedSpecifiers.join(", ")} }`;
69
+ const mergedImport = `import ${[defaultSpecifierText, mergedSpecifiersText].filter(Boolean).join(", ")} from '${moduleName}';`;
70
+ fixes.push(fixer.replaceText(firstDeclaration, mergedImport));
71
+ declarations.slice(1).forEach((declaration) => {
72
+ fixes.push(fixer.removeRange([declaration.range[0], declaration.range[1] + 1]));
73
+ });
74
+ return fixes;
75
+ }
76
+ });
77
+ }
78
+ }
79
+ };
80
+ }
81
+ });
82
+ var no_duplicated_imports_default = rule;
83
+ export {
84
+ no_duplicated_imports_default as default,
85
+ ruleId
86
+ };
87
+ //# sour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EVBQ3ZGO0FBQUEsa0JBQUksQ0FBQztBQUFBO0FBQUEsb0JBRUosZ0JBQ0ksV0FBVyxRQUFRLFNBQVMsRUFBRSxRQUFRLFNBQVMsRUFBRSxJQUNqRCwrQkFDRSxRQUFRLFdBQVcsUUFBUSxTQUFTLENBQUMsS0FDckMsV0FBVyxRQUFRLFNBQVM7QUFBQTtBQUFBLGdCQUNwQztBQUFBLGNBQ0osQ0FBQztBQUNELG9CQUFNLHVCQUF1QixHQUFHLGdCQUFnQixVQUFVLEVBQUUsS0FBSyxpQkFBaUIsS0FBSyxJQUFJLENBQUM7QUFHNUYsb0JBQU0sZUFBZSxVQUFVLENBQUMsc0JBQXNCLG9CQUFvQixFQUFFLE9BQU8sT0FBTyxFQUFFLEtBQUssSUFBSSxDQUFDLFVBQVUsVUFBVTtBQUMxSCxvQkFBTSxLQUFLLE1BQU0sWUFBWSxrQkFBa0IsWUFBWSxDQUFDO0FBRzVELDJCQUFhLE1BQU0sQ0FBQyxFQUFFLFFBQVEsQ0FBQyxnQkFBZ0I7QUFDN0Msc0JBQU0sS0FBSyxNQUFNLFlBQVksQ0FBQyxZQUFZLE1BQU0sQ0FBQyxHQUFHLFlBQVksTUFBTSxDQUFDLElBQUksQ0FBQyxDQUFDLENBQUM7QUFBQSxjQUNoRixDQUFDO0FBRUQscUJBQU87QUFBQSxZQUNUO0FBQUEsVUFDRixDQUFDO0FBQUEsUUFDSDtBQUFBLE1BQ0Y7QUFBQSxJQUNGO0FBQUEsRUFDRjtBQUNGLENBQUM7QUFFRCxJQUFPLGdDQUFROyIsCiAgIm5hbWVzIjogW10KfQo=
@@ -0,0 +1,46 @@
1
+ // src/require-fixed-services-import.ts
2
+ import { ESLintUtils } from "@typescript-eslint/utils";
3
+ import getDocumentationUrl from "./get-documentation-url.mjs";
4
+ var ruleId = "require-fixed-services-import";
5
+ var createRule = ESLintUtils.RuleCreator((name) => getDocumentationUrl(name));
6
+ var SERVICE_TYPINGS_IMPORT_PATH_PREFIX = /(?<path>\.\.\/)+services\/.*/u;
7
+ var rule = createRule({
8
+ name: ruleId,
9
+ meta: {
10
+ type: "suggestion",
11
+ docs: {
12
+ description: 'Require fixed "from" with service typing imports from "src/services".'
13
+ },
14
+ messages: {
15
+ updateServicesImportFrom: 'Update service typing imports to be from the fixed "src/services" path.'
16
+ },
17
+ fixable: "code",
18
+ schema: []
19
+ },
20
+ defaultOptions: [],
21
+ create(context) {
22
+ return {
23
+ ImportDeclaration(node) {
24
+ const moduleName = node.source.value;
25
+ if (SERVICE_TYPINGS_IMPORT_PATH_PREFIX.test(moduleName)) {
26
+ context.report({
27
+ messageId: "updateServicesImportFrom",
28
+ node: node.source,
29
+ *fix(fixer) {
30
+ yield fixer.replaceText(
31
+ node.source,
32
+ `'${moduleName.slice(0, moduleName.indexOf("../services") + "../services".length)}'`
33
+ );
34
+ }
35
+ });
36
+ }
37
+ }
38
+ };
39
+ }
40
+ });
41
+ var require_fixed_services_import_default = rule;
42
+ export {
43
+ require_fixed_services_import_default as default,
44
+ ruleId
45
+ };
46
+ //# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL3JlcXVpcmUtZml4ZWQtc2VydmljZXMtaW1wb3J0LnRzIl0sCiAgIm1hcHBpbmdzIjogIjtBQVFBLFNBQVMsbUJBQW1CO0FBQzVCLE9BQU8seUJBQXlCO0FBRXpCLElBQU0sU0FBUztBQUV0QixJQUFNLGFBQWEsWUFBWSxZQUFZLENBQUMsU0FBUyxvQkFBb0IsSUFBSSxDQUFDO0FBQzlFLElBQU0scUNBQXFDO0FBRTNDLElBQU0sT0FBTyxXQUFXO0FBQUEsRUFDdEIsTUFBTTtBQUFBLEVBQ04sTUFBTTtBQUFBLElBQ0osTUFBTTtBQUFBLElBQ04sTUFBTTtBQUFBLE1BQ0osYUFBYTtBQUFBLElBQ2Y7QUFBQSxJQUNBLFVBQVU7QUFBQSxNQUNSLDBCQUEwQjtBQUFBLElBQzVCO0FBQUEsSUFDQSxTQUFTO0FBQUEsSUFDVCxRQUFRLENBQUM7QUFBQSxFQUNYO0FBQUEsRUFDQSxnQkFBZ0IsQ0FBQztBQUFBLEVBQ2pCLE9BQU8sU0FBUztBQUNkLFdBQU87QUFBQSxNQUNMLGtCQUFrQixNQUFNO0FBQ3RCLGNBQU0sYUFBYSxLQUFLLE9BQU87QUFDL0IsWUFBSSxtQ0FBbUMsS0FBSyxVQUFVLEdBQUc7QUFDdkQsa0JBQVEsT0FBTztBQUFBLFlBQ2IsV0FBVztBQUFBLFlBQ1gsTUFBTSxLQUFLO0FBQUEsWUFDWCxDQUFDLElBQUksT0FBTztBQUNWLG9CQUFNLE1BQU07QUFBQSxnQkFDVixLQUFLO0FBQUEsZ0JBQ0wsSUFBSSxXQUFXLE1BQU0sR0FBRyxXQUFXLFFBQVEsYUFBYSxJQUFJLGNBQWMsTUFBTSxDQUFDO0FBQUEsY0FDbkY7QUFBQSxZQUNGO0FBQUEsVUFDRixDQUFDO0FBQUEsUUFDSDtBQUFBLE1BQ0Y7QUFBQSxJQUNGO0FBQUEsRUFDRjtBQUNGLENBQUM7QUFFRCxJQUFPLHdDQUFROyIsCiAgIm5hbWVzIjogW10KfQo=
@@ -13,6 +13,8 @@ declare const _default: {
13
13
  "no-promise-instance-method": import("eslint").Rule.RuleModule;
14
14
  "no-full-response": import("@typescript-eslint/utils/ts-eslint").RuleModule<"removeFullResponse" | "unknownError", never[], import("@typescript-eslint/utils/ts-eslint").RuleListener>;
15
15
  "require-resolve-full-response": import("@typescript-eslint/utils/ts-eslint").RuleModule<"unknownError" | "invalidOptions", never[], import("@typescript-eslint/utils/ts-eslint").RuleListener>;
16
+ "no-duplicated-imports": import("@typescript-eslint/utils/ts-eslint").RuleModule<"mergeDuplicatedImports", never[], import("@typescript-eslint/utils/ts-eslint").RuleListener>;
17
+ "require-fixed-services-import": import("@typescript-eslint/utils/ts-eslint").RuleModule<"updateServicesImportFrom", never[], import("@typescript-eslint/utils/ts-eslint").RuleListener>;
16
18
  "require-type-out-of-type-only-imports": import("@typescript-eslint/utils/ts-eslint").RuleModule<"moveTypeOutside", never[], import("@typescript-eslint/utils/ts-eslint").RuleListener>;
17
19
  };
18
20
  configs: {
@@ -31,6 +33,8 @@ declare const _default: {
31
33
  "@checkdigit/no-promise-instance-method": string;
32
34
  "@checkdigit/no-full-response": string;
33
35
  "@checkdigit/require-resolve-full-response": string;
36
+ "@checkdigit/no-duplicated-imports": string;
37
+ "@checkdigit/require-fixed-services-import": string;
34
38
  "@checkdigit/require-type-out-of-type-only-imports": string;
35
39
  };
36
40
  };
@@ -0,0 +1,4 @@
1
+ import { ESLintUtils } from '@typescript-eslint/utils';
2
+ export declare const ruleId = "no-duplicated-imports";
3
+ declare const rule: ESLintUtils.RuleModule<"mergeDuplicatedImports", never[], ESLintUtils.RuleListener>;
4
+ export default rule;
@@ -0,0 +1,4 @@
1
+ import { ESLintUtils } from '@typescript-eslint/utils';
2
+ export declare const ruleId = "require-fixed-services-import";
3
+ declare const rule: ESLintUtils.RuleModule<"updateServicesImportFrom", never[], ESLintUtils.RuleListener>;
4
+ export default rule;
package/package.json CHANGED
@@ -1,92 +1 @@
1
- {
2
- "name": "@checkdigit/eslint-plugin",
3
- "version": "6.8.0",
4
- "description": "Check Digit eslint plugins",
5
- "keywords": [
6
- "eslint",
7
- "eslintplugin"
8
- ],
9
- "homepage": "https://github.com/checkdigit/eslint-plugin#readme",
10
- "bugs": {
11
- "url": "https://github.com/checkdigit/eslint-plugin/issues"
12
- },
13
- "repository": {
14
- "type": "git",
15
- "url": "https://github.com/checkdigit/eslint-plugin"
16
- },
17
- "license": "MIT",
18
- "author": "Check Digit, LLC",
19
- "sideEffects": false,
20
- "type": "module",
21
- "exports": {
22
- ".": {
23
- "types": "./dist-types/index.d.ts",
24
- "require": "./dist-cjs/index.cjs",
25
- "import": "./dist-mjs/index.mjs",
26
- "default": "./dist-mjs/index.mjs"
27
- }
28
- },
29
- "files": [
30
- "src",
31
- "dist-types",
32
- "dist-cjs",
33
- "dist-mjs",
34
- "!src/**/*.test.ts",
35
- "!src/**/*.spec.ts",
36
- "!dist-types/**/*.test.d.ts",
37
- "!dist-types/**/*.spec.d.ts",
38
- "!dist-cjs/**/*.test.cjs",
39
- "!dist-cjs/**/*.spec.cjs",
40
- "!dist-mjs/**/*.test.mjs",
41
- "!dist-mjs/**/*.spec.mjs",
42
- "SECURITY.md"
43
- ],
44
- "scripts": {
45
- "build:dist-cjs": "rimraf dist-cjs && npx builder --type=commonjs --sourceMap --entryPoint=index.ts --outDir=dist-cjs --outFile=index.cjs --external=espree && echo \"module.exports = module.exports.default;\" >> dist-cjs/index.cjs && node dist-cjs/index.cjs",
46
- "build:dist-mjs": "rimraf dist-mjs && npx builder --type=module --sourceMap --outDir=dist-mjs && node dist-mjs/index.mjs",
47
- "build:dist-types": "rimraf dist-types && npx builder --type=types --outDir=dist-types",
48
- "ci:compile": "tsc --noEmit",
49
- "ci:coverage": "NODE_OPTIONS=\"--disable-warning ExperimentalWarning --experimental-vm-modules\" jest --coverage=true",
50
- "ci:lint": "npm run lint",
51
- "ci:style": "npm run prettier",
52
- "ci:test": "NODE_OPTIONS=\"--disable-warning ExperimentalWarning --experimental-vm-modules\" jest --coverage=false",
53
- "lint": "eslint --max-warnings 0 --ignore-path .gitignore .",
54
- "lint:fix": "eslint --ignore-path .gitignore . --fix",
55
- "prepublishOnly": "npm run build:dist-types && npm run build:dist-cjs && npm run build:dist-mjs",
56
- "prettier": "prettier --ignore-path .gitignore --list-different .",
57
- "prettier:fix": "prettier --ignore-path .gitignore --write .",
58
- "test": "npm run ci:compile && npm run ci:test && npm run ci:lint && npm run ci:style"
59
- },
60
- "prettier": "@checkdigit/prettier-config",
61
- "jest": {
62
- "preset": "@checkdigit/jest-config"
63
- },
64
- "dependencies": {
65
- "@typescript-eslint/type-utils": "7.18.0",
66
- "@typescript-eslint/utils": "7.18.0",
67
- "ts-api-utils": "^1.3.0"
68
- },
69
- "devDependencies": {
70
- "@checkdigit/jest-config": "^6.0.2",
71
- "@checkdigit/prettier-config": "^5.5.1",
72
- "@checkdigit/typescript-config": "6.0.0",
73
- "@types/eslint": "8.56.10",
74
- "@typescript-eslint/eslint-plugin": "7.18.0",
75
- "@typescript-eslint/parser": "7.18.0",
76
- "@typescript-eslint/rule-tester": "7.18.0",
77
- "eslint-config-prettier": "^9.1.0",
78
- "eslint-plugin-eslint-plugin": "^6.2.0",
79
- "eslint-plugin-import": "^2.31.0",
80
- "eslint-plugin-no-only-tests": "^3.3.0",
81
- "eslint-plugin-no-secrets": "^1.0.2",
82
- "eslint-plugin-node": "^11.1.0",
83
- "eslint-plugin-sonarjs": "0.24.0",
84
- "http-status-codes": "^2.3.0"
85
- },
86
- "peerDependencies": {
87
- "eslint": ">=8 <9"
88
- },
89
- "engines": {
90
- "node": ">=20.14"
91
- }
92
- }
1
+ {"name":"@checkdigit/eslint-plugin","version":"6.9.0-PR.86-3a12","description":"Check Digit eslint plugins","keywords":["eslint","eslintplugin"],"homepage":"https://github.com/checkdigit/eslint-plugin#readme","bugs":{"url":"https://github.com/checkdigit/eslint-plugin/issues"},"repository":{"type":"git","url":"https://github.com/checkdigit/eslint-plugin"},"license":"MIT","author":"Check Digit, LLC","sideEffects":false,"type":"module","exports":{".":{"types":"./dist-types/index.d.ts","require":"./dist-cjs/index.cjs","import":"./dist-mjs/index.mjs","default":"./dist-mjs/index.mjs"}},"files":["src","dist-types","dist-cjs","dist-mjs","!src/**/*.test.ts","!src/**/*.spec.ts","!dist-types/**/*.test.d.ts","!dist-types/**/*.spec.d.ts","!dist-cjs/**/*.test.cjs","!dist-cjs/**/*.spec.cjs","!dist-mjs/**/*.test.mjs","!dist-mjs/**/*.spec.mjs","SECURITY.md"],"scripts":{"build:dist-cjs":"rimraf dist-cjs && npx builder --type=commonjs --sourceMap --entryPoint=index.ts --outDir=dist-cjs --outFile=index.cjs --external=espree && echo \"module.exports = module.exports.default;\" >> dist-cjs/index.cjs && node dist-cjs/index.cjs","build:dist-mjs":"rimraf dist-mjs && npx builder --type=module --sourceMap --outDir=dist-mjs && node dist-mjs/index.mjs","build:dist-types":"rimraf dist-types && npx builder --type=types --outDir=dist-types","ci:compile":"tsc --noEmit","ci:coverage":"NODE_OPTIONS=\"--disable-warning ExperimentalWarning --experimental-vm-modules\" jest --coverage=true","ci:lint":"npm run lint","ci:style":"npm run prettier","ci:test":"NODE_OPTIONS=\"--disable-warning ExperimentalWarning --experimental-vm-modules\" jest --coverage=false","lint":"eslint --max-warnings 0 --ignore-path .gitignore .","lint:fix":"eslint --ignore-path .gitignore . --fix","prepublishOnly":"npm run build:dist-types && npm run build:dist-cjs && npm run build:dist-mjs","prettier":"prettier --ignore-path .gitignore --list-different .","prettier:fix":"prettier --ignore-path .gitignore --write .","test":"npm run ci:compile && npm run ci:test && npm run ci:lint && npm run ci:style"},"prettier":"@checkdigit/prettier-config","jest":{"preset":"@checkdigit/jest-config"},"dependencies":{"@typescript-eslint/type-utils":"7.18.0","@typescript-eslint/utils":"7.18.0","ts-api-utils":"^1.3.0"},"devDependencies":{"@checkdigit/jest-config":"^6.0.2","@checkdigit/prettier-config":"^5.5.1","@checkdigit/typescript-config":"6.0.0","@types/eslint":"8.56.10","@typescript-eslint/eslint-plugin":"7.18.0","@typescript-eslint/parser":"7.18.0","@typescript-eslint/rule-tester":"7.18.0","eslint-config-prettier":"^9.1.0","eslint-plugin-eslint-plugin":"^6.2.0","eslint-plugin-import":"^2.31.0","eslint-plugin-no-only-tests":"^3.3.0","eslint-plugin-no-secrets":"^1.0.2","eslint-plugin-node":"^11.1.0","eslint-plugin-sonarjs":"0.24.0","http-status-codes":"^2.3.0"},"peerDependencies":{"eslint":">=8 <9"},"engines":{"node":">=20.14"}}
package/src/index.ts CHANGED
@@ -7,8 +7,12 @@
7
7
  */
8
8
 
9
9
  import invalidJsonStringify, { ruleId as invalidJsonStringifyRuleId } from './invalid-json-stringify';
10
+ import noDuplicatedImports, { ruleId as noDuplicatedImportsRuleId } from './no-duplicated-imports';
10
11
  import noFullResponse, { ruleId as noFullResponseRuleId } from './agent/no-full-response';
11
12
  import noPromiseInstanceMethod, { ruleId as noPromiseInstanceMethodRuleId } from './no-promise-instance-method';
13
+ import requireFixedServicesImport, {
14
+ ruleId as requireFixedServicesImportRuleId,
15
+ } from './require-fixed-services-import';
12
16
  import requireResolveFullResponse, {
13
17
  ruleId as requireResolveFullResponseRuleId,
14
18
  } from './require-resolve-full-response';
@@ -40,6 +44,8 @@ export default {
40
44
  [noPromiseInstanceMethodRuleId]: noPromiseInstanceMethod,
41
45
  [noFullResponseRuleId]: noFullResponse,
42
46
  [requireResolveFullResponseRuleId]: requireResolveFullResponse,
47
+ [noDuplicatedImportsRuleId]: noDuplicatedImports,
48
+ [requireFixedServicesImportRuleId]: requireFixedServicesImport,
43
49
  [requireTypeOutOfTypeOnlyImportsRuleId]: requireTypeOutOfTypeOnlyImports,
44
50
  },
45
51
  configs: {
@@ -58,6 +64,8 @@ export default {
58
64
  [`@checkdigit/${noPromiseInstanceMethodRuleId}`]: 'error',
59
65
  [`@checkdigit/${noFullResponseRuleId}`]: 'error',
60
66
  [`@checkdigit/${requireResolveFullResponseRuleId}`]: 'error',
67
+ [`@checkdigit/${noDuplicatedImportsRuleId}`]: 'error',
68
+ [`@checkdigit/${requireFixedServicesImportRuleId}`]: 'error',
61
69
  [`@checkdigit/${requireTypeOutOfTypeOnlyImportsRuleId}`]: 'error',
62
70
  },
63
71
  },
@@ -0,0 +1,116 @@
1
+ // no-duplicated-imports.ts
2
+
3
+ /*
4
+ * Copyright (c) 2021-2024 Check Digit, LLC
5
+ *
6
+ * This code is licensed under the MIT license (see LICENSE.txt for details).
7
+ */
8
+
9
+ import { ESLintUtils, TSESTree } from '@typescript-eslint/utils';
10
+ import { strict as assert } from 'node:assert';
11
+ import getDocumentationUrl from './get-documentation-url';
12
+
13
+ export const ruleId = 'no-duplicated-imports';
14
+
15
+ const createRule = ESLintUtils.RuleCreator((name) => getDocumentationUrl(name));
16
+
17
+ const rule = createRule({
18
+ name: ruleId,
19
+ meta: {
20
+ type: 'suggestion',
21
+ docs: {
22
+ description: 'Merge duplicated import statements with the same "from".',
23
+ },
24
+ messages: {
25
+ mergeDuplicatedImports: 'Merge duplicated import statements with the same "from".',
26
+ },
27
+ fixable: 'code',
28
+ schema: [],
29
+ },
30
+ defaultOptions: [],
31
+ create(context) {
32
+ const sourceCode = context.sourceCode;
33
+ const importDeclarations = new Map<string, TSESTree.ImportDeclaration[]>();
34
+
35
+ return {
36
+ ImportDeclaration(node) {
37
+ const moduleName = node.source.value;
38
+ let declarations = importDeclarations.get(moduleName);
39
+ if (declarations === undefined) {
40
+ declarations = [];
41
+ importDeclarations.set(moduleName, declarations);
42
+ }
43
+ declarations.push(node);
44
+ },
45
+ 'Program:exit'() {
46
+ for (const [moduleName, declarations] of importDeclarations.entries()) {
47
+ if (declarations.length <= 1) {
48
+ continue;
49
+ }
50
+
51
+ const firstDeclaration = declarations[0];
52
+ assert.ok(firstDeclaration);
53
+
54
+ const isAllTypeOnly = declarations.every(
55
+ (declaration) =>
56
+ declaration.importKind === 'type' ||
57
+ declaration.specifiers.every(
58
+ (specifier) =>
59
+ specifier.type === TSESTree.AST_NODE_TYPES.ImportSpecifier && specifier.importKind === 'type',
60
+ ),
61
+ );
62
+
63
+ context.report({
64
+ messageId: 'mergeDuplicatedImports',
65
+ node: firstDeclaration,
66
+ fix(fixer) {
67
+ const fixes = [];
68
+
69
+ const defaultSpecifier = declarations
70
+ .flatMap((declaration) =>
71
+ declaration.specifiers.map((specifier) =>
72
+ specifier.type === TSESTree.AST_NODE_TYPES.ImportDefaultSpecifier ? specifier : undefined,
73
+ ),
74
+ )
75
+ .filter(Boolean);
76
+ const defaultSpecifierText = defaultSpecifier[0] ? sourceCode.getText(defaultSpecifier[0]) : undefined;
77
+
78
+ const mergedSpecifiers = declarations.flatMap((declaration) => {
79
+ const isCurrentDeclarationTypeOnly =
80
+ declaration.importKind === 'type' ||
81
+ declaration.specifiers.every(
82
+ (specifier) =>
83
+ specifier.type === TSESTree.AST_NODE_TYPES.ImportSpecifier && specifier.importKind === 'type',
84
+ );
85
+ return declaration.specifiers
86
+ .filter((specifier) => specifier.type !== TSESTree.AST_NODE_TYPES.ImportDefaultSpecifier)
87
+ .map((specifier) =>
88
+ // eslint-disable-next-line no-nested-ternary
89
+ isAllTypeOnly
90
+ ? sourceCode.getText(specifier).replace('type ', '')
91
+ : isCurrentDeclarationTypeOnly
92
+ ? `type ${sourceCode.getText(specifier)}`
93
+ : sourceCode.getText(specifier),
94
+ );
95
+ });
96
+ const mergedSpecifiersText = `${isAllTypeOnly ? 'type ' : ''}{ ${mergedSpecifiers.join(', ')} }`;
97
+
98
+ // Replace the first import with the merged import
99
+ const mergedImport = `import ${[defaultSpecifierText, mergedSpecifiersText].filter(Boolean).join(', ')} from '${moduleName}';`;
100
+ fixes.push(fixer.replaceText(firstDeclaration, mergedImport));
101
+
102
+ // Remove the remaining imports
103
+ declarations.slice(1).forEach((declaration) => {
104
+ fixes.push(fixer.removeRange([declaration.range[0], declaration.range[1] + 1]));
105
+ });
106
+
107
+ return fixes;
108
+ },
109
+ });
110
+ }
111
+ },
112
+ };
113
+ },
114
+ });
115
+
116
+ export default rule;
@@ -0,0 +1,52 @@
1
+ // require-fixed-services-import.ts
2
+
3
+ /*
4
+ * Copyright (c) 2021-2024 Check Digit, LLC
5
+ *
6
+ * This code is licensed under the MIT license (see LICENSE.txt for details).
7
+ */
8
+
9
+ import { ESLintUtils } from '@typescript-eslint/utils';
10
+ import getDocumentationUrl from './get-documentation-url';
11
+
12
+ export const ruleId = 'require-fixed-services-import';
13
+
14
+ const createRule = ESLintUtils.RuleCreator((name) => getDocumentationUrl(name));
15
+ const SERVICE_TYPINGS_IMPORT_PATH_PREFIX = /(?<path>\.\.\/)+services\/.*/u;
16
+
17
+ const rule = createRule({
18
+ name: ruleId,
19
+ meta: {
20
+ type: 'suggestion',
21
+ docs: {
22
+ description: 'Require fixed "from" with service typing imports from "src/services".',
23
+ },
24
+ messages: {
25
+ updateServicesImportFrom: 'Update service typing imports to be from the fixed "src/services" path.',
26
+ },
27
+ fixable: 'code',
28
+ schema: [],
29
+ },
30
+ defaultOptions: [],
31
+ create(context) {
32
+ return {
33
+ ImportDeclaration(node) {
34
+ const moduleName = node.source.value;
35
+ if (SERVICE_TYPINGS_IMPORT_PATH_PREFIX.test(moduleName)) {
36
+ context.report({
37
+ messageId: 'updateServicesImportFrom',
38
+ node: node.source,
39
+ *fix(fixer) {
40
+ yield fixer.replaceText(
41
+ node.source,
42
+ `'${moduleName.slice(0, moduleName.indexOf('../services') + '../services'.length)}'`,
43
+ );
44
+ },
45
+ });
46
+ }
47
+ },
48
+ };
49
+ },
50
+ });
51
+
52
+ export default rule;