Skip to content

feat: enhance MismatchValidator to track empty files#82

Merged
konradmichalik merged 1 commit intomainfrom
support-empty-xliff
Nov 10, 2025
Merged

feat: enhance MismatchValidator to track empty files#82
konradmichalik merged 1 commit intomainfrom
support-empty-xliff

Conversation

@konradmichalik
Copy link
Copy Markdown
Contributor

@konradmichalik konradmichalik commented Nov 10, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of empty translation files by tracking them for missing key detection instead of logging errors.
    • Enhanced validation to properly detect and report missing translations across empty and partial translation files.
  • Tests

    • Extended test coverage for empty file scenarios and mixed multi-file validation cases.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Nov 10, 2025

Walkthrough

MismatchValidator refactors file-key indexing by introducing a consistent fileKey variable derived from file paths, changes empty-file handling to track rather than error-log them, eliminates redundant variable declarations, and strengthens key deduplication type checking. Test coverage expands with renamed and new test methods for empty and mixed-file scenarios.

Changes

Cohort / File(s) Summary
Implementation refactor
src/Validator/MismatchValidator.php
Introduces fileKey variable for consistent translation indexing; stores empty arrays for files with no extracted keys instead of logging errors; removes redundant in-loop fileKey declaration; applies strict type checking to in_array call during key deduplication
Test coverage expansion
tests/src/Validator/MismatchValidatorTest.php
Renames testProcessFileWithInvalidFile() to testProcessFileWithEmptyFile() and updates mocks to reflect empty file scenario; adds testPostProcessDetectsEmptyFileWithMissingKeys() validating empty file paired with non-empty source; adds testPostProcessWithMixedScenario() covering three-file scenario with partial translations

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

  • The empty-file tracking logic change should be verified to ensure it correctly defers error detection to post-processing
  • Confirm that strict in_array type checking doesn't inadvertently filter valid keys

Possibly related PRs

Poem

🐰 A rabbit hops through cleaner paths,
Where fileKeys dance, no more mishaps!
Empty files now tracked with care,
Strict dedup checks—no slipping there! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: enhance MismatchValidator to track empty files' directly and clearly summarizes the main change: adding functionality to track empty files in the MismatchValidator, which aligns with the code modifications that introduce empty file tracking and change error handling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch support-empty-xliff

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4cd989b and cde4039.

📒 Files selected for processing (2)
  • src/Validator/MismatchValidator.php (2 hunks)
  • tests/src/Validator/MismatchValidatorTest.php (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/Validator/MismatchValidator.php (4)
tests/src/Result/ValidationRunTest.php (1)
  • getFileName (243-246)
src/Parser/AbstractParser.php (1)
  • getFileName (54-57)
src/Parser/ParserInterface.php (1)
  • getFileName (38-38)
tests/src/Validator/AbstractValidatorTest.php (1)
  • getFileName (115-118)
tests/src/Validator/MismatchValidatorTest.php (2)
src/Validator/MismatchValidator.php (3)
  • MismatchValidator (31-247)
  • processFile (38-56)
  • postProcess (58-93)
src/Result/Issue.php (1)
  • toArray (60-68)
🔇 Additional comments (5)
src/Validator/MismatchValidator.php (2)

41-46: File key handling now preserves per-path identity

Leaning on currentFilePath when available keeps entries unique per physical file, and seeding empty files with [] gives postProcess the signal it needs without spamming errors. Nicely done.


175-176: Strict dedupe avoids key collisions

The true flag on in_array eliminates type-juggling surprises ('0' vs 0) while keeping the dedupe lightweight.

tests/src/Validator/MismatchValidatorTest.php (3)

60-77: Great regression guard for empty files

This nails the expectation that empty translations still register in keyArray, setting the stage for downstream mismatch detection.


323-372: Empty vs. non-empty comparison covered thoroughly

The assertions ensure both keys bubble up as issues and verify the empty file’s null values, so we won’t regress on the new tracking behaviour.


374-426: Comprehensive mixed-file scenario

Validating six-key coverage across source, partial, and empty translations gives strong confidence the aggregation logic scales.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@konradmichalik konradmichalik merged commit 12aa3f8 into main Nov 10, 2025
26 checks passed
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