Skip to content

🐛 Always end generated pubspec section with a final newline - #10

Merged
AlexV525 merged 4 commits into
masterfrom
fix/pubspec-final-newline
Sep 4, 2026
Merged

AlexV525 merged 4 commits into
masterfrom
fix/pubspec-final-newline

Conversation

@AlexV525

@AlexV525 AlexV525 commented Sep 4, 2026

Copy link
Copy Markdown
Member

Goal

Closes the endless diff churn when a project's tooling (editorconfig insert_final_newline, format-on-save, git hooks) enforces a final newline: Yaml.write() ended with yamlString.trim(), so the generated # assets end block always landed at EOF without a trailing newline. Newline-enforcing tools re-added it, the next generation stripped it again — dirty diffs on every run.

Changes

  • lib/src/yaml.dart: write ${yamlString.trim()}\n so the file always ends with exactly one newline, whether the block is at EOF or mid-file.
  • test/yaml_test.dart (first test suite in the repo): each test runs Yaml.write() 5× the way the generator does (fresh instance + fresh asset list per run) and asserts byte-stability, covering:
    • block present with content below it (comments, fonts: section) — below-content preserved verbatim, runs converge
    • insertion into an empty assets: key with a sibling key below
    • insertion into flutter: with a top-level key below
    • block at EOF keeps the final newline (regression for this fix)
  • example/ pubspecs: one-time normalization to the new stable output (adds the missing final newline).
  • pubspec.yaml: adds test dev dependency.

Verification

  • dart test — 4/4 pass.
  • Ran the generator against example/ twice: 2nd run byte-identical (md5 match) — rerun churn eliminated.
  • dart analyze lib test clean.

@AlexV525
AlexV525 requested a review from zmtzawqlp as a code owner September 4, 2026 07:39
@AlexV525
AlexV525 merged commit 27d97e6 into master Sep 4, 2026
2 checks passed
@AlexV525
AlexV525 deleted the fix/pubspec-final-newline branch September 4, 2026 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant