(program: RuleNode)
| 87 | const defaults = (context.options[0] ?? undefined) as CodegenDefaults | undefined |
| 88 | return { |
| 89 | Program(program: RuleNode) { |
| 90 | const source = context.sourceCode.getText() |
| 91 | const filename = context.physicalFilename |
| 92 | const resolver = nativeResolverFor(filename) |
| 93 | |
| 94 | // Create a fresh regex instance per Program visit to avoid shared lastIndex state |
| 95 | const re = new RegExp(blockRe.source, blockRe.flags) |
| 96 | let match: RegExpExecArray | null |
| 97 | |
| 98 | while ((match = re.exec(source)) !== null) { |
| 99 | const [fullMatch, indent = "", rawOptions = "", body = "", endIndent = ""] = match |
| 100 | const matchStart = match.index |
| 101 | const matchEnd = match.index + fullMatch.length |
| 102 | |
| 103 | let options: BlockOptions |
| 104 | try { |
| 105 | options = applyDefaults(parseBlockOptions(rawOptions), defaults) |
| 106 | } catch { |
| 107 | continue |
| 108 | } |
| 109 | |
| 110 | const existingContent = trimTrailingNewline(body) |
| 111 | let generatedContent: string |
| 112 | try { |
| 113 | generatedContent = trimTrailingNewline( |
| 114 | normaliseGeneratedContent( |
| 115 | options, |
| 116 | filename, |
| 117 | renderPreset(options, { filename, existingContent }, source, resolver) |
| 118 | ) |
| 119 | ) |
| 120 | } catch { |
| 121 | continue |
| 122 | } |
| 123 | |
| 124 | const nextBody = generatedContent.length > 0 ? `${indentBlock(generatedContent, indent)}\n` : "" |
| 125 | const replacement = `${indent}// codegen:start ${rawOptions}\n${nextBody}${endIndent}// codegen:end` |
| 126 | |
| 127 | if (replacement !== fullMatch) { |
| 128 | context.report({ |
| 129 | node: program, |
| 130 | message: `codegen block with preset "${options.preset}" is stale`, |
| 131 | fix(fixer: RuleFixer) { |
| 132 | return fixer.replaceTextRange([matchStart, matchEnd], replacement) |
| 133 | } |
| 134 | }) |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…