@starci/eslint-canon-fe 9.2.0 → 9.4.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.
Files changed (178) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +5 -1
  3. package/dist/brand-values.d.ts +28 -0
  4. package/dist/brand-values.js +172 -0
  5. package/dist/button-intent.d.ts +11 -0
  6. package/dist/button-intent.js +361 -0
  7. package/dist/callback-shape.d.ts +7 -0
  8. package/dist/callback-shape.js +396 -0
  9. package/dist/class-names.d.ts +19 -0
  10. package/dist/class-names.js +170 -0
  11. package/dist/client-boundary.d.ts +42 -0
  12. package/dist/client-boundary.js +404 -0
  13. package/dist/comments.d.ts +47 -0
  14. package/dist/comments.js +156 -0
  15. package/dist/control-height.d.ts +7 -0
  16. package/dist/control-height.js +83 -0
  17. package/dist/drawing.d.ts +31 -0
  18. package/dist/drawing.js +376 -0
  19. package/dist/env-owner.d.ts +22 -0
  20. package/dist/env-owner.js +291 -0
  21. package/dist/fe-stack.d.ts +10 -0
  22. package/dist/fe-stack.js +73 -0
  23. package/dist/file-layout.d.ts +71 -0
  24. package/dist/file-layout.js +465 -0
  25. package/dist/formatting.d.ts +25 -0
  26. package/dist/formatting.js +104 -0
  27. package/dist/function-budget.d.ts +9 -0
  28. package/dist/function-budget.js +48 -0
  29. package/dist/grammar-shim.d.ts +5 -0
  30. package/dist/grammar-shim.js +126 -0
  31. package/dist/hooks-folder.d.ts +34 -0
  32. package/dist/hooks-folder.js +320 -0
  33. package/dist/hygiene.d.ts +39 -0
  34. package/dist/hygiene.js +540 -0
  35. package/dist/index.d.ts +105 -0
  36. package/dist/index.js +310 -0
  37. package/{landmark.mjs → dist/landmark.d.ts} +4 -6
  38. package/dist/landmark.js +6 -0
  39. package/dist/lib/ast.d.ts +36 -0
  40. package/dist/lib/ast.js +94 -0
  41. package/dist/lib/bindings.d.ts +84 -0
  42. package/dist/lib/bindings.js +168 -0
  43. package/dist/lib/class-text.d.ts +3 -0
  44. package/dist/lib/class-text.js +30 -0
  45. package/dist/lib/config.d.ts +81 -0
  46. package/dist/lib/config.js +141 -0
  47. package/dist/lib/drawing-scope.d.ts +5 -0
  48. package/{lib/drawing-scope.mjs → dist/lib/drawing-scope.js} +6 -11
  49. package/dist/lib/eslint-boundary.d.ts +23 -0
  50. package/dist/lib/eslint-boundary.js +6 -0
  51. package/dist/lib/fe-stack.d.ts +49 -0
  52. package/dist/lib/fe-stack.js +98 -0
  53. package/dist/lib/hfs-view.d.ts +74 -0
  54. package/dist/lib/hfs-view.js +6 -0
  55. package/dist/lib/hfs.d.ts +34 -0
  56. package/dist/lib/hfs.js +72 -0
  57. package/dist/lib/next.d.ts +4 -0
  58. package/dist/lib/next.js +10 -0
  59. package/dist/lib/own-hook-origin.d.ts +17 -0
  60. package/dist/lib/own-hook-origin.js +52 -0
  61. package/dist/lib/package-root.d.ts +4 -0
  62. package/dist/lib/package-root.js +10 -0
  63. package/dist/lib/path.d.ts +2 -0
  64. package/{lib/path.mjs → dist/lib/path.js} +1 -1
  65. package/dist/lib/platform.d.ts +26 -0
  66. package/{lib/platform.mjs → dist/lib/platform.js} +38 -35
  67. package/dist/lib/program-for.d.ts +5 -0
  68. package/dist/lib/program-for.js +23 -0
  69. package/dist/lib/pure-owner-helper.d.ts +10 -0
  70. package/dist/lib/pure-owner-helper.js +156 -0
  71. package/dist/lib/react.d.ts +16 -0
  72. package/dist/lib/react.js +22 -0
  73. package/dist/lib/redux-hook-origin.d.ts +4 -0
  74. package/dist/lib/redux-hook-origin.js +50 -0
  75. package/dist/lib/rule.d.ts +28 -0
  76. package/dist/lib/rule.js +5 -0
  77. package/dist/lib/scope.d.ts +88 -0
  78. package/{lib/scope.mjs → dist/lib/scope.js} +83 -93
  79. package/dist/lib/typed-class-values.d.ts +13 -0
  80. package/dist/lib/typed-class-values.js +92 -0
  81. package/dist/lib/types.d.ts +44 -0
  82. package/dist/lib/types.js +64 -0
  83. package/dist/lib/why.d.ts +350 -0
  84. package/dist/lib/why.js +350 -0
  85. package/dist/lint-escape-hatch.d.ts +24 -0
  86. package/{lint-escape-hatch.mjs → dist/lint-escape-hatch.js} +38 -45
  87. package/dist/lists.d.ts +31 -0
  88. package/dist/lists.js +202 -0
  89. package/dist/loading.d.ts +34 -0
  90. package/dist/loading.js +157 -0
  91. package/dist/naming.d.ts +33 -0
  92. package/dist/naming.js +176 -0
  93. package/dist/native-controls.d.ts +24 -0
  94. package/dist/native-controls.js +105 -0
  95. package/dist/next-conventions.d.ts +48 -0
  96. package/dist/next-conventions.js +452 -0
  97. package/dist/project-graph.d.ts +5 -0
  98. package/{project-graph.mjs → dist/project-graph.js} +8 -12
  99. package/dist/props-and-slots.d.ts +19 -0
  100. package/dist/props-and-slots.js +320 -0
  101. package/dist/served-locale.d.ts +38 -0
  102. package/dist/served-locale.js +263 -0
  103. package/dist/shape-slot.d.ts +18 -0
  104. package/dist/shape-slot.js +324 -0
  105. package/dist/size-and-state-budget.d.ts +46 -0
  106. package/dist/size-and-state-budget.js +424 -0
  107. package/dist/size-growth.d.ts +24 -0
  108. package/dist/size-growth.js +64 -0
  109. package/dist/sonar-parity.d.ts +5 -0
  110. package/{sonar-parity.mjs → dist/sonar-parity.js} +11 -7
  111. package/dist/surface-rules.d.ts +18 -0
  112. package/dist/surface-rules.js +491 -0
  113. package/dist/swr-family.d.ts +15 -0
  114. package/dist/swr-family.js +419 -0
  115. package/dist/the-split.d.ts +27 -0
  116. package/dist/the-split.js +157 -0
  117. package/dist/tokens.d.ts +9 -0
  118. package/dist/tokens.js +35 -0
  119. package/dist/translation.d.ts +51 -0
  120. package/dist/translation.js +403 -0
  121. package/dist/transport.d.ts +73 -0
  122. package/dist/transport.js +885 -0
  123. package/dist/type-safety.d.ts +43 -0
  124. package/dist/type-safety.js +139 -0
  125. package/dist/ui-rulings.d.ts +11 -0
  126. package/dist/ui-rulings.js +121 -0
  127. package/package.json +31 -9
  128. package/runtime/knowledge/hfs/canon-pins.yaml +22 -14
  129. package/runtime/scripts/lib/package-at.mjs +5 -5
  130. package/brand-values.mjs +0 -172
  131. package/button-intent.mjs +0 -320
  132. package/callback-shape.mjs +0 -332
  133. package/class-names.mjs +0 -149
  134. package/client-boundary.mjs +0 -400
  135. package/comments.mjs +0 -159
  136. package/control-height.mjs +0 -77
  137. package/drawing.mjs +0 -315
  138. package/env-owner.mjs +0 -244
  139. package/fe-stack.mjs +0 -86
  140. package/file-layout.mjs +0 -472
  141. package/formatting.mjs +0 -110
  142. package/function-budget.mjs +0 -49
  143. package/grammar-shim.mjs +0 -123
  144. package/hooks-folder.mjs +0 -300
  145. package/hygiene.mjs +0 -513
  146. package/index.mjs +0 -317
  147. package/lib/ast.mjs +0 -97
  148. package/lib/bindings.mjs +0 -159
  149. package/lib/class-text.mjs +0 -29
  150. package/lib/config.mjs +0 -142
  151. package/lib/fe-stack.mjs +0 -77
  152. package/lib/hfs.mjs +0 -49
  153. package/lib/next.mjs +0 -6
  154. package/lib/own-hook-origin.mjs +0 -53
  155. package/lib/program-for.mjs +0 -22
  156. package/lib/pure-owner-helper.mjs +0 -148
  157. package/lib/react.mjs +0 -28
  158. package/lib/redux-hook-origin.mjs +0 -44
  159. package/lib/typed-class-values.mjs +0 -81
  160. package/lib/types.mjs +0 -63
  161. package/lib/why.mjs +0 -352
  162. package/lists.mjs +0 -193
  163. package/loading.mjs +0 -156
  164. package/naming.mjs +0 -185
  165. package/native-controls.mjs +0 -108
  166. package/next-conventions.mjs +0 -447
  167. package/props-and-slots.mjs +0 -276
  168. package/served-locale.mjs +0 -243
  169. package/size-and-state-budget.mjs +0 -376
  170. package/size-growth.mjs +0 -62
  171. package/surface-rules.mjs +0 -443
  172. package/swr-family.mjs +0 -326
  173. package/the-split.mjs +0 -155
  174. package/tokens.mjs +0 -39
  175. package/translation.mjs +0 -392
  176. package/transport.mjs +0 -830
  177. package/type-safety.mjs +0 -147
  178. package/ui-rulings.mjs +0 -134
@@ -1,332 +0,0 @@
1
- /**
2
- * R287 FE_CALLBACK_SHAPE: the Supabase callback only reads the PKCE code (or the email-link `token_hash` and `type`), exchanges it
3
- * through the auth owner with exactly one `exchangeAuthCode(code)` or one `verifyOtp({ token_hash, type })`, and redirects. It may read
4
- * the exchange result's `success` or `ok` flag and call PURE text helpers of `modules/routes` or `modules/auth` (`requestOrigin`,
5
- * `safeNextPath`), found by symbol resolution in lib/pure-owner-helper.mjs, so open-redirect protection stays in the app's owner modules.
6
- * Cookie configuration and writes belong in the Supabase helper in fe.modules.auth; application data belongs in the back end.
7
- * This syntax check follows lexical bindings and local aliases rather than trusting a method's spelling.
8
- */
9
- import { stringOf, walk } from "./lib/ast.mjs"
10
- import { patternPath } from "./lib/bindings.mjs"
11
- import { normalizePath } from "./lib/path.mjs"
12
- import { ownerExportKind } from "./lib/pure-owner-helper.mjs"
13
- import { classifyImport, inSlot, resolveImport } from "./lib/scope.mjs"
14
-
15
- /** Runtime expression wrappers that preserve the value's source. */
16
- const unwrap = (node) => {
17
- while (node && ["AwaitExpression", "ChainExpression", "TSAsExpression", "TSTypeAssertion", "TSNonNullExpression", "TSInstantiationExpression"].includes(node.type)) node = node.expression ?? node.argument
18
- return node
19
- }
20
-
21
- /** A member's static key, including a bracketed string spelling. */
22
- const memberName = (node) => node.computed ? stringOf(node.property) : node.property.name
23
-
24
- /** The lexical binding of an identifier, including shadowing inside the handler. */
25
- const bindingOf = (sourceCode, node) => {
26
- for (let scope = sourceCode.getScope(node); scope; scope = scope.upper) {
27
- const variable = scope.set.get(node.name)
28
- if (variable) return variable
29
- }
30
- return null
31
- }
32
-
33
- /** Whether an identifier refers to the actual unshadowed platform global. */
34
- const isGlobal = (sourceCode, node, name) => node?.type === "Identifier" && node.name === name && !(bindingOf(sourceCode, node)?.defs.length)
35
-
36
- /** Route configuration is inert; a second HTTP door or an exported helper is not. */
37
- const CONFIG_EXPORTS = new Set(["runtime", "dynamic", "revalidate", "fetchCache", "preferredRegion", "maxDuration"])
38
- const FUNCTIONS = new Set(["FunctionDeclaration", "FunctionExpression", "ArrowFunctionExpression"])
39
- const FORBIDDEN = new Set(["AssignmentExpression", "UpdateExpression", "ImportExpression", "TaggedTemplateExpression", "ClassDeclaration", "ClassExpression", "ForStatement", "ForInStatement", "ForOfStatement", "WhileStatement", "DoWhileStatement", "ThrowStatement", "YieldExpression", "SpreadElement", "ArrayPattern", "JSXElement", "JSXFragment"])
40
- const TEXT = new Set(["text", "code", "otp-type"])
41
- const CALLS = new Set(["factory", "exchange", "verify-otp", "pure", "redirect", "params-get", "params-has", "text-guard"])
42
- /** What a pure owner helper may be given: query text, the page URL or request, and plain values; never the credential itself. */
43
- const PURE_ARGUMENTS = new Set(["text", "otp-type", "scalar", "url", "request"])
44
- const URL_TEXT = new Set(["origin", "href", "pathname", "search", "hash", "host", "hostname", "protocol"])
45
- const CALL_RESULTS = new Map([["factory", "client"], ["exchange", "exchange-result"], ["verify-otp", "exchange-result"], ["pure", "text"], ["redirect", "redirect-result"], ["params-has", "scalar"], ["text-guard", "scalar"]])
46
- const MEMBERS = new Map([
47
- ["request", new Map([["nextUrl", "url"], ["url", "text"]])],
48
- ["url", new Map([["searchParams", "params"], ...[...URL_TEXT].map((key) => [key, "text"])])],
49
- ["params", new Map([["get", "params-get"], ["has", "params-has"]])],
50
- ["client", new Map([["auth", "auth"]])],
51
- ["auth", new Map([["exchangeCodeForSession", "exchange"], ["verifyOtp", "verify-otp"]])],
52
- ["next-response", new Map([["redirect", "redirect"]])],
53
- ["exchange-result", new Map([["error", "exchange-error"], ["success", "scalar"], ["ok", "scalar"]])],
54
- ])
55
-
56
- /** The query parameters whose provenance an exchange requires: the PKCE code, and the email link's token hash and type. */
57
- const PARAM_ORIGINS = new Map([["code", "code"], ["token_hash", "token-hash"], ["type", "otp-type"]])
58
-
59
- /** A locally exported binding's implementation. */
60
- const exportValue = (sourceCode, entry) => {
61
- const definition = bindingOf(sourceCode, entry.local)?.defs[0]?.node
62
- return unwrap(definition?.type === "VariableDeclarator" ? definition.init : definition)
63
- }
64
-
65
- /** The runtime names introduced by one local named export. */
66
- const namedExports = (statement, sourceCode) => {
67
- const declaration = statement.declaration
68
- if (declaration?.type === "FunctionDeclaration") return [{ name: declaration.id.name, value: declaration }]
69
- if (declaration?.type === "VariableDeclaration") {
70
- if (declaration.declarations.some((entry) => entry.id.type !== "Identifier")) return null
71
- return declaration.declarations.map((entry) => ({ name: entry.id.name, value: unwrap(entry.init) }))
72
- }
73
- if (declaration) return []
74
- return statement.specifiers.filter((entry) => entry.exportKind !== "type")
75
- .map((entry) => ({ name: entry.exported.name ?? entry.exported.value, value: exportValue(sourceCode, entry) }))
76
- }
77
-
78
- /** Collect runtime exports, refusing reexports and default exports. */
79
- const exportsOf = (program, sourceCode) => {
80
- const exported = []
81
- for (const statement of program.body) {
82
- if (statement.type === "ExportDefaultDeclaration" || statement.type === "ExportAllDeclaration") return null
83
- if (statement.type !== "ExportNamedDeclaration" || statement.exportKind === "type") continue
84
- if (statement.source) return null
85
- const entries = namedExports(statement, sourceCode)
86
- if (!entries) return null
87
- exported.push(...entries)
88
- }
89
- return exported
90
- }
91
-
92
- /** Find the one locally implemented GET export and its single request parameter. */
93
- const handlerOf = (program, sourceCode) => {
94
- const exported = exportsOf(program, sourceCode)
95
- if (!exported || exported.some((entry) => entry.name !== "GET" && !CONFIG_EXPORTS.has(entry.name))) return null
96
- const handlers = exported.filter((entry) => entry.name === "GET")
97
- if (handlers.length !== 1) return null
98
- const handler = handlers[0].value
99
- if (!handler || !FUNCTIONS.has(handler.type) || !handler.async || handler.generator) return null
100
- return handler.params.length === 1 && handler.params[0].type === "Identifier" ? handler : null
101
- }
102
-
103
- /** Framework imports retain their actual owner even under a local alias. */
104
- const frameworkImportKind = (source, name) => {
105
- if (source === "next/server" && name === "NextResponse") return "next-response"
106
- if (source === "next/server" && name === "NextRequest") return "request-type"
107
- if (source === "next/navigation" && name === "redirect") return "redirect"
108
- return null
109
- }
110
-
111
- /** Only the server auth entry exposes the cookie-owning exchangeAuthCode helper. */
112
- const isServerAuthImport = (context, source) => {
113
- const target = normalizePath(resolveImport(context, source))
114
- return target.endsWith("/modules/auth/server") || target.endsWith("/modules/auth/server.ts")
115
- }
116
-
117
- /** A directory import resolves to its index, before the generic modules slot's hypothetical routes.ts. */
118
- const isRoutesImport = (context, source, slot) => slot === "fe.modules.routes" || classifyImport(context, `${source}/index`)?.slot === "fe.modules.routes"
119
-
120
- /** The exchange, client and factory names of the auth owner. */
121
- const authImportKind = (context, source, name) => {
122
- if (name === "exchangeAuthCode" && isServerAuthImport(context, source)) return "exchange"
123
- if (name === "verifyOtp" && isServerAuthImport(context, source)) return "verify-otp"
124
- if (name === "exchangeCodeForSession") return "exchange"
125
- if (/^(?:create|get)\w*Client$/.test(name ?? "")) return "factory"
126
- if (["supabase", "supabaseClient", "authClient"].includes(name)) return "client"
127
- return null
128
- }
129
-
130
- /** Auth helpers and static route values must come from their declared HFS owners; any other export of `modules/routes` or `modules/auth` counts only as a pure helper or a static table. */
131
- const ownerImportKind = (context, source, name) => {
132
- const slot = classifyImport(context, source)?.slot
133
- if (name === "APP_ROUTES" && isRoutesImport(context, source, slot)) return "routes"
134
- const authKind = slot === "fe.modules.auth" ? authImportKind(context, source, name) : null
135
- if (authKind || !(slot === "fe.modules.auth" || isRoutesImport(context, source, slot))) return authKind
136
- return ownerExportKind(context, source, name)
137
- }
138
-
139
- /** Register the allowed bindings in a single import statement. */
140
- const addImportBindings = (context, sourceCode, statement, imports) => {
141
- const source = String(statement.source.value)
142
- if (source === "server-only" && statement.specifiers.length === 0) return true
143
- if (statement.specifiers.length === 0) return false
144
- const variables = sourceCode.getDeclaredVariables(statement)
145
- for (const specifier of statement.specifiers) {
146
- if (specifier.importKind === "type") continue
147
- const name = specifier.imported?.name ?? specifier.imported?.value
148
- const kind = frameworkImportKind(source, name) ?? ownerImportKind(context, source, name)
149
- if (!kind) return false
150
- imports.set(variables.find((entry) => entry.name === specifier.local.name), kind)
151
- }
152
- return true
153
- }
154
-
155
- /** Every runtime import is restricted, even if it is unused in the handler. */
156
- const importsOf = (context, program, sourceCode) => {
157
- const imports = new Map()
158
- for (const statement of program.body) {
159
- if (statement.type !== "ImportDeclaration" || statement.importKind === "type") continue
160
- if (!addImportBindings(context, sourceCode, statement, imports)) return null
161
- }
162
- return imports
163
- }
164
-
165
- /** Select a known property without granting arbitrary methods on the selected value. */
166
- const memberKind = (kind, key) => {
167
- if (kind === "routes" && typeof key === "string" && !["__proto__", "constructor", "prototype"].includes(key)) return "text"
168
- if (TEXT.has(kind) && ["startsWith", "endsWith", "includes"].includes(key)) return "text-guard"
169
- return MEMBERS.get(kind)?.get(key) ?? null
170
- }
171
-
172
- /** An identifier keeps the provenance of its one initializer or the GET request parameter. */
173
- const identifierOrigin = (node, seen, env, origin) => {
174
- const variable = bindingOf(env.sourceCode, node)
175
- if (env.imports.has(variable)) return env.imports.get(variable)
176
- if (!variable || seen.has(variable) || variable.defs.length !== 1) return null
177
- const definition = variable.defs[0]
178
- if (definition.type === "Parameter" && definition.node === env.handler) return "request"
179
- if (definition.node.type !== "VariableDeclarator") return null
180
- const path = patternPath(definition.node.id, node.name)
181
- const nextSeen = new Set([...seen, variable])
182
- return path?.reduce((kind, key) => memberKind(kind, key), origin(definition.node.init, nextSeen)) ?? null
183
- }
184
-
185
- /** Combining known primitive values cannot introduce user-defined coercion. */
186
- const combinedOrigin = (kinds, conditional = false) => {
187
- if (conditional && kinds[0] === kinds[1]) return kinds[0]
188
- if (kinds.every((kind) => TEXT.has(kind))) return "text"
189
- if (!conditional && kinds.every((kind) => TEXT.has(kind) || kind === "scalar")) return "scalar"
190
- return null
191
- }
192
-
193
- /** The source of a call's return value, independent of argument validation. */
194
- const callOrigin = (node, seen, origin) => {
195
- const kind = origin(node.callee, seen)
196
- if (kind === "params-get") return PARAM_ORIGINS.get(stringOf(node.arguments[0])) ?? "text"
197
- return CALL_RESULTS.get(kind) ?? null
198
- }
199
-
200
- /** Composite expressions retain provenance only for supported primitive operations. */
201
- const expressionOrigin = (node, seen, env, origin) => {
202
- if (node.type === "TemplateLiteral") return node.expressions.every((expression) => TEXT.has(origin(expression, seen)) || origin(expression, seen) === "scalar") ? "text" : null
203
- if (node.type === "MemberExpression") return memberKind(origin(node.object, seen), memberName(node))
204
- if (node.type === "NewExpression" && isGlobal(env.sourceCode, node.callee, "URL")) return "url"
205
- if (node.type === "LogicalExpression" || node.type === "BinaryExpression") return combinedOrigin([origin(node.left, seen), origin(node.right, seen)])
206
- if (node.type === "ConditionalExpression") return combinedOrigin([origin(node.consequent, seen), origin(node.alternate, seen)], true)
207
- if (node.type === "CallExpression") return callOrigin(node, seen, origin)
208
- return null
209
- }
210
-
211
- /** Follow lexical aliases rather than trusting the spelling of an identifier. */
212
- const originOf = (env) => {
213
- const origin = (input, seen = new Set()) => {
214
- const node = unwrap(input)
215
- if (!node) return null
216
- if (node.type === "Identifier") return identifierOrigin(node, seen, env, origin)
217
- if (node.type === "Literal") return typeof node.value === "string" || node.value === null ? "text" : "scalar"
218
- return expressionOrigin(node, seen, env, origin)
219
- }
220
- return origin
221
- }
222
-
223
- /** The closest enclosing function must be the GET handler. */
224
- const insideHandler = (node, handler) => {
225
- for (let parent = node.parent; parent; parent = parent.parent) if (FUNCTIONS.has(parent.type)) return parent === handler
226
- return false
227
- }
228
-
229
- /** Await must wrap the actual exchange call before its enclosing statement ends. */
230
- const isAwaited = (node, handler) => {
231
- for (let parent = node.parent; parent && parent !== handler; parent = parent.parent) {
232
- if (parent.type === "AwaitExpression") return true
233
- if (parent.type.endsWith("Statement")) return false
234
- }
235
- return false
236
- }
237
-
238
- /** Only a literal redirect status is allowed in an options object. */
239
- const isRedirectStatus = (property) => {
240
- if (property.type !== "Property" || property.computed || property.method || property.kind !== "init") return false
241
- return (property.key.name ?? property.key.value) === "status" && property.value.type === "Literal" && [301, 302, 303, 307, 308].includes(property.value.value)
242
- }
243
-
244
- /** Arbitrary objects can invoke getters or toString during coercion; only redirect options belong here. */
245
- const isRedirectOptions = (node, origin) => node.parent.type === "CallExpression" && origin(node.parent.callee) === "redirect" && node.parent.arguments[1] === node && node.properties.every(isRedirectStatus)
246
-
247
- /** The one object `verifyOtp` takes: exactly `token_hash` read from the query `token_hash` and `type` read from the query `type`. */
248
- const isOtpArguments = (node, origin) => {
249
- if (node.parent.type !== "CallExpression" || origin(node.parent.callee) !== "verify-otp" || node.parent.arguments[0] !== node) return false
250
- const keyOf = (property) => property.type === "Property" && !property.computed && !property.method && property.kind === "init" ? property.key.name ?? property.key.value : null
251
- const expected = new Map([["token_hash", "token-hash"], ["type", "otp-type"]])
252
- return node.properties.length === expected.size && node.properties.every((property) => expected.get(keyOf(property)) === origin(property.value))
253
- && new Set(node.properties.map(keyOf)).size === expected.size
254
- }
255
-
256
- /** Non-call expressions must preserve the callback's narrow set of values and effects. */
257
- const validExpression = (node, env, origin) => {
258
- if (node.type === "MemberExpression") return Boolean(origin(node))
259
- if (node.type === "ObjectExpression") return isRedirectOptions(node, origin) || isOtpArguments(node, origin)
260
- if (node.type === "VariableDeclarator" && node.id.type === "ObjectPattern") return env.sourceCode.getDeclaredVariables(node).every((variable) => origin(variable.identifiers[0]))
261
- if (node.type === "NewExpression") return isGlobal(env.sourceCode, node.callee, "URL") && node.arguments.length >= 1 && node.arguments.length <= 2 && node.arguments.every((argument) => TEXT.has(origin(argument)))
262
- if (node.type === "ReturnStatement") return insideHandler(node, env.handler) && origin(node.argument) === "redirect-result"
263
- if (node === env.handler && node.body.type !== "BlockStatement") return origin(node.body) === "redirect-result"
264
- return true
265
- }
266
-
267
- /** Validate arguments to each permitted operation. */
268
- const validCall = (node, kind, env, origin) => {
269
- if (!insideHandler(node, env.handler) || !CALLS.has(kind) || node.arguments.some((argument) => argument.type === "SpreadElement")) return false
270
- if (kind === "exchange") return isAwaited(node, env.handler) && node.arguments.length === 1 && origin(node.arguments[0]) === "code"
271
- if (kind === "verify-otp") return isAwaited(node, env.handler) && node.arguments.length === 1 && node.arguments[0].type === "ObjectExpression"
272
- if (kind === "pure") return node.arguments.length <= 4 && node.arguments.every((argument) => PURE_ARGUMENTS.has(origin(argument)))
273
- if (kind === "redirect") return node.arguments.length >= 1 && node.arguments.length <= 2 && ["text", "url"].includes(origin(node.arguments[0]))
274
- if (kind === "factory") return node.arguments.length <= 1 && node.arguments.every((argument) => origin(argument) === "request")
275
- return node.arguments.length === 1 && TEXT.has(origin(node.arguments[0]))
276
- }
277
-
278
- /** Syntactic forms that add work beyond the one handler are refused outright. */
279
- const forbiddenNode = (node, handler) => FORBIDDEN.has(node.type) || (FUNCTIONS.has(node.type) && node !== handler) || (node.type === "UnaryExpression" && node.operator === "delete")
280
-
281
- /** Walk all runtime syntax, counting the single exchange and permitted redirects. */
282
- const validOperations = (program, env) => {
283
- const origin = originOf(env)
284
- const counts = new Map()
285
- let valid = true
286
- walk(env.sourceCode, program, (node) => {
287
- if (!valid) return false
288
- valid = !forbiddenNode(node, env.handler) && validExpression(node, env, origin)
289
- if (!valid || node.type !== "CallExpression") return undefined
290
- const kind = origin(node.callee)
291
- valid = validCall(node, kind, env, origin)
292
- counts.set(kind, (counts.get(kind) ?? 0) + 1)
293
- return undefined
294
- })
295
- const exchanges = (counts.get("exchange") ?? 0) + (counts.get("verify-otp") ?? 0)
296
- return valid && exchanges >= 1 && (counts.get("exchange") ?? 0) <= 1 && (counts.get("verify-otp") ?? 0) <= 1 && (counts.get("factory") ?? 0) <= 1 && counts.get("redirect") > 0
297
- }
298
-
299
- /** The callback's request, imports and operations must all have known owners. */
300
- const callbackVerdict = (context, program) => {
301
- const sourceCode = context.sourceCode ?? context.getSourceCode()
302
- const handler = handlerOf(program, sourceCode)
303
- if (!handler) return false
304
- const imports = importsOf(context, program, sourceCode)
305
- return imports !== null && validOperations(program, { sourceCode, handler, imports })
306
- }
307
-
308
- /** A callback stays a PKCE exchange and redirect, with every side effect owned by the auth helper. */
309
- export const callbackShape = {
310
- meta: {
311
- type: "problem",
312
- docs: { description: "R287 FE_CALLBACK_SHAPE: the Supabase callback reads the PKCE code or the email-link token_hash and type, exchanges it through modules/auth (exchangeAuthCode or verifyOtp), and redirects only." },
313
- schema: [],
314
- messages: {
315
- shape: "FE_CALLBACK_SHAPE: the auth callback must export an async GET that reads the query code (or the email-link token_hash and type), awaits one exchangeAuthCode(code) from modules/auth/server or auth.exchangeCodeForSession(code) and, for an email link, one verifyOtp({ token_hash, type }) built from exactly those two query values, may call pure text helpers of modules/routes or modules/auth (no I/O, no await) to compute the target and validate next, and redirects with NextResponse.redirect or next/navigation redirect. Create the client in modules/auth; keep data access, cookie writes, other calls and additional HTTP handlers outside the callback.",
316
- },
317
- },
318
- create(context) {
319
- if (!inSlot(context, "fe.route.callback")) return {}
320
- return {
321
- "Program:exit"(program) {
322
- if (!callbackVerdict(context, program)) context.report({ node: program, messageId: "shape" })
323
- },
324
- }
325
- },
326
- }
327
-
328
- /** The rule R287 contributes to the front-end plugin. */
329
- export const rules = { "callback-shape": callbackShape }
330
-
331
- /** Every callback shape violation is an error. */
332
- export const recommended = { "starci-fe/callback-shape": "error" }
package/class-names.mjs DELETED
@@ -1,149 +0,0 @@
1
- /**
2
- * The classNames law: component markup consumes named styling declarations, while colocated
3
- * classNames files own the utility-token composition.
4
- */
5
-
6
- import { isComponentFile, roleOfFile } from "./lib/scope.mjs"
7
-
8
- /** The styling declarations of a component owner: the file its slot gives the role `styles`. */
9
- const isClassNamesFile = (context) => isComponentFile(context) && roleOfFile(context) === "styles"
10
- const isClassAttribute = (node) => node.type === "JSXAttribute" && ["className", "class"].includes(node.name?.name)
11
- const isCn = (node) => node?.type === "Identifier" && node.name === "cn"
12
-
13
- const importedClassNames = (context) => {
14
- const imports = new Set()
15
- const sourceCode = context.sourceCode || context.getSourceCode()
16
- for (const statement of sourceCode.ast.body) {
17
- if (statement.type !== "ImportDeclaration" || statement.source.value !== "./classNames") continue
18
- for (const specifier of statement.specifiers) imports.add(specifier.local.name)
19
- }
20
- return imports
21
- }
22
-
23
- const isExportedOwner = (node) => {
24
- let current = node
25
- while (current) {
26
- if (["FunctionDeclaration", "FunctionExpression", "ArrowFunctionExpression"].includes(current.type)) {
27
- current = current.parent
28
- if (current?.type === "VariableDeclarator") current = current.parent
29
- if (current?.type === "VariableDeclaration") current = current.parent
30
- return ["ExportNamedDeclaration", "ExportDefaultDeclaration"].includes(current?.type)
31
- }
32
- if (current.type === "VariableDeclarator") {
33
- current = current.parent?.parent
34
- return ["ExportNamedDeclaration", "ExportDefaultDeclaration"].includes(current?.type)
35
- }
36
- current = current.parent
37
- }
38
- return false
39
- }
40
-
41
- const visitTokenLeaves = (node, report) => {
42
- if (!node) return
43
- if (node.type === "ArrayExpression") {
44
- report(node, "array")
45
- return
46
- }
47
- if (node.type === "Literal" && typeof node.value === "string") {
48
- if (/\s/.test(node.value) || /\d+,\d+/.test(node.value)) report(node, "token")
49
- return
50
- }
51
- if (node.type === "ConditionalExpression" || node.type === "LogicalExpression") {
52
- visitTokenLeaves(node.consequent ?? node.left, report)
53
- visitTokenLeaves(node.alternate ?? node.right, report)
54
- }
55
- }
56
-
57
- const isEmptyClassName = (node) => node?.type === "Literal" && node.value === null || node?.type === "Identifier" && node.name === "undefined"
58
-
59
- const usesImportedClassName = (node, imported) => {
60
- if (!node) return false
61
- if (node.type === "Identifier") return imported.has(node.name) || node.name === "undefined"
62
- if (isEmptyClassName(node)) return true
63
- if (node.type === "CallExpression") {
64
- if (node.callee.type === "Identifier") return imported.has(node.callee.name)
65
- return node.callee.type === "MemberExpression" && node.callee.object.type === "Identifier" && imported.has(node.callee.object.name)
66
- }
67
- if (node.type === "MemberExpression") return node.object.type === "Identifier" && imported.has(node.object.name)
68
- if (node.type === "ConditionalExpression") return usesImportedClassName(node.consequent, imported) && usesImportedClassName(node.alternate, imported)
69
- if (node.type === "LogicalExpression") {
70
- if (node.operator === "&&") return usesImportedClassName(node.right, imported)
71
- return usesImportedClassName(node.left, imported) && usesImportedClassName(node.right, imported)
72
- }
73
- return false
74
- }
75
-
76
- /** Report className values written directly in component JSX. */
77
- export const noInlineClassName = {
78
- meta: {
79
- type: "problem",
80
- docs: { description: "Component JSX must import a named className declaration." },
81
- schema: [],
82
- messages: { inline: "Move this className value to an imported colocated classNames.ts export." },
83
- },
84
- create(context) {
85
- if (!isComponentFile(context)) return {}
86
- const imported = importedClassNames(context)
87
- return {
88
- JSXAttribute(node) {
89
- if (!isClassAttribute(node) || !node.value) return
90
- const expression = node.value.type === "JSXExpressionContainer" ? node.value.expression : node.value
91
- if (!usesImportedClassName(expression, imported)) context.report({ node, messageId: "inline" })
92
- },
93
- }
94
- },
95
- }
96
-
97
- /** Require every classNames declaration to use the colocated classNames.ts convention. */
98
- export const classNamesInColocatedFile = {
99
- meta: {
100
- type: "problem",
101
- docs: { description: "Reusable className declarations belong in colocated classNames.ts files." },
102
- schema: [],
103
- messages: { misplaced: "Put reusable className declarations in a colocated classNames.ts file." },
104
- },
105
- create(context) {
106
- if (!isComponentFile(context)) return {}
107
- const styles = isClassNamesFile(context)
108
- return {
109
- CallExpression(node) {
110
- if (!isCn(node.callee) || styles) return
111
- context.report({ node, messageId: "misplaced" })
112
- },
113
- }
114
- },
115
- }
116
-
117
- /** Require variadic cn utility tokens: no arrays, whitespace-packed values, or fractional commas. */
118
- export const cnArgumentsAreSingleTokens = {
119
- meta: {
120
- type: "problem",
121
- docs: { description: "Each cn argument is one valid utility token." },
122
- schema: [],
123
- messages: {
124
- array: "Pass utility tokens to cn as variadic arguments, not an array.",
125
- token: "Each cn argument must be one utility token without whitespace or malformed fractional commas.",
126
- unexported: "Export every className declaration or function that produces a cn value.",
127
- },
128
- },
129
- create(context) {
130
- if (!isClassNamesFile(context)) return {}
131
- return {
132
- CallExpression(node) {
133
- if (!isCn(node.callee)) return
134
- if (!isExportedOwner(node)) context.report({ node, messageId: "unexported" })
135
- for (const argument of node.arguments) visitTokenLeaves(argument, (reportedNode, messageId) => context.report({ node: reportedNode, messageId }))
136
- },
137
- }
138
- },
139
- }
140
-
141
- /** Every rule this law publishes. */
142
- export const rules = {
143
- "no-inline-class-name": noInlineClassName,
144
- "class-names-in-colocated-file": classNamesInColocatedFile,
145
- "cn-arguments-are-single-tokens": cnArgumentsAreSingleTokens,
146
- }
147
-
148
- /** Recommended severity for the classNames law. */
149
- export const recommended = Object.fromEntries(Object.keys(rules).map((name) => [`starci-fe/${name}`, "error"]))