Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 2, 2025

Implementation of wp i18n audit command - Complete ✅

Latest Updates

Fixed FileDataExtractor data access:

  • Updated theme and plugin name checks to access ['value'] key from FileDataExtractor data
  • Matches parent class MakePotCommand implementation
  • FileDataExtractor returns data in format ['value' => ..., 'line' => ...]

Code refactoring for better readability:

  • Simplified unique translator comment detection using array_map + array_unique instead of array_filter with side effects
  • Reduced duplication in theme detection logic by consolidating stylesheet path detection before file data extraction

Code cleanup:

  • Removed unnecessary preg_replace call that stripped quotes from strings, as the gettext library already provides unquoted strings via $translation->getOriginal()

Fixed --ignore-domain flag handling:

  • When --ignore-domain is used, domain is now properly left unset to extract all strings regardless of text domain
  • Matches the behavior of wp i18n make-pot --ignore-domain
  • Fixes failing test: "Respects --ignore-domain flag"

Suppressed informational messages in non-plaintext formats:

  • When using --format=json or --format=github-actions, the command now only outputs the formatted data
  • Removed "Plugin file detected.", "Theme stylesheet detected." messages in JSON/GitHub formats
  • Removed "Warning: Found X issues." and "Success: No issues found." messages in JSON/GitHub formats
  • Plaintext format retains all informational messages for better user experience

Major Refactoring (addressing code review feedback)

Refactored AuditCommand to extend MakePotCommand instead of duplicating code:

  • Eliminates ~188 lines of duplicated code (~28% reduction)
  • Fixes hallucinated methods (FileDataExtractor::get_file_type(), FileDataExtractor::find_main_file())
  • Reuses existing file type detection and main file discovery logic from parent class
  • Maintains all functionality while significantly reducing maintenance burden

Key Changes

  1. Refactored AuditCommand class (src/AuditCommand.php):

    • Now extends MakePotCommand to reuse string extraction logic
    • Overrides get_main_file_data() to conditionally suppress log messages based on format
    • Conditionally outputs summary messages only in plaintext format
    • Properly handles --ignore-domain flag to extract all strings
    • Correctly accesses FileDataExtractor data via ['value'] key
    • Supports three output formats:
    • Helper method get_comment_text() to reduce code duplication
  2. Command registration (i18n-command.php): Unchanged

  3. Test coverage (features/audit.feature): All tests now passing

Audit Checks Implemented

  1. ✅ Strings with placeholders missing translator comments
  2. ✅ Strings with multiple different translator comments
  3. ✅ Strings without translatable content
  4. ✅ Multiple unordered placeholders
  5. ✅ Missing singular placeholders in plural strings
  6. ✅ Mismatched placeholders between singular and plural strings

Backward Compatibility

✅ The existing audit functionality in wp i18n make-pot remains completely unchanged.

Code Quality Improvements

  • ✅ Eliminated hallucinated methods
  • ✅ Reduced code duplication by extending parent class
  • ✅ Clean output for machine-readable formats
  • ✅ Proper --ignore-domain flag handling
  • ✅ Removed unnecessary regex operations
  • ✅ Simplified unique comment detection
  • ✅ Reduced theme detection duplication
  • ✅ Fixed FileDataExtractor data access consistency
  • ✅ Simpler, more maintainable code
  • ✅ All original functionality preserved
  • ✅ All tests passing
Original prompt

This section details on the original issue you should resolve

<issue_title>Dedicated i18n audit command</issue_title>
<issue_description>Looking at #39 again, I feel like it might be easier to have a dedicated command for the audit part, e.g. wp i18n audit.

Then make-pot doesn't have to deal with this, and we can have all the different output formats that we need. Also, it makes it easier to add further audits.

For example, one audit that I could think of is string similarity. If there are two strings which are quite similar, but only different in casing or punctuation, it could suggest merging the strings. Levenshtein distance alone might work for that.</issue_description>

<agent_instructions>Introduce this new wp i18n audit command with different output formats, including plaintext (default), JSON and GitHub Actions annotations (see #39).

The audit logic in wp i18n make-pot should stay for backward compatibility.

In plaintext output, the file name should be before the warning message, addressing #119.

Ensure code formatting with composer phpcs and composer phpcbf. Run Behat tests with composer behat</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@swissspidy Such a command could also include the checks from https://github.com/ePascalC/CheckPluginForTranslation

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits November 2, 2025 14:28
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Add dedicated i18n audit command Add dedicated wp i18n audit command with JSON and GitHub Actions output formats Nov 2, 2025
Copilot AI requested a review from swissspidy November 2, 2025 14:38
@codecov
Copy link

codecov bot commented Nov 2, 2025

Codecov Report

❌ Patch coverage is 90.03690% with 27 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/AuditCommand.php 90.07% 26 Missing ⚠️
i18n-command.php 88.88% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@swissspidy

This comment was marked as resolved.

…lication

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

…f text domain

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@swissspidy swissspidy requested a review from Copilot November 3, 2025 13:07

This comment was marked as resolved.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@swissspidy

This comment was marked as resolved.

gemini-code-assist[bot]

This comment was marked as resolved.

This comment was marked as resolved.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…unquoted strings

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
…eme detection

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copy link

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

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


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

swissspidy and others added 2 commits January 20, 2026 12:10
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
… with parent class

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
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.

Dedicated i18n audit command

2 participants