eslint-plugin-no-mistakes 0.70.0 → 0.72.0
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/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const { quasiText, sqlText, unwrapTs } = require("./postgres-query-text");
|
|
4
4
|
|
|
5
|
-
const DEFAULT_IMPORT_SPECIFIER = "
|
|
5
|
+
const DEFAULT_IMPORT_SPECIFIER = "";
|
|
6
6
|
const DEFAULT_EXECUTOR_NAMES = ["query", "read", "write"];
|
|
7
7
|
const DEFAULT_CHUNK_FUNCTION_NAMES = ["chunkArray"];
|
|
8
8
|
const TRANSACTION_IMPORTS = new Set(["withTransaction", "withTransactionOptions"]);
|
|
@@ -10,9 +10,14 @@ const QUERY_PROPERTY = "query";
|
|
|
10
10
|
const TRANSACTION_COMMAND = /^\s*(?:BEGIN|COMMIT|ROLLBACK)\b/i;
|
|
11
11
|
|
|
12
12
|
function executorOptionDefaults(options = {}) {
|
|
13
|
+
if (!options.importSpecifier && !Array.isArray(options.executorNames)) {
|
|
14
|
+
throw new Error(
|
|
15
|
+
"PostgreSQL option importSpecifier: set importSpecifier (or executorNames) to select executor calls; set executorNames: [] to select no executor calls (see docs/migrations/explicit-postgres-executors.md)",
|
|
16
|
+
);
|
|
17
|
+
}
|
|
13
18
|
return {
|
|
14
19
|
importSpecifier: options.importSpecifier ?? DEFAULT_IMPORT_SPECIFIER,
|
|
15
|
-
executorNames: options.executorNames ?? DEFAULT_EXECUTOR_NAMES,
|
|
20
|
+
executorNames: options.executorNames ?? (options.importSpecifier ? DEFAULT_EXECUTOR_NAMES : []),
|
|
16
21
|
owners: options.owners ?? [],
|
|
17
22
|
chunkFunctionNames: options.chunkFunctionNames ?? DEFAULT_CHUNK_FUNCTION_NAMES,
|
|
18
23
|
};
|
|
@@ -39,15 +44,16 @@ function importedName(specifier) {
|
|
|
39
44
|
function executorBindings(program, options = {}) {
|
|
40
45
|
const bindings = new Set();
|
|
41
46
|
const { importSpecifier, executorNames } = executorOptionDefaults(options);
|
|
47
|
+
bindings.queryMembers = Boolean(importSpecifier) || executorNames.includes(QUERY_PROPERTY);
|
|
42
48
|
for (const statement of program?.body ?? []) {
|
|
43
49
|
if (statement.type !== "ImportDeclaration") continue;
|
|
44
50
|
if (statement.importKind === "type") continue;
|
|
45
|
-
if (statement.source?.value !== importSpecifier) continue;
|
|
51
|
+
if (importSpecifier && statement.source?.value !== importSpecifier) continue;
|
|
46
52
|
for (const specifier of statement.specifiers ?? []) {
|
|
47
53
|
if (specifier.type !== "ImportSpecifier") continue;
|
|
48
54
|
if (specifier.importKind === "type") continue;
|
|
49
55
|
const imported = importedName(specifier);
|
|
50
|
-
if (TRANSACTION_IMPORTS.has(imported)) bindings.add(QUERY_PROPERTY);
|
|
56
|
+
if (importSpecifier && TRANSACTION_IMPORTS.has(imported)) bindings.add(QUERY_PROPERTY);
|
|
51
57
|
if (imported && executorNames.includes(imported)) bindings.add(specifier.local.name);
|
|
52
58
|
}
|
|
53
59
|
}
|
|
@@ -75,7 +81,11 @@ function calleeName(call, bindings) {
|
|
|
75
81
|
const callee = unwrapTs(call?.callee);
|
|
76
82
|
if (!callee) return null;
|
|
77
83
|
if (callee.type === "Identifier" && bindings?.has(callee.name)) return callee.name;
|
|
78
|
-
if (
|
|
84
|
+
if (
|
|
85
|
+
bindings?.queryMembers !== false &&
|
|
86
|
+
callee.type === "MemberExpression" &&
|
|
87
|
+
memberPropertyName(callee) === QUERY_PROPERTY
|
|
88
|
+
) {
|
|
79
89
|
return QUERY_PROPERTY;
|
|
80
90
|
}
|
|
81
91
|
return null;
|