eslint-plugin-no-mistakes 0.74.0 → 0.76.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-no-mistakes",
3
- "version": "0.74.0",
3
+ "version": "0.76.0",
4
4
  "description": "ESLint and Oxlint rules that keep code static enough for no-mistakes analyzers and coding agents",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -94,6 +94,18 @@ module.exports = rule(
94
94
  includeFiles: { type: "array", items: { type: "string" } },
95
95
  annotation: { type: "string" },
96
96
  sqlTagModules: { type: "array", items: { type: "string" } },
97
+ trustedSqlTags: {
98
+ type: "array",
99
+ items: {
100
+ type: "object",
101
+ additionalProperties: false,
102
+ required: ["module", "name"],
103
+ properties: {
104
+ module: { type: "string" },
105
+ name: { type: "string" },
106
+ },
107
+ },
108
+ },
97
109
  },
98
110
  },
99
111
  ],
@@ -34,6 +34,27 @@ function optionalStringArray(value, present) {
34
34
  return Array.isArray(value) && value.every((entry) => typeof entry === "string") ? value : null;
35
35
  }
36
36
 
37
+ function trustedSqlTagEntry(entry) {
38
+ return (
39
+ entry !== null &&
40
+ typeof entry === "object" &&
41
+ !Array.isArray(entry) &&
42
+ typeof entry.module === "string" &&
43
+ typeof entry.name === "string"
44
+ );
45
+ }
46
+
47
+ function parseTrustedSqlTags(value, present) {
48
+ if (!present) return undefined;
49
+ if (!Array.isArray(value)) return null;
50
+ const tags = [];
51
+ for (const entry of value) {
52
+ if (!trustedSqlTagEntry(entry)) return null;
53
+ tags.push({ module: entry.module, name: entry.name });
54
+ }
55
+ return tags;
56
+ }
57
+
37
58
  function resolveCursorContractOptions(raw) {
38
59
  if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return null;
39
60
  const modules = stringArray(raw.modules);
@@ -44,7 +65,14 @@ function resolveCursorContractOptions(raw) {
44
65
  const exclude = optionalStringArray(raw.exclude, raw.exclude !== undefined);
45
66
  const includeFiles = optionalStringArray(raw.includeFiles, raw.includeFiles !== undefined);
46
67
  const sqlTagModules = optionalStringArray(raw.sqlTagModules, raw.sqlTagModules !== undefined);
47
- if (include === null || exclude === null || includeFiles === null || sqlTagModules === null) {
68
+ const trustedSqlTags = parseTrustedSqlTags(raw.trustedSqlTags, raw.trustedSqlTags !== undefined);
69
+ if (
70
+ include === null ||
71
+ exclude === null ||
72
+ includeFiles === null ||
73
+ sqlTagModules === null ||
74
+ trustedSqlTags === null
75
+ ) {
48
76
  return null;
49
77
  }
50
78
  let annotation;
@@ -64,6 +92,7 @@ function resolveCursorContractOptions(raw) {
64
92
  exclude: exclude ?? [],
65
93
  includeFiles: (includeFiles ?? []).map((file) => file.replace(/^(?:\.\/)+/, "")),
66
94
  sqlTagModules: new Set(sqlTagModules ?? DEFAULT_SQL_TAG_MODULES),
95
+ trustedSqlTags: trustedSqlTags ?? [],
67
96
  annotation,
68
97
  };
69
98
  }
@@ -38,6 +38,37 @@ function firstQuasiText(template, allowRaw) {
38
38
  return quasi.value?.cooked ?? (allowRaw ? (quasi.value?.raw ?? null) : null);
39
39
  }
40
40
 
41
+ function importedBindingName(specifier) {
42
+ const imported = specifier?.imported;
43
+ if (!imported) return null;
44
+ return imported.type === "Literal" ? String(imported.value) : imported.name;
45
+ }
46
+
47
+ // Named opt-in only. An empty module must not match every import.
48
+ function matchesTrustedSqlTag(source, imported, tag) {
49
+ if (!tag.module || !tag.name || tag.name !== imported) return false;
50
+ return source === tag.module || String(source).startsWith(`${tag.module}/`);
51
+ }
52
+
53
+ function trustedNamedSqlImport(specifier, declaration, source, config) {
54
+ if (specifier?.type !== "ImportSpecifier") return false;
55
+ if (specifier.importKind === "type" || declaration?.importKind === "type") return false;
56
+ if (declaration?.type !== "ImportDeclaration" || typeof source !== "string") return false;
57
+ const imported = importedBindingName(specifier);
58
+ return (config.trustedSqlTags ?? []).some((tag) => matchesTrustedSqlTag(source, imported, tag));
59
+ }
60
+
61
+ function defaultSqlTagImport(specifier, declaration, source, config) {
62
+ return (
63
+ specifier.type === "ImportDefaultSpecifier" &&
64
+ specifier.importKind !== "type" &&
65
+ declaration?.type === "ImportDeclaration" &&
66
+ declaration.importKind !== "type" &&
67
+ typeof source === "string" &&
68
+ config.sqlTagModules.has(source)
69
+ );
70
+ }
71
+
41
72
  function exactSqlTag(context, tag, helpers, config) {
42
73
  const identifier = helpers.unwrap(tag);
43
74
  if (identifier?.type !== "Identifier") return false;
@@ -46,14 +77,10 @@ function exactSqlTag(context, tag, helpers, config) {
46
77
  const specifier = candidate.node;
47
78
  const declaration = candidate.parent || specifier.parent;
48
79
  const source = declaration?.source?.value;
80
+ if (candidate.type !== "ImportBinding") return false;
49
81
  return (
50
- candidate.type === "ImportBinding" &&
51
- specifier.type === "ImportDefaultSpecifier" &&
52
- specifier.importKind !== "type" &&
53
- declaration?.type === "ImportDeclaration" &&
54
- declaration.importKind !== "type" &&
55
- typeof source === "string" &&
56
- config.sqlTagModules.has(source)
82
+ trustedNamedSqlImport(specifier, declaration, source, config) ||
83
+ defaultSqlTagImport(specifier, declaration, source, config)
57
84
  );
58
85
  });
59
86
  return Boolean(
@@ -21,6 +21,7 @@ function executorOptionDefaults(options = {}) {
21
21
  executorNames: options.executorNames ?? (options.importSpecifier ? DEFAULT_EXECUTOR_NAMES : []),
22
22
  executorFactoryNames: options.executorFactoryNames ?? [],
23
23
  executorTypeNames: options.executorTypeNames ?? [],
24
+ trustedSqlTags: options.trustedSqlTags ?? [],
24
25
  owners: options.owners ?? [],
25
26
  chunkFunctionNames: options.chunkFunctionNames ?? DEFAULT_CHUNK_FUNCTION_NAMES,
26
27
  };
@@ -34,6 +35,18 @@ function executorOptionSchema(extraProperties = {}) {
34
35
  executorNames: { type: "array", items: { type: "string" } },
35
36
  executorFactoryNames: { type: "array", items: { type: "string" } },
36
37
  executorTypeNames: { type: "array", items: { type: "string" } },
38
+ trustedSqlTags: {
39
+ type: "array",
40
+ items: {
41
+ type: "object",
42
+ additionalProperties: false,
43
+ required: ["module", "name"],
44
+ properties: {
45
+ module: { type: "string" },
46
+ name: { type: "string" },
47
+ },
48
+ },
49
+ },
37
50
  ...extraProperties,
38
51
  },
39
52
  additionalProperties: false,