@checkdigit/eslint-plugin 4.1.0-PR.32-b8ce → 4.1.1

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/src/no-uuid.ts DELETED
@@ -1,109 +0,0 @@
1
- // no-uuid.ts
2
-
3
- /*
4
- * Copyright (c) 2022 Check Digit, LLC
5
- *
6
- * This code is licensed under the MIT license (see LICENSE.txt for details).
7
- */
8
-
9
- import type { Node, SourceLocation } from 'estree';
10
- import type { Rule } from 'eslint';
11
-
12
- const UUID_FOUND = 'UUID_FOUND';
13
- const UUIDS_FOUND = 'UUIDS_FOUND';
14
- const uuidRegex = /[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}/gmu;
15
-
16
- function checkForUuid(value: string, context: Rule.RuleContext, node?: Node, loc?: SourceLocation) {
17
- const matches = value.match(uuidRegex);
18
- if (matches === null) {
19
- return;
20
- }
21
- if (matches.length === 1) {
22
- if (node !== undefined) {
23
- context.report({
24
- messageId: UUID_FOUND,
25
- data: {
26
- uuid: matches[0] ?? '',
27
- },
28
- node,
29
- });
30
- } else if (loc !== undefined) {
31
- context.report({
32
- messageId: UUID_FOUND,
33
- data: {
34
- uuid: matches[0] ?? '',
35
- },
36
- loc: {
37
- start: loc.start,
38
- end: loc.end,
39
- },
40
- });
41
- }
42
- } else if (matches.length > 1) {
43
- if (node !== undefined) {
44
- context.report({
45
- messageId: UUIDS_FOUND,
46
- data: {
47
- uuids: matches.join(', '),
48
- },
49
- node,
50
- });
51
- } else if (loc !== undefined) {
52
- context.report({
53
- messageId: UUIDS_FOUND,
54
- data: {
55
- uuids: matches.join(', '),
56
- },
57
- loc: {
58
- start: loc.start,
59
- end: loc.end,
60
- },
61
- });
62
- }
63
- }
64
- }
65
-
66
- export default {
67
- meta: {
68
- type: 'problem',
69
- docs: {
70
- description: 'Detects if a string literal contains a UUID',
71
- url: 'https://github.com/checkdigit/eslint-plugin',
72
- },
73
- messages: {
74
- [UUID_FOUND]: `UUID found: "{{ uuid }}"`,
75
- [UUIDS_FOUND]: `Multiple UUIDs found: "{{ uuids }}"`,
76
- },
77
- },
78
- create(context) {
79
- const sourceCode = context.getSourceCode();
80
- const comments = sourceCode.getAllComments();
81
-
82
- comments.forEach((comment) => {
83
- if (comment.loc !== undefined && comment.loc !== null) {
84
- checkForUuid(comment.value, context, undefined, comment.loc);
85
- }
86
- });
87
- return {
88
- Literal(node) {
89
- if (node.value === undefined) {
90
- return;
91
- }
92
- if (typeof node.value !== 'string') {
93
- return;
94
- }
95
- const value = `${node.value}`;
96
- checkForUuid(value, context, node);
97
- },
98
- TemplateElement(node) {
99
- if (!node.value) {
100
- return;
101
- }
102
- if (typeof node.value.cooked !== 'string') {
103
- return;
104
- }
105
- checkForUuid(node.value.cooked, context, node);
106
- },
107
- };
108
- },
109
- } as Rule.RuleModule;