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

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,46 +0,0 @@
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=
@@ -1,4 +0,0 @@
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;
@@ -1,4 +0,0 @@
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;
@@ -1,116 +0,0 @@
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;
@@ -1,52 +0,0 @@
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;