* Detect code fragments that can't be validated as standalone files. * These are typically partial snippets showing configuration options * or code that's meant to be part of a larger context.
(block: CodeBlock)
| 166 | * or code that's meant to be part of a larger context. |
| 167 | */ |
| 168 | function shouldSkipFragment(block: CodeBlock): boolean { |
| 169 | const code = block.code.trim(); |
| 170 | |
| 171 | // TypeScript/JavaScript: Skip bare object literals (config snippets) |
| 172 | if (block.language === "typescript") { |
| 173 | // Starts with property: value pattern (e.g., "provider: {") |
| 174 | if (/^[a-zA-Z_]+\s*:\s*[\{\[]/.test(code)) { |
| 175 | return true; |
| 176 | } |
| 177 | // Starts with just an object/array that's not assigned |
| 178 | if (/^\{[\s\S]*\}$/.test(code) && !code.includes("import ") && !code.includes("export ")) { |
| 179 | return true; |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | // Go: Skip fragments that are just type definitions without package |
| 184 | if (block.language === "go") { |
| 185 | // Function signatures without bodies (interface definitions shown in docs) |
| 186 | if (/^func\s+\w+\([^)]*\)\s*\([^)]*\)\s*$/.test(code)) { |
| 187 | return true; |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | // Java: Skip interface definitions, annotations-only, or method signatures without bodies |
| 192 | if (block.language === "java") { |
| 193 | // Just an annotation |
| 194 | if (/^@\w+/.test(code) && !code.includes("{")) { |
| 195 | return true; |
| 196 | } |
| 197 | // Method signature without body |
| 198 | if (/^(public|private|protected)?\s*(static\s+)?[\w<>\[\]]+\s+\w+\([^)]*\)\s*(throws\s+[\w,\s]+)?;\s*$/.test(code)) { |
| 199 | return true; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | return false; |
| 204 | } |
| 205 | |
| 206 | function wrapCodeForValidation(block: CodeBlock): string { |
| 207 | let code = block.code; |
no outgoing calls
no test coverage detected
searching dependent graphs…