(cwd: string, input: Pick<CreateRuleInput, "scope" | "kind" | "modeSlug">)
| 289 | } |
| 290 | |
| 291 | function getTargetRuleDirectory(cwd: string, input: Pick<CreateRuleInput, "scope" | "kind" | "modeSlug">): string { |
| 292 | if (input.scope !== "global" && input.scope !== "project") { |
| 293 | throw new Error("Invalid rule scope") |
| 294 | } |
| 295 | |
| 296 | if (input.kind !== "generic" && input.kind !== "mode") { |
| 297 | throw new Error("Invalid rule kind") |
| 298 | } |
| 299 | |
| 300 | if (input.kind === "mode" && !input.modeSlug) { |
| 301 | throw new Error("Mode-specific rules require a mode") |
| 302 | } |
| 303 | |
| 304 | if (input.kind === "generic" && input.modeSlug) { |
| 305 | throw new Error("Generic rules cannot specify a mode") |
| 306 | } |
| 307 | |
| 308 | if (input.scope === "project" && !cwd) { |
| 309 | throw new Error("Workspace rules require an open workspace") |
| 310 | } |
| 311 | |
| 312 | const basePath = input.scope === "global" ? getGlobalRooDirectory() : getProjectRooDirectoryForCwd(cwd) |
| 313 | return path.join(basePath, input.kind === "generic" ? "rules" : `rules-${validateModeSlug(input.modeSlug!)}`) |
| 314 | } |
| 315 | |
| 316 | function normalizeRuleFileName(fileName: string): string { |
| 317 | const trimmed = fileName.trim() |
no test coverage detected