@checkdigit/eslint-plugin 6.6.0-PR.75-1f73 → 6.6.0-PR.75-b19c
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/dist-cjs/index.cjs +780 -615
- package/dist-cjs/metafile.json +106 -24
- package/dist-mjs/index.mjs +20 -14
- package/dist-mjs/no-duplicated-imports.mjs +87 -0
- package/dist-mjs/require-fixed-services-import.mjs +46 -0
- package/dist-mjs/require-type-out-of-type-only-imports.mjs +48 -0
- package/dist-types/index.d.ts +9 -12
- package/dist-types/no-duplicated-imports.d.ts +4 -0
- package/dist-types/require-fixed-services-import.d.ts +4 -0
- package/dist-types/require-type-out-of-type-only-imports.d.ts +4 -0
- package/package.json +1 -1
- package/src/agent/add-url-domain.ts +1 -1
- package/src/agent/fetch-response-body-json.ts +1 -1
- package/src/agent/fetch-response-header-getter.ts +1 -1
- package/src/agent/fetch-then.ts +1 -1
- package/src/agent/fetch.ts +1 -1
- package/src/agent/no-fixture.ts +1 -1
- package/src/agent/no-full-response.ts +1 -1
- package/src/agent/no-mapped-response.ts +1 -1
- package/src/agent/no-service-wrapper.ts +1 -1
- package/src/agent/no-status-code.ts +1 -1
- package/src/agent/response-reference.ts +1 -1
- package/src/agent/url.ts +1 -1
- package/src/index.ts +18 -12
- package/src/library/format.ts +1 -1
- package/src/library/tree.ts +1 -1
- package/src/library/ts-tree.ts +1 -1
- package/src/library/variable.ts +1 -1
- package/src/no-duplicated-imports.ts +116 -0
- package/src/require-fixed-services-import.ts +52 -0
- package/src/require-type-out-of-type-only-imports.ts +63 -0
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@checkdigit/eslint-plugin","version":"6.6.0-PR.75-
|
|
1
|
+
{"name":"@checkdigit/eslint-plugin","version":"6.6.0-PR.75-b19c","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","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.0","@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.29.1","eslint-plugin-no-only-tests":"^3.1.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/agent/fetch-then.ts
CHANGED
package/src/agent/fetch.ts
CHANGED
package/src/agent/no-fixture.ts
CHANGED
package/src/agent/url.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -13,15 +13,22 @@ import fetchResponseHeaderGetter, {
|
|
|
13
13
|
} from './agent/fetch-response-header-getter';
|
|
14
14
|
import fetchThen, { ruleId as fetchThenRuleId } from './agent/fetch-then';
|
|
15
15
|
import invalidJsonStringify, { ruleId as invalidJsonStringifyRuleId } from './invalid-json-stringify';
|
|
16
|
+
import noDuplicatedImports, { ruleId as noDuplicatedImportsRuleId } from './no-duplicated-imports';
|
|
16
17
|
import noFixture, { ruleId as noFixtureRuleId } from './agent/no-fixture';
|
|
17
18
|
import noFullResponse, { ruleId as noFullResponseRuleId } from './agent/no-full-response';
|
|
18
19
|
import noMappedResponse, { ruleId as noMappedResponseRuleId } from './agent/no-mapped-response';
|
|
19
20
|
import noPromiseInstanceMethod, { ruleId as noPromiseInstanceMethodRuleId } from './no-promise-instance-method';
|
|
20
21
|
import noServiceWrapper, { ruleId as noServiceWrapperRuleId } from './agent/no-service-wrapper';
|
|
21
22
|
import noStatusCode, { ruleId as noStatusCodeRuleId } from './agent/no-status-code';
|
|
23
|
+
import requireFixedServicesImport, {
|
|
24
|
+
ruleId as requireFixedServicesImportRuleId,
|
|
25
|
+
} from './require-fixed-services-import';
|
|
22
26
|
import requireResolveFullResponse, {
|
|
23
27
|
ruleId as requireResolveFullResponseRuleId,
|
|
24
28
|
} from './require-resolve-full-response';
|
|
29
|
+
import requireTypeOutOfTypeOnlyImports, {
|
|
30
|
+
ruleId as requireTypeOutOfTypeOnlyImportsRuleId,
|
|
31
|
+
} from './require-type-out-of-type-only-imports';
|
|
25
32
|
import filePathComment from './file-path-comment';
|
|
26
33
|
import noCardNumbers from './no-card-numbers';
|
|
27
34
|
import noTestImport from './no-test-import';
|
|
@@ -55,6 +62,9 @@ export default {
|
|
|
55
62
|
[noFullResponseRuleId]: noFullResponse,
|
|
56
63
|
[noMappedResponseRuleId]: noMappedResponse,
|
|
57
64
|
[requireResolveFullResponseRuleId]: requireResolveFullResponse,
|
|
65
|
+
[noDuplicatedImportsRuleId]: noDuplicatedImports,
|
|
66
|
+
[requireFixedServicesImportRuleId]: requireFixedServicesImport,
|
|
67
|
+
[requireTypeOutOfTypeOnlyImportsRuleId]: requireTypeOutOfTypeOnlyImports,
|
|
58
68
|
},
|
|
59
69
|
configs: {
|
|
60
70
|
all: {
|
|
@@ -72,13 +82,9 @@ export default {
|
|
|
72
82
|
[`@checkdigit/${noPromiseInstanceMethodRuleId}`]: 'error',
|
|
73
83
|
[`@checkdigit/${noFullResponseRuleId}`]: 'error',
|
|
74
84
|
[`@checkdigit/${requireResolveFullResponseRuleId}`]: 'error',
|
|
75
|
-
[`@checkdigit/${
|
|
76
|
-
[`@checkdigit/${
|
|
77
|
-
[`@checkdigit/${
|
|
78
|
-
[`@checkdigit/${noStatusCodeRuleId}`]: 'off',
|
|
79
|
-
[`@checkdigit/${fetchResponseBodyJsonRuleId}`]: 'off',
|
|
80
|
-
[`@checkdigit/${fetchResponseHeaderGetterRuleId}`]: 'off',
|
|
81
|
-
[`@checkdigit/${fetchThenRuleId}`]: 'off',
|
|
85
|
+
[`@checkdigit/${noDuplicatedImportsRuleId}`]: 'error',
|
|
86
|
+
[`@checkdigit/${requireFixedServicesImportRuleId}`]: 'error',
|
|
87
|
+
[`@checkdigit/${requireTypeOutOfTypeOnlyImportsRuleId}`]: 'error',
|
|
82
88
|
},
|
|
83
89
|
},
|
|
84
90
|
recommended: {
|
|
@@ -97,10 +103,12 @@ export default {
|
|
|
97
103
|
},
|
|
98
104
|
},
|
|
99
105
|
'agent-phase-1-test': {
|
|
100
|
-
|
|
106
|
+
overrides: [
|
|
107
|
+
{
|
|
108
|
+
files: ['*.spec.ts', '*.test.ts', 'src/api/v*/index.ts'],
|
|
109
|
+
},
|
|
110
|
+
],
|
|
101
111
|
rules: {
|
|
102
|
-
[`@checkdigit/${noFullResponseRuleId}`]: 'error',
|
|
103
|
-
[`@checkdigit/${requireResolveFullResponseRuleId}`]: 'error',
|
|
104
112
|
[`@checkdigit/${noMappedResponseRuleId}`]: 'error',
|
|
105
113
|
[`@checkdigit/${addUrlDomainRuleId}`]: 'error',
|
|
106
114
|
[`@checkdigit/${noFixtureRuleId}`]: 'error',
|
|
@@ -114,8 +122,6 @@ export default {
|
|
|
114
122
|
'agent-phase-2-production': {
|
|
115
123
|
ignorePatterns: ['*.spec.ts', '*.test.ts'],
|
|
116
124
|
rules: {
|
|
117
|
-
[`@checkdigit/${noFullResponseRuleId}`]: 'error',
|
|
118
|
-
[`@checkdigit/${requireResolveFullResponseRuleId}`]: 'error',
|
|
119
125
|
[`@checkdigit/${noMappedResponseRuleId}`]: 'error',
|
|
120
126
|
[`@checkdigit/${addUrlDomainRuleId}`]: 'error',
|
|
121
127
|
[`@checkdigit/${noFixtureRuleId}`]: 'off',
|
package/src/library/format.ts
CHANGED
package/src/library/tree.ts
CHANGED
package/src/library/ts-tree.ts
CHANGED
package/src/library/variable.ts
CHANGED
|
@@ -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;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// require-type-out-of-type-only-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 getDocumentationUrl from './get-documentation-url';
|
|
11
|
+
|
|
12
|
+
export const ruleId = 'require-type-out-of-type-only-imports';
|
|
13
|
+
|
|
14
|
+
const createRule = ESLintUtils.RuleCreator((name) => getDocumentationUrl(name));
|
|
15
|
+
|
|
16
|
+
const rule = createRule({
|
|
17
|
+
name: ruleId,
|
|
18
|
+
meta: {
|
|
19
|
+
type: 'suggestion',
|
|
20
|
+
docs: {
|
|
21
|
+
description: 'Require "type" to be out side of type-only imports.',
|
|
22
|
+
},
|
|
23
|
+
messages: {
|
|
24
|
+
moveTypeOutside: 'Update the type-only imports to use "tpe" outside of the curly braces.',
|
|
25
|
+
},
|
|
26
|
+
fixable: 'code',
|
|
27
|
+
schema: [],
|
|
28
|
+
},
|
|
29
|
+
defaultOptions: [],
|
|
30
|
+
create(context) {
|
|
31
|
+
const sourceCode = context.sourceCode;
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
ImportDeclaration(declaration) {
|
|
35
|
+
if (
|
|
36
|
+
declaration.importKind === 'type' ||
|
|
37
|
+
!declaration.specifiers.every(
|
|
38
|
+
(specifier) =>
|
|
39
|
+
specifier.type === TSESTree.AST_NODE_TYPES.ImportSpecifier && specifier.importKind === 'type',
|
|
40
|
+
)
|
|
41
|
+
) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
context.report({
|
|
46
|
+
messageId: 'moveTypeOutside',
|
|
47
|
+
node: declaration,
|
|
48
|
+
*fix(fixer) {
|
|
49
|
+
const moduleName = declaration.source.value;
|
|
50
|
+
const mergedSpecifiers = declaration.specifiers
|
|
51
|
+
.filter((specifier) => specifier.type !== TSESTree.AST_NODE_TYPES.ImportDefaultSpecifier)
|
|
52
|
+
.map((specifier) => sourceCode.getText(specifier).replace('type ', ''));
|
|
53
|
+
const updatedImportDeclaration = `import type { ${mergedSpecifiers.join(', ')} } from '${moduleName}';`;
|
|
54
|
+
|
|
55
|
+
yield fixer.replaceText(declaration, updatedImportDeclaration);
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
export default rule;
|