This repository contains the Moodle Coding Style configuration.
Currently this only includes the configuration for PHP Coding style, but this may be extended to include custom rules for JavaScript, and any other supported languages or syntaxes.
You can include these coding style rules using Composer to make them available globally across your system.
This will install the correct version of phpcs, with the Moodle rules, and their dependencies.
composer global require moodlehq/moodle-cs
This plugin is included as part of the moodle-local_codechecker plugin.
You can set the Moodle standard as the system default:
phpcs --config-set default_standard moodle
This will inform most IDEs automatically. Alternatively you can configuration your IDE to use phpcs with the Moodle ruleset as required.
- Open PhpStorm preferences
- Go to Inspections > PHP > PHP Code Sniffer Validation
- In the 'coding standard' dropdown, select 'moodle'
Find documentation here.
-
Go in your Sublime Text to Preferences -> Package Control -> Package Control: Install Package
-
Write 'phpcs' in the search field, if you see Phpcs and SublimeLinter-phpcs, click on them to install them.
-
If not, check if they are already installed Preferences -> Package Control -> Package Control: Remove Package.
-
To set your codecheck to moodle standards go to Preferences -> Package Settings -> PHP Code Sniffer -> Settings-User and write:
{ "phpcs_additional_args": { "--standard": "moodle", "-n": " }, }
-
If you don’t have the auto-save plugin turned on, YOU’RE DONE!
-
If you have the auto-save plugin turned on, because the codecheck gets triggered on save, the quick panel will keep popping making it impossible to type. To stop quick panel from showing go to Settings-User file and add:
"phpcs_show_quick_panel": false,
The line with the error will still get marked and if you’ll click on it you’ll see the error text in the status bar.
Find documentation here.
-
Install PHPSniffer.
-
Open VSCode settings.json and add the following setting to define standard PHP CS (if you haven't set it as default in your system):
"phpSniffer.standard": "moodle",