|
| 1 | +--- |
| 2 | +applyTo: '**/*.php, **/*.js, **/*.mustache, **/*.xml, **/*.css, **/*.scss' |
| 3 | +description: 'Instructions for GitHub Copilot to generate code in a Moodle project context.' |
| 4 | +--- |
| 5 | + |
| 6 | +# Project Context |
| 7 | + |
| 8 | +This repository contains a Moodle project. Ensure that any generated code is compatible with the specific Moodle version used in this project (for example, Moodle 3.11, 4.1 LTS, or later). |
| 9 | + |
| 10 | +It includes: |
| 11 | +- Plugin development (local, block, mod, auth, enrol, tool, etc.) |
| 12 | +- Theme customization |
| 13 | +- CLI scripts |
| 14 | +- Integrations with external services using the Moodle API |
| 15 | + |
| 16 | +# Code Standards |
| 17 | + |
| 18 | +- Follow the official Moodle Coding guidelines: https://moodledev.io/general/development/policies/codingstyle |
| 19 | +- PHP must be compatible with the core version (e.g., PHP 7.4 / 8.0 / 8.1). |
| 20 | +- Do not use modern syntax that is not supported by core if it breaks compatibility. |
| 21 | +- Class naming must use Moodle namespaces. |
| 22 | +- Follow Moodle’s standard plugin directory layout (for example: classes/output, classes/form, db/, lang/, templates/…). |
| 23 | +- Mandatory use of Moodle security functions: |
| 24 | + - `$DB` with SQL placeholders |
| 25 | + - `require_login()`, `require_capability()` |
| 26 | + - Parameters handled with `required_param()` / `optional_param()` |
| 27 | + |
| 28 | +# Code Generation Rules |
| 29 | + |
| 30 | +- When creating new PHP classes in plugins, use the Moodle component (Frankenstyle) namespace that matches the plugin's component name, e.g. `local_myplugin`, `mod_forum`, `block_mycatalog`, `tool_mytool`. |
| 31 | +- In plugins, always respect the structure: |
| 32 | + - /db |
| 33 | + - /lang |
| 34 | + - /classes |
| 35 | + - /templates |
| 36 | + - /version.php |
| 37 | + - /settings.php |
| 38 | + - /lib.php (only if necessary) |
| 39 | + |
| 40 | +- Use renderers and Mustache templates for HTML. Do not mix HTML inside PHP. |
| 41 | +- In JavaScript code, use AMD modules, not inline scripts. |
| 42 | +- Prefer Moodle API functions over manual code whenever possible. |
| 43 | +- Do not invent Moodle functions that do not exist. |
| 44 | + |
| 45 | +# Examples of What Copilot Should Be Able to Answer |
| 46 | + |
| 47 | +- "Generate a basic local plugin with version.php, settings.php, and lib.php." |
| 48 | +- "Create a new table in db/install.xml and an upgrade script in db/upgrade.php." |
| 49 | +- "Generate a Moodle form using moodleform." |
| 50 | +- "Create a renderer with Mustache to display a table." |
| 51 | + |
| 52 | +# Expected Style |
| 53 | + |
| 54 | +- Clear and specific answers in the Moodle context. |
| 55 | +- Always include files with full paths. |
| 56 | +- If there are multiple ways to do something, use the approach recommended by Moodle. |
| 57 | + |
0 commit comments