@checkdigit/eslint-plugin 7.13.0-PR.119-2212 → 7.13.0-PR.119-72c1
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-mjs/no-random-v4-uuid.mjs +3 -18
- package/package.json +1 -1
- package/src/no-random-v4-uuid.ts +11 -32
|
@@ -11,7 +11,7 @@ var processImportDeclaration = (node, aliases) => {
|
|
|
11
11
|
if (node.source.value === "uuid" && specifier.imported.type === AST_NODE_TYPES.Identifier && specifier.imported.name === "v4") {
|
|
12
12
|
aliases.uuid4Alias = specifier.local.name;
|
|
13
13
|
} else if (node.source.value === "node:crypto" && specifier.imported.type === AST_NODE_TYPES.Identifier && specifier.imported.name === "randomUUID") {
|
|
14
|
-
aliases.
|
|
14
|
+
aliases.nodeCryptoRandomUUIDAlias = specifier.local.name;
|
|
15
15
|
}
|
|
16
16
|
} else if (specifier.type === AST_NODE_TYPES.ImportDefaultSpecifier && node.source.value === "uuid") {
|
|
17
17
|
aliases.uuidDefaultAlias = specifier.local.name;
|
|
@@ -36,14 +36,9 @@ var rule = createRule({
|
|
|
36
36
|
defaultOptions: [],
|
|
37
37
|
create(context) {
|
|
38
38
|
const aliases = {};
|
|
39
|
-
let uuidImportNode = null;
|
|
40
|
-
let hasReportedCallExpression = false;
|
|
41
39
|
return {
|
|
42
40
|
ImportDeclaration(node) {
|
|
43
41
|
processImportDeclaration(node, aliases);
|
|
44
|
-
if (node.source.value === "uuid") {
|
|
45
|
-
uuidImportNode = node;
|
|
46
|
-
}
|
|
47
42
|
},
|
|
48
43
|
CallExpression(node) {
|
|
49
44
|
if (isUuid4Call(node, aliases)) {
|
|
@@ -51,21 +46,11 @@ var rule = createRule({
|
|
|
51
46
|
node,
|
|
52
47
|
messageId: NO_UUID_MODULE_FOR_V4
|
|
53
48
|
});
|
|
54
|
-
|
|
55
|
-
} else if (isCryptoRandomUUIDCall(node, aliases.cryptoRandomUUIDAlias)) {
|
|
49
|
+
} else if (isCryptoRandomUUIDCall(node, aliases.nodeCryptoRandomUUIDAlias)) {
|
|
56
50
|
context.report({
|
|
57
51
|
node,
|
|
58
52
|
messageId: NO_RANDOM_V4_UUID
|
|
59
53
|
});
|
|
60
|
-
hasReportedCallExpression = true;
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
"Program:exit"() {
|
|
64
|
-
if (uuidImportNode && !hasReportedCallExpression && aliases.uuid4Alias !== void 0 && aliases.uuid4Alias !== "" && (aliases.uuidDefaultAlias === void 0 || aliases.uuidDefaultAlias === "")) {
|
|
65
|
-
context.report({
|
|
66
|
-
node: uuidImportNode,
|
|
67
|
-
messageId: NO_UUID_MODULE_FOR_V4
|
|
68
|
-
});
|
|
69
54
|
}
|
|
70
55
|
}
|
|
71
56
|
};
|
|
@@ -76,4 +61,4 @@ export {
|
|
|
76
61
|
no_random_v4_uuid_default as default,
|
|
77
62
|
ruleId
|
|
78
63
|
};
|
|
79
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
64
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL25vLXJhbmRvbS12NC11dWlkLnRzIl0sCiAgIm1hcHBpbmdzIjogIjtBQVFBLFNBQVMsZ0JBQWdCLG1CQUF1QztBQUNoRSxPQUFPLHlCQUF5QjtBQUV6QixJQUFNLFNBQVM7QUFDdEIsSUFBTSxvQkFBb0I7QUFDMUIsSUFBTSx3QkFBd0I7QUFFOUIsSUFBTSxhQUFhLFlBQVksWUFBWSxDQUFDLFNBQVMsb0JBQW9CLElBQUksQ0FBQztBQVE5RSxJQUFNLDJCQUEyQixDQUFDLE1BQWtDLFlBQXFCO0FBQ3ZGLE9BQUssV0FBVyxRQUFRLENBQUMsY0FBYztBQUNyQyxRQUFJLFVBQVUsU0FBUyxlQUFlLGlCQUFpQjtBQUNyRCxVQUNFLEtBQUssT0FBTyxVQUFVLFVBQ3RCLFVBQVUsU0FBUyxTQ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E1BQU07QUFBQSxFQUNOLE1BQU07QUFBQSxJQUNKLE1BQU07QUFBQSxJQUNOLE1BQU07QUFBQSxNQUNKLGFBQ0U7QUFBQSxJQUNKO0FBQUEsSUFDQSxRQUFRLENBQUM7QUFBQSxJQUNULFVBQVU7QUFBQSxNQUNSLENBQUMsaUJBQWlCLEdBQUc7QUFBQSxNQUNyQixDQUFDLHFCQUFxQixHQUFHO0FBQUEsSUFDM0I7QUFBQSxFQUNGO0FBQUEsRUFDQSxnQkFBZ0IsQ0FBQztBQUFBLEVBQ2pCLE9BQU8sU0FBUztBQUNkLFVBQU0sVUFBbUIsQ0FBQztBQUUxQixXQUFPO0FBQUEsTUFDTCxrQkFBa0IsTUFBa0M7QUFDbEQsaUNBQXlCLE1BQU0sT0FBTztBQUFBLE1BQ3hDO0FBQUEsTUFDQSxlQUFlLE1BQStCO0FBQzVDLFlBQUksWUFBWSxNQUFNLE9BQU8sR0FBRztBQUM5QixrQkFBUSxPQUFPO0FBQUEsWUFDYjtBQUFBLFlBQ0EsV0FBVztBQUFBLFVBQ2IsQ0FBQztBQUFBLFFBQ0gsV0FBVyx1QkFBdUIsTUFBTSxRQUFRLHlCQUF5QixHQUFHO0FBQzFFLGtCQUFRLE9BQU87QUFBQSxZQUNiO0FBQUEsWUFDQSxXQUFXO0FBQUEsVUFDYixDQUFDO0FBQUEsUUFDSDtBQUFBLE1BQ0Y7QUFBQSxJQUNGO0FBQUEsRUFDRjtBQUNGLENBQUM7QUFFRCxJQUFPLDRCQUFROyIsCiAgIm5hbWVzIjogW10KfQo=
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@checkdigit/eslint-plugin","version":"7.13.0-PR.119-
|
|
1
|
+
{"name":"@checkdigit/eslint-plugin","version":"7.13.0-PR.119-72c1","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.23.0","@typescript-eslint/utils":"^8.23.0","http-status-codes":"^2.3.0","ts-api-utils":"^2.0.1"},"devDependencies":{"@checkdigit/jest-config":"^6.0.2","@checkdigit/prettier-config":"^6.1.0","@checkdigit/typescript-config":"^9.0.0","@eslint/js":"^9.19.0","@types/eslint":"^9.6.1","@types/eslint-config-prettier":"^6.11.3","@typescript-eslint/parser":"^8.23.0","@typescript-eslint/rule-tester":"^8.23.0","eslint":"^9.19.0","eslint-config-prettier":"^10.0.1","eslint-import-resolver-typescript":"^3.7.0","eslint-plugin-eslint-plugin":"^6.4.0","eslint-plugin-import":"^2.31.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.23.0"},"peerDependencies":{"eslint":">=9 <10"},"engines":{"node":">=20.17"}}
|
package/src/no-random-v4-uuid.ts
CHANGED
|
@@ -15,10 +15,13 @@ const NO_UUID_MODULE_FOR_V4 = 'NO_UUID_MODULE_FOR_V4';
|
|
|
15
15
|
|
|
16
16
|
const createRule = ESLintUtils.RuleCreator((name) => getDocumentationUrl(name));
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
interface Aliases {
|
|
19
|
+
uuid4Alias?: string;
|
|
20
|
+
uuidDefaultAlias?: string;
|
|
21
|
+
nodeCryptoRandomUUIDAlias?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const processImportDeclaration = (node: TSESTree.ImportDeclaration, aliases: Aliases) => {
|
|
22
25
|
node.specifiers.forEach((specifier) => {
|
|
23
26
|
if (specifier.type === AST_NODE_TYPES.ImportSpecifier) {
|
|
24
27
|
if (
|
|
@@ -32,7 +35,7 @@ const processImportDeclaration = (
|
|
|
32
35
|
specifier.imported.type === AST_NODE_TYPES.Identifier &&
|
|
33
36
|
specifier.imported.name === 'randomUUID'
|
|
34
37
|
) {
|
|
35
|
-
aliases.
|
|
38
|
+
aliases.nodeCryptoRandomUUIDAlias = specifier.local.name;
|
|
36
39
|
}
|
|
37
40
|
} else if (specifier.type === AST_NODE_TYPES.ImportDefaultSpecifier && node.source.value === 'uuid') {
|
|
38
41
|
aliases.uuidDefaultAlias = specifier.local.name;
|
|
@@ -40,10 +43,7 @@ const processImportDeclaration = (
|
|
|
40
43
|
});
|
|
41
44
|
};
|
|
42
45
|
|
|
43
|
-
const isUuid4Call = (
|
|
44
|
-
node: TSESTree.CallExpression,
|
|
45
|
-
aliases: { uuid4Alias?: string; uuidDefaultAlias?: string },
|
|
46
|
-
): boolean =>
|
|
46
|
+
const isUuid4Call = (node: TSESTree.CallExpression, aliases: Aliases): boolean =>
|
|
47
47
|
(node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === aliases.uuid4Alias) ||
|
|
48
48
|
(node.callee.type === AST_NODE_TYPES.MemberExpression &&
|
|
49
49
|
node.callee.object.type === AST_NODE_TYPES.Identifier &&
|
|
@@ -75,16 +75,11 @@ const rule: TSESLint.RuleModule<typeof NO_RANDOM_V4_UUID | typeof NO_UUID_MODULE
|
|
|
75
75
|
},
|
|
76
76
|
defaultOptions: [],
|
|
77
77
|
create(context) {
|
|
78
|
-
const aliases:
|
|
79
|
-
let uuidImportNode: TSESTree.ImportDeclaration | null = null;
|
|
80
|
-
let hasReportedCallExpression = false;
|
|
78
|
+
const aliases: Aliases = {};
|
|
81
79
|
|
|
82
80
|
return {
|
|
83
81
|
ImportDeclaration(node: TSESTree.ImportDeclaration) {
|
|
84
82
|
processImportDeclaration(node, aliases);
|
|
85
|
-
if (node.source.value === 'uuid') {
|
|
86
|
-
uuidImportNode = node;
|
|
87
|
-
}
|
|
88
83
|
},
|
|
89
84
|
CallExpression(node: TSESTree.CallExpression) {
|
|
90
85
|
if (isUuid4Call(node, aliases)) {
|
|
@@ -92,27 +87,11 @@ const rule: TSESLint.RuleModule<typeof NO_RANDOM_V4_UUID | typeof NO_UUID_MODULE
|
|
|
92
87
|
node,
|
|
93
88
|
messageId: NO_UUID_MODULE_FOR_V4,
|
|
94
89
|
});
|
|
95
|
-
|
|
96
|
-
} else if (isCryptoRandomUUIDCall(node, aliases.cryptoRandomUUIDAlias)) {
|
|
90
|
+
} else if (isCryptoRandomUUIDCall(node, aliases.nodeCryptoRandomUUIDAlias)) {
|
|
97
91
|
context.report({
|
|
98
92
|
node,
|
|
99
93
|
messageId: NO_RANDOM_V4_UUID,
|
|
100
94
|
});
|
|
101
|
-
hasReportedCallExpression = true;
|
|
102
|
-
}
|
|
103
|
-
},
|
|
104
|
-
'Program:exit'() {
|
|
105
|
-
if (
|
|
106
|
-
uuidImportNode &&
|
|
107
|
-
!hasReportedCallExpression &&
|
|
108
|
-
aliases.uuid4Alias !== undefined &&
|
|
109
|
-
aliases.uuid4Alias !== '' &&
|
|
110
|
-
(aliases.uuidDefaultAlias === undefined || aliases.uuidDefaultAlias === '')
|
|
111
|
-
) {
|
|
112
|
-
context.report({
|
|
113
|
-
node: uuidImportNode,
|
|
114
|
-
messageId: NO_UUID_MODULE_FOR_V4,
|
|
115
|
-
});
|
|
116
95
|
}
|
|
117
96
|
},
|
|
118
97
|
};
|