@stardeck-customer-apps/eslint-plugin 1.1.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 +21 -0
- package/SKILL.md +124 -0
- package/dist/index.cjs +454 -2
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +444 -2
- package/package.json +3 -2
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
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
@@ -112,10 +122,450 @@ var rule2 = {
|
|
|
112
122
|
};
|
|
113
123
|
var no_kysely_interactive_transaction_default = rule2;
|
|
114
124
|
|
|
125
|
+
// src/rules/no-module-internal-import.ts
|
|
126
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
127
|
+
var ALIAS_PREFIX = "@/";
|
|
128
|
+
function toPosix(filePath) {
|
|
129
|
+
return filePath.split(import_node_path.default.sep).join("/");
|
|
130
|
+
}
|
|
131
|
+
function findSrcRoot(filename) {
|
|
132
|
+
const parts = toPosix(filename).split("/");
|
|
133
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
134
|
+
if (parts[i] === "src" && parts[i + 1] === "modules") {
|
|
135
|
+
return parts.slice(0, i + 1).join("/");
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
let lastSrcIdx = -1;
|
|
139
|
+
for (let i = 0; i < parts.length; i++) {
|
|
140
|
+
if (parts[i] === "src") lastSrcIdx = i;
|
|
141
|
+
}
|
|
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;
|
|
149
|
+
}
|
|
150
|
+
function normalizePosixPath(raw) {
|
|
151
|
+
const absolute = raw.startsWith("/");
|
|
152
|
+
const parts = raw.split("/");
|
|
153
|
+
const stack = [];
|
|
154
|
+
for (const part of parts) {
|
|
155
|
+
if (part === "" || part === ".") continue;
|
|
156
|
+
if (part === "..") {
|
|
157
|
+
if (stack.length === 0) return null;
|
|
158
|
+
stack.pop();
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
stack.push(part);
|
|
162
|
+
}
|
|
163
|
+
const joined = stack.join("/");
|
|
164
|
+
return absolute ? `/${joined}` : joined;
|
|
165
|
+
}
|
|
166
|
+
function dirnamePosix(filePath) {
|
|
167
|
+
const idx = filePath.lastIndexOf("/");
|
|
168
|
+
if (idx <= 0) return "/";
|
|
169
|
+
return filePath.slice(0, idx);
|
|
170
|
+
}
|
|
171
|
+
function resolveImportPath(filename, srcRoot, specifier) {
|
|
172
|
+
let candidate;
|
|
173
|
+
if (specifier.startsWith(ALIAS_PREFIX)) {
|
|
174
|
+
candidate = `${srcRoot}/${specifier.slice(ALIAS_PREFIX.length)}`;
|
|
175
|
+
} else if (specifier.startsWith("./") || specifier.startsWith("../")) {
|
|
176
|
+
candidate = `${dirnamePosix(toPosix(filename))}/${specifier}`;
|
|
177
|
+
} else {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
const normalized = normalizePosixPath(candidate);
|
|
181
|
+
if (!normalized) return null;
|
|
182
|
+
if (normalized !== srcRoot && !normalized.startsWith(`${srcRoot}/`)) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
return normalized;
|
|
186
|
+
}
|
|
187
|
+
function getModuleName(filePath, srcRoot) {
|
|
188
|
+
if (!filePath.startsWith(`${srcRoot}/`)) return null;
|
|
189
|
+
const rel = filePath.slice(srcRoot.length + 1);
|
|
190
|
+
const match = /^modules\/([^/]+)/.exec(rel);
|
|
191
|
+
return match ? match[1] : null;
|
|
192
|
+
}
|
|
193
|
+
function isPublicSurface(resolvedPath, srcRoot, moduleName) {
|
|
194
|
+
const base = `${srcRoot}/modules/${moduleName}`;
|
|
195
|
+
if (resolvedPath === base) return true;
|
|
196
|
+
if (resolvedPath === `${base}/index`) return true;
|
|
197
|
+
if (resolvedPath === `${base}/index.ts`) return true;
|
|
198
|
+
if (resolvedPath === `${base}/index.tsx`) return true;
|
|
199
|
+
return false;
|
|
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
|
+
}
|
|
294
|
+
var rule3 = {
|
|
295
|
+
meta: {
|
|
296
|
+
type: "problem",
|
|
297
|
+
docs: {
|
|
298
|
+
description: "Disallow imports that reach into a vendored module's internals; import only through `@/modules/<name>` (its index)",
|
|
299
|
+
recommended: true
|
|
300
|
+
},
|
|
301
|
+
messages: {
|
|
302
|
+
noInternalImport: "Import '{{module}}' through its public surface ('@/modules/{{module}}') \u2014 '{{source}}' reaches into module internals, which breaks module install/update isolation."
|
|
303
|
+
},
|
|
304
|
+
schema: []
|
|
305
|
+
},
|
|
306
|
+
create(context) {
|
|
307
|
+
const filename = context.filename;
|
|
308
|
+
if (!filename || filename === "<input>" || filename === "<text>") {
|
|
309
|
+
return {};
|
|
310
|
+
}
|
|
311
|
+
const srcRoot = findSrcRoot(filename);
|
|
312
|
+
if (!srcRoot) {
|
|
313
|
+
return {};
|
|
314
|
+
}
|
|
315
|
+
const root = srcRoot;
|
|
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);
|
|
322
|
+
function check(node, sourceNode) {
|
|
323
|
+
if (!sourceNode || sourceNode.type !== "Literal") return;
|
|
324
|
+
const value = sourceNode.value;
|
|
325
|
+
if (typeof value !== "string") return;
|
|
326
|
+
const resolved = resolveImportPath(filename, root, value);
|
|
327
|
+
if (!resolved) return;
|
|
328
|
+
const targetModule = getModuleName(resolved, root);
|
|
329
|
+
if (!targetModule) return;
|
|
330
|
+
if (isPublicSurface(resolved, root, targetModule)) return;
|
|
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;
|
|
340
|
+
context.report({
|
|
341
|
+
node,
|
|
342
|
+
messageId: "noInternalImport",
|
|
343
|
+
data: { module: targetModule, source: value }
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
return {
|
|
347
|
+
ImportDeclaration(node) {
|
|
348
|
+
check(node, node.source);
|
|
349
|
+
},
|
|
350
|
+
ImportExpression(node) {
|
|
351
|
+
const src = node.source;
|
|
352
|
+
check(node, src);
|
|
353
|
+
},
|
|
354
|
+
ExportNamedDeclaration(node) {
|
|
355
|
+
check(node, node.source);
|
|
356
|
+
},
|
|
357
|
+
ExportAllDeclaration(node) {
|
|
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);
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
var no_module_internal_import_default = rule3;
|
|
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
|
+
|
|
115
563
|
// src/rules/index.ts
|
|
116
564
|
var rules = {
|
|
117
565
|
"no-template-literal-classname": no_template_literal_classname_default,
|
|
118
|
-
"no-kysely-interactive-transaction": no_kysely_interactive_transaction_default
|
|
566
|
+
"no-kysely-interactive-transaction": no_kysely_interactive_transaction_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
|
|
119
569
|
};
|
|
120
570
|
|
|
121
571
|
// src/configs/recommended.ts
|
|
@@ -128,7 +578,9 @@ var recommended = {
|
|
|
128
578
|
},
|
|
129
579
|
rules: {
|
|
130
580
|
[`${pluginName}/no-template-literal-classname`]: "error",
|
|
131
|
-
[`${pluginName}/no-kysely-interactive-transaction`]: "error"
|
|
581
|
+
[`${pluginName}/no-kysely-interactive-transaction`]: "error",
|
|
582
|
+
[`${pluginName}/no-module-internal-import`]: "error",
|
|
583
|
+
[`${pluginName}/no-server-import-in-conventional-entry`]: "error"
|
|
132
584
|
}
|
|
133
585
|
};
|
|
134
586
|
|
package/dist/index.d.cts
CHANGED
|
@@ -4,6 +4,8 @@ import { Linter, ESLint } from 'eslint';
|
|
|
4
4
|
declare const rules: {
|
|
5
5
|
"no-template-literal-classname": eslint.Rule.RuleModule;
|
|
6
6
|
"no-kysely-interactive-transaction": eslint.Rule.RuleModule;
|
|
7
|
+
"no-module-internal-import": eslint.Rule.RuleModule;
|
|
8
|
+
"no-server-import-in-conventional-entry": eslint.Rule.RuleModule;
|
|
7
9
|
};
|
|
8
10
|
|
|
9
11
|
declare const configs: Record<string, Linter.Config>;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ import { Linter, ESLint } from 'eslint';
|
|
|
4
4
|
declare const rules: {
|
|
5
5
|
"no-template-literal-classname": eslint.Rule.RuleModule;
|
|
6
6
|
"no-kysely-interactive-transaction": eslint.Rule.RuleModule;
|
|
7
|
+
"no-module-internal-import": eslint.Rule.RuleModule;
|
|
8
|
+
"no-server-import-in-conventional-entry": eslint.Rule.RuleModule;
|
|
7
9
|
};
|
|
8
10
|
|
|
9
11
|
declare const configs: Record<string, Linter.Config>;
|
package/dist/index.js
CHANGED
|
@@ -84,10 +84,450 @@ var rule2 = {
|
|
|
84
84
|
};
|
|
85
85
|
var no_kysely_interactive_transaction_default = rule2;
|
|
86
86
|
|
|
87
|
+
// src/rules/no-module-internal-import.ts
|
|
88
|
+
import path from "path";
|
|
89
|
+
var ALIAS_PREFIX = "@/";
|
|
90
|
+
function toPosix(filePath) {
|
|
91
|
+
return filePath.split(path.sep).join("/");
|
|
92
|
+
}
|
|
93
|
+
function findSrcRoot(filename) {
|
|
94
|
+
const parts = toPosix(filename).split("/");
|
|
95
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
96
|
+
if (parts[i] === "src" && parts[i + 1] === "modules") {
|
|
97
|
+
return parts.slice(0, i + 1).join("/");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
let lastSrcIdx = -1;
|
|
101
|
+
for (let i = 0; i < parts.length; i++) {
|
|
102
|
+
if (parts[i] === "src") lastSrcIdx = i;
|
|
103
|
+
}
|
|
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;
|
|
111
|
+
}
|
|
112
|
+
function normalizePosixPath(raw) {
|
|
113
|
+
const absolute = raw.startsWith("/");
|
|
114
|
+
const parts = raw.split("/");
|
|
115
|
+
const stack = [];
|
|
116
|
+
for (const part of parts) {
|
|
117
|
+
if (part === "" || part === ".") continue;
|
|
118
|
+
if (part === "..") {
|
|
119
|
+
if (stack.length === 0) return null;
|
|
120
|
+
stack.pop();
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
stack.push(part);
|
|
124
|
+
}
|
|
125
|
+
const joined = stack.join("/");
|
|
126
|
+
return absolute ? `/${joined}` : joined;
|
|
127
|
+
}
|
|
128
|
+
function dirnamePosix(filePath) {
|
|
129
|
+
const idx = filePath.lastIndexOf("/");
|
|
130
|
+
if (idx <= 0) return "/";
|
|
131
|
+
return filePath.slice(0, idx);
|
|
132
|
+
}
|
|
133
|
+
function resolveImportPath(filename, srcRoot, specifier) {
|
|
134
|
+
let candidate;
|
|
135
|
+
if (specifier.startsWith(ALIAS_PREFIX)) {
|
|
136
|
+
candidate = `${srcRoot}/${specifier.slice(ALIAS_PREFIX.length)}`;
|
|
137
|
+
} else if (specifier.startsWith("./") || specifier.startsWith("../")) {
|
|
138
|
+
candidate = `${dirnamePosix(toPosix(filename))}/${specifier}`;
|
|
139
|
+
} else {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
const normalized = normalizePosixPath(candidate);
|
|
143
|
+
if (!normalized) return null;
|
|
144
|
+
if (normalized !== srcRoot && !normalized.startsWith(`${srcRoot}/`)) {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
return normalized;
|
|
148
|
+
}
|
|
149
|
+
function getModuleName(filePath, srcRoot) {
|
|
150
|
+
if (!filePath.startsWith(`${srcRoot}/`)) return null;
|
|
151
|
+
const rel = filePath.slice(srcRoot.length + 1);
|
|
152
|
+
const match = /^modules\/([^/]+)/.exec(rel);
|
|
153
|
+
return match ? match[1] : null;
|
|
154
|
+
}
|
|
155
|
+
function isPublicSurface(resolvedPath, srcRoot, moduleName) {
|
|
156
|
+
const base = `${srcRoot}/modules/${moduleName}`;
|
|
157
|
+
if (resolvedPath === base) return true;
|
|
158
|
+
if (resolvedPath === `${base}/index`) return true;
|
|
159
|
+
if (resolvedPath === `${base}/index.ts`) return true;
|
|
160
|
+
if (resolvedPath === `${base}/index.tsx`) return true;
|
|
161
|
+
return false;
|
|
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
|
+
}
|
|
256
|
+
var rule3 = {
|
|
257
|
+
meta: {
|
|
258
|
+
type: "problem",
|
|
259
|
+
docs: {
|
|
260
|
+
description: "Disallow imports that reach into a vendored module's internals; import only through `@/modules/<name>` (its index)",
|
|
261
|
+
recommended: true
|
|
262
|
+
},
|
|
263
|
+
messages: {
|
|
264
|
+
noInternalImport: "Import '{{module}}' through its public surface ('@/modules/{{module}}') \u2014 '{{source}}' reaches into module internals, which breaks module install/update isolation."
|
|
265
|
+
},
|
|
266
|
+
schema: []
|
|
267
|
+
},
|
|
268
|
+
create(context) {
|
|
269
|
+
const filename = context.filename;
|
|
270
|
+
if (!filename || filename === "<input>" || filename === "<text>") {
|
|
271
|
+
return {};
|
|
272
|
+
}
|
|
273
|
+
const srcRoot = findSrcRoot(filename);
|
|
274
|
+
if (!srcRoot) {
|
|
275
|
+
return {};
|
|
276
|
+
}
|
|
277
|
+
const root = srcRoot;
|
|
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);
|
|
284
|
+
function check(node, sourceNode) {
|
|
285
|
+
if (!sourceNode || sourceNode.type !== "Literal") return;
|
|
286
|
+
const value = sourceNode.value;
|
|
287
|
+
if (typeof value !== "string") return;
|
|
288
|
+
const resolved = resolveImportPath(filename, root, value);
|
|
289
|
+
if (!resolved) return;
|
|
290
|
+
const targetModule = getModuleName(resolved, root);
|
|
291
|
+
if (!targetModule) return;
|
|
292
|
+
if (isPublicSurface(resolved, root, targetModule)) return;
|
|
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;
|
|
302
|
+
context.report({
|
|
303
|
+
node,
|
|
304
|
+
messageId: "noInternalImport",
|
|
305
|
+
data: { module: targetModule, source: value }
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
return {
|
|
309
|
+
ImportDeclaration(node) {
|
|
310
|
+
check(node, node.source);
|
|
311
|
+
},
|
|
312
|
+
ImportExpression(node) {
|
|
313
|
+
const src = node.source;
|
|
314
|
+
check(node, src);
|
|
315
|
+
},
|
|
316
|
+
ExportNamedDeclaration(node) {
|
|
317
|
+
check(node, node.source);
|
|
318
|
+
},
|
|
319
|
+
ExportAllDeclaration(node) {
|
|
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);
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
var no_module_internal_import_default = rule3;
|
|
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
|
+
|
|
87
525
|
// src/rules/index.ts
|
|
88
526
|
var rules = {
|
|
89
527
|
"no-template-literal-classname": no_template_literal_classname_default,
|
|
90
|
-
"no-kysely-interactive-transaction": no_kysely_interactive_transaction_default
|
|
528
|
+
"no-kysely-interactive-transaction": no_kysely_interactive_transaction_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
|
|
91
531
|
};
|
|
92
532
|
|
|
93
533
|
// src/configs/recommended.ts
|
|
@@ -100,7 +540,9 @@ var recommended = {
|
|
|
100
540
|
},
|
|
101
541
|
rules: {
|
|
102
542
|
[`${pluginName}/no-template-literal-classname`]: "error",
|
|
103
|
-
[`${pluginName}/no-kysely-interactive-transaction`]: "error"
|
|
543
|
+
[`${pluginName}/no-kysely-interactive-transaction`]: "error",
|
|
544
|
+
[`${pluginName}/no-module-internal-import`]: "error",
|
|
545
|
+
[`${pluginName}/no-server-import-in-conventional-entry`]: "error"
|
|
104
546
|
}
|
|
105
547
|
};
|
|
106
548
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stardeck-customer-apps/eslint-plugin",
|
|
3
|
-
"version": "1.
|
|
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
|
".": {
|