Use noCommonJs for CommonJS import policy

This commit is contained in:
murashit 2026-06-26 08:17:58 +09:00
parent 1a90cf977d
commit 4e107dadd3
11 changed files with 43 additions and 110 deletions

View file

@ -173,6 +173,9 @@
}
}
},
"style": {
"noCommonJs": "error"
},
"suspicious": {
"noImportCycles": "error"
}

View file

@ -10,15 +10,9 @@ private pattern js_module_reference() {
}
}
or {
js_module_reference() as $stmt where {
$stmt <: contains `$source` where {
$source <: r"^[\"'](?:(?:\.\./)+app-server/protocol|src/app-server/protocol)/[^/\"']+(?:/.*)?[\"']$"
},
register_diagnostic(span=$stmt, message="Source modules outside app-server must use domain models and app-server services instead of app-server protocol modules. Chat ingestion and message-stream conversion may consume app-server turn protocol at the boundary; feature state and UI must use Panel-owned models.", severity="error")
js_module_reference() as $stmt where {
$stmt <: contains `$source` where {
$source <: r"^[\"'](?:(?:\.\./)+app-server/protocol|src/app-server/protocol)/[^/\"']+(?:/.*)?[\"']$"
},
`require($source)` as $stmt where {
$source <: r"^[\"'](?:(?:\.\./)+app-server/protocol|src/app-server/protocol)/[^/\"']+(?:/.*)?[\"']$",
register_diagnostic(span=$stmt, message="Source modules outside app-server must use domain models and app-server services instead of app-server protocol modules. Chat ingestion and message-stream conversion may consume app-server turn protocol at the boundary; feature state and UI must use Panel-owned models.", severity="error")
}
register_diagnostic(span=$stmt, message="Source modules outside app-server must use domain models and app-server services instead of app-server protocol modules. Chat ingestion and message-stream conversion may consume app-server turn protocol at the boundary; feature state and UI must use Panel-owned models.", severity="error")
}

View file

@ -10,17 +10,10 @@ private pattern js_module_reference() {
}
}
or {
js_module_reference() as $stmt where {
$stmt <: contains `$source` where {
$source <: r"^[\"'](?:(?:\.\./)+app-server/protocol|src/app-server/protocol)/[^/\"']+(?:/.*)?[\"']$",
not { $source <: r"^[\"'](?:(?:\.\./)+app-server/protocol/server-requests|src/app-server/protocol/server-requests)(?:/.*)?[\"']$" }
},
register_diagnostic(span=$stmt, message="Chat app-server request handling may consume server request protocol projections only. Convert app-server payloads to chat pending request domain models at this boundary.", severity="error")
},
`require($source)` as $stmt where {
js_module_reference() as $stmt where {
$stmt <: contains `$source` where {
$source <: r"^[\"'](?:(?:\.\./)+app-server/protocol|src/app-server/protocol)/[^/\"']+(?:/.*)?[\"']$",
not { $source <: r"^[\"'](?:(?:\.\./)+app-server/protocol/server-requests|src/app-server/protocol/server-requests)(?:/.*)?[\"']$" },
register_diagnostic(span=$stmt, message="Chat app-server request handling may consume server request protocol projections only. Convert app-server payloads to chat pending request domain models at this boundary.", severity="error")
}
not { $source <: r"^[\"'](?:(?:\.\./)+app-server/protocol/server-requests|src/app-server/protocol/server-requests)(?:/.*)?[\"']$" }
},
register_diagnostic(span=$stmt, message="Chat app-server request handling may consume server request protocol projections only. Convert app-server payloads to chat pending request domain models at this boundary.", severity="error")
}

View file

@ -10,17 +10,10 @@ private pattern js_module_reference() {
}
}
or {
js_module_reference() as $stmt where {
$stmt <: contains `$source` where {
$source <: r"^[\"'](?:(?:\.\./)+app-server/protocol|src/app-server/protocol)/[^/\"']+(?:/.*)?[\"']$",
not { $source <: r"^[\"'](?:(?:\.\./)+app-server/protocol/turn|src/app-server/protocol/turn)(?:/.*)?[\"']$" }
},
register_diagnostic(span=$stmt, message="Chat app-server ingestion and message-stream conversion may consume the app-server turn protocol only. Convert other protocol payloads to local or domain models at the boundary.", severity="error")
},
`require($source)` as $stmt where {
js_module_reference() as $stmt where {
$stmt <: contains `$source` where {
$source <: r"^[\"'](?:(?:\.\./)+app-server/protocol|src/app-server/protocol)/[^/\"']+(?:/.*)?[\"']$",
not { $source <: r"^[\"'](?:(?:\.\./)+app-server/protocol/turn|src/app-server/protocol/turn)(?:/.*)?[\"']$" },
register_diagnostic(span=$stmt, message="Chat app-server ingestion and message-stream conversion may consume the app-server turn protocol only. Convert other protocol payloads to local or domain models at the boundary.", severity="error")
}
not { $source <: r"^[\"'](?:(?:\.\./)+app-server/protocol/turn|src/app-server/protocol/turn)(?:/.*)?[\"']$" }
},
register_diagnostic(span=$stmt, message="Chat app-server ingestion and message-stream conversion may consume the app-server turn protocol only. Convert other protocol payloads to local or domain models at the boundary.", severity="error")
}

View file

@ -10,15 +10,9 @@ private pattern js_module_reference() {
}
}
or {
js_module_reference() as $stmt where {
$stmt <: contains `$source` where {
$source <: r"^[\"'](?:(?:\.\./)+|src/features/chat/)(?:app-server|application|host|panel|presentation|ui)(?:/.*)?[\"']$"
},
register_diagnostic(span=$stmt, message="Keep chat/domain as Panel-owned meaning models and pure derivations; app-server, application, host, panel, presentation, and UI layers may depend on domain, not the reverse.", severity="error")
js_module_reference() as $stmt where {
$stmt <: contains `$source` where {
$source <: r"^[\"'](?:(?:\.\./)+|src/features/chat/)(?:app-server|application|host|panel|presentation|ui)(?:/.*)?[\"']$"
},
`require($source)` as $stmt where {
$source <: r"^[\"'](?:(?:\.\./)+|src/features/chat/)(?:app-server|application|host|panel|presentation|ui)(?:/.*)?[\"']$",
register_diagnostic(span=$stmt, message="Keep chat/domain as Panel-owned meaning models and pure derivations; app-server, application, host, panel, presentation, and UI layers may depend on domain, not the reverse.", severity="error")
}
register_diagnostic(span=$stmt, message="Keep chat/domain as Panel-owned meaning models and pure derivations; app-server, application, host, panel, presentation, and UI layers may depend on domain, not the reverse.", severity="error")
}

View file

@ -10,15 +10,8 @@ private pattern js_module_reference() {
}
}
or {
js_module_reference() as $stmt where {
$stmt <: contains `$source` where { $source <: r"^[\"']@preact/signals[\"']$" },
not { $filename <: r".*/src/features/chat/panel/shell-state\.tsx$" },
register_diagnostic(span=$stmt, message="Use @preact/signals only in src/features/chat/panel/shell-state.tsx as the reducer-to-Preact derived projection adapter.", severity="error")
},
`require($source)` as $stmt where {
$source <: r"^[\"']@preact/signals[\"']$",
not { $filename <: r".*/src/features/chat/panel/shell-state\.tsx$" },
register_diagnostic(span=$stmt, message="Use @preact/signals only in src/features/chat/panel/shell-state.tsx as the reducer-to-Preact derived projection adapter.", severity="error")
}
js_module_reference() as $stmt where {
$stmt <: contains `$source` where { $source <: r"^[\"']@preact/signals[\"']$" },
not { $filename <: r".*/src/features/chat/panel/shell-state\.tsx$" },
register_diagnostic(span=$stmt, message="Use @preact/signals only in src/features/chat/panel/shell-state.tsx as the reducer-to-Preact derived projection adapter.", severity="error")
}

View file

@ -10,13 +10,7 @@ private pattern js_module_reference() {
}
}
or {
js_module_reference() as $stmt where {
$stmt <: contains `$source` where { $source <: r"^[\"'].*(?:src/)?generated/app-server(?:/.*)?[\"']$" },
register_diagnostic(span=$stmt, message="Keep generated app-server types behind src/app-server adapters; expose Panel-owned models outside raw app-server boundaries.", severity="error")
},
`require($source)` as $stmt where {
$source <: r"^[\"'].*(?:src/)?generated/app-server(?:/.*)?[\"']$",
register_diagnostic(span=$stmt, message="Keep generated app-server types behind src/app-server adapters; expose Panel-owned models outside raw app-server boundaries.", severity="error")
}
js_module_reference() as $stmt where {
$stmt <: contains `$source` where { $source <: r"^[\"'].*(?:src/)?generated/app-server(?:/.*)?[\"']$" },
register_diagnostic(span=$stmt, message="Keep generated app-server types behind src/app-server adapters; expose Panel-owned models outside raw app-server boundaries.", severity="error")
}

View file

@ -10,17 +10,10 @@ private pattern js_module_reference() {
}
}
or {
js_module_reference() as $stmt where {
$stmt <: contains `$source` where {
$source <: r"^[\"'].*generated/app-server/.*[\"']$",
not { $source <: r"^[\"'].*generated/app-server/(?:RequestId|ServerRequest)[\"']$" }
},
register_diagnostic(span=$stmt, message="Only generated RequestId and ServerRequest are allowed in the server request protocol exception.", severity="error")
},
`require($source)` as $stmt where {
js_module_reference() as $stmt where {
$stmt <: contains `$source` where {
$source <: r"^[\"'].*generated/app-server/.*[\"']$",
not { $source <: r"^[\"'].*generated/app-server/(?:RequestId|ServerRequest)[\"']$" },
register_diagnostic(span=$stmt, message="Only generated RequestId and ServerRequest are allowed in the server request protocol exception.", severity="error")
}
not { $source <: r"^[\"'].*generated/app-server/(?:RequestId|ServerRequest)[\"']$" }
},
register_diagnostic(span=$stmt, message="Only generated RequestId and ServerRequest are allowed in the server request protocol exception.", severity="error")
}

View file

@ -31,22 +31,5 @@ or {
$source <: r"^[\"'](?:(?:\.\./)+(?:app-server/)?connection|src/app-server/connection)(?:/.*)?[\"']$"
},
register_diagnostic(span=$stmt, message="Lower-level modules must not import feature modules or app-server connection internals. Move shared behavior to shared, domain, or app-server adapters.", severity="error")
},
`require($source)` as $stmt where {
$filename <: r".*/src/domain/.*",
or {
$source <: r"^[\"'](?:(?:\.\./)+(?:app-server|settings|workspace|shared/ui)|src/(?:app-server|settings|workspace|shared/ui))(?:/.*)?[\"']$",
$source <: r"^[\"']obsidian[\"']$"
},
register_diagnostic(span=$stmt, message="Domain modules must stay pure and generated-independent; keep app-server, settings, workspace, UI, and Obsidian dependencies at boundary callers.", severity="error")
},
`require($source)` as $stmt where {
$source <: r"^[\"'](?:(?:\.\./)+features|src/features)(?:/.*)?[\"']$",
register_diagnostic(span=$stmt, message="Lower-level modules must not import feature modules or app-server connection internals. Move shared behavior to shared, domain, or app-server adapters.", severity="error")
},
`require($source)` as $stmt where {
$filename <: r".*/src/(?:app-server/protocol|domain|shared)/.*",
$source <: r"^[\"'](?:(?:\.\./)+(?:app-server/)?connection|src/app-server/connection)(?:/.*)?[\"']$",
register_diagnostic(span=$stmt, message="Lower-level modules must not import feature modules or app-server connection internals. Move shared behavior to shared, domain, or app-server adapters.", severity="error")
}
}

View file

@ -10,15 +10,8 @@ private pattern js_module_reference() {
}
}
or {
js_module_reference() as $stmt where {
$stmt <: contains `$source` where { $source <: r"^[\"'].*shared/ui/ui-root\.dom[\"']$" },
not { $filename <: r".*\.(?:dom|obsidian|measure)\.tsx?$" },
register_diagnostic(span=$stmt, message="Import the Preact root adapter only from explicit root bridge files.", severity="error")
},
`require($source)` as $stmt where {
$source <: r"^[\"'].*shared/ui/ui-root\.dom[\"']$",
not { $filename <: r".*\.(?:dom|obsidian|measure)\.tsx?$" },
register_diagnostic(span=$stmt, message="Import the Preact root adapter only from explicit root bridge files.", severity="error")
}
js_module_reference() as $stmt where {
$stmt <: contains `$source` where { $source <: r"^[\"'].*shared/ui/ui-root\.dom[\"']$" },
not { $filename <: r".*\.(?:dom|obsidian|measure)\.tsx?$" },
register_diagnostic(span=$stmt, message="Import the Preact root adapter only from explicit root bridge files.", severity="error")
}

View file

@ -164,7 +164,7 @@ export async function loadSignals() {
return import("@preact/signals");
}
const signals = require("@preact/signals");
const signals = await import("@preact/signals");
export const loadedSignals = signals;
`.trimStart(),
);
@ -196,7 +196,7 @@ export async function loadComposer() {
return import("src/features/chat/ui/composer");
}
const host = require("../../host/session");
const host = await import("../../host/session");
export const outerHost = host;
`.trimStart(),
);
@ -252,7 +252,7 @@ export async function loadRoot() {
return import("../../../shared/ui/ui-root.dom");
}
const root = require("../../../shared/ui/ui-root.dom");
const root = await import("../../../shared/ui/ui-root.dom");
export const loadedRoot = root;
`.trimStart(),
);
@ -500,7 +500,7 @@ export const response = appServerUserInputResponse;
`
import { toolInventoryAppsFromAppInfos } from "../../../../app-server/protocol/tool-inventory";
const toolInventory = require("../../../../app-server/protocol/tool-inventory");
const toolInventory = await import("../../../../app-server/protocol/tool-inventory");
export const convert = [toolInventoryAppsFromAppInfos, toolInventory];
`.trimStart(),
@ -531,7 +531,7 @@ export type Item = TurnItem;
await writeFile(
path.join(cwd, "src/features/chat/app-server/inbound/handler.ts"),
`
const runtimeMetrics = require("../../../../app-server/protocol/runtime-metrics");
const runtimeMetrics = await import("../../../../app-server/protocol/runtime-metrics");
export const response = runtimeMetrics;
`.trimStart(),
@ -727,7 +727,7 @@ export async function loadParams() {
return import("../../generated/app-server/v2/ToolRequestUserInputParams");
}
const params = require("../../generated/app-server/v2/ToolRequestUserInputParams");
const params = await import("../../generated/app-server/v2/ToolRequestUserInputParams");
export const loadedParams = params;
`.trimStart(),
);