Skip to content

Latest commit

 

History

History
95 lines (60 loc) · 3.55 KB

README.md

File metadata and controls

95 lines (60 loc) · 3.55 KB

Moodle Coding Style

Latest Stable Version Release Date of the Latest Version

Unit Tests

License Total Downloads Number of Contributors

Information

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.

Installation

Using Composer

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

As a part of moodle-local_codechecker

This plugin is included as part of the moodle-local_codechecker plugin.

Configuration

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.

IDE Integration

PhpStorm

  1. Open PhpStorm preferences
  2. Go to Inspections > PHP > PHP Code Sniffer Validation
  3. In the 'coding standard' dropdown, select 'moodle'

Sublime Text

Find documentation here.

  1. Go in your Sublime Text to Preferences -> Package Control -> Package Control: Install Package

  2. Write 'phpcs' in the search field, if you see Phpcs and SublimeLinter-phpcs, click on them to install them.

  3. If not, check if they are already installed Preferences -> Package Control -> Package Control: Remove Package.

  4. 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": "
         },
     }
    
  5. If you don’t have the auto-save plugin turned on, YOU’RE DONE!

  6. 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.

VSCode

Find documentation here.

  1. Install PHPSniffer.

  2. 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",