MCPcopy Create free account
hub / github.com/effect-app/libs / Program

Function Program

packages/eslint-codegen-model/src/oxlint/rules/codegen.ts:89–137  ·  view source on GitHub ↗
(program: RuleNode)

Source from the content-addressed store, hash-verified

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}

Callers

nothing calls this directly

Calls 9

applyDefaultsFunction · 0.90
parseBlockOptionsFunction · 0.90
trimTrailingNewlineFunction · 0.90
renderPresetFunction · 0.90
indentBlockFunction · 0.90
nativeResolverForFunction · 0.85
execMethod · 0.80
reportMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…