Skip to content

[code-simplifier] refactor: simplify fastParseTitle state machine and deduplicate formatCompilerError#21050

Merged
pelikhan merged 1 commit intomainfrom
code-simplifier/2026-03-15-09a4b2bb09f0f410
Mar 15, 2026
Merged

[code-simplifier] refactor: simplify fastParseTitle state machine and deduplicate formatCompilerError#21050
pelikhan merged 1 commit intomainfrom
code-simplifier/2026-03-15-09a4b2bb09f0f410

Conversation

@github-actions
Copy link
Contributor

This PR simplifies two pieces of code from PRs merged in the last 24 hours, improving clarity while preserving identical functionality.

Files Simplified

  • pkg/cli/workflows.go — simplified fastParseTitle state machine
  • pkg/workflow/compiler_error_formatter.go — eliminated duplicated struct construction

Improvements Made

1. fastParseTitle — removed redundant pastFrontmatter variable

The function tracked three booleans (firstLine, inFrontmatter, pastFrontmatter), but pastFrontmatter is redundant: once inFrontmatter becomes false after the opening ---, the code is already past any frontmatter. Removing it:

  • Reduces state from 3 variables → 2
  • Eliminates the pastFrontmatter && guard on the H1 check (implicit from !inFrontmatter)
  • Simplifies the else if inFrontmatter && !pastFrontmatter branch to else if inFrontmatter
  • Simplifies the post-loop check from inFrontmatter && !pastFrontmatterinFrontmatter

2. formatCompilerError — deduplicated via wrapper

formatCompilerError and formatCompilerErrorWithPosition shared identical logic (same console.FormatError struct, same wrappedCompilerError return). formatCompilerError is now a thin wrapper that calls formatCompilerErrorWithPosition(filePath, 1, 1, ...), removing ~15 lines of duplicated code.

Changes Based On

Recent changes from:

Testing

  • ✅ All 10 TestFastParseTitle subtests pass
  • ✅ All TestIsFormattedCompilerError, TestFindFrontmatterFieldLine, TestEngineValidationErrorHasFileLocation tests pass
  • ✅ Build succeeds (make build)
  • gofmt clean
  • ✅ No functional changes — behavior is identical

Review Focus

Please verify:

  • The fastParseTitle state transitions are equivalent to the original
  • formatCompilerError delegation preserves the same log output (now shows line=1, column=1 in the log, same information)

Automated by Code Simplifier Agent — analyzing code from the last 24 hours

References: §23110390758

Generated by Code Simplifier ·

  • expires on Mar 16, 2026, 12:38 PM UTC

…tCompilerError

- Remove redundant pastFrontmatter variable from fastParseTitle; the
  inFrontmatter flag already encodes the distinction between 'inside
  frontmatter' and 'past frontmatter'. Reduces 3-variable state to 2.
- Make formatCompilerError a thin wrapper over formatCompilerErrorWithPosition
  (line=1, col=1) to eliminate ~15 lines of duplicated struct construction.

No functional change; all existing tests pass.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pelikhan pelikhan marked this pull request as ready for review March 15, 2026 12:42
Copilot AI review requested due to automatic review settings March 15, 2026 12:42
@pelikhan pelikhan merged commit 2a95b68 into main Mar 15, 2026
2 checks passed
@pelikhan pelikhan deleted the code-simplifier/2026-03-15-09a4b2bb09f0f410 branch March 15, 2026 12:43
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors two recently added helpers to reduce state/duplication while preserving behavior: fastParseTitle is simplified by removing redundant state, and formatCompilerError is simplified by delegating to formatCompilerErrorWithPosition.

Changes:

  • Simplified fastParseTitle by removing pastFrontmatter and directly toggling inFrontmatter on close delimiter.
  • Deduplicated compiler error formatting by making formatCompilerError a thin wrapper over formatCompilerErrorWithPosition(filePath, 1, 1, ...).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
pkg/cli/workflows.go Simplifies frontmatter/title scanning state machine while keeping frontmatter semantics and error behavior intact.
pkg/workflow/compiler_error_formatter.go Removes duplicated error-formatting struct construction by delegating to the positioned formatter.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants