@checkdigit/eslint-plugin 7.17.0-PR.137-74ca → 7.17.0-PR.137-0238
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.
|
@@ -3,23 +3,34 @@ import { AST_NODE_TYPES, ESLintUtils } from "@typescript-eslint/utils";
|
|
|
3
3
|
import getDocumentationUrl from "../get-documentation-url.mjs";
|
|
4
4
|
var ruleId = "require-aws-bare-bones";
|
|
5
5
|
var MESSAGE_ID_AGGREGATED_CLIENT = "noAggregatedClient";
|
|
6
|
-
var BARE_BONES_SUFFIXES =
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
var BARE_BONES_SUFFIXES = /* @__PURE__ */ new Set(["Client", "Command", "Exception", "Input", "Output"]);
|
|
7
|
+
var AWS_LIB_AGGREGATED_SUFFIXES = /* @__PURE__ */ new Set(["Document"]);
|
|
8
|
+
var AWS_SDK_CLIENT = "@aws-sdk/client-";
|
|
9
|
+
var AWS_SDK_LIB = "@aws-sdk/lib-";
|
|
10
|
+
var createRule = ESLintUtils.RuleCreator(getDocumentationUrl);
|
|
11
|
+
var isAwsSdkClientModule = ({ source }) => typeof source.value === "string" && (source.value.startsWith(AWS_SDK_CLIENT) || source.value.startsWith(AWS_SDK_LIB));
|
|
12
|
+
var kebabToPascal = (str) => str.split("-").map((item) => item.charAt(0).toUpperCase() + item.slice(1)).join("");
|
|
13
|
+
var endsWithAnySuffix = (name, suffixes) => Array.from(suffixes).some((suffix) => name.endsWith(suffix));
|
|
14
|
+
var isAggregatedClient = (name, importSource) => {
|
|
15
|
+
if (importSource.startsWith(AWS_SDK_CLIENT)) {
|
|
16
|
+
return !endsWithAnySuffix(name, BARE_BONES_SUFFIXES);
|
|
17
|
+
}
|
|
18
|
+
if (importSource.startsWith(AWS_SDK_LIB)) {
|
|
19
|
+
const pkg = importSource.replace(AWS_SDK_LIB, "");
|
|
20
|
+
const pkgPascal = kebabToPascal(pkg);
|
|
21
|
+
return name.startsWith(pkgPascal) || endsWithAnySuffix(name, AWS_LIB_AGGREGATED_SUFFIXES);
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
};
|
|
14
25
|
var rule = createRule({
|
|
15
26
|
name: ruleId,
|
|
16
27
|
meta: {
|
|
17
28
|
type: "problem",
|
|
18
29
|
docs: {
|
|
19
|
-
description: "Disallow importing aggregated AWS SDK v3 clients. Use bare-bones pattern (Client
|
|
30
|
+
description: "Disallow importing aggregated AWS SDK v3 clients. Use bare-bones pattern (Client/Lib plus Command) for better tree-shaking."
|
|
20
31
|
},
|
|
21
32
|
messages: {
|
|
22
|
-
[MESSAGE_ID_AGGREGATED_CLIENT]: 'Do not import aggregated AWS SDK v3 client "{{clientName}}". Use bare-bones pattern ({{clientName}}Client
|
|
33
|
+
[MESSAGE_ID_AGGREGATED_CLIENT]: 'Do not import aggregated AWS SDK v3 client "{{clientName}}". Use bare-bones pattern ({{clientName}}Client/Lib plus Command) instead.'
|
|
23
34
|
},
|
|
24
35
|
schema: []
|
|
25
36
|
},
|
|
@@ -32,8 +43,7 @@ var rule = createRule({
|
|
|
32
43
|
}
|
|
33
44
|
for (const specifier of node.specifiers) {
|
|
34
45
|
const isTypeImport = specifier.type === AST_NODE_TYPES.ImportSpecifier && specifier.importKind === "type";
|
|
35
|
-
|
|
36
|
-
if (specifier.type === AST_NODE_TYPES.ImportSpecifier && !isTypeImport && !isException && isAggregatedClient(specifier.local.name)) {
|
|
46
|
+
if (specifier.type === AST_NODE_TYPES.ImportSpecifier && !isTypeImport && isAggregatedClient(specifier.local.name, node.source.value)) {
|
|
37
47
|
context.report({
|
|
38
48
|
node: specifier,
|
|
39
49
|
messageId: MESSAGE_ID_AGGREGATED_CLIENT,
|
|
@@ -51,4 +61,4 @@ export {
|
|
|
51
61
|
require_aws_bare_bones_default as default,
|
|
52
62
|
ruleId
|
|
53
63
|
};
|
|
54
|
-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EsVUFDSDtBQUFBLFFBQ0Y7QUFBQSxNQUNGO0FBQUEsSUFDRjtBQUFBLEVBQ0Y7QUFDRixDQUFDO0FBRUQsSUFBTyxpQ0FBUTsiLAogICJuYW1lcyI6IFtdCn0K
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@checkdigit/eslint-plugin","version":"7.17.0-PR.137-
|
|
1
|
+
{"name":"@checkdigit/eslint-plugin","version":"7.17.0-PR.137-0238","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","import":"./dist-mjs/index.mjs","default":"./dist-mjs/index.mjs"}},"files":["src","dist-types","dist-mjs","!src/**/test/**","!src/**/*.test.ts","!src/**/*.spec.ts","!dist-types/**/test/**","!dist-types/**/*.test.d.ts","!dist-types/**/*.spec.d.ts","!dist-mjs/**/test/**","!dist-mjs/**/*.test.mjs","!dist-mjs/**/*.spec.mjs","SECURITY.md"],"scripts":{"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 .","lint:fix":"eslint --max-warnings 0 --fix .","prepare":"","prepublishOnly":"npm run build:dist-types && 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":"^8.46.0","@typescript-eslint/utils":"^8.46.0","http-status-codes":"^2.3.0","ts-api-utils":"^2.1.0"},"devDependencies":{"@checkdigit/jest-config":"^6.0.2","@checkdigit/prettier-config":"^6.1.0","@checkdigit/typescript-config":"^9.3.2","@eslint/js":"^9.37.0","@types/eslint":"^9.6.1","@types/eslint-config-prettier":"^6.11.3","@typescript-eslint/parser":"^8.46.0","@typescript-eslint/rule-tester":"^8.46.0","eslint":"^9.37.0","eslint-config-prettier":"^10.1.8","eslint-import-resolver-typescript":"^4.4.4","eslint-plugin-eslint-plugin":"^6.4.0","eslint-plugin-import":"^2.32.0","eslint-plugin-no-only-tests":"^3.3.0","eslint-plugin-no-secrets":"^2.2.1","eslint-plugin-node":"^11.1.0","eslint-plugin-sonarjs":"1.0.4","rimraf":"^6.0.1","typescript-eslint":"^8.46.0"},"peerDependencies":{"eslint":">=9 <10"},"engines":{"node":">=22.18"}}
|
|
@@ -6,19 +6,36 @@ import getDocumentationUrl from '../get-documentation-url.ts';
|
|
|
6
6
|
export const ruleId = 'require-aws-bare-bones';
|
|
7
7
|
export const MESSAGE_ID_AGGREGATED_CLIENT = 'noAggregatedClient';
|
|
8
8
|
|
|
9
|
-
const BARE_BONES_SUFFIXES =
|
|
9
|
+
const BARE_BONES_SUFFIXES = new Set(['Client', 'Command', 'Exception', 'Input', 'Output']);
|
|
10
|
+
const AWS_LIB_AGGREGATED_SUFFIXES = new Set(['Document']);
|
|
11
|
+
const AWS_SDK_CLIENT = '@aws-sdk/client-';
|
|
12
|
+
const AWS_SDK_LIB = '@aws-sdk/lib-';
|
|
10
13
|
|
|
11
|
-
const createRule = ESLintUtils.RuleCreator(
|
|
14
|
+
const createRule = ESLintUtils.RuleCreator(getDocumentationUrl);
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
typeof importDeclaration.source.value === 'string' && importDeclaration.source.value.startsWith('@aws-sdk/client-')
|
|
16
|
-
);
|
|
17
|
-
}
|
|
16
|
+
const isAwsSdkClientModule = ({ source }: TSESTree.ImportDeclaration): boolean =>
|
|
17
|
+
typeof source.value === 'string' && (source.value.startsWith(AWS_SDK_CLIENT) || source.value.startsWith(AWS_SDK_LIB));
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
const kebabToPascal = (str: string): string =>
|
|
20
|
+
str
|
|
21
|
+
.split('-')
|
|
22
|
+
.map((item) => item.charAt(0).toUpperCase() + item.slice(1))
|
|
23
|
+
.join('');
|
|
24
|
+
|
|
25
|
+
const endsWithAnySuffix = (name: string, suffixes: Set<string>): boolean =>
|
|
26
|
+
Array.from(suffixes).some((suffix) => name.endsWith(suffix));
|
|
27
|
+
|
|
28
|
+
const isAggregatedClient = (name: string, importSource: string): boolean => {
|
|
29
|
+
if (importSource.startsWith(AWS_SDK_CLIENT)) {
|
|
30
|
+
return !endsWithAnySuffix(name, BARE_BONES_SUFFIXES);
|
|
31
|
+
}
|
|
32
|
+
if (importSource.startsWith(AWS_SDK_LIB)) {
|
|
33
|
+
const pkg = importSource.replace(AWS_SDK_LIB, '');
|
|
34
|
+
const pkgPascal = kebabToPascal(pkg);
|
|
35
|
+
return name.startsWith(pkgPascal) || endsWithAnySuffix(name, AWS_LIB_AGGREGATED_SUFFIXES);
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
};
|
|
22
39
|
|
|
23
40
|
const rule: ESLintUtils.RuleModule<typeof MESSAGE_ID_AGGREGATED_CLIENT> = createRule({
|
|
24
41
|
name: ruleId,
|
|
@@ -26,11 +43,11 @@ const rule: ESLintUtils.RuleModule<typeof MESSAGE_ID_AGGREGATED_CLIENT> = create
|
|
|
26
43
|
type: 'problem',
|
|
27
44
|
docs: {
|
|
28
45
|
description:
|
|
29
|
-
'Disallow importing aggregated AWS SDK v3 clients. Use bare-bones pattern (Client
|
|
46
|
+
'Disallow importing aggregated AWS SDK v3 clients. Use bare-bones pattern (Client/Lib plus Command) for better tree-shaking.',
|
|
30
47
|
},
|
|
31
48
|
messages: {
|
|
32
49
|
[MESSAGE_ID_AGGREGATED_CLIENT]:
|
|
33
|
-
'Do not import aggregated AWS SDK v3 client "{{clientName}}". Use bare-bones pattern ({{clientName}}Client
|
|
50
|
+
'Do not import aggregated AWS SDK v3 client "{{clientName}}". Use bare-bones pattern ({{clientName}}Client/Lib plus Command) instead.',
|
|
34
51
|
},
|
|
35
52
|
schema: [],
|
|
36
53
|
},
|
|
@@ -44,13 +61,11 @@ const rule: ESLintUtils.RuleModule<typeof MESSAGE_ID_AGGREGATED_CLIENT> = create
|
|
|
44
61
|
|
|
45
62
|
for (const specifier of node.specifiers) {
|
|
46
63
|
const isTypeImport = specifier.type === AST_NODE_TYPES.ImportSpecifier && specifier.importKind === 'type';
|
|
47
|
-
const isException = specifier.local.name.endsWith('Exception');
|
|
48
64
|
|
|
49
65
|
if (
|
|
50
66
|
specifier.type === AST_NODE_TYPES.ImportSpecifier &&
|
|
51
67
|
!isTypeImport &&
|
|
52
|
-
|
|
53
|
-
isAggregatedClient(specifier.local.name)
|
|
68
|
+
isAggregatedClient(specifier.local.name, node.source.value)
|
|
54
69
|
) {
|
|
55
70
|
context.report({
|
|
56
71
|
node: specifier,
|