@checkdigit/eslint-plugin 7.1.0-PR.86-deaf → 7.1.0-PR.89-9433
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/README.md +1 -0
- package/dist-mjs/index.mjs +13 -11
- package/dist-mjs/no-random-v4-uuid.mjs +67 -0
- package/dist-types/no-random-v4-uuid.d.ts +5 -0
- package/package.json +1 -1
- package/src/index.ts +11 -8
- package/src/no-random-v4-uuid.ts +92 -0
- package/dist-mjs/no-duplicated-imports.mjs +0 -87
- package/dist-mjs/require-fixed-services-import.mjs +0 -46
- package/dist-types/no-duplicated-imports.d.ts +0 -4
- package/dist-types/require-fixed-services-import.d.ts +0 -4
- package/src/no-duplicated-imports.ts +0 -118
- package/src/require-fixed-services-import.ts +0 -53
package/README.md
CHANGED
|
@@ -6,6 +6,7 @@ Copyright (c) 2021-2024 [Check Digit, LLC](https://checkdigit.com)
|
|
|
6
6
|
|
|
7
7
|
- `@checkdigit/no-card-numbers`
|
|
8
8
|
- `@checkdigit/file-path-comment`
|
|
9
|
+
- `@checkdigit/no-random-v4-uuid`
|
|
9
10
|
- `@checkdigit/no-uuid`
|
|
10
11
|
- `@checkdigit/require-strict-assert`
|
|
11
12
|
- `@checkdigit/no-wallaby-comment`
|
package/dist-mjs/index.mjs
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
+
import fs from "node:fs";
|
|
2
3
|
import invalidJsonStringify, { ruleId as invalidJsonStringifyRuleId } from "./invalid-json-stringify.mjs";
|
|
3
|
-
import noDuplicatedImports, { ruleId as noDuplicatedImportsRuleId } from "./no-duplicated-imports.mjs";
|
|
4
4
|
import noFullResponse, { ruleId as noFullResponseRuleId } from "./agent/no-full-response.mjs";
|
|
5
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";
|
|
9
6
|
import requireResolveFullResponse, {
|
|
10
7
|
ruleId as requireResolveFullResponseRuleId
|
|
11
8
|
} from "./require-resolve-full-response.mjs";
|
|
@@ -14,6 +11,7 @@ import requireTypeOutOfTypeOnlyImports, {
|
|
|
14
11
|
} from "./require-type-out-of-type-only-imports.mjs";
|
|
15
12
|
import filePathComment from "./file-path-comment.mjs";
|
|
16
13
|
import noCardNumbers from "./no-card-numbers.mjs";
|
|
14
|
+
import noRandomV4UUID from "./no-random-v4-uuid.mjs";
|
|
17
15
|
import noTestImport from "./no-test-import.mjs";
|
|
18
16
|
import noUuid from "./no-uuid.mjs";
|
|
19
17
|
import noWallabyComment from "./no-wallaby-comment.mjs";
|
|
@@ -24,6 +22,7 @@ import requireStrictAssert from "./require-strict-assert.mjs";
|
|
|
24
22
|
var rules = {
|
|
25
23
|
"file-path-comment": filePathComment,
|
|
26
24
|
"no-card-numbers": noCardNumbers,
|
|
25
|
+
"no-random-v4-uuid": noRandomV4UUID,
|
|
27
26
|
"no-uuid": noUuid,
|
|
28
27
|
"require-strict-assert": requireStrictAssert,
|
|
29
28
|
"no-test-import": noTestImport,
|
|
@@ -35,11 +34,14 @@ var rules = {
|
|
|
35
34
|
[noPromiseInstanceMethodRuleId]: noPromiseInstanceMethod,
|
|
36
35
|
[noFullResponseRuleId]: noFullResponse,
|
|
37
36
|
[requireResolveFullResponseRuleId]: requireResolveFullResponse,
|
|
38
|
-
[requireTypeOutOfTypeOnlyImportsRuleId]: requireTypeOutOfTypeOnlyImports
|
|
39
|
-
[noDuplicatedImportsRuleId]: noDuplicatedImports,
|
|
40
|
-
[requireFixedServicesImportRuleId]: requireFixedServicesImport
|
|
37
|
+
[requireTypeOutOfTypeOnlyImportsRuleId]: requireTypeOutOfTypeOnlyImports
|
|
41
38
|
};
|
|
39
|
+
var packageJson = JSON.parse(fs.readFileSync("package.json", "utf-8"));
|
|
42
40
|
var plugin = {
|
|
41
|
+
meta: {
|
|
42
|
+
name: packageJson.name,
|
|
43
|
+
version: packageJson.version
|
|
44
|
+
},
|
|
43
45
|
rules
|
|
44
46
|
};
|
|
45
47
|
var configs = {
|
|
@@ -50,6 +52,7 @@ var configs = {
|
|
|
50
52
|
rules: {
|
|
51
53
|
"@checkdigit/no-card-numbers": "error",
|
|
52
54
|
"@checkdigit/file-path-comment": "error",
|
|
55
|
+
"@checkdigit/no-random-v4-uuid": "error",
|
|
53
56
|
"@checkdigit/no-uuid": "error",
|
|
54
57
|
"@checkdigit/require-strict-assert": "error",
|
|
55
58
|
"@checkdigit/no-wallaby-comment": "error",
|
|
@@ -61,9 +64,7 @@ var configs = {
|
|
|
61
64
|
[`@checkdigit/${noPromiseInstanceMethodRuleId}`]: "error",
|
|
62
65
|
[`@checkdigit/${noFullResponseRuleId}`]: "error",
|
|
63
66
|
[`@checkdigit/${requireResolveFullResponseRuleId}`]: "error",
|
|
64
|
-
[`@checkdigit/${requireTypeOutOfTypeOnlyImportsRuleId}`]: "error"
|
|
65
|
-
[`@checkdigit/${noDuplicatedImportsRuleId}`]: "error",
|
|
66
|
-
[`@checkdigit/${requireFixedServicesImportRuleId}`]: "error"
|
|
67
|
+
[`@checkdigit/${requireTypeOutOfTypeOnlyImportsRuleId}`]: "error"
|
|
67
68
|
}
|
|
68
69
|
},
|
|
69
70
|
recommended: {
|
|
@@ -73,6 +74,7 @@ var configs = {
|
|
|
73
74
|
rules: {
|
|
74
75
|
"@checkdigit/no-card-numbers": "error",
|
|
75
76
|
"@checkdigit/file-path-comment": "off",
|
|
77
|
+
"@checkdigit/no-random-v4-uuid": "error",
|
|
76
78
|
"@checkdigit/no-uuid": "error",
|
|
77
79
|
"@checkdigit/require-strict-assert": "error",
|
|
78
80
|
"@checkdigit/no-wallaby-comment": "off",
|
|
@@ -93,4 +95,4 @@ var src_default = pluginToExport;
|
|
|
93
95
|
export {
|
|
94
96
|
src_default as default
|
|
95
97
|
};
|
|
96
|
-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lDQUFpQztBQUFBLE1BQ2pDLHVCQUF1QjtBQUFBLE1BQ3ZCLHFDQUFxQztBQUFBLE1BQ3JDLGtDQUFrQztBQUFBLE1BQ2xDLDBDQUEwQztBQUFBLE1BQzFDLHVEQUF1RDtBQUFBLE1BQ3ZELHVDQUF1QztBQUFBLE1BQ3ZDLDhCQUE4QjtBQUFBLE1BQzlCLENBQUMsZUFBZSwwQkFBMEIsRUFBRSxHQUFHO0FBQUEsTUFDL0MsQ0FBQyxlQUFlLDZCQUE2QixFQUFFLEdBQUc7QUFBQSxJQUNwRDtBQUFBLEVBQ0Y7QUFDRjtBQUVBLElBQU0saUJBQTZDO0FBQUEsRUFDakQsR0FBRztBQUFBLEVBQ0g7QUFDRjtBQUNBLElBQU8sY0FBUTsiLAogICJuYW1lcyI6IFtdCn0K
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// src/no-random-v4-uuid.ts
|
|
2
|
+
import { AST_NODE_TYPES, ESLintUtils } from "@typescript-eslint/utils";
|
|
3
|
+
import getDocumentationUrl from "./get-documentation-url.mjs";
|
|
4
|
+
var ruleId = "no-random-v4-uuid";
|
|
5
|
+
var NO_RANDOM_V4_UUID = "NO_RANDOM_V4_UUID";
|
|
6
|
+
var createRule = ESLintUtils.RuleCreator((name) => getDocumentationUrl(name));
|
|
7
|
+
var processImportDeclaration = (node, uuid4Alias, uuidDefaultAlias) => {
|
|
8
|
+
let updatedUuid4Alias = uuid4Alias;
|
|
9
|
+
let updatedUuidDefaultAlias = uuidDefaultAlias;
|
|
10
|
+
node.specifiers.forEach((specifier) => {
|
|
11
|
+
switch (specifier.type) {
|
|
12
|
+
case AST_NODE_TYPES.ImportSpecifier:
|
|
13
|
+
if (specifier.imported.type === AST_NODE_TYPES.Identifier && specifier.imported.name === "v4") {
|
|
14
|
+
updatedUuid4Alias = specifier.local.name;
|
|
15
|
+
}
|
|
16
|
+
break;
|
|
17
|
+
case AST_NODE_TYPES.ImportDefaultSpecifier:
|
|
18
|
+
updatedUuidDefaultAlias = specifier.local.name;
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
return { uuid4Alias: updatedUuid4Alias, uuidDefaultAlias: updatedUuidDefaultAlias };
|
|
23
|
+
};
|
|
24
|
+
var isUuid4Call = (node, uuid4Alias, uuidDefaultAlias) => node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === uuid4Alias || node.callee.type === AST_NODE_TYPES.MemberExpression && node.callee.object.type === AST_NODE_TYPES.Identifier && node.callee.object.name === uuidDefaultAlias && node.callee.property.type === AST_NODE_TYPES.Identifier && node.callee.property.name === "v4";
|
|
25
|
+
var rule = createRule({
|
|
26
|
+
name: ruleId,
|
|
27
|
+
meta: {
|
|
28
|
+
type: "problem",
|
|
29
|
+
docs: {
|
|
30
|
+
description: "Disallow the use of `uuid.v4` for generating random v4 UUIDs"
|
|
31
|
+
},
|
|
32
|
+
schema: [],
|
|
33
|
+
messages: {
|
|
34
|
+
[NO_RANDOM_V4_UUID]: "Avoid using `uuid.v4` for generating random v4 UUIDs."
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
defaultOptions: [],
|
|
38
|
+
create(context) {
|
|
39
|
+
let uuid4Alias;
|
|
40
|
+
let uuidDefaultAlias;
|
|
41
|
+
let hasUuidImport = false;
|
|
42
|
+
return {
|
|
43
|
+
ImportDeclaration(node) {
|
|
44
|
+
if (node.source.value === "uuid") {
|
|
45
|
+
hasUuidImport = true;
|
|
46
|
+
const result = processImportDeclaration(node, uuid4Alias, uuidDefaultAlias);
|
|
47
|
+
uuid4Alias = result.uuid4Alias;
|
|
48
|
+
uuidDefaultAlias = result.uuidDefaultAlias;
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
CallExpression(node) {
|
|
52
|
+
if (hasUuidImport && isUuid4Call(node, uuid4Alias, uuidDefaultAlias)) {
|
|
53
|
+
context.report({
|
|
54
|
+
node,
|
|
55
|
+
messageId: NO_RANDOM_V4_UUID
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
var no_random_v4_uuid_default = rule;
|
|
63
|
+
export {
|
|
64
|
+
no_random_v4_uuid_default as default,
|
|
65
|
+
ruleId
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL25vLXJhbmRvbS12NC11dWlkLnRzIl0sCiAgIm1hcHBpbmdzIjogIjtBQVFBLFNBQVMsZ0JBQWdCLG1CQUF1QztBQUNoRSxPQUFPLHlCQUF5QjtBQUV6QixJQUFNLFNBQVM7QUFDdEIsSUFBTSxvQkFBb0I7QUFFMUIsSUFBTSxhQUFhLFlBQVksWUFBWSxDQUFDLFNBQVMsb0JBQW9CLElBQUksQ0FBQztBQUc5RSxJQUFNLDJCQUEyQixDQUMvQixNQUNBLFlBQ0EscUJBQ0c7QUFDSCxNQUFJLG9CQUFvQjtBQUN4QixNQUFJLDBCQUEwQjtBQUM5QixPQUFLLFdBQVcsUUFBUSxDQUFDLGNBQWM7QUFDckMsWUFBUSxVQUFVLE1BQU07QUFBQSxNQUN0QixLQUFLLGVBQWU7QUFDbEIsWUFBSSxVQUFVLFNBQVMsU0FBUyxlQUFlLGNBQWMsVUFBVSxTQUFTLFNBQVMsTUFBTTtBQUM3Riw4QkFBb0IsVUFBVSxNQUFNO0FBQUEsUUFDdEM7QUFDQTtBQUFBLE1BQ0YsS0FBSyxlQUFlO0FBQ2xCLGtDQUEwQixVQUFVLE1BQU07QUFDMUM7QUFBQSxJQUNKO0FBQUEsRUFDRixDQUFDO0FBQ0QsU0FBTyxFQUFFLFlBQVksbUJBQW1CLGtCQUFrQix3QkFBd0I7QUFDcEY7QUFHQSxJQUFNLGNBQWMsQ0FDbEIsTUFDQSxZQUNBLHFCQUVDLEtBQUssT0FBTyxTQUFTLGVBQWUsY0FBYyxLQUFLLE9BQU8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sSUFBTyw0QkFBUTsiLAogICJuYW1lcyI6IFtdCn0K
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@checkdigit/eslint-plugin","version":"7.1.0-PR.
|
|
1
|
+
{"name":"@checkdigit/eslint-plugin","version":"7.1.0-PR.89-9433","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.10.0","@typescript-eslint/utils":"^8.10.0","ts-api-utils":"^1.3.0"},"devDependencies":{"@checkdigit/jest-config":"^6.0.2","@checkdigit/prettier-config":"^5.5.1","@checkdigit/typescript-config":"8.0.0","@eslint/js":"^9.12.0","@types/eslint":"^9.6.1","@types/eslint-config-prettier":"^6.11.3","@typescript-eslint/parser":"^8.10.0","@typescript-eslint/rule-tester":"^8.10.0","eslint":"^9.12.0","eslint-config-prettier":"^9.1.0","eslint-import-resolver-typescript":"^3.6.3","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":"1.0.4","http-status-codes":"^2.3.0","rimraf":"^6.0.1","typescript-eslint":"^8.10.0"},"peerDependencies":{"eslint":">=9 <10"},"engines":{"node":">=20.17"}}
|
package/src/index.ts
CHANGED
|
@@ -6,15 +6,13 @@
|
|
|
6
6
|
* This code is licensed under the MIT license (see LICENSE.txt for details).
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
import fs from 'node:fs';
|
|
10
|
+
|
|
9
11
|
import type { TSESLint } from '@typescript-eslint/utils';
|
|
10
12
|
|
|
11
13
|
import invalidJsonStringify, { ruleId as invalidJsonStringifyRuleId } from './invalid-json-stringify';
|
|
12
|
-
import noDuplicatedImports, { ruleId as noDuplicatedImportsRuleId } from './no-duplicated-imports';
|
|
13
14
|
import noFullResponse, { ruleId as noFullResponseRuleId } from './agent/no-full-response';
|
|
14
15
|
import noPromiseInstanceMethod, { ruleId as noPromiseInstanceMethodRuleId } from './no-promise-instance-method';
|
|
15
|
-
import requireFixedServicesImport, {
|
|
16
|
-
ruleId as requireFixedServicesImportRuleId,
|
|
17
|
-
} from './require-fixed-services-import';
|
|
18
16
|
import requireResolveFullResponse, {
|
|
19
17
|
ruleId as requireResolveFullResponseRuleId,
|
|
20
18
|
} from './require-resolve-full-response';
|
|
@@ -23,6 +21,7 @@ import requireTypeOutOfTypeOnlyImports, {
|
|
|
23
21
|
} from './require-type-out-of-type-only-imports';
|
|
24
22
|
import filePathComment from './file-path-comment';
|
|
25
23
|
import noCardNumbers from './no-card-numbers';
|
|
24
|
+
import noRandomV4UUID from './no-random-v4-uuid';
|
|
26
25
|
import noTestImport from './no-test-import';
|
|
27
26
|
import noUuid from './no-uuid';
|
|
28
27
|
import noWallabyComment from './no-wallaby-comment';
|
|
@@ -34,6 +33,7 @@ import requireStrictAssert from './require-strict-assert';
|
|
|
34
33
|
const rules: Record<string, TSESLint.LooseRuleDefinition> = {
|
|
35
34
|
'file-path-comment': filePathComment,
|
|
36
35
|
'no-card-numbers': noCardNumbers,
|
|
36
|
+
'no-random-v4-uuid': noRandomV4UUID,
|
|
37
37
|
'no-uuid': noUuid,
|
|
38
38
|
'require-strict-assert': requireStrictAssert,
|
|
39
39
|
'no-test-import': noTestImport,
|
|
@@ -46,11 +46,14 @@ const rules: Record<string, TSESLint.LooseRuleDefinition> = {
|
|
|
46
46
|
[noFullResponseRuleId]: noFullResponse,
|
|
47
47
|
[requireResolveFullResponseRuleId]: requireResolveFullResponse,
|
|
48
48
|
[requireTypeOutOfTypeOnlyImportsRuleId]: requireTypeOutOfTypeOnlyImports,
|
|
49
|
-
[noDuplicatedImportsRuleId]: noDuplicatedImports,
|
|
50
|
-
[requireFixedServicesImportRuleId]: requireFixedServicesImport,
|
|
51
49
|
};
|
|
52
50
|
|
|
51
|
+
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf-8')) as { name: string; version: string };
|
|
53
52
|
const plugin: TSESLint.FlatConfig.Plugin = {
|
|
53
|
+
meta: {
|
|
54
|
+
name: packageJson.name,
|
|
55
|
+
version: packageJson.version,
|
|
56
|
+
},
|
|
54
57
|
rules,
|
|
55
58
|
};
|
|
56
59
|
|
|
@@ -62,6 +65,7 @@ const configs: Record<string, TSESLint.FlatConfig.Config> = {
|
|
|
62
65
|
rules: {
|
|
63
66
|
'@checkdigit/no-card-numbers': 'error',
|
|
64
67
|
'@checkdigit/file-path-comment': 'error',
|
|
68
|
+
'@checkdigit/no-random-v4-uuid': 'error',
|
|
65
69
|
'@checkdigit/no-uuid': 'error',
|
|
66
70
|
'@checkdigit/require-strict-assert': 'error',
|
|
67
71
|
'@checkdigit/no-wallaby-comment': 'error',
|
|
@@ -74,8 +78,6 @@ const configs: Record<string, TSESLint.FlatConfig.Config> = {
|
|
|
74
78
|
[`@checkdigit/${noFullResponseRuleId}`]: 'error',
|
|
75
79
|
[`@checkdigit/${requireResolveFullResponseRuleId}`]: 'error',
|
|
76
80
|
[`@checkdigit/${requireTypeOutOfTypeOnlyImportsRuleId}`]: 'error',
|
|
77
|
-
[`@checkdigit/${noDuplicatedImportsRuleId}`]: 'error',
|
|
78
|
-
[`@checkdigit/${requireFixedServicesImportRuleId}`]: 'error',
|
|
79
81
|
},
|
|
80
82
|
},
|
|
81
83
|
recommended: {
|
|
@@ -85,6 +87,7 @@ const configs: Record<string, TSESLint.FlatConfig.Config> = {
|
|
|
85
87
|
rules: {
|
|
86
88
|
'@checkdigit/no-card-numbers': 'error',
|
|
87
89
|
'@checkdigit/file-path-comment': 'off',
|
|
90
|
+
'@checkdigit/no-random-v4-uuid': 'error',
|
|
88
91
|
'@checkdigit/no-uuid': 'error',
|
|
89
92
|
'@checkdigit/require-strict-assert': 'error',
|
|
90
93
|
'@checkdigit/no-wallaby-comment': 'off',
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// no-random-v4-uuid.ts
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2022-2024 Check Digit, LLC
|
|
5
|
+
*
|
|
6
|
+
* This code is licensed under the MIT license (see LICENSE.txt for details).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { AST_NODE_TYPES, ESLintUtils, TSESLint, TSESTree } from '@typescript-eslint/utils';
|
|
10
|
+
import getDocumentationUrl from './get-documentation-url';
|
|
11
|
+
|
|
12
|
+
export const ruleId = 'no-random-v4-uuid';
|
|
13
|
+
const NO_RANDOM_V4_UUID = 'NO_RANDOM_V4_UUID';
|
|
14
|
+
|
|
15
|
+
const createRule = ESLintUtils.RuleCreator((name) => getDocumentationUrl(name));
|
|
16
|
+
|
|
17
|
+
// process the import declaration to get the alias for uuid.v4 and uuid.
|
|
18
|
+
const processImportDeclaration = (
|
|
19
|
+
node: TSESTree.ImportDeclaration,
|
|
20
|
+
uuid4Alias: string | undefined,
|
|
21
|
+
uuidDefaultAlias: string | undefined,
|
|
22
|
+
) => {
|
|
23
|
+
let updatedUuid4Alias = uuid4Alias;
|
|
24
|
+
let updatedUuidDefaultAlias = uuidDefaultAlias;
|
|
25
|
+
node.specifiers.forEach((specifier) => {
|
|
26
|
+
switch (specifier.type) {
|
|
27
|
+
case AST_NODE_TYPES.ImportSpecifier:
|
|
28
|
+
if (specifier.imported.type === AST_NODE_TYPES.Identifier && specifier.imported.name === 'v4') {
|
|
29
|
+
updatedUuid4Alias = specifier.local.name;
|
|
30
|
+
}
|
|
31
|
+
break;
|
|
32
|
+
case AST_NODE_TYPES.ImportDefaultSpecifier:
|
|
33
|
+
updatedUuidDefaultAlias = specifier.local.name;
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return { uuid4Alias: updatedUuid4Alias, uuidDefaultAlias: updatedUuidDefaultAlias };
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// checks if the function call is either directly using the alias for uuid.v4 or using uuid.v4 as a member expression.
|
|
41
|
+
const isUuid4Call = (
|
|
42
|
+
node: TSESTree.CallExpression,
|
|
43
|
+
uuid4Alias: string | undefined,
|
|
44
|
+
uuidDefaultAlias: string | undefined,
|
|
45
|
+
): boolean =>
|
|
46
|
+
(node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === uuid4Alias) ||
|
|
47
|
+
(node.callee.type === AST_NODE_TYPES.MemberExpression &&
|
|
48
|
+
node.callee.object.type === AST_NODE_TYPES.Identifier &&
|
|
49
|
+
node.callee.object.name === uuidDefaultAlias &&
|
|
50
|
+
node.callee.property.type === AST_NODE_TYPES.Identifier &&
|
|
51
|
+
node.callee.property.name === 'v4');
|
|
52
|
+
|
|
53
|
+
const rule: TSESLint.RuleModule<typeof NO_RANDOM_V4_UUID> = createRule({
|
|
54
|
+
name: ruleId,
|
|
55
|
+
meta: {
|
|
56
|
+
type: 'problem',
|
|
57
|
+
docs: {
|
|
58
|
+
description: 'Disallow the use of `uuid.v4` for generating random v4 UUIDs',
|
|
59
|
+
},
|
|
60
|
+
schema: [],
|
|
61
|
+
messages: {
|
|
62
|
+
[NO_RANDOM_V4_UUID]: 'Avoid using `uuid.v4` for generating random v4 UUIDs.',
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
defaultOptions: [],
|
|
66
|
+
create(context) {
|
|
67
|
+
let uuid4Alias: string | undefined;
|
|
68
|
+
let uuidDefaultAlias: string | undefined;
|
|
69
|
+
let hasUuidImport = false;
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
ImportDeclaration(node: TSESTree.ImportDeclaration) {
|
|
73
|
+
if (node.source.value === 'uuid') {
|
|
74
|
+
hasUuidImport = true;
|
|
75
|
+
const result = processImportDeclaration(node, uuid4Alias, uuidDefaultAlias);
|
|
76
|
+
uuid4Alias = result.uuid4Alias;
|
|
77
|
+
uuidDefaultAlias = result.uuidDefaultAlias;
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
CallExpression(node: TSESTree.CallExpression) {
|
|
81
|
+
if (hasUuidImport && isUuid4Call(node, uuid4Alias, uuidDefaultAlias)) {
|
|
82
|
+
context.report({
|
|
83
|
+
node,
|
|
84
|
+
messageId: NO_RANDOM_V4_UUID,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
export default rule;
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
// src/no-duplicated-imports.ts
|
|
2
|
-
import { strict as assert } from "node:assert";
|
|
3
|
-
import { ESLintUtils, TSESTree } from "@typescript-eslint/utils";
|
|
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
|
-
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL25vLWR1cGxpY2F0ZWQtaW1wb3J0cy50cyJdLAogICJtYXBwaW5ncyI6ICI7QUFRQSxTQUFTLFVBQVUsY0FBYztBQUVqQyxTQUFTLGFBQWEsZ0JBQWdCO0FBRXRDLE9BQU8seUJBQXlCO0FBRXpCLElBQU0sU0FBUztBQUV0QixJQUFNLGFBQWEsWUFBWSxZQUFZLENBQUMsU0FBUyxvQkFBb0IsSUFBSSxDQUFDO0FBRTlFLElBQU0sT0FBeUQsV0FBVztBQUFBLEVBQ3hFLE1BQU07QUFBQSxFQUNOLE1BQU07QUFBQSxJQUNKLE1BQU07QUFBQSxJQUNOLE1BQU07QUFBQSxNQUNKLGFBQWE7QUFBQSxJQUNmO0FBQUEsSUFDQSxVQUFVO0FBQUEsTUFDUix3QkFBd0I7QUFBQSxJQUMxQjtBQUFBLElBQ0EsU0FBUztBQUFBLElBQ1QsUUFBUSxDQUFDO0FBQUEsRUFDWDtBQUFBLEVBQ0EsZ0JBQWdCLENBQUM7QUFBQSxFQUNqQixPQUFPLFNBQVM7QUFDZCxVQUFNLGFBQWEsUUFBUTtBQUMzQixVQUFNLHFCQUFxQixvQkFBSSxJQUEwQztBQUV6RSxXQUFPO0FBQUEsTUFDTCxrQkFBa0IsTUFBTTtBQUN0QixjQUFNLGFBQWEsS0FBSyxPQUFPO0FBQy9CLFlBQUksZUFBZSxtQkFBbUIsSUFBSSxVQUFVO0FBQ3BELFlBQUksaUJBQWlCLFFBQVc7QUFDOUIseUJBQWUsQ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+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,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BLEVBQ0Y7QUFDRixDQUFDO0FBRUQsSUFBTyx3Q0FBUTsiLAogICJuYW1lcyI6IFtdCn0K
|
|
@@ -1,118 +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 { strict as assert } from 'node:assert';
|
|
10
|
-
|
|
11
|
-
import { ESLintUtils, TSESTree } from '@typescript-eslint/utils';
|
|
12
|
-
|
|
13
|
-
import getDocumentationUrl from './get-documentation-url';
|
|
14
|
-
|
|
15
|
-
export const ruleId = 'no-duplicated-imports';
|
|
16
|
-
|
|
17
|
-
const createRule = ESLintUtils.RuleCreator((name) => getDocumentationUrl(name));
|
|
18
|
-
|
|
19
|
-
const rule: ESLintUtils.RuleModule<'mergeDuplicatedImports'> = createRule({
|
|
20
|
-
name: ruleId,
|
|
21
|
-
meta: {
|
|
22
|
-
type: 'suggestion',
|
|
23
|
-
docs: {
|
|
24
|
-
description: 'Merge duplicated import statements with the same "from".',
|
|
25
|
-
},
|
|
26
|
-
messages: {
|
|
27
|
-
mergeDuplicatedImports: 'Merge duplicated import statements with the same "from".',
|
|
28
|
-
},
|
|
29
|
-
fixable: 'code',
|
|
30
|
-
schema: [],
|
|
31
|
-
},
|
|
32
|
-
defaultOptions: [],
|
|
33
|
-
create(context) {
|
|
34
|
-
const sourceCode = context.sourceCode;
|
|
35
|
-
const importDeclarations = new Map<string, TSESTree.ImportDeclaration[]>();
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
ImportDeclaration(node) {
|
|
39
|
-
const moduleName = node.source.value;
|
|
40
|
-
let declarations = importDeclarations.get(moduleName);
|
|
41
|
-
if (declarations === undefined) {
|
|
42
|
-
declarations = [];
|
|
43
|
-
importDeclarations.set(moduleName, declarations);
|
|
44
|
-
}
|
|
45
|
-
declarations.push(node);
|
|
46
|
-
},
|
|
47
|
-
'Program:exit'() {
|
|
48
|
-
for (const [moduleName, declarations] of importDeclarations.entries()) {
|
|
49
|
-
if (declarations.length <= 1) {
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const firstDeclaration = declarations[0];
|
|
54
|
-
assert.ok(firstDeclaration);
|
|
55
|
-
|
|
56
|
-
const isAllTypeOnly = declarations.every(
|
|
57
|
-
(declaration) =>
|
|
58
|
-
declaration.importKind === 'type' ||
|
|
59
|
-
declaration.specifiers.every(
|
|
60
|
-
(specifier) =>
|
|
61
|
-
specifier.type === TSESTree.AST_NODE_TYPES.ImportSpecifier && specifier.importKind === 'type',
|
|
62
|
-
),
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
context.report({
|
|
66
|
-
messageId: 'mergeDuplicatedImports',
|
|
67
|
-
node: firstDeclaration,
|
|
68
|
-
fix(fixer) {
|
|
69
|
-
const fixes = [];
|
|
70
|
-
|
|
71
|
-
const defaultSpecifier = declarations
|
|
72
|
-
.flatMap((declaration) =>
|
|
73
|
-
declaration.specifiers.map((specifier) =>
|
|
74
|
-
specifier.type === TSESTree.AST_NODE_TYPES.ImportDefaultSpecifier ? specifier : undefined,
|
|
75
|
-
),
|
|
76
|
-
)
|
|
77
|
-
.filter(Boolean);
|
|
78
|
-
const defaultSpecifierText = defaultSpecifier[0] ? sourceCode.getText(defaultSpecifier[0]) : undefined;
|
|
79
|
-
|
|
80
|
-
const mergedSpecifiers = declarations.flatMap((declaration) => {
|
|
81
|
-
const isCurrentDeclarationTypeOnly =
|
|
82
|
-
declaration.importKind === 'type' ||
|
|
83
|
-
declaration.specifiers.every(
|
|
84
|
-
(specifier) =>
|
|
85
|
-
specifier.type === TSESTree.AST_NODE_TYPES.ImportSpecifier && specifier.importKind === 'type',
|
|
86
|
-
);
|
|
87
|
-
return declaration.specifiers
|
|
88
|
-
.filter((specifier) => specifier.type !== TSESTree.AST_NODE_TYPES.ImportDefaultSpecifier)
|
|
89
|
-
.map((specifier) =>
|
|
90
|
-
// eslint-disable-next-line no-nested-ternary
|
|
91
|
-
isAllTypeOnly
|
|
92
|
-
? sourceCode.getText(specifier).replace('type ', '')
|
|
93
|
-
: isCurrentDeclarationTypeOnly
|
|
94
|
-
? `type ${sourceCode.getText(specifier)}`
|
|
95
|
-
: sourceCode.getText(specifier),
|
|
96
|
-
);
|
|
97
|
-
});
|
|
98
|
-
const mergedSpecifiersText = `${isAllTypeOnly ? 'type ' : ''}{ ${mergedSpecifiers.join(', ')} }`;
|
|
99
|
-
|
|
100
|
-
// Replace the first import with the merged import
|
|
101
|
-
const mergedImport = `import ${[defaultSpecifierText, mergedSpecifiersText].filter(Boolean).join(', ')} from '${moduleName}';`;
|
|
102
|
-
fixes.push(fixer.replaceText(firstDeclaration, mergedImport));
|
|
103
|
-
|
|
104
|
-
// Remove the remaining imports
|
|
105
|
-
declarations.slice(1).forEach((declaration) => {
|
|
106
|
-
fixes.push(fixer.removeRange([declaration.range[0], declaration.range[1] + 1]));
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
return fixes;
|
|
110
|
-
},
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
|
-
};
|
|
115
|
-
},
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
export default rule;
|
|
@@ -1,53 +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
|
-
|
|
11
|
-
import getDocumentationUrl from './get-documentation-url';
|
|
12
|
-
|
|
13
|
-
export const ruleId = 'require-fixed-services-import';
|
|
14
|
-
|
|
15
|
-
const createRule = ESLintUtils.RuleCreator((name) => getDocumentationUrl(name));
|
|
16
|
-
const SERVICE_TYPINGS_IMPORT_PATH_PREFIX = /(?<path>\.\.\/)+services\/.*/u;
|
|
17
|
-
|
|
18
|
-
const rule: ESLintUtils.RuleModule<'updateServicesImportFrom'> = createRule({
|
|
19
|
-
name: ruleId,
|
|
20
|
-
meta: {
|
|
21
|
-
type: 'suggestion',
|
|
22
|
-
docs: {
|
|
23
|
-
description: 'Require fixed "from" with service typing imports from "src/services".',
|
|
24
|
-
},
|
|
25
|
-
messages: {
|
|
26
|
-
updateServicesImportFrom: 'Update service typing imports to be from the fixed "src/services" path.',
|
|
27
|
-
},
|
|
28
|
-
fixable: 'code',
|
|
29
|
-
schema: [],
|
|
30
|
-
},
|
|
31
|
-
defaultOptions: [],
|
|
32
|
-
create(context) {
|
|
33
|
-
return {
|
|
34
|
-
ImportDeclaration(node) {
|
|
35
|
-
const moduleName = node.source.value;
|
|
36
|
-
if (SERVICE_TYPINGS_IMPORT_PATH_PREFIX.test(moduleName)) {
|
|
37
|
-
context.report({
|
|
38
|
-
messageId: 'updateServicesImportFrom',
|
|
39
|
-
node: node.source,
|
|
40
|
-
*fix(fixer) {
|
|
41
|
-
yield fixer.replaceText(
|
|
42
|
-
node.source,
|
|
43
|
-
`'${moduleName.slice(0, moduleName.indexOf('../services') + '../services'.length)}'`,
|
|
44
|
-
);
|
|
45
|
-
},
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
},
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
export default rule;
|