@stardeck-customer-apps/eslint-plugin 1.2.0 → 1.5.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Stardeck Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/SKILL.md ADDED
@@ -0,0 +1,124 @@
1
+ # ESLint Plugin
2
+
3
+ Custom ESLint rules for Stardeck customer apps. Requires ESLint 9+ flat config.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @stardeck-customer-apps/eslint-plugin
9
+ ```
10
+
11
+ ## Setup
12
+
13
+ ```javascript
14
+ // eslint.config.mjs
15
+ import stardeckEslint from "@stardeck-customer-apps/eslint-plugin";
16
+
17
+ export default [
18
+ // ... your other configs
19
+ stardeckEslint.configs.recommended,
20
+ ];
21
+ ```
22
+
23
+ ## Rules
24
+
25
+ ### `no-template-literal-classname`
26
+
27
+ Disallows template literal interpolation in `className`. Use `cn()` instead.
28
+
29
+ ```tsx
30
+ // Bad
31
+ <div className={`px-4 ${isActive ? "bg-primary" : "bg-muted"}`} />
32
+
33
+ // Good
34
+ <div className={cn("px-4", isActive ? "bg-primary" : "bg-muted")} />
35
+ ```
36
+
37
+ **Why?** Template literals in className break Tailwind IntelliSense and class merging.
38
+
39
+ ### `no-kysely-interactive-transaction`
40
+
41
+ Disallows Kysely interactive and controlled transactions. The Kysely instance
42
+ returned by `createDataStore()` is backed by the Neon HTTP driver, which cannot
43
+ hold a transaction open across round-trips and throws at runtime:
44
+
45
+ > NeonDialect doesn't support interactive transactions, while Kysely doesn't support batch requests (yet).
46
+
47
+ ```ts
48
+ // Bad — throws at runtime
49
+ await db.transaction().execute(async (trx) => {
50
+ await trx.insertInto("orders").values(order).execute();
51
+ await trx.updateTable("inventory").set({ count }).execute();
52
+ });
53
+
54
+ // Bad — controlled transactions are unsupported too
55
+ const trx = await db.startTransaction().execute();
56
+
57
+ // Good — fold the work into a single statement (CTE)
58
+ await db
59
+ .with("new_order", (qb) => qb.insertInto("orders").values(order).returning("id"))
60
+ .updateTable("inventory")
61
+ .set({ count })
62
+ .execute();
63
+
64
+ // Good — or run the statements sequentially
65
+ await db.insertInto("orders").values(order).execute();
66
+ await db.updateTable("inventory").set({ count }).execute();
67
+ ```
68
+
69
+ **Why?** Drizzle's `db.transaction(cb)` and the Neon client's `sql.transaction([...])`
70
+ take arguments, so only the zero-argument `db.transaction()` builder (and
71
+ `db.startTransaction()`) — the Kysely interactive/controlled APIs — are flagged.
72
+
73
+ ### `no-module-internal-import`
74
+
75
+ Vendored modules live at `src/modules/<name>/` with `index.ts` as the only public
76
+ surface. Import other modules (and modules from app code) only through that index —
77
+ e.g. `@/modules/booking`. Deep paths like `@/modules/booking/server/reservations`
78
+ are an error (including type imports, `export * from`, and dynamic `import()`).
79
+ A file inside a module may still import its own internals freely.
80
+
81
+ ```ts
82
+ // Bad — reaches into module internals
83
+ import { list } from "@/modules/booking/server/reservations";
84
+
85
+ // Good — public surface only
86
+ import { listReservations } from "@/modules/booking";
87
+ ```
88
+
89
+ **Why?** Deep imports break module install/update isolation by coupling callers to
90
+ files that can move or disappear when the module is swapped.
91
+
92
+ ### `no-server-import-in-conventional-entry`
93
+
94
+ `contributions.ts` and `slots.ts` (root, or enhancement-scoped `contributions.ts`)
95
+ are bundled into client-reachable composition artifacts. They must not directly
96
+ import `server-only`, a Node builtin, a `.server` file, any `/server` module
97
+ entry, or an enhancement root barrel (which may re-export `initialize.server`).
98
+ `initialize.server.ts` itself is server-only by design and is not linted by
99
+ this rule.
100
+
101
+ ```ts
102
+ // contributions.ts — Bad
103
+ import "server-only";
104
+ import fs from "node:fs";
105
+ import { handlers } from "@/modules/booking/server";
106
+ import { initializeEnhancement } from "./initialize.server";
107
+
108
+ // contributions.ts — Good
109
+ import { z } from "zod";
110
+ import { helper } from "./helpers";
111
+ ```
112
+
113
+ **Why?** This is the immediate-import lint signal for a fail-closed contract also
114
+ enforced by canonical AST evidence in the module structure collector and the
115
+ install rail. Only the direct specifier is checked — it does not prove the
116
+ entry's full import graph never reaches server code (that's the real Next
117
+ client-build seam's job) — so do not add exemptions here to work around it.
118
+
119
+ ## Disable for a Line
120
+
121
+ ```tsx
122
+ // eslint-disable-next-line @stardeck-customer-apps/eslint-plugin/no-template-literal-classname
123
+ <div className={`legacy ${dynamicClass}`} />
124
+ ```
package/dist/index.cjs CHANGED
@@ -139,8 +139,13 @@ function findSrcRoot(filename) {
139
139
  for (let i = 0; i < parts.length; i++) {
140
140
  if (parts[i] === "src") lastSrcIdx = i;
141
141
  }
142
- if (lastSrcIdx === -1) return null;
143
- return parts.slice(0, lastSrcIdx + 1).join("/");
142
+ if (lastSrcIdx !== -1) return parts.slice(0, lastSrcIdx + 1).join("/");
143
+ for (let i = 0; i < parts.length - 1; i++) {
144
+ if (parts[i] === "apps" && parts[i + 1] === "web") {
145
+ return parts.slice(0, i + 2).concat("src").join("/");
146
+ }
147
+ }
148
+ return null;
144
149
  }
145
150
  function normalizePosixPath(raw) {
146
151
  const absolute = raw.startsWith("/");
@@ -193,6 +198,99 @@ function isPublicSurface(resolvedPath, srcRoot, moduleName) {
193
198
  if (resolvedPath === `${base}/index.tsx`) return true;
194
199
  return false;
195
200
  }
201
+ function isModuleRoutesEntry(resolvedPath, srcRoot, moduleName) {
202
+ const prefix = `${srcRoot}/modules/${moduleName}/routes/`;
203
+ return resolvedPath === `${srcRoot}/modules/${moduleName}/routes` || resolvedPath.startsWith(prefix);
204
+ }
205
+ var RAIL_MARKER = "@stardeck-module-rail-generated";
206
+ var I18N_GEN_MARKER = `// ${RAIL_MARKER} scope=i18n`;
207
+ var LOCALE_BASENAME_REGEX = /^[a-z]{2,3}(?:-[A-Za-z0-9]+)*$/;
208
+ var MAX_LOCALE_BASENAME_LENGTH = 35;
209
+ function isRailGeneratedRouteStub(filename, sourceText) {
210
+ const posix = toPosix(filename);
211
+ if (!/\/src\/app\/.+\/page\.tsx$/.test(posix) && !/\/src\/app\/page\.tsx$/.test(posix)) {
212
+ return false;
213
+ }
214
+ const firstLine = sourceText.split(/\r?\n/, 1)[0]?.trim() ?? "";
215
+ return firstLine.startsWith(`// ${RAIL_MARKER} `) && firstLine.includes("scope=route ");
216
+ }
217
+ function isRailGeneratedCompositionImporter(filename, sourceText) {
218
+ const posix = toPosix(filename);
219
+ if (!/\/src\/(?:modules\.gen|module-contributions\.gen|module-i18n\.gen|module-init\.server\.gen)\.ts$/.test(
220
+ posix
221
+ )) {
222
+ return false;
223
+ }
224
+ const firstLine = sourceText.split(/\r?\n/, 1)[0]?.trim() ?? "";
225
+ if (!firstLine.startsWith(`// ${RAIL_MARKER} `)) return false;
226
+ return firstLine.includes("scope=contributions") || firstLine.includes("scope=i18n") || firstLine.includes("scope=init") || firstLine.includes("scope=registry");
227
+ }
228
+ function isConventionalCompositionEntry(resolvedPath, srcRoot, moduleName) {
229
+ const base = `${srcRoot}/modules/${moduleName}`;
230
+ const allowedExact = /* @__PURE__ */ new Set([
231
+ `${base}/contributions`,
232
+ `${base}/contributions.ts`,
233
+ `${base}/slots`,
234
+ `${base}/slots.ts`,
235
+ `${base}/i18n`,
236
+ `${base}/i18n/index`,
237
+ `${base}/i18n/index.ts`
238
+ ]);
239
+ if (allowedExact.has(resolvedPath)) return true;
240
+ const enhMatch = resolvedPath.match(
241
+ new RegExp(
242
+ `^${base.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/enhancements/([^/]+)/(contributions|initialize\\.server)(?:\\.ts)?$`
243
+ )
244
+ );
245
+ if (enhMatch) return true;
246
+ const enhI18n = resolvedPath.match(
247
+ new RegExp(
248
+ `^${base.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/enhancements/([^/]+)/i18n(?:/index(?:\\.ts)?)?$`
249
+ )
250
+ );
251
+ return Boolean(enhI18n);
252
+ }
253
+ function isRailGeneratedI18nJsonImporter(filename, sourceText) {
254
+ const posix = toPosix(filename);
255
+ if (!/\/src\/module-i18n\.gen\.ts$/.test(posix)) return false;
256
+ const firstLine = sourceText.split(/\r?\n/, 1)[0]?.trim() ?? "";
257
+ return firstLine === I18N_GEN_MARKER;
258
+ }
259
+ function localeBasenameFromI18nJsonPath(resolvedPath, srcRoot, moduleName) {
260
+ const base = `${srcRoot}/modules/${moduleName}`;
261
+ const escaped = base.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
262
+ const rootMatch = new RegExp(`^${escaped}/i18n/([^/]+)\\.json$`).exec(resolvedPath);
263
+ if (rootMatch) return rootMatch[1] ?? null;
264
+ const sliceMatch = new RegExp(`^${escaped}/enhancements/[^/]+/i18n/([^/]+)\\.json$`).exec(
265
+ resolvedPath
266
+ );
267
+ return sliceMatch ? sliceMatch[1] ?? null : null;
268
+ }
269
+ function isValidLocaleBasename(basename) {
270
+ return basename.length > 0 && basename.length <= MAX_LOCALE_BASENAME_LENGTH && LOCALE_BASENAME_REGEX.test(basename);
271
+ }
272
+ function isConventionalI18nJsonEntry(resolvedPath, srcRoot, moduleName) {
273
+ const basename = localeBasenameFromI18nJsonPath(resolvedPath, srcRoot, moduleName);
274
+ return basename != null && isValidLocaleBasename(basename);
275
+ }
276
+ function isRailGeneratedEndpointStub(filename, sourceText) {
277
+ const posix = toPosix(filename);
278
+ if (!/\/src\/app\/api\/.+\/route\.ts$/.test(posix)) return false;
279
+ const firstLine = sourceText.split(/\r?\n/, 1)[0]?.trim() ?? "";
280
+ return firstLine.startsWith(`// ${RAIL_MARKER} `) && (firstLine.includes("scope=root") || firstLine.includes("scope=enhancement:"));
281
+ }
282
+ function isEndpointHandlerEntry(resolvedPath, srcRoot, moduleName) {
283
+ const base = `${srcRoot}/modules/${moduleName}`;
284
+ if (resolvedPath === `${base}/server` || resolvedPath === `${base}/server/index` || resolvedPath === `${base}/server/index.ts`) {
285
+ return true;
286
+ }
287
+ const enh = resolvedPath.match(
288
+ new RegExp(
289
+ `^${base.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/enhancements/([^/]+)(?:/index(?:\\.ts)?)?$`
290
+ )
291
+ );
292
+ return Boolean(enh);
293
+ }
196
294
  var rule3 = {
197
295
  meta: {
198
296
  type: "problem",
@@ -216,6 +314,11 @@ var rule3 = {
216
314
  }
217
315
  const root = srcRoot;
218
316
  const importerModule = getModuleName(toPosix(filename), root);
317
+ const sourceText = context.sourceCode.getText();
318
+ const railRouteStub = isRailGeneratedRouteStub(filename, sourceText);
319
+ const railCompositionImporter = isRailGeneratedCompositionImporter(filename, sourceText);
320
+ const railI18nJsonImporter = isRailGeneratedI18nJsonImporter(filename, sourceText);
321
+ const railEndpointStub = isRailGeneratedEndpointStub(filename, sourceText);
219
322
  function check(node, sourceNode) {
220
323
  if (!sourceNode || sourceNode.type !== "Literal") return;
221
324
  const value = sourceNode.value;
@@ -226,6 +329,14 @@ var rule3 = {
226
329
  if (!targetModule) return;
227
330
  if (isPublicSurface(resolved, root, targetModule)) return;
228
331
  if (importerModule === targetModule) return;
332
+ if (railRouteStub && isModuleRoutesEntry(resolved, root, targetModule)) return;
333
+ if (railCompositionImporter && isConventionalCompositionEntry(resolved, root, targetModule)) {
334
+ return;
335
+ }
336
+ if (railI18nJsonImporter && isConventionalI18nJsonEntry(resolved, root, targetModule)) {
337
+ return;
338
+ }
339
+ if (railEndpointStub && isEndpointHandlerEntry(resolved, root, targetModule)) return;
229
340
  context.report({
230
341
  node,
231
342
  messageId: "noInternalImport",
@@ -245,17 +356,216 @@ var rule3 = {
245
356
  },
246
357
  ExportAllDeclaration(node) {
247
358
  check(node, node.source);
359
+ },
360
+ // Literal CommonJS `require("...")` — same isolation rule as ESM imports.
361
+ CallExpression(node) {
362
+ const call = node;
363
+ if (call.callee?.type !== "Identifier" || call.callee.name !== "require") return;
364
+ const arg0 = call.arguments?.[0];
365
+ if (!arg0 || arg0.type !== "Literal" || typeof arg0.value !== "string") return;
366
+ check(node, arg0);
367
+ },
368
+ // TypeScript `import x = require("...")` (TS-ESLint AST).
369
+ TSImportEqualsDeclaration(node) {
370
+ const decl = node;
371
+ const ref = decl.moduleReference;
372
+ if (!ref || ref.type !== "TSExternalModuleReference") return;
373
+ const expression = ref.expression;
374
+ if (!expression || expression.type !== "Literal" || typeof expression.value !== "string") {
375
+ return;
376
+ }
377
+ check(node, expression);
248
378
  }
249
379
  };
250
380
  }
251
381
  };
252
382
  var no_module_internal_import_default = rule3;
253
383
 
384
+ // src/rules/no-server-import-in-conventional-entry.ts
385
+ var import_node_path2 = __toESM(require("path"), 1);
386
+ function toPosix2(filePath) {
387
+ return filePath.split(import_node_path2.default.sep).join("/");
388
+ }
389
+ function isClientSafeConventionalEntry(filename) {
390
+ const posix = toPosix2(filename);
391
+ return /\/src\/modules\/[^/]+\/(?:contributions|slots)\.ts$/.test(posix) || /\/src\/modules\/[^/]+\/enhancements\/[^/]+\/contributions\.ts$/.test(posix);
392
+ }
393
+ var NODE_BUILTIN_MODULE_NAMES = /* @__PURE__ */ new Set([
394
+ "assert",
395
+ "async_hooks",
396
+ "buffer",
397
+ "child_process",
398
+ "cluster",
399
+ "console",
400
+ "constants",
401
+ "crypto",
402
+ "dgram",
403
+ "diagnostics_channel",
404
+ "dns",
405
+ "domain",
406
+ "events",
407
+ "fs",
408
+ "http",
409
+ "http2",
410
+ "https",
411
+ "inspector",
412
+ "module",
413
+ "net",
414
+ "os",
415
+ "path",
416
+ "perf_hooks",
417
+ "process",
418
+ "punycode",
419
+ "querystring",
420
+ "readline",
421
+ "repl",
422
+ "stream",
423
+ "string_decoder",
424
+ "sys",
425
+ "timers",
426
+ "tls",
427
+ "trace_events",
428
+ "tty",
429
+ "url",
430
+ "util",
431
+ "v8",
432
+ "vm",
433
+ "wasi",
434
+ "worker_threads",
435
+ "zlib"
436
+ ]);
437
+ function isNodeBuiltinImportSpecifier(specifier) {
438
+ const withoutNodePrefix = specifier.startsWith("node:") ? specifier.slice("node:".length) : specifier;
439
+ if (withoutNodePrefix.startsWith("@")) return false;
440
+ const firstSegment = withoutNodePrefix.split("/")[0] ?? withoutNodePrefix;
441
+ return specifier.startsWith("node:") || NODE_BUILTIN_MODULE_NAMES.has(firstSegment);
442
+ }
443
+ function classifyForbiddenSpecifier(specifier) {
444
+ if (specifier === "server-only") {
445
+ return {
446
+ reason: "server-only-package",
447
+ message: `import of "server-only" package "${specifier}" is forbidden in a client-safe conventional entry`
448
+ };
449
+ }
450
+ if (isNodeBuiltinImportSpecifier(specifier)) {
451
+ return {
452
+ reason: "node-builtin",
453
+ message: `import of Node builtin "${specifier}" is forbidden in a client-safe conventional entry`
454
+ };
455
+ }
456
+ const pathPart = specifier.split(/[?#]/, 1)[0] ?? specifier;
457
+ const segments = pathPart.split("/").filter((s) => s.length > 0 && s !== ".");
458
+ if (/\.server(?:\.[cm]?[tj]sx?)?$/.test(pathPart)) {
459
+ return {
460
+ reason: "dot-server-file",
461
+ message: `import of a ".server" file "${specifier}" is forbidden in a client-safe conventional entry`
462
+ };
463
+ }
464
+ if (segments.some((seg) => seg === "server")) {
465
+ return {
466
+ reason: "server-path-segment",
467
+ message: `import reaching a "/server" module entry "${specifier}" is forbidden in a client-safe conventional entry`
468
+ };
469
+ }
470
+ const enhIdx = segments.lastIndexOf("enhancements");
471
+ if (enhIdx !== -1) {
472
+ const rest = segments.slice(enhIdx + 1);
473
+ const isRootBarrel = rest.length === 1 || rest.length === 2 && (rest[1] === "index" || rest[1] === "index.ts");
474
+ if (isRootBarrel) {
475
+ return {
476
+ reason: "enhancement-root-entry",
477
+ message: `import of enhancement root entry "${specifier}" is forbidden in a client-safe conventional entry (may carry server initialization)`
478
+ };
479
+ }
480
+ }
481
+ return null;
482
+ }
483
+ var rule4 = {
484
+ meta: {
485
+ type: "problem",
486
+ docs: {
487
+ description: "Disallow direct server-only / node builtin / .server / /server / enhancement-root imports inside contributions.ts and slots.ts, which are bundled into client-reachable composition artifacts",
488
+ recommended: true
489
+ },
490
+ messages: {
491
+ forbiddenServerImport: "{{message}}"
492
+ },
493
+ schema: []
494
+ },
495
+ create(context) {
496
+ const filename = context.filename;
497
+ if (!filename || filename === "<input>" || filename === "<text>") {
498
+ return {};
499
+ }
500
+ if (!isClientSafeConventionalEntry(filename)) {
501
+ return {};
502
+ }
503
+ function check(node, sourceNode) {
504
+ if (!sourceNode || sourceNode.type !== "Literal") return;
505
+ const value = sourceNode.value;
506
+ if (typeof value !== "string") return;
507
+ const forbidden = classifyForbiddenSpecifier(value);
508
+ if (!forbidden) return;
509
+ context.report({
510
+ node,
511
+ messageId: "forbiddenServerImport",
512
+ data: { message: forbidden.message }
513
+ });
514
+ }
515
+ return {
516
+ ImportDeclaration(node) {
517
+ check(node, node.source);
518
+ },
519
+ ImportExpression(node) {
520
+ const src = node.source;
521
+ check(node, src);
522
+ },
523
+ ExportNamedDeclaration(node) {
524
+ check(node, node.source);
525
+ },
526
+ ExportAllDeclaration(node) {
527
+ check(node, node.source);
528
+ },
529
+ // Literal CommonJS `require("...")` — same client-bundle risk as ESM import.
530
+ CallExpression(node) {
531
+ const call = node;
532
+ if (call.callee?.type !== "Identifier" || call.callee.name !== "require") return;
533
+ const arg0 = call.arguments?.[0];
534
+ if (!arg0 || arg0.type !== "Literal" || typeof arg0.value !== "string") return;
535
+ const forbidden = classifyForbiddenSpecifier(arg0.value);
536
+ if (!forbidden) return;
537
+ context.report({
538
+ node,
539
+ messageId: "forbiddenServerImport",
540
+ data: { message: forbidden.message }
541
+ });
542
+ },
543
+ // TypeScript `import x = require("...")` (TS-ESLint AST).
544
+ TSImportEqualsDeclaration(node) {
545
+ const decl = node;
546
+ const ref = decl.moduleReference;
547
+ if (!ref || ref.type !== "TSExternalModuleReference") return;
548
+ const expr = ref.expression;
549
+ if (!expr || expr.type !== "Literal" || typeof expr.value !== "string") return;
550
+ const forbidden = classifyForbiddenSpecifier(expr.value);
551
+ if (!forbidden) return;
552
+ context.report({
553
+ node,
554
+ messageId: "forbiddenServerImport",
555
+ data: { message: forbidden.message }
556
+ });
557
+ }
558
+ };
559
+ }
560
+ };
561
+ var no_server_import_in_conventional_entry_default = rule4;
562
+
254
563
  // src/rules/index.ts
255
564
  var rules = {
256
565
  "no-template-literal-classname": no_template_literal_classname_default,
257
566
  "no-kysely-interactive-transaction": no_kysely_interactive_transaction_default,
258
- "no-module-internal-import": no_module_internal_import_default
567
+ "no-module-internal-import": no_module_internal_import_default,
568
+ "no-server-import-in-conventional-entry": no_server_import_in_conventional_entry_default
259
569
  };
260
570
 
261
571
  // src/configs/recommended.ts
@@ -269,7 +579,8 @@ var recommended = {
269
579
  rules: {
270
580
  [`${pluginName}/no-template-literal-classname`]: "error",
271
581
  [`${pluginName}/no-kysely-interactive-transaction`]: "error",
272
- [`${pluginName}/no-module-internal-import`]: "error"
582
+ [`${pluginName}/no-module-internal-import`]: "error",
583
+ [`${pluginName}/no-server-import-in-conventional-entry`]: "error"
273
584
  }
274
585
  };
275
586
 
package/dist/index.d.cts CHANGED
@@ -5,6 +5,7 @@ declare const rules: {
5
5
  "no-template-literal-classname": eslint.Rule.RuleModule;
6
6
  "no-kysely-interactive-transaction": eslint.Rule.RuleModule;
7
7
  "no-module-internal-import": eslint.Rule.RuleModule;
8
+ "no-server-import-in-conventional-entry": eslint.Rule.RuleModule;
8
9
  };
9
10
 
10
11
  declare const configs: Record<string, Linter.Config>;
package/dist/index.d.ts CHANGED
@@ -5,6 +5,7 @@ declare const rules: {
5
5
  "no-template-literal-classname": eslint.Rule.RuleModule;
6
6
  "no-kysely-interactive-transaction": eslint.Rule.RuleModule;
7
7
  "no-module-internal-import": eslint.Rule.RuleModule;
8
+ "no-server-import-in-conventional-entry": eslint.Rule.RuleModule;
8
9
  };
9
10
 
10
11
  declare const configs: Record<string, Linter.Config>;
package/dist/index.js CHANGED
@@ -101,8 +101,13 @@ function findSrcRoot(filename) {
101
101
  for (let i = 0; i < parts.length; i++) {
102
102
  if (parts[i] === "src") lastSrcIdx = i;
103
103
  }
104
- if (lastSrcIdx === -1) return null;
105
- return parts.slice(0, lastSrcIdx + 1).join("/");
104
+ if (lastSrcIdx !== -1) return parts.slice(0, lastSrcIdx + 1).join("/");
105
+ for (let i = 0; i < parts.length - 1; i++) {
106
+ if (parts[i] === "apps" && parts[i + 1] === "web") {
107
+ return parts.slice(0, i + 2).concat("src").join("/");
108
+ }
109
+ }
110
+ return null;
106
111
  }
107
112
  function normalizePosixPath(raw) {
108
113
  const absolute = raw.startsWith("/");
@@ -155,6 +160,99 @@ function isPublicSurface(resolvedPath, srcRoot, moduleName) {
155
160
  if (resolvedPath === `${base}/index.tsx`) return true;
156
161
  return false;
157
162
  }
163
+ function isModuleRoutesEntry(resolvedPath, srcRoot, moduleName) {
164
+ const prefix = `${srcRoot}/modules/${moduleName}/routes/`;
165
+ return resolvedPath === `${srcRoot}/modules/${moduleName}/routes` || resolvedPath.startsWith(prefix);
166
+ }
167
+ var RAIL_MARKER = "@stardeck-module-rail-generated";
168
+ var I18N_GEN_MARKER = `// ${RAIL_MARKER} scope=i18n`;
169
+ var LOCALE_BASENAME_REGEX = /^[a-z]{2,3}(?:-[A-Za-z0-9]+)*$/;
170
+ var MAX_LOCALE_BASENAME_LENGTH = 35;
171
+ function isRailGeneratedRouteStub(filename, sourceText) {
172
+ const posix = toPosix(filename);
173
+ if (!/\/src\/app\/.+\/page\.tsx$/.test(posix) && !/\/src\/app\/page\.tsx$/.test(posix)) {
174
+ return false;
175
+ }
176
+ const firstLine = sourceText.split(/\r?\n/, 1)[0]?.trim() ?? "";
177
+ return firstLine.startsWith(`// ${RAIL_MARKER} `) && firstLine.includes("scope=route ");
178
+ }
179
+ function isRailGeneratedCompositionImporter(filename, sourceText) {
180
+ const posix = toPosix(filename);
181
+ if (!/\/src\/(?:modules\.gen|module-contributions\.gen|module-i18n\.gen|module-init\.server\.gen)\.ts$/.test(
182
+ posix
183
+ )) {
184
+ return false;
185
+ }
186
+ const firstLine = sourceText.split(/\r?\n/, 1)[0]?.trim() ?? "";
187
+ if (!firstLine.startsWith(`// ${RAIL_MARKER} `)) return false;
188
+ return firstLine.includes("scope=contributions") || firstLine.includes("scope=i18n") || firstLine.includes("scope=init") || firstLine.includes("scope=registry");
189
+ }
190
+ function isConventionalCompositionEntry(resolvedPath, srcRoot, moduleName) {
191
+ const base = `${srcRoot}/modules/${moduleName}`;
192
+ const allowedExact = /* @__PURE__ */ new Set([
193
+ `${base}/contributions`,
194
+ `${base}/contributions.ts`,
195
+ `${base}/slots`,
196
+ `${base}/slots.ts`,
197
+ `${base}/i18n`,
198
+ `${base}/i18n/index`,
199
+ `${base}/i18n/index.ts`
200
+ ]);
201
+ if (allowedExact.has(resolvedPath)) return true;
202
+ const enhMatch = resolvedPath.match(
203
+ new RegExp(
204
+ `^${base.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/enhancements/([^/]+)/(contributions|initialize\\.server)(?:\\.ts)?$`
205
+ )
206
+ );
207
+ if (enhMatch) return true;
208
+ const enhI18n = resolvedPath.match(
209
+ new RegExp(
210
+ `^${base.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/enhancements/([^/]+)/i18n(?:/index(?:\\.ts)?)?$`
211
+ )
212
+ );
213
+ return Boolean(enhI18n);
214
+ }
215
+ function isRailGeneratedI18nJsonImporter(filename, sourceText) {
216
+ const posix = toPosix(filename);
217
+ if (!/\/src\/module-i18n\.gen\.ts$/.test(posix)) return false;
218
+ const firstLine = sourceText.split(/\r?\n/, 1)[0]?.trim() ?? "";
219
+ return firstLine === I18N_GEN_MARKER;
220
+ }
221
+ function localeBasenameFromI18nJsonPath(resolvedPath, srcRoot, moduleName) {
222
+ const base = `${srcRoot}/modules/${moduleName}`;
223
+ const escaped = base.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
224
+ const rootMatch = new RegExp(`^${escaped}/i18n/([^/]+)\\.json$`).exec(resolvedPath);
225
+ if (rootMatch) return rootMatch[1] ?? null;
226
+ const sliceMatch = new RegExp(`^${escaped}/enhancements/[^/]+/i18n/([^/]+)\\.json$`).exec(
227
+ resolvedPath
228
+ );
229
+ return sliceMatch ? sliceMatch[1] ?? null : null;
230
+ }
231
+ function isValidLocaleBasename(basename) {
232
+ return basename.length > 0 && basename.length <= MAX_LOCALE_BASENAME_LENGTH && LOCALE_BASENAME_REGEX.test(basename);
233
+ }
234
+ function isConventionalI18nJsonEntry(resolvedPath, srcRoot, moduleName) {
235
+ const basename = localeBasenameFromI18nJsonPath(resolvedPath, srcRoot, moduleName);
236
+ return basename != null && isValidLocaleBasename(basename);
237
+ }
238
+ function isRailGeneratedEndpointStub(filename, sourceText) {
239
+ const posix = toPosix(filename);
240
+ if (!/\/src\/app\/api\/.+\/route\.ts$/.test(posix)) return false;
241
+ const firstLine = sourceText.split(/\r?\n/, 1)[0]?.trim() ?? "";
242
+ return firstLine.startsWith(`// ${RAIL_MARKER} `) && (firstLine.includes("scope=root") || firstLine.includes("scope=enhancement:"));
243
+ }
244
+ function isEndpointHandlerEntry(resolvedPath, srcRoot, moduleName) {
245
+ const base = `${srcRoot}/modules/${moduleName}`;
246
+ if (resolvedPath === `${base}/server` || resolvedPath === `${base}/server/index` || resolvedPath === `${base}/server/index.ts`) {
247
+ return true;
248
+ }
249
+ const enh = resolvedPath.match(
250
+ new RegExp(
251
+ `^${base.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/enhancements/([^/]+)(?:/index(?:\\.ts)?)?$`
252
+ )
253
+ );
254
+ return Boolean(enh);
255
+ }
158
256
  var rule3 = {
159
257
  meta: {
160
258
  type: "problem",
@@ -178,6 +276,11 @@ var rule3 = {
178
276
  }
179
277
  const root = srcRoot;
180
278
  const importerModule = getModuleName(toPosix(filename), root);
279
+ const sourceText = context.sourceCode.getText();
280
+ const railRouteStub = isRailGeneratedRouteStub(filename, sourceText);
281
+ const railCompositionImporter = isRailGeneratedCompositionImporter(filename, sourceText);
282
+ const railI18nJsonImporter = isRailGeneratedI18nJsonImporter(filename, sourceText);
283
+ const railEndpointStub = isRailGeneratedEndpointStub(filename, sourceText);
181
284
  function check(node, sourceNode) {
182
285
  if (!sourceNode || sourceNode.type !== "Literal") return;
183
286
  const value = sourceNode.value;
@@ -188,6 +291,14 @@ var rule3 = {
188
291
  if (!targetModule) return;
189
292
  if (isPublicSurface(resolved, root, targetModule)) return;
190
293
  if (importerModule === targetModule) return;
294
+ if (railRouteStub && isModuleRoutesEntry(resolved, root, targetModule)) return;
295
+ if (railCompositionImporter && isConventionalCompositionEntry(resolved, root, targetModule)) {
296
+ return;
297
+ }
298
+ if (railI18nJsonImporter && isConventionalI18nJsonEntry(resolved, root, targetModule)) {
299
+ return;
300
+ }
301
+ if (railEndpointStub && isEndpointHandlerEntry(resolved, root, targetModule)) return;
191
302
  context.report({
192
303
  node,
193
304
  messageId: "noInternalImport",
@@ -207,17 +318,216 @@ var rule3 = {
207
318
  },
208
319
  ExportAllDeclaration(node) {
209
320
  check(node, node.source);
321
+ },
322
+ // Literal CommonJS `require("...")` — same isolation rule as ESM imports.
323
+ CallExpression(node) {
324
+ const call = node;
325
+ if (call.callee?.type !== "Identifier" || call.callee.name !== "require") return;
326
+ const arg0 = call.arguments?.[0];
327
+ if (!arg0 || arg0.type !== "Literal" || typeof arg0.value !== "string") return;
328
+ check(node, arg0);
329
+ },
330
+ // TypeScript `import x = require("...")` (TS-ESLint AST).
331
+ TSImportEqualsDeclaration(node) {
332
+ const decl = node;
333
+ const ref = decl.moduleReference;
334
+ if (!ref || ref.type !== "TSExternalModuleReference") return;
335
+ const expression = ref.expression;
336
+ if (!expression || expression.type !== "Literal" || typeof expression.value !== "string") {
337
+ return;
338
+ }
339
+ check(node, expression);
210
340
  }
211
341
  };
212
342
  }
213
343
  };
214
344
  var no_module_internal_import_default = rule3;
215
345
 
346
+ // src/rules/no-server-import-in-conventional-entry.ts
347
+ import path2 from "path";
348
+ function toPosix2(filePath) {
349
+ return filePath.split(path2.sep).join("/");
350
+ }
351
+ function isClientSafeConventionalEntry(filename) {
352
+ const posix = toPosix2(filename);
353
+ return /\/src\/modules\/[^/]+\/(?:contributions|slots)\.ts$/.test(posix) || /\/src\/modules\/[^/]+\/enhancements\/[^/]+\/contributions\.ts$/.test(posix);
354
+ }
355
+ var NODE_BUILTIN_MODULE_NAMES = /* @__PURE__ */ new Set([
356
+ "assert",
357
+ "async_hooks",
358
+ "buffer",
359
+ "child_process",
360
+ "cluster",
361
+ "console",
362
+ "constants",
363
+ "crypto",
364
+ "dgram",
365
+ "diagnostics_channel",
366
+ "dns",
367
+ "domain",
368
+ "events",
369
+ "fs",
370
+ "http",
371
+ "http2",
372
+ "https",
373
+ "inspector",
374
+ "module",
375
+ "net",
376
+ "os",
377
+ "path",
378
+ "perf_hooks",
379
+ "process",
380
+ "punycode",
381
+ "querystring",
382
+ "readline",
383
+ "repl",
384
+ "stream",
385
+ "string_decoder",
386
+ "sys",
387
+ "timers",
388
+ "tls",
389
+ "trace_events",
390
+ "tty",
391
+ "url",
392
+ "util",
393
+ "v8",
394
+ "vm",
395
+ "wasi",
396
+ "worker_threads",
397
+ "zlib"
398
+ ]);
399
+ function isNodeBuiltinImportSpecifier(specifier) {
400
+ const withoutNodePrefix = specifier.startsWith("node:") ? specifier.slice("node:".length) : specifier;
401
+ if (withoutNodePrefix.startsWith("@")) return false;
402
+ const firstSegment = withoutNodePrefix.split("/")[0] ?? withoutNodePrefix;
403
+ return specifier.startsWith("node:") || NODE_BUILTIN_MODULE_NAMES.has(firstSegment);
404
+ }
405
+ function classifyForbiddenSpecifier(specifier) {
406
+ if (specifier === "server-only") {
407
+ return {
408
+ reason: "server-only-package",
409
+ message: `import of "server-only" package "${specifier}" is forbidden in a client-safe conventional entry`
410
+ };
411
+ }
412
+ if (isNodeBuiltinImportSpecifier(specifier)) {
413
+ return {
414
+ reason: "node-builtin",
415
+ message: `import of Node builtin "${specifier}" is forbidden in a client-safe conventional entry`
416
+ };
417
+ }
418
+ const pathPart = specifier.split(/[?#]/, 1)[0] ?? specifier;
419
+ const segments = pathPart.split("/").filter((s) => s.length > 0 && s !== ".");
420
+ if (/\.server(?:\.[cm]?[tj]sx?)?$/.test(pathPart)) {
421
+ return {
422
+ reason: "dot-server-file",
423
+ message: `import of a ".server" file "${specifier}" is forbidden in a client-safe conventional entry`
424
+ };
425
+ }
426
+ if (segments.some((seg) => seg === "server")) {
427
+ return {
428
+ reason: "server-path-segment",
429
+ message: `import reaching a "/server" module entry "${specifier}" is forbidden in a client-safe conventional entry`
430
+ };
431
+ }
432
+ const enhIdx = segments.lastIndexOf("enhancements");
433
+ if (enhIdx !== -1) {
434
+ const rest = segments.slice(enhIdx + 1);
435
+ const isRootBarrel = rest.length === 1 || rest.length === 2 && (rest[1] === "index" || rest[1] === "index.ts");
436
+ if (isRootBarrel) {
437
+ return {
438
+ reason: "enhancement-root-entry",
439
+ message: `import of enhancement root entry "${specifier}" is forbidden in a client-safe conventional entry (may carry server initialization)`
440
+ };
441
+ }
442
+ }
443
+ return null;
444
+ }
445
+ var rule4 = {
446
+ meta: {
447
+ type: "problem",
448
+ docs: {
449
+ description: "Disallow direct server-only / node builtin / .server / /server / enhancement-root imports inside contributions.ts and slots.ts, which are bundled into client-reachable composition artifacts",
450
+ recommended: true
451
+ },
452
+ messages: {
453
+ forbiddenServerImport: "{{message}}"
454
+ },
455
+ schema: []
456
+ },
457
+ create(context) {
458
+ const filename = context.filename;
459
+ if (!filename || filename === "<input>" || filename === "<text>") {
460
+ return {};
461
+ }
462
+ if (!isClientSafeConventionalEntry(filename)) {
463
+ return {};
464
+ }
465
+ function check(node, sourceNode) {
466
+ if (!sourceNode || sourceNode.type !== "Literal") return;
467
+ const value = sourceNode.value;
468
+ if (typeof value !== "string") return;
469
+ const forbidden = classifyForbiddenSpecifier(value);
470
+ if (!forbidden) return;
471
+ context.report({
472
+ node,
473
+ messageId: "forbiddenServerImport",
474
+ data: { message: forbidden.message }
475
+ });
476
+ }
477
+ return {
478
+ ImportDeclaration(node) {
479
+ check(node, node.source);
480
+ },
481
+ ImportExpression(node) {
482
+ const src = node.source;
483
+ check(node, src);
484
+ },
485
+ ExportNamedDeclaration(node) {
486
+ check(node, node.source);
487
+ },
488
+ ExportAllDeclaration(node) {
489
+ check(node, node.source);
490
+ },
491
+ // Literal CommonJS `require("...")` — same client-bundle risk as ESM import.
492
+ CallExpression(node) {
493
+ const call = node;
494
+ if (call.callee?.type !== "Identifier" || call.callee.name !== "require") return;
495
+ const arg0 = call.arguments?.[0];
496
+ if (!arg0 || arg0.type !== "Literal" || typeof arg0.value !== "string") return;
497
+ const forbidden = classifyForbiddenSpecifier(arg0.value);
498
+ if (!forbidden) return;
499
+ context.report({
500
+ node,
501
+ messageId: "forbiddenServerImport",
502
+ data: { message: forbidden.message }
503
+ });
504
+ },
505
+ // TypeScript `import x = require("...")` (TS-ESLint AST).
506
+ TSImportEqualsDeclaration(node) {
507
+ const decl = node;
508
+ const ref = decl.moduleReference;
509
+ if (!ref || ref.type !== "TSExternalModuleReference") return;
510
+ const expr = ref.expression;
511
+ if (!expr || expr.type !== "Literal" || typeof expr.value !== "string") return;
512
+ const forbidden = classifyForbiddenSpecifier(expr.value);
513
+ if (!forbidden) return;
514
+ context.report({
515
+ node,
516
+ messageId: "forbiddenServerImport",
517
+ data: { message: forbidden.message }
518
+ });
519
+ }
520
+ };
521
+ }
522
+ };
523
+ var no_server_import_in_conventional_entry_default = rule4;
524
+
216
525
  // src/rules/index.ts
217
526
  var rules = {
218
527
  "no-template-literal-classname": no_template_literal_classname_default,
219
528
  "no-kysely-interactive-transaction": no_kysely_interactive_transaction_default,
220
- "no-module-internal-import": no_module_internal_import_default
529
+ "no-module-internal-import": no_module_internal_import_default,
530
+ "no-server-import-in-conventional-entry": no_server_import_in_conventional_entry_default
221
531
  };
222
532
 
223
533
  // src/configs/recommended.ts
@@ -231,7 +541,8 @@ var recommended = {
231
541
  rules: {
232
542
  [`${pluginName}/no-template-literal-classname`]: "error",
233
543
  [`${pluginName}/no-kysely-interactive-transaction`]: "error",
234
- [`${pluginName}/no-module-internal-import`]: "error"
544
+ [`${pluginName}/no-module-internal-import`]: "error",
545
+ [`${pluginName}/no-server-import-in-conventional-entry`]: "error"
235
546
  }
236
547
  };
237
548
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stardeck-customer-apps/eslint-plugin",
3
- "version": "1.2.0",
3
+ "version": "1.5.0",
4
4
  "description": "Custom ESLint rules for Stardeck customer apps",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -11,7 +11,8 @@
11
11
  "access": "public"
12
12
  },
13
13
  "files": [
14
- "dist"
14
+ "dist",
15
+ "SKILL.md"
15
16
  ],
16
17
  "exports": {
17
18
  ".": {