(ruleSpec: string)
| 77 | * Hub slug resolution has been removed. |
| 78 | */ |
| 79 | export async function processRule(ruleSpec: string): Promise<string> { |
| 80 | const trimmedRuleSpec = ruleSpec.trim(); |
| 81 | const hasNewline = /[\r\n]/.test(ruleSpec); |
| 82 | |
| 83 | // If it looks like a file path (single line, typical path indicators) |
| 84 | const looksLikePath = |
| 85 | !hasNewline && |
| 86 | (trimmedRuleSpec.startsWith(".") || |
| 87 | trimmedRuleSpec.startsWith("/") || |
| 88 | trimmedRuleSpec.includes("\\") || |
| 89 | /\.[a-zA-Z]+$/.test(trimmedRuleSpec)); |
| 90 | |
| 91 | if (looksLikePath) { |
| 92 | const fs = await import("fs"); |
| 93 | const path = await import("path"); |
| 94 | |
| 95 | try { |
| 96 | const absolutePath = path.resolve(trimmedRuleSpec); |
| 97 | if (!fs.existsSync(absolutePath)) { |
| 98 | throw new Error(`Rule file not found: ${ruleSpec}`); |
| 99 | } |
| 100 | return fs.readFileSync(absolutePath, "utf-8"); |
| 101 | } catch (error: any) { |
| 102 | throw new Error( |
| 103 | `Failed to read rule file "${ruleSpec}": ${error.message}`, |
| 104 | ); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | // Otherwise, treat it as direct string content |
| 109 | return ruleSpec; |
| 110 | } |
| 111 | |
| 112 | export function isStringRule(rule: string) { |
| 113 | if (rule.includes(" ") || rule.includes("\n")) { |
no test coverage detected