@autotelic/plumb 0.5.0 → 0.6.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.
@@ -23,6 +23,8 @@ import { preferEffectMatchRule } from "./rules/prefer-effect-match.js";
23
23
  import { noNestedLayerProvideRule } from "./rules/no-nested-layer-provide.js";
24
24
  import { noCascadingLayerProvideRule } from "./rules/no-cascading-layer-provide.js";
25
25
  import { noStaticEffectServiceForwardersRule } from "./rules/no-static-effect-service-forwarders.js";
26
+ import { noRawErrorForwardingRule } from "./rules/no-raw-error-forwarding.js";
27
+ import { noNullishDefaultOnPartialInputRule } from "./rules/no-nullish-default-on-partial-input.js";
26
28
  /** Opt-in Oxlint rules for Effect service and Layer architecture. */
27
29
  const plumbEffectPlugin = eslintCompatPlugin({
28
30
  meta: { name: "plumb-effect" },
@@ -51,6 +53,8 @@ const plumbEffectPlugin = eslintCompatPlugin({
51
53
  "no-nested-layer-provide": noNestedLayerProvideRule,
52
54
  "no-cascading-layer-provide": noCascadingLayerProvideRule,
53
55
  "no-static-effect-service-forwarders": noStaticEffectServiceForwardersRule,
56
+ "no-raw-error-forwarding": noRawErrorForwardingRule,
57
+ "no-nullish-default-on-partial-input": noNullishDefaultOnPartialInputRule,
54
58
  },
55
59
  });
56
60
  export default plumbEffectPlugin;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Disallow using nullish coalescing (`??`) with a literal default on a
3
+ * member expression of an external input object. In partial updates
4
+ * (PATCH/PUT), a field might be intentionally absent; `?? false` conflates
5
+ * "absent" with "explicitly false", so you can't distinguish "don't change
6
+ * this field" from "set it to false".
7
+ *
8
+ * This pattern re-invent's Effect's Schema: it manually detects absence where
9
+ * `Schema.optional` / `Schema.nullable` would distinguish absent from falsy
10
+ * with full type safety. The schema also centralizes the rule so it can't
11
+ * drift between the API and the UI.
12
+ */
13
+ export declare const noNullishDefaultOnPartialInputRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,109 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { firstOptionRecord } from "../../shared/rule-options.js";
3
+ import { isString } from "../../shared/structural.js";
4
+ const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$|\/test\//u;
5
+ /** Object names that suggest external input: request bodies, params, etc. */
6
+ const DEFAULT_INPUT_NAMES = new Set([
7
+ "body",
8
+ "params",
9
+ "query",
10
+ "data",
11
+ "input",
12
+ "payload",
13
+ ]);
14
+ /**
15
+ * Whether a node is a literal value (boolean, string, number, null).
16
+ * @param {ESTree.Node} node - The node to test.
17
+ * @returns {boolean} True when the node is a literal.
18
+ */
19
+ function isLiteral(node) {
20
+ return node.type === "Literal";
21
+ }
22
+ /**
23
+ * The display string for a literal value.
24
+ * @param {ESTree.Expression} node - The literal node.
25
+ * @returns {string} The display string.
26
+ */
27
+ function literalDisplay(node) {
28
+ if (node.type === "Literal" && node.value === null)
29
+ return "null";
30
+ if (node.type === "Literal")
31
+ return String(node.value);
32
+ if (node.type === "UnaryExpression" && node.argument.type === "Literal")
33
+ return String(node.argument.value);
34
+ return "unknown";
35
+ }
36
+ /**
37
+ * Disallow using nullish coalescing (`??`) with a literal default on a
38
+ * member expression of an external input object. In partial updates
39
+ * (PATCH/PUT), a field might be intentionally absent; `?? false` conflates
40
+ * "absent" with "explicitly false", so you can't distinguish "don't change
41
+ * this field" from "set it to false".
42
+ *
43
+ * This pattern re-invent's Effect's Schema: it manually detects absence where
44
+ * `Schema.optional` / `Schema.nullable` would distinguish absent from falsy
45
+ * with full type safety. The schema also centralizes the rule so it can't
46
+ * drift between the API and the UI.
47
+ */
48
+ export const noNullishDefaultOnPartialInputRule = defineRule({
49
+ meta: {
50
+ type: "problem",
51
+ docs: {
52
+ description: "Disallow nullish coalescing (??) with literal defaults on member expressions of external input objects; this conflates 'absent' with 'falsy' in partial updates and re-invent's Effect's Schema. Use Schema.optional / Schema.nullable to distinguish absent from falsy.",
53
+ },
54
+ messages: {
55
+ nullishDefaultOnPartialInput: "`?? {{default}}` on `{{object}}.{{property}}` conflates 'absent' with '{{default}}' in partial updates and re-invent's Effect's Schema. Use `Schema.optional` / `Schema.nullable` to distinguish absent from falsy with full type safety.",
56
+ },
57
+ schema: [
58
+ {
59
+ type: "object",
60
+ properties: {
61
+ allow: { type: "array", items: { type: "string" } },
62
+ },
63
+ additionalProperties: false,
64
+ },
65
+ ],
66
+ defaultOptions: [{ allow: [] }],
67
+ },
68
+ createOnce(context) {
69
+ const option = firstOptionRecord(context.options);
70
+ const allowed = new Set(Array.isArray(option.allow) ? option.allow.filter(isString) : []);
71
+ const inputNames = new Set(DEFAULT_INPUT_NAMES);
72
+ for (const name of allowed)
73
+ inputNames.delete(name);
74
+ return {
75
+ before() {
76
+ if (TEST_FILE.test(context.filename.replaceAll("\\\\", "/")))
77
+ return false;
78
+ },
79
+ LogicalExpression(node) {
80
+ if (node.operator !== "??")
81
+ return;
82
+ if (node.left.type !== "MemberExpression")
83
+ return;
84
+ if (!isLiteral(node.right))
85
+ return;
86
+ const member = node.left;
87
+ if (member.object.type !== "Identifier")
88
+ return;
89
+ const objectName = member.object.name;
90
+ if (!inputNames.has(objectName))
91
+ return;
92
+ const propertyName = !member.computed && member.property.type === "Identifier"
93
+ ? member.property.name
94
+ : undefined;
95
+ if (propertyName === undefined)
96
+ return;
97
+ context.report({
98
+ node,
99
+ messageId: "nullishDefaultOnPartialInput",
100
+ data: {
101
+ default: literalDisplay(node.right),
102
+ object: objectName,
103
+ property: propertyName,
104
+ },
105
+ });
106
+ },
107
+ };
108
+ },
109
+ });
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Disallow forwarding raw error messages from caught exceptions. This pattern
3
+ * re-invent's Effect's typed error channel: raw strings leak internal details
4
+ * (stack traces, file paths, database errors) and lose structure so callers
5
+ * can't match on the failure kind.
6
+ *
7
+ * Use Effect's `TaggedError`: a tagged class per failure kind carrying
8
+ * structured evidence as fields, rendering its message from those fields. The
9
+ * error then flows through Effect's typed error channel instead of being
10
+ * stringified at every boundary.
11
+ */
12
+ export declare const noRawErrorForwardingRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,103 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { ancestorsOf } from "../../shared/ancestors.js";
3
+ const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$|\/test\//u;
4
+ /** Error properties that carry internal details and must not be forwarded raw. */
5
+ const ERROR_PROPS = new Set(["message", "stack"]);
6
+ /**
7
+ * Whether a member expression accesses an error property on a catch parameter.
8
+ * @param {ESTree.MemberExpression} member - The member expression to test.
9
+ * @param {ReadonlySet<string>} catchParams - Names of catch parameters in scope.
10
+ * @returns {boolean} True when the member accesses an error property on a catch param.
11
+ */
12
+ function isErrorPropAccess(member, catchParams) {
13
+ if (member.object.type !== "Identifier")
14
+ return false;
15
+ if (!catchParams.has(member.object.name))
16
+ return false;
17
+ if (member.computed)
18
+ return false;
19
+ return member.property.type === "Identifier" && ERROR_PROPS.has(member.property.name);
20
+ }
21
+ /**
22
+ * Whether the error property access is inside a console.* call (logging, not forwarding).
23
+ * @param {SourceCode} sourceCode - The rule's source-code accessor.
24
+ * @param {ESTree.Node} node - The node to test.
25
+ * @returns {boolean} True when the access is inside a console.* call.
26
+ */
27
+ function isLoggingCall(sourceCode, node) {
28
+ const chain = ancestorsOf(sourceCode, node);
29
+ for (let i = chain.length - 1; i >= 0; i--) {
30
+ const ancestor = chain[i];
31
+ if (ancestor === undefined)
32
+ continue;
33
+ if (ancestor.type === "CallExpression" && ancestor.callee.type === "MemberExpression") {
34
+ const obj = ancestor.callee.object;
35
+ if (obj.type === "Identifier" && obj.name === "console")
36
+ return true;
37
+ }
38
+ if (ancestor.type === "Program" || ancestor.type === "BlockStatement")
39
+ return false;
40
+ }
41
+ return false;
42
+ }
43
+ /**
44
+ * Disallow forwarding raw error messages from caught exceptions. This pattern
45
+ * re-invent's Effect's typed error channel: raw strings leak internal details
46
+ * (stack traces, file paths, database errors) and lose structure so callers
47
+ * can't match on the failure kind.
48
+ *
49
+ * Use Effect's `TaggedError`: a tagged class per failure kind carrying
50
+ * structured evidence as fields, rendering its message from those fields. The
51
+ * error then flows through Effect's typed error channel instead of being
52
+ * stringified at every boundary.
53
+ */
54
+ export const noRawErrorForwardingRule = defineRule({
55
+ meta: {
56
+ type: "problem",
57
+ docs: {
58
+ description: "Disallow forwarding raw error messages (e.message, e.stack) from caught exceptions; this pattern re-invent's Effect's typed error channel. Use Effect's TaggedError so failures carry structured evidence and flow through the typed channel.",
59
+ },
60
+ messages: {
61
+ rawErrorForwarding: "Forwarding the raw error '{{prop}}' re-invent's Effect's typed error channel: it leaks internal details and loses structure so callers can't match on the failure kind. Use Effect's TaggedError (a tagged class per failure kind carrying structured evidence as fields) so the error flows through the typed channel.",
62
+ },
63
+ },
64
+ createOnce(context) {
65
+ const catchParamStack = [];
66
+ return {
67
+ before() {
68
+ if (TEST_FILE.test(context.filename.replaceAll("\\\\", "/")))
69
+ return false;
70
+ },
71
+ CatchClause(node) {
72
+ const param = node.param;
73
+ if (param !== null && param !== undefined && param.type === "Identifier") {
74
+ catchParamStack.push(new Set([param.name]));
75
+ }
76
+ else {
77
+ catchParamStack.push(new Set());
78
+ }
79
+ },
80
+ "CatchClause:exit"() {
81
+ catchParamStack.pop();
82
+ },
83
+ MemberExpression(node) {
84
+ if (catchParamStack.length === 0)
85
+ return;
86
+ const allParams = new Set();
87
+ for (const params of catchParamStack) {
88
+ for (const name of params)
89
+ allParams.add(name);
90
+ }
91
+ if (!isErrorPropAccess(node, allParams))
92
+ return;
93
+ if (isLoggingCall(context.sourceCode, node))
94
+ return;
95
+ context.report({
96
+ node,
97
+ messageId: "rawErrorForwarding",
98
+ data: { prop: node.property.type === "Identifier" ? node.property.name : "message" },
99
+ });
100
+ },
101
+ };
102
+ },
103
+ });
package/dist/index.js CHANGED
@@ -47,6 +47,7 @@ import { noMultipleFunctionParamsRule } from "./rules/no-multiple-function-param
47
47
  import { noOptionalFunctionParametersRule } from "./rules/no-optional-function-parameters.js";
48
48
  import { noSingleUsePrivateFunctionsRule } from "./rules/no-single-use-private-functions.js";
49
49
  import { noMutableEnvironmentCaptureRule } from "./rules/no-mutable-environment-capture.js";
50
+ import { noSqlStringInterpolationRule } from "./rules/no-sql-string-interpolation.js";
50
51
  /** Generic Oxlint rules that reject low-evidence and low-signal implementation patterns. */
51
52
  const plumbPlugin = eslintCompatPlugin({
52
53
  meta: { name: "plumb" },
@@ -99,6 +100,7 @@ const plumbPlugin = eslintCompatPlugin({
99
100
  "no-optional-function-parameters": noOptionalFunctionParametersRule,
100
101
  "no-single-use-private-functions": noSingleUsePrivateFunctionsRule,
101
102
  "no-mutable-environment-capture": noMutableEnvironmentCaptureRule,
103
+ "no-sql-string-interpolation": noSqlStringInterpolationRule,
102
104
  },
103
105
  });
104
106
  export default plumbPlugin;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Whether a binding name denotes a context Provider (the generic Provider or a
3
+ * family-scoped XProvider). A Provider is the stateful root of a context family
4
+ * and the only component legitimately allowed to use React hooks inline.
5
+ *
6
+ * @param {string} name - The binding name.
7
+ * @returns {boolean} True when the name is `Provider` or ends with `Provider`.
8
+ */
9
+ export declare function isProviderName(name: string): boolean;
10
+ /**
11
+ * Family name contributed by a useXxx export binding.
12
+ *
13
+ * @param {string} name - The exported binding name.
14
+ * @returns {string | null} The family name, or null when not a useXxx hook.
15
+ */
16
+ export declare function hookFamily(name: string): string | null;
17
+ /**
18
+ * Whether a binding name denotes a custom hook (use + an uppercase letter).
19
+ *
20
+ * @param {string | null} name - The binding name, if known.
21
+ * @returns {name is string} True when the name starts with `use` + a capital.
22
+ */
23
+ export declare function isHookName(name: string | null): name is string;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Whether a binding name denotes a context Provider (the generic Provider or a
3
+ * family-scoped XProvider). A Provider is the stateful root of a context family
4
+ * and the only component legitimately allowed to use React hooks inline.
5
+ *
6
+ * @param {string} name - The binding name.
7
+ * @returns {boolean} True when the name is `Provider` or ends with `Provider`.
8
+ */
9
+ export function isProviderName(name) {
10
+ return name === "Provider" || name.endsWith("Provider");
11
+ }
12
+ /**
13
+ * Family name contributed by a useXxx export binding.
14
+ *
15
+ * @param {string} name - The exported binding name.
16
+ * @returns {string | null} The family name, or null when not a useXxx hook.
17
+ */
18
+ export function hookFamily(name) {
19
+ const match = /^use([A-Z]\w*)$/u.exec(name);
20
+ return match === null ? null : (match[1] ?? null);
21
+ }
22
+ /**
23
+ * Whether a binding name denotes a custom hook (use + an uppercase letter).
24
+ *
25
+ * @param {string | null} name - The binding name, if known.
26
+ * @returns {name is string} True when the name starts with `use` + a capital.
27
+ */
28
+ export function isHookName(name) {
29
+ return name !== null && /^use[A-Z]/u.test(name);
30
+ }
@@ -1,13 +1,17 @@
1
1
  /**
2
- * Whether a component family (a Provider export plus a useXxx hook export)
3
- * must carry a dot-notation aggregate export.
2
+ * Whether a component family (a Provider plus a useXxx hook sharing one family
3
+ * name) must carry a dot-notation aggregate export. The useXxx hook is the
4
+ * family's consumption API and is exported separately by convention, so
5
+ * `aggregateOk` only asks whether the aggregate (export const Family = {
6
+ * Provider, ... }) exists and carries its Provider.
4
7
  *
5
- * @param {{ hasProvider: boolean; hasHook: boolean; aggregateOk: boolean }} input - The family's export facts.
6
- * @returns {boolean} True when an aggregate is required but absent/incomplete.
8
+ * @param {{ providerFamily: string | null; hookFamily: string; singleFamily: boolean; aggregateOk: boolean }} input - The family's export facts.
9
+ * @returns {boolean} True when an aggregate is required but absent.
7
10
  */
8
11
  export declare function familyRequiresAggregate(input: {
9
- hasProvider: boolean;
10
- hasHook: boolean;
12
+ providerFamily: string | null;
13
+ hookFamily: string;
14
+ singleFamily: boolean;
11
15
  aggregateOk: boolean;
12
16
  }): boolean;
13
17
  /**
@@ -16,5 +20,8 @@ export declare function familyRequiresAggregate(input: {
16
20
  * so consumers compose `Family.Provider` / `Family.Header` and the blocks are
17
21
  * discoverable. Bare re-exports of `Provider`/`useXxx` without the aggregate
18
22
  * hide the family boundary.
23
+ *
24
+ * Uses createOnce; per-file state is reset in before() (which oxlint calls per
25
+ * file), so a family seen in one file cannot leak into another.
19
26
  */
20
27
  export declare const requireDotNotationExportsRule: import("@oxlint/plugins").Rule;
@@ -1,15 +1,21 @@
1
1
  import { defineRule } from "@oxlint/plugins";
2
2
  import { isString } from "../../shared/structural.js";
3
+ import { hookFamily, isProviderName } from "../role.js";
3
4
  const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
4
5
  /**
5
- * Whether a component family (a Provider export plus a useXxx hook export)
6
- * must carry a dot-notation aggregate export.
6
+ * Whether a component family (a Provider plus a useXxx hook sharing one family
7
+ * name) must carry a dot-notation aggregate export. The useXxx hook is the
8
+ * family's consumption API and is exported separately by convention, so
9
+ * `aggregateOk` only asks whether the aggregate (export const Family = {
10
+ * Provider, ... }) exists and carries its Provider.
7
11
  *
8
- * @param {{ hasProvider: boolean; hasHook: boolean; aggregateOk: boolean }} input - The family's export facts.
9
- * @returns {boolean} True when an aggregate is required but absent/incomplete.
12
+ * @param {{ providerFamily: string | null; hookFamily: string; singleFamily: boolean; aggregateOk: boolean }} input - The family's export facts.
13
+ * @returns {boolean} True when an aggregate is required but absent.
10
14
  */
11
15
  export function familyRequiresAggregate(input) {
12
- return input.hasProvider && input.hasHook && !input.aggregateOk;
16
+ const providerPresent = input.providerFamily === input.hookFamily ||
17
+ (input.providerFamily === "" && input.singleFamily);
18
+ return providerPresent && !input.aggregateOk;
13
19
  }
14
20
  /**
15
21
  * Property key names of an object literal.
@@ -33,14 +39,18 @@ function objectPropKeys(node) {
33
39
  return keys;
34
40
  }
35
41
  /**
36
- * Family name contributed by a useXxx export binding.
42
+ * Whether an aggregate's keys include the Provider (the family's stateful root).
43
+ * The useXxx hook is the family's consumption API and is exported separately by
44
+ * convention, so it need not appear as a key of the aggregate.
37
45
  *
38
- * @param {string} name - The exported binding name.
39
- * @returns {string | null} The family name, or null when not a useXxx hook.
46
+ * @param {Set<string>} keys - The aggregate object's property keys.
47
+ * @returns {boolean} True when both the Provider and the hook are present.
40
48
  */
41
- function hookFamily(name) {
42
- const match = /^use([A-Z]\w*)$/u.exec(name);
43
- return match === null ? null : (match[1] ?? null);
49
+ function hasProviderKey(keys) {
50
+ for (const k of keys)
51
+ if (k === "Provider" || /Provider$/u.test(k))
52
+ return true;
53
+ return false;
44
54
  }
45
55
  /**
46
56
  * A component family (a Provider plus a `useXxx` consumer hook) must be exported
@@ -48,6 +58,9 @@ function hookFamily(name) {
48
58
  * so consumers compose `Family.Provider` / `Family.Header` and the blocks are
49
59
  * discoverable. Bare re-exports of `Provider`/`useXxx` without the aggregate
50
60
  * hide the family boundary.
61
+ *
62
+ * Uses createOnce; per-file state is reset in before() (which oxlint calls per
63
+ * file), so a family seen in one file cannot leak into another.
51
64
  */
52
65
  export const requireDotNotationExportsRule = defineRule({
53
66
  meta: {
@@ -60,33 +73,26 @@ export const requireDotNotationExportsRule = defineRule({
60
73
  },
61
74
  },
62
75
  createOnce(context) {
63
- const providerExports = new Set();
76
+ const providerBases = new Set();
64
77
  const hookFamilies = new Set();
65
78
  const aggregates = new Map();
66
79
  let reportNode = null;
67
80
  const recordName = (entry) => {
68
81
  if (reportNode === null)
69
82
  reportNode = entry.node;
70
- if (entry.name === "Provider" || entry.name.endsWith("Provider"))
71
- providerExports.add(entry.name);
83
+ if (isProviderName(entry.name)) {
84
+ providerBases.add(entry.name === "Provider" ? "" : entry.name.slice(0, -"Provider".length));
85
+ }
72
86
  const hf = hookFamily(entry.name);
73
87
  if (hf !== null)
74
88
  hookFamilies.add(hf);
75
89
  };
76
- /**
77
- * Whether an aggregate's keys include the Provider and the useXxx hook.
78
- *
79
- * @param {Set<string>} keys - The aggregate object's property keys.
80
- * @returns {boolean} True when both the Provider and the hook are present.
81
- */
82
- function hasProviderKey(keys) {
83
- for (const k of keys)
84
- if (k === "Provider" || /Provider$/u.test(k))
85
- return true;
86
- return false;
87
- }
88
90
  return {
89
91
  before() {
92
+ providerBases.clear();
93
+ hookFamilies.clear();
94
+ aggregates.clear();
95
+ reportNode = null;
90
96
  if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
91
97
  return false;
92
98
  },
@@ -116,14 +122,18 @@ export const requireDotNotationExportsRule = defineRule({
116
122
  }
117
123
  },
118
124
  "Program:exit"() {
119
- if (providerExports.size === 0 || hookFamilies.size === 0)
125
+ if (hookFamilies.size === 0)
120
126
  return;
121
127
  const node = reportNode;
122
128
  if (node === null)
123
129
  return;
130
+ const singleFamily = hookFamilies.size === 1;
124
131
  for (const family of hookFamilies) {
132
+ const providerPresent = providerBases.has(family) || (providerBases.has("") && singleFamily);
133
+ if (!providerPresent)
134
+ continue;
125
135
  const agg = aggregates.get(family);
126
- const ok = agg !== undefined && hasProviderKey(agg) && agg.has("use" + family);
136
+ const ok = agg !== undefined && hasProviderKey(agg);
127
137
  if (ok)
128
138
  continue;
129
139
  context.report({ node, messageId: "missingAggregate", data: { family } });
@@ -1,5 +1,6 @@
1
1
  import { defineRule } from "@oxlint/plugins";
2
2
  import { ancestorsOf } from "../../shared/ancestors.js";
3
+ import { isHookName } from "../role.js";
3
4
  const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
4
5
  /**
5
6
  * Whether a custom context hook that reads context must be reported for
@@ -11,15 +12,6 @@ const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
11
12
  export function requiresContextGuard(input) {
12
13
  return input.isHook && input.callsUseContext && !input.guarded;
13
14
  }
14
- /**
15
- * Whether a function name denotes a custom hook.
16
- *
17
- * @param {string | null} name - The function's name, if known.
18
- * @returns {name is string} True when the name starts with "use" + a capital.
19
- */
20
- function isHookName(name) {
21
- return name !== null && /^use[A-Z]/u.test(name);
22
- }
23
15
  /**
24
16
  * The variable name an `if` test guards against a nullish value.
25
17
  *
@@ -118,6 +110,7 @@ export const requireGuardedContextHookRule = defineRule({
118
110
  }
119
111
  return {
120
112
  before() {
113
+ frames.length = 0;
121
114
  if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
122
115
  return false;
123
116
  },
@@ -116,6 +116,8 @@ export const requireTripartiteContextRule = defineRule({
116
116
  }
117
117
  return {
118
118
  before() {
119
+ localTypes.clear();
120
+ calls.length = 0;
119
121
  if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
120
122
  return false;
121
123
  },
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * Whether a React hook used at `hookName` inside a function named `parentName`
3
- * violates the encapsulation rule (hook used directly in a non-hook function).
3
+ * violates the encapsulation rule. Provider components (XProvider) are the
4
+ * stateful root of a context family and legitimately use hooks inline, so they
5
+ * are exempt.
4
6
  *
5
7
  * @param {{ hookName: string; parentName: string }} input - The usage facts.
6
8
  * @returns {boolean} True when the usage should be reported.
@@ -14,6 +16,7 @@ export declare function isEncapsulationViolation(input: {
14
16
  * functionality into a custom hook (`useXxx`) and call that instead - the
15
17
  * "useEncapsulation" pattern. A component that reaches for `useState`/`useEffect`
16
18
  * inline hides its state and effects; a custom hook names them and can be tested
17
- * and composed in isolation.
19
+ * and composed in isolation. Provider components (XProvider) are exempt: they are
20
+ * the stateful root of a context family and must use hooks inline.
18
21
  */
19
22
  export declare const useEncapsulationRule: import("@oxlint/plugins").Rule;
@@ -1,6 +1,7 @@
1
1
  import { defineRule } from "@oxlint/plugins";
2
2
  import { ancestorsOf } from "../../shared/ancestors.js";
3
3
  import { readField } from "../../shared/structural.js";
4
+ import { isProviderName } from "../role.js";
4
5
  const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
5
6
  /** Pattern identifying custom hooks (names starting with `use`). */
6
7
  const HOOK_PATTERN = /^use/u;
@@ -24,20 +25,23 @@ const REACT_HOOKS = new Set([
24
25
  ]);
25
26
  /**
26
27
  * Whether a React hook used at `hookName` inside a function named `parentName`
27
- * violates the encapsulation rule (hook used directly in a non-hook function).
28
+ * violates the encapsulation rule. Provider components (XProvider) are the
29
+ * stateful root of a context family and legitimately use hooks inline, so they
30
+ * are exempt.
28
31
  *
29
32
  * @param {{ hookName: string; parentName: string }} input - The usage facts.
30
33
  * @returns {boolean} True when the usage should be reported.
31
34
  */
32
35
  export function isEncapsulationViolation(input) {
33
- return REACT_HOOKS.has(input.hookName) && !HOOK_PATTERN.test(input.parentName);
36
+ return REACT_HOOKS.has(input.hookName) && !HOOK_PATTERN.test(input.parentName) && !isProviderName(input.parentName);
34
37
  }
35
38
  /**
36
39
  * Do not call React's hooks directly inside a component. Abstract the
37
40
  * functionality into a custom hook (`useXxx`) and call that instead - the
38
41
  * "useEncapsulation" pattern. A component that reaches for `useState`/`useEffect`
39
42
  * inline hides its state and effects; a custom hook names them and can be tested
40
- * and composed in isolation.
43
+ * and composed in isolation. Provider components (XProvider) are exempt: they are
44
+ * the stateful root of a context family and must use hooks inline.
41
45
  */
42
46
  export const useEncapsulationRule = defineRule({
43
47
  meta: {
@@ -84,7 +88,7 @@ export const useEncapsulationRule = defineRule({
84
88
  if (!hooksToCheck.has(node.name))
85
89
  return;
86
90
  const parent = nearestFunctionName(node);
87
- if (parent !== null && !HOOK_PATTERN.test(parent)) {
91
+ if (parent !== null && !HOOK_PATTERN.test(parent) && !isProviderName(parent)) {
88
92
  context.report({ node, messageId: "noDirectHooks", data: { hook: node.name, parent } });
89
93
  }
90
94
  },
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Disallow SQL queries built from template literal interpolation. String
3
+ * interpolation in SQL is an injection vector: attacker-controlled values
4
+ * become query structure. Use parameterized queries or a query builder
5
+ * instead so values never become syntax.
6
+ */
7
+ export declare const noSqlStringInterpolationRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,62 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
3
+ /**
4
+ * SQL keywords that suggest a string is a query. Case-insensitive match
5
+ * against the raw template string portions.
6
+ */
7
+ const SQL_KEYWORDS = [
8
+ "SELECT",
9
+ "INSERT",
10
+ "UPDATE",
11
+ "DELETE",
12
+ "FROM",
13
+ "WHERE",
14
+ "JOIN",
15
+ "CREATE\\s+TABLE",
16
+ "DROP\\s+TABLE",
17
+ "ALTER\\s+TABLE",
18
+ ];
19
+ const SQL_PATTERN = new RegExp("\\b(?:" + SQL_KEYWORDS.join("|") + ")\\b", "iu");
20
+ /**
21
+ * Whether a template literal's raw text contains a SQL keyword.
22
+ * @param {ESTree.TemplateElement} quasi - The template element to test.
23
+ * @returns {boolean} True when the raw text contains a SQL keyword.
24
+ */
25
+ function hasSqlKeyword(quasi) {
26
+ return SQL_PATTERN.test(quasi.value.raw);
27
+ }
28
+ /**
29
+ * Disallow SQL queries built from template literal interpolation. String
30
+ * interpolation in SQL is an injection vector: attacker-controlled values
31
+ * become query structure. Use parameterized queries or a query builder
32
+ * instead so values never become syntax.
33
+ */
34
+ export const noSqlStringInterpolationRule = defineRule({
35
+ meta: {
36
+ type: "problem",
37
+ docs: {
38
+ description: "Disallow SQL queries built via template literal interpolation; use parameterized queries or a query builder to prevent SQL injection.",
39
+ },
40
+ messages: {
41
+ sqlInterpolation: "SQL via template literal interpolation is an injection vector. Use parameterized queries or a query builder so values never become syntax.",
42
+ },
43
+ },
44
+ createOnce(context) {
45
+ return {
46
+ before() {
47
+ if (TEST_FILE.test(context.filename.replaceAll("\\\\", "/")))
48
+ return false;
49
+ },
50
+ TemplateLiteral(node) {
51
+ if (node.expressions.length === 0)
52
+ return;
53
+ for (const quasi of node.quasis) {
54
+ if (hasSqlKeyword(quasi)) {
55
+ context.report({ node, messageId: "sqlInterpolation" });
56
+ return;
57
+ }
58
+ }
59
+ },
60
+ };
61
+ },
62
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autotelic/plumb",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Opinionated Oxlint rules that keep TypeScript true: generic and Effect-specific patterns, maintained as one source of truth for the autotelic repos.",
5
5
  "license": "MIT",
6
6
  "files": [