Skip to content

Add Missing Strings Validation for Moodle Plugin CI#356

Open
volodymyrdovhan wants to merge 6 commits intomoodlehq:mainfrom
volodymyrdovhan:feature/missing-strings-validator
Open

Add Missing Strings Validation for Moodle Plugin CI#356
volodymyrdovhan wants to merge 6 commits intomoodlehq:mainfrom
volodymyrdovhan:feature/missing-strings-validator

Conversation

@volodymyrdovhan
Copy link
Copy Markdown

Summary

  • Add a comprehensive language string validation tool for Moodle plugins
  • Validates required strings, detects missing/unused strings from PHP, JavaScript, templates, and database files
  • Includes automatic subplugin discovery and validation

What It Checks

Code Usage

  • get_string() and new lang_string() calls in PHP
  • JavaScript string methods (str.get_string(), str.get_strings(), getString(), getStrings(), Prefetch methods)
  • Mustache template strings ({{#str}}, {{#cleanstr}})
  • Help button strings (->addHelpButton())
  • Dynamic strings automatically filtered (variables like $row->state are ignored)

Plugin Requirements

  • All plugins: pluginname
  • Activity modules: modulename, modulenameplural
  • Database files: capabilities, caches, messages, tags, mobile addons, subplugins
  • Class implementations: Privacy providers, search areas, grade items, exceptions

Subplugin Support

  • Automatic discovery: Reads db/subplugins.json and db/subplugins.php
  • Recursive validation: Validates main plugin + all discovered subplugins

Usage

# Basic validation
moodle-plugin-ci missingstrings /path/to/plugin

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 23, 2025

Codecov Report

❌ Patch coverage is 82.78175% with 385 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.55%. Comparing base (d5e4885) to head (4bc19fd).
⚠️ Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
src/MissingStrings/Checker/CheckerUtils.php 65.11% 60 Missing ⚠️
src/MissingStrings/FileDiscovery/FileDiscovery.php 50.00% 54 Missing ⚠️
...ssingStrings/Extractor/MustacheStringExtractor.php 51.81% 53 Missing ⚠️
...hecker/ClassMethodChecker/AbstractClassChecker.php 74.04% 34 Missing ⚠️
src/MissingStrings/ValidationResult.php 70.00% 27 Missing ⚠️
...rc/MissingStrings/Discovery/SubpluginDiscovery.php 78.76% 24 Missing ⚠️
...er/DatabaseFileChecker/AbstractDatabaseChecker.php 56.52% 20 Missing ⚠️
...cker/ClassMethodChecker/PrivacyProviderChecker.php 82.29% 17 Missing ⚠️
src/MissingStrings/StringValidator.php 91.79% 16 Missing ⚠️
...gs/Checker/ClassMethodChecker/GradeItemChecker.php 87.95% 10 Missing ⚠️
... and 13 more
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #356      +/-   ##
============================================
- Coverage     88.31%   85.55%   -2.76%     
- Complexity      761     1639     +878     
============================================
  Files            77      114      +37     
  Lines          2344     4563    +2219     
============================================
+ Hits           2070     3904    +1834     
- Misses          274      659     +385     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@volodymyrdovhan volodymyrdovhan force-pushed the feature/missing-strings-validator branch 4 times, most recently from 94f10f2 to dd9f119 Compare June 23, 2025 22:54
- Add a comprehensive language string validation tool for Moodle plugins
- Validates required strings, detects missing/unused strings from PHP, JavaScript, templates, and database files
- Includes automatic subplugin discovery and validation
@volodymyrdovhan volodymyrdovhan force-pushed the feature/missing-strings-validator branch from dd9f119 to 8817822 Compare June 23, 2025 23:06
@kabalin
Copy link
Copy Markdown
Member

kabalin commented Jun 24, 2025

Wow, that is the biggest PR to this project I have ever seen! 🥇Well done @volodymyrdovhan, missing strings check definitely would be useful to have.

Do you have some performance info, it is fast on projects with numerous strings?

@volodymyrdovhan volodymyrdovhan force-pushed the feature/missing-strings-validator branch 3 times, most recently from 84f6082 to dcd824a Compare June 25, 2025 11:03
@volodymyrdovhan volodymyrdovhan force-pushed the feature/missing-strings-validator branch from dcd824a to 6609072 Compare June 25, 2025 13:31
@volodymyrdovhan
Copy link
Copy Markdown
Author

Hi @kabalin,
I added some validation stats to display with the --debug option.

image

Here are some stats for some Moodle core plugins.

mod/assign:

  • Total processing time: 1.829 seconds
  • Plugins processed: 8
    • Main: 1, Subplugins: 7
  • Files processed: 842
  • String processing metrics:
    • Defined strings: 842
    • Required strings: 10
    • Strings extracted: 1025
    • String usages found: 1268

mod/quiz

  • Total processing time: 1.664 seconds
  • Plugins processed: 15
    • Main: 1, Subplugins: 14
  • Files processed: 887
  • String processing metrics:
    • Defined strings: 1545
    • Required strings: 17
    • Strings extracted: 1109
    • String usages found: 1230

mod/lesson

  • Total processing time: 0.995 seconds
  • Plugins processed: 1
  • Files processed: 160
  • String processing metrics:
    • Defined strings: 571
    • Required strings: 3
    • Strings extracted: 605
    • String usages found: 736

mod/bigbluebuttonbn/

  • Total processing time: 1.180 seconds
  • Plugins processed: 1
  • Files processed: 328
  • String processing metrics:
    • Defined strings: 561
    • Required strings: 3
    • Strings extracted: 522
    • String usages found: 538

@kabalin
Copy link
Copy Markdown
Member

kabalin commented Jul 6, 2025

Cross referencing https://moodle.atlassian.net/browse/MDL-85666, there is some overlapping with this patch I think. I might worth reviewing what will be tested already, so this feature will be smaller and easier to maintain.

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.

2 participants