Skip to content

Remove 3 stub init() functions in pkg/workflow that only log and do no real work #32546

@github-actions

Description

@github-actions

Summary

An audit of all 11 init() functions in pkg/ non-test (Sergo Run 11) found 3 stub functions whose bodies contain nothing but a single log statement. Two of them advertise that they register scripts — but their accompanying comments admit the scripts were already removed. The third claims to initialize regex compilation, but the regex variables it references are compiled in package-level var (...) blocks that run independently. All three add startup cost and reader confusion for zero functional benefit.

Locations

1. pkg/workflow/js.go:14-16

func init() {
    jsLog.Print("Script registration completed (embedded scripts removed)")
}

File-level comment at line 12-13 already says: "init registers scripts from js.go with the DefaultScriptRegistry. Note: Embedded scripts have been removed - scripts are now provided by actions/setup at runtime."

2. pkg/workflow/scripts.go:20-22

func init() {
    scriptsLog.Print("Script registration completed (embedded scripts removed)")
}

File header (lines 5-6) already says: "This file previously managed embedded JavaScript scripts, but inline bundling has been removed. Scripts are now provided by the actions/setup action at runtime."

3. pkg/workflow/expression_patterns.go:92-94

func init() {
    expressionPatternsLog.Print("Initializing expression pattern regex compilation")
}

The regex compilation is not performed here — it's done in the file-scope var (...) blocks that follow (lines 96+), which are evaluated independently of init(). The log message is misleading.

Impact

  • Severity: Low — no correctness impact, but contributes to startup-time noise and confuses readers who expect init() to do meaningful work.
  • Affected files: 3 files in pkg/workflow/.
  • Risk of leaving: Future maintainers may copy this anti-pattern into new init() bodies; the misleading log message in expression_patterns.go could send debuggers down a false trail when investigating slow startup.

Recommendation

Delete all 3 init() functions. The package-level logger variables (jsLog, scriptsLog, expressionPatternsLog) can remain — they're used elsewhere in their files. The log lines themselves provide zero diagnostic value: they fire on every CLI invocation and just confirm that Go ran init().

Before (js.go):

var jsLog = logger.New("workflow:js")

func init() {
    jsLog.Print("Script registration completed (embedded scripts removed)")
}

After:

var jsLog = logger.New("workflow:js")

Validation

  • Run go vet ./... and go test ./... after deletion — no behavioral change expected.
  • Grep for jsLog, scriptsLog, expressionPatternsLog to confirm they're still used elsewhere (they are; safe to keep the var declarations).
  • Confirm no other init() in the package depends on ordering relative to these three (none do — they have no observable side effects).

Audit Context

Acceptable init() patterns identified in Run 11 (kept):

  • pkg/linters/*/Analyzer.Flags.IntVar — flag registration into go/analysis
  • pkg/parser/virtual_fs_wasm.go — overrides readFileFunc under //go:build js || wasm
  • pkg/workflow/domains.go, permissions_toolset_data.go, github_tool_to_toolset.go — unmarshal embedded JSON into runtime maps
  • pkg/workflow/runtime_definitions.go, safe_update_enforcement.go — derive lookup maps from knownRuntimes

References:

Generated by Sergo — Run 11

Generated by 🤖 Sergo - Serena Go Expert · ● 15.6M ·

  • expires on May 23, 2026, 4:57 AM UTC

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions