Skip to content
77 changes: 74 additions & 3 deletions assets/js/plugin-check-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,46 @@
return false;
}

/**
* Counts the total number of errors and warnings in the aggregated results.
*
* @since 1.0.0
*
* @return {Object} Object with errorCount and warningCount properties.
*/
function countResults() {
let errorCount = 0;
let warningCount = 0;

// Count errors.
for ( const file of Object.keys( aggregatedResults.errors ) ) {
const lines = aggregatedResults.errors[ file ] || {};

for ( const line of Object.keys( lines ) ) {
const columns = lines[ line ] || {};

for ( const column of Object.keys( columns ) ) {
errorCount += ( columns[ column ] || [] ).length;
}
}
}

// Count warnings.
for ( const file of Object.keys( aggregatedResults.warnings ) ) {
const lines = aggregatedResults.warnings[ file ] || {};

for ( const line of Object.keys( lines ) ) {
const columns = lines[ line ] || {};

for ( const column of Object.keys( columns ) ) {
warningCount += ( columns[ column ] || [] ).length;
}
}
}

return { errorCount, warningCount };
}

function defaultString( key ) {
if (
pluginCheck.strings &&
Expand Down Expand Up @@ -545,9 +585,40 @@
*/
function renderResultsMessage( isSuccessMessage ) {
const messageType = isSuccessMessage ? 'success' : 'error';
const messageText = isSuccessMessage
? pluginCheck.successMessage
: pluginCheck.errorMessage;
let messageText;

if ( isSuccessMessage ) {
messageText = pluginCheck.successMessage;
} else {
Comment on lines 586 to +592
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

messageType is derived only from isSuccessMessage, so a warnings-only run will still render notice-error even when errorCount is 0 (but warningCount > 0). Consider deriving the notice type from the counted totals (e.g., success when both 0, warning when only warnings, error when errors > 0) so the notice styling matches the actual result severity.

Copilot uses AI. Check for mistakes.
// Count errors and warnings.
const { errorCount, warningCount } = countResults();

// Build the message with counts.
let errorPart = '';
if ( errorCount > 0 ) {
errorPart =
errorCount === 1 ? '1 error' : errorCount + ' errors';
}

let warningPart = '';
if ( warningCount > 0 ) {
warningPart =
warningCount === 1
? '1 warning'
: warningCount + ' warnings';
}

if ( errorPart && warningPart ) {
messageText = errorPart + ' and ' + warningPart + ' found.';
} else if ( errorPart ) {
messageText = errorPart + ' found.';
} else if ( warningPart ) {
messageText = warningPart + ' found.';
Comment on lines +619 to +624
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

The summary message concatenates hard-coded English fragments (' and ', ' found.'). This makes the overall sentence partially non-translatable and prevents languages from reordering words/clauses. Consider providing fully translatable message templates (e.g., strings for errors-only, warnings-only, both) with placeholders, rather than composing English sentence parts in JS.

Suggested change
if ( errorPart && warningPart ) {
messageText = errorPart + ' and ' + warningPart + ' found.';
} else if ( errorPart ) {
messageText = errorPart + ' found.';
} else if ( warningPart ) {
messageText = warningPart + ' found.';
// Use fully translatable summary templates with placeholders.
const summaryBothTemplate =
pluginCheck.summaryBothTemplate ||
'%1$s and %2$s found.';
const summarySingleTemplate =
pluginCheck.summarySingleTemplate || '%s found.';
if ( errorPart && warningPart ) {
messageText = summaryBothTemplate
.replace( '%1$s', errorPart )
.replace( '%2$s', warningPart );
} else if ( errorPart ) {
messageText = summarySingleTemplate.replace(
'%s',
errorPart
);
} else if ( warningPart ) {
messageText = summarySingleTemplate.replace(
'%s',
warningPart
);

Copilot uses AI. Check for mistakes.
} else {
// Fallback to default message if somehow no errors/warnings.
messageText = pluginCheck.errorMessage;
}
}

resultsContainer.innerHTML =
renderTemplate( 'plugin-check-results-complete', {
Expand Down
Loading