(cwd: string, input: RuleLookupInput)
| 117 | } |
| 118 | |
| 119 | export async function resolveRuleFile(cwd: string, input: RuleLookupInput): Promise<string | undefined> { |
| 120 | const directoryPath = getTargetRuleDirectory(cwd, input) |
| 121 | const relativePath = normalizeRelativeRulePath(input.relativePath) |
| 122 | const filePath = path.resolve(directoryPath, relativePath) |
| 123 | |
| 124 | assertPathInsideDirectory(filePath, directoryPath) |
| 125 | |
| 126 | try { |
| 127 | const stats = await fs.lstat(filePath) |
| 128 | if (stats.isFile() || stats.isSymbolicLink()) { |
| 129 | await assertRealPathInsideDirectory(filePath, directoryPath) |
| 130 | return filePath |
| 131 | } |
| 132 | } catch (error) { |
| 133 | if (["ENOENT", "ENOTDIR"].includes((error as NodeJS.ErrnoException).code ?? "")) { |
| 134 | return undefined |
| 135 | } |
| 136 | |
| 137 | throw error |
| 138 | } |
| 139 | |
| 140 | return undefined |
| 141 | } |
| 142 | |
| 143 | export function getRulesDirectoryPath( |
| 144 | cwd: string, |
no test coverage detected