@murky-web/simplelog 0.1.0 → 1.0.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/README.md +78 -34
- package/dist/bun_logger.d.ts.map +1 -1
- package/dist/deno_logger.d.ts.map +1 -1
- package/dist/hono_middleware.d.ts.map +1 -1
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger_factory.d.ts +1 -0
- package/dist/logger_factory.d.ts.map +1 -1
- package/dist/logger_factory.js +7 -3
- package/dist/logger_factory.js.map +1 -1
- package/dist/web_logger.d.ts.map +1 -1
- package/oxlint/index.mjs +26 -0
- package/oxlint/no-ad-hoc-console-fallback.mjs +65 -0
- package/oxlint/no-console-alias.mjs +69 -0
- package/oxlint/prefer-child-logger.mjs +77 -0
- package/oxlint/prefer-hono-context-logger.mjs +113 -0
- package/oxlint/prefer-runtime-entry.mjs +50 -0
- package/oxlint/prefer-simplelog.mjs +64 -0
- package/oxlint/require-logger-name.mjs +85 -0
- package/oxlint/utils.mjs +211 -0
- package/package.json +74 -68
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { isInsideFunctionScope, isLoggerImportSource } from "./utils.mjs";
|
|
2
|
+
|
|
3
|
+
export const preferChildLoggerRule = {
|
|
4
|
+
meta: {
|
|
5
|
+
type: "suggestion",
|
|
6
|
+
docs: {
|
|
7
|
+
description:
|
|
8
|
+
"Prefer deriving child loggers from an existing SimpleLog logger inside functions and request handlers.",
|
|
9
|
+
},
|
|
10
|
+
schema: [],
|
|
11
|
+
messages: {
|
|
12
|
+
preferChildLogger:
|
|
13
|
+
"Prefer logger.createChildLogger(...) over creating a new root Logger inside a nested function scope.",
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
create(context) {
|
|
17
|
+
const loggerConstructors = new Set();
|
|
18
|
+
const loggerNamespaces = new Set();
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
ImportDeclaration(node) {
|
|
22
|
+
if (
|
|
23
|
+
node.source?.type !== "Literal" ||
|
|
24
|
+
typeof node.source.value !== "string" ||
|
|
25
|
+
!isLoggerImportSource(node.source.value)
|
|
26
|
+
) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
for (const specifier of node.specifiers ?? []) {
|
|
31
|
+
if (specifier.type === "ImportSpecifier") {
|
|
32
|
+
if (
|
|
33
|
+
specifier.imported?.type === "Identifier" &&
|
|
34
|
+
specifier.imported.name === "Logger"
|
|
35
|
+
) {
|
|
36
|
+
loggerConstructors.add(specifier.local.name);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (specifier.type === "ImportNamespaceSpecifier") {
|
|
41
|
+
loggerNamespaces.add(specifier.local.name);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
NewExpression(node) {
|
|
46
|
+
if (!isInsideFunctionScope(node)) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (
|
|
51
|
+
node.callee?.type === "Identifier" &&
|
|
52
|
+
loggerConstructors.has(node.callee.name)
|
|
53
|
+
) {
|
|
54
|
+
context.report({
|
|
55
|
+
messageId: "preferChildLogger",
|
|
56
|
+
node: node.callee,
|
|
57
|
+
});
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (
|
|
62
|
+
node.callee?.type === "MemberExpression" &&
|
|
63
|
+
!node.callee.computed &&
|
|
64
|
+
node.callee.object?.type === "Identifier" &&
|
|
65
|
+
loggerNamespaces.has(node.callee.object.name) &&
|
|
66
|
+
node.callee.property?.type === "Identifier" &&
|
|
67
|
+
node.callee.property.name === "Logger"
|
|
68
|
+
) {
|
|
69
|
+
context.report({
|
|
70
|
+
messageId: "preferChildLogger",
|
|
71
|
+
node: node.callee.property,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SIMPLELOG_LOG_METHODS,
|
|
3
|
+
functionHasContextParam,
|
|
4
|
+
getEnclosingFunction,
|
|
5
|
+
} from "./utils.mjs";
|
|
6
|
+
|
|
7
|
+
export const preferHonoContextLoggerRule = {
|
|
8
|
+
meta: {
|
|
9
|
+
type: "suggestion",
|
|
10
|
+
docs: {
|
|
11
|
+
description:
|
|
12
|
+
"Prefer c.var.logger over a root logger inside Hono request handlers.",
|
|
13
|
+
},
|
|
14
|
+
schema: [],
|
|
15
|
+
messages: {
|
|
16
|
+
preferHonoContextLogger:
|
|
17
|
+
"Prefer c.var.logger inside Hono handlers instead of calling a root logger directly.",
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
create(context) {
|
|
21
|
+
let honoImported = false;
|
|
22
|
+
const rootLoggerBindings = new Set();
|
|
23
|
+
const loggerConstructors = new Set();
|
|
24
|
+
const loggerNamespaces = new Set();
|
|
25
|
+
|
|
26
|
+
function isLoggerConstructor(node) {
|
|
27
|
+
if (node?.type === "Identifier") {
|
|
28
|
+
return loggerConstructors.has(node.name);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
node?.type === "MemberExpression" &&
|
|
33
|
+
!node.computed &&
|
|
34
|
+
node.object?.type === "Identifier" &&
|
|
35
|
+
loggerNamespaces.has(node.object.name) &&
|
|
36
|
+
node.property?.type === "Identifier" &&
|
|
37
|
+
node.property.name === "Logger"
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
ImportDeclaration(node) {
|
|
43
|
+
if (
|
|
44
|
+
node.source?.type === "Literal" &&
|
|
45
|
+
typeof node.source.value === "string" &&
|
|
46
|
+
node.source.value.startsWith("hono")
|
|
47
|
+
) {
|
|
48
|
+
honoImported = true;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (
|
|
52
|
+
node.source?.type !== "Literal" ||
|
|
53
|
+
typeof node.source.value !== "string" ||
|
|
54
|
+
!node.source.value.startsWith("@murky-web/simplelog")
|
|
55
|
+
) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
for (const specifier of node.specifiers ?? []) {
|
|
60
|
+
if (specifier.type === "ImportSpecifier") {
|
|
61
|
+
if (
|
|
62
|
+
specifier.imported?.type === "Identifier" &&
|
|
63
|
+
specifier.imported.name === "Logger"
|
|
64
|
+
) {
|
|
65
|
+
loggerConstructors.add(specifier.local.name);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (specifier.type === "ImportNamespaceSpecifier") {
|
|
70
|
+
loggerNamespaces.add(specifier.local.name);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
VariableDeclarator(node) {
|
|
75
|
+
if (
|
|
76
|
+
node.parent?.type === "VariableDeclaration" &&
|
|
77
|
+
node.parent.parent?.type === "Program" &&
|
|
78
|
+
node.id?.type === "Identifier" &&
|
|
79
|
+
node.init?.type === "NewExpression" &&
|
|
80
|
+
isLoggerConstructor(node.init.callee)
|
|
81
|
+
) {
|
|
82
|
+
rootLoggerBindings.add(node.id.name);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
CallExpression(node) {
|
|
86
|
+
if (!honoImported) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (
|
|
91
|
+
node.callee?.type !== "MemberExpression" ||
|
|
92
|
+
node.callee.computed ||
|
|
93
|
+
node.callee.object?.type !== "Identifier" ||
|
|
94
|
+
!rootLoggerBindings.has(node.callee.object.name) ||
|
|
95
|
+
node.callee.property?.type !== "Identifier" ||
|
|
96
|
+
!SIMPLELOG_LOG_METHODS.has(node.callee.property.name)
|
|
97
|
+
) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const enclosingFunction = getEnclosingFunction(node);
|
|
102
|
+
if (!functionHasContextParam(enclosingFunction)) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
context.report({
|
|
107
|
+
messageId: "preferHonoContextLogger",
|
|
108
|
+
node: node.callee.object,
|
|
109
|
+
});
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
},
|
|
113
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { isBareSimplelogSource, SIMPLELOG_PACKAGE } from "./utils.mjs";
|
|
2
|
+
|
|
3
|
+
export const preferRuntimeEntryRule = {
|
|
4
|
+
meta: {
|
|
5
|
+
type: "suggestion",
|
|
6
|
+
docs: {
|
|
7
|
+
description:
|
|
8
|
+
"Prefer explicit SimpleLog runtime entries over the package root import.",
|
|
9
|
+
},
|
|
10
|
+
schema: [],
|
|
11
|
+
messages: {
|
|
12
|
+
preferRuntimeEntry: `Prefer an explicit runtime entry over "${SIMPLELOG_PACKAGE}". Use a runtime-specific import like "@murky-web/simplelog/node", "@murky-web/simplelog/web", "@murky-web/simplelog/bun", "@murky-web/simplelog/deno", or "@murky-web/simplelog/hono".`,
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
create(context) {
|
|
16
|
+
function reportSourceNode(node) {
|
|
17
|
+
if (
|
|
18
|
+
node?.type === "Literal" &&
|
|
19
|
+
typeof node.value === "string" &&
|
|
20
|
+
isBareSimplelogSource(node.value)
|
|
21
|
+
) {
|
|
22
|
+
context.report({
|
|
23
|
+
messageId: "preferRuntimeEntry",
|
|
24
|
+
node,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
ImportDeclaration(node) {
|
|
31
|
+
reportSourceNode(node.source);
|
|
32
|
+
},
|
|
33
|
+
ExportNamedDeclaration(node) {
|
|
34
|
+
reportSourceNode(node.source);
|
|
35
|
+
},
|
|
36
|
+
ExportAllDeclaration(node) {
|
|
37
|
+
reportSourceNode(node.source);
|
|
38
|
+
},
|
|
39
|
+
CallExpression(node) {
|
|
40
|
+
if (
|
|
41
|
+
node.callee?.type === "Identifier" &&
|
|
42
|
+
node.callee.name === "require" &&
|
|
43
|
+
node.arguments?.[0]
|
|
44
|
+
) {
|
|
45
|
+
reportSourceNode(node.arguments[0]);
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const CONSOLE_METHOD_TO_LOGGER_METHOD = {
|
|
2
|
+
debug: "debug",
|
|
3
|
+
error: "error",
|
|
4
|
+
info: "info",
|
|
5
|
+
log: "info",
|
|
6
|
+
trace: "debug",
|
|
7
|
+
warn: "warn",
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const preferSimplelogRule = {
|
|
11
|
+
meta: {
|
|
12
|
+
type: "suggestion",
|
|
13
|
+
docs: {
|
|
14
|
+
description:
|
|
15
|
+
"Prefer @murky-web/simplelog over direct console method calls.",
|
|
16
|
+
},
|
|
17
|
+
schema: [],
|
|
18
|
+
messages: {
|
|
19
|
+
preferSimplelog:
|
|
20
|
+
"Prefer a SimpleLog logger over direct console.{{consoleMethod}}(). Use logger.{{loggerMethod}}(...) instead.",
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
create(context) {
|
|
24
|
+
return {
|
|
25
|
+
CallExpression(node) {
|
|
26
|
+
if (node.callee?.type !== "MemberExpression") {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (node.callee.computed) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (
|
|
35
|
+
node.callee.object?.type !== "Identifier" ||
|
|
36
|
+
node.callee.object.name !== "console"
|
|
37
|
+
) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (node.callee.property?.type !== "Identifier") {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const consoleMethod = node.callee.property.name;
|
|
46
|
+
const loggerMethod =
|
|
47
|
+
CONSOLE_METHOD_TO_LOGGER_METHOD[consoleMethod];
|
|
48
|
+
|
|
49
|
+
if (!loggerMethod) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
context.report({
|
|
54
|
+
messageId: "preferSimplelog",
|
|
55
|
+
data: {
|
|
56
|
+
consoleMethod,
|
|
57
|
+
loggerMethod,
|
|
58
|
+
},
|
|
59
|
+
node: node.callee.property,
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
export const requireLoggerNameRule = {
|
|
2
|
+
meta: {
|
|
3
|
+
type: "problem",
|
|
4
|
+
docs: {
|
|
5
|
+
description:
|
|
6
|
+
"Require SimpleLog Logger instances to have a non-empty name for useful log output.",
|
|
7
|
+
},
|
|
8
|
+
schema: [],
|
|
9
|
+
messages: {
|
|
10
|
+
requireLoggerName:
|
|
11
|
+
"Provide a non-empty logger name when creating a SimpleLog Logger.",
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
create(context) {
|
|
15
|
+
const loggerConstructors = new Set();
|
|
16
|
+
const loggerNamespaces = new Set();
|
|
17
|
+
|
|
18
|
+
function isLoggerConstructor(node) {
|
|
19
|
+
if (node?.type === "Identifier") {
|
|
20
|
+
return loggerConstructors.has(node.name);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
node?.type === "MemberExpression" &&
|
|
25
|
+
!node.computed &&
|
|
26
|
+
node.object?.type === "Identifier" &&
|
|
27
|
+
loggerNamespaces.has(node.object.name) &&
|
|
28
|
+
node.property?.type === "Identifier" &&
|
|
29
|
+
node.property.name === "Logger"
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
ImportDeclaration(node) {
|
|
35
|
+
if (
|
|
36
|
+
node.source?.type !== "Literal" ||
|
|
37
|
+
typeof node.source.value !== "string" ||
|
|
38
|
+
!node.source.value.startsWith("@murky-web/simplelog")
|
|
39
|
+
) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
for (const specifier of node.specifiers ?? []) {
|
|
44
|
+
if (specifier.type === "ImportSpecifier") {
|
|
45
|
+
if (
|
|
46
|
+
specifier.imported?.type === "Identifier" &&
|
|
47
|
+
specifier.imported.name === "Logger"
|
|
48
|
+
) {
|
|
49
|
+
loggerConstructors.add(specifier.local.name);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (specifier.type === "ImportNamespaceSpecifier") {
|
|
54
|
+
loggerNamespaces.add(specifier.local.name);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
NewExpression(node) {
|
|
59
|
+
if (!isLoggerConstructor(node.callee)) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const [firstArgument] = node.arguments ?? [];
|
|
64
|
+
if (!firstArgument) {
|
|
65
|
+
context.report({
|
|
66
|
+
messageId: "requireLoggerName",
|
|
67
|
+
node: node.callee,
|
|
68
|
+
});
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (
|
|
73
|
+
firstArgument.type === "Literal" &&
|
|
74
|
+
typeof firstArgument.value === "string" &&
|
|
75
|
+
firstArgument.value.trim().length === 0
|
|
76
|
+
) {
|
|
77
|
+
context.report({
|
|
78
|
+
messageId: "requireLoggerName",
|
|
79
|
+
node: firstArgument,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
};
|
package/oxlint/utils.mjs
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
const SIMPLELOG_PACKAGE = "@murky-web/simplelog";
|
|
2
|
+
const SIMPLELOG_LOG_METHODS = new Set([
|
|
3
|
+
"debug",
|
|
4
|
+
"error",
|
|
5
|
+
"info",
|
|
6
|
+
"warn",
|
|
7
|
+
"startPerformanceBenchmark",
|
|
8
|
+
"endPerformanceBenchmark",
|
|
9
|
+
"assert",
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
function isSimplelogSource(source) {
|
|
13
|
+
return (
|
|
14
|
+
typeof source === "string" &&
|
|
15
|
+
(source === SIMPLELOG_PACKAGE ||
|
|
16
|
+
source.startsWith(`${SIMPLELOG_PACKAGE}/`))
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function isBareSimplelogSource(source) {
|
|
21
|
+
return source === SIMPLELOG_PACKAGE;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function isLoggerImportSource(source) {
|
|
25
|
+
return isSimplelogSource(source) && source !== `${SIMPLELOG_PACKAGE}/hono`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function isConsoleObjectExpression(node) {
|
|
29
|
+
if (!node) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (node.type === "Identifier" && node.name === "console") {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (node.type !== "MemberExpression" || node.computed) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
node.object?.type === "Identifier" &&
|
|
43
|
+
(node.object.name === "globalThis" ||
|
|
44
|
+
node.object.name === "global" ||
|
|
45
|
+
node.object.name === "window") &&
|
|
46
|
+
node.property?.type === "Identifier" &&
|
|
47
|
+
node.property.name === "console"
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function isLoggerLikeName(name) {
|
|
52
|
+
return typeof name === "string" && /logger/iu.test(name);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function isConsoleMethodReference(node) {
|
|
56
|
+
if (!node || node.type !== "MemberExpression" || node.computed) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
isConsoleObjectExpression(node.object) &&
|
|
62
|
+
node.property?.type === "Identifier" &&
|
|
63
|
+
typeof node.property.name === "string"
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function isConsoleBindCall(node) {
|
|
68
|
+
if (node?.type !== "CallExpression") {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (
|
|
73
|
+
node.callee?.type !== "MemberExpression" ||
|
|
74
|
+
node.callee.computed ||
|
|
75
|
+
node.callee.property?.type !== "Identifier" ||
|
|
76
|
+
node.callee.property.name !== "bind"
|
|
77
|
+
) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return isConsoleMethodReference(node.callee.object);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function collectAssignedNames(node, names = []) {
|
|
85
|
+
if (!node) {
|
|
86
|
+
return names;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (node.type === "Identifier") {
|
|
90
|
+
names.push(node.name);
|
|
91
|
+
return names;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (node.type === "RestElement") {
|
|
95
|
+
return collectAssignedNames(node.argument, names);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (node.type === "AssignmentPattern") {
|
|
99
|
+
return collectAssignedNames(node.left, names);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (node.type === "ObjectPattern") {
|
|
103
|
+
for (const property of node.properties ?? []) {
|
|
104
|
+
if (property?.type === "Property") {
|
|
105
|
+
collectAssignedNames(property.value, names);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (property?.type === "RestElement") {
|
|
109
|
+
collectAssignedNames(property.argument, names);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return names;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (node.type === "ArrayPattern") {
|
|
117
|
+
for (const element of node.elements ?? []) {
|
|
118
|
+
if (element) {
|
|
119
|
+
collectAssignedNames(element, names);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return names;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (
|
|
127
|
+
node.type === "MemberExpression" &&
|
|
128
|
+
!node.computed &&
|
|
129
|
+
node.property?.type === "Identifier"
|
|
130
|
+
) {
|
|
131
|
+
names.push(node.property.name);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return names;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function isLoggerLikeTarget(node) {
|
|
138
|
+
return collectAssignedNames(node).some((name) => isLoggerLikeName(name));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function isInsideFunctionScope(node) {
|
|
142
|
+
let current = node.parent;
|
|
143
|
+
|
|
144
|
+
while (current) {
|
|
145
|
+
if (current.type === "Program") {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (
|
|
150
|
+
current.type === "FunctionDeclaration" ||
|
|
151
|
+
current.type === "FunctionExpression" ||
|
|
152
|
+
current.type === "ArrowFunctionExpression"
|
|
153
|
+
) {
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
current = current.parent;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function getEnclosingFunction(node) {
|
|
164
|
+
let current = node.parent;
|
|
165
|
+
|
|
166
|
+
while (current) {
|
|
167
|
+
if (
|
|
168
|
+
current.type === "FunctionDeclaration" ||
|
|
169
|
+
current.type === "FunctionExpression" ||
|
|
170
|
+
current.type === "ArrowFunctionExpression"
|
|
171
|
+
) {
|
|
172
|
+
return current;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
current = current.parent;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function functionHasContextParam(node) {
|
|
182
|
+
if (!node) {
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return (node.params ?? []).some((param) => {
|
|
187
|
+
return collectAssignedNames(param).some(
|
|
188
|
+
(name) => name === "c" || name === "ctx" || name === "context",
|
|
189
|
+
);
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function isTopLevelNode(node) {
|
|
194
|
+
return node?.parent?.type === "Program";
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export {
|
|
198
|
+
functionHasContextParam,
|
|
199
|
+
getEnclosingFunction,
|
|
200
|
+
isBareSimplelogSource,
|
|
201
|
+
isConsoleBindCall,
|
|
202
|
+
isConsoleObjectExpression,
|
|
203
|
+
isConsoleMethodReference,
|
|
204
|
+
isInsideFunctionScope,
|
|
205
|
+
isLoggerImportSource,
|
|
206
|
+
isLoggerLikeTarget,
|
|
207
|
+
isTopLevelNode,
|
|
208
|
+
isSimplelogSource,
|
|
209
|
+
SIMPLELOG_LOG_METHODS,
|
|
210
|
+
SIMPLELOG_PACKAGE,
|
|
211
|
+
};
|