moodlehq / moodle-cs
Moodle Coding Sniffer rules
Installs: 1 541 422
Dependents: 5
Suggesters: 0
Security: 0
Stars: 18
Watchers: 20
Forks: 16
Open Issues: 48
Type:phpcodesniffer-standard
Requires
- php: >=7.4.0
- ext-json: *
- dealerdirect/phpcodesniffer-composer-installer: ^1.0.0
- phpcompatibility/php-compatibility: dev-develop#96072c30
- phpcsstandards/phpcsextra: ^1.2.1
- squizlabs/php_codesniffer: ^3.10.1
Requires (Dev)
- mikey179/vfsstream: ^1.6
- nikic/php-parser: ^4.18
- overtrue/phplint: ^3.4.0 | ^9.0.4
- phpmd/phpmd: ^2.11
- phpunit/phpunit: ^9.6
- sebastian/phpcpd: ^6.0
- thor-juhasz/phpunit-coverage-check: ^0.3.0
Replaces
This package is auto-updated.
Last update: 2024-11-04 04:27:31 UTC
README
Information
This repository contains the Moodle Coding Style configurations, written as PHP CodeSniffer rulesets.
Two coding styles are included:
moodle
- the main ruleset for the Moodle Coding Stylemoodle-extra
- extended ruleset which includes recommended best practices- extends the main
moodle
ruleset
- extends the main
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 (recommended)
You can install 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 config minimum-stability dev composer global require moodlehq/moodle-cs
Configuration
Typically configuration is not required. Recent versions of Moodle (3.11 onwards) include a configuration file for the PHP CodeSniffer, which will set the standard when run within a Moodle directory.
Additional configuration can be generated automatically to have PHP CodeSniffer ignore any third-party library code. This can be generated by running:
npx grunt ignorefiles
Using the moodle-extra
coding style
The recommended way of configuring PHP CodeSniffer to use the moodle-extra
coding style is to provide an additional configuration file.
For Moodle 3.11 onwards you can create a file named .phpcs.xml
with the following contents:
<?xml version="1.0" encoding="UTF-8"?> <ruleset name="MoodleCore"> <rule ref="./phpcs.xml"/> <rule ref="moodle-extra"/> </ruleset>
This will load the phpcs.xml
file (generated by npx grunt ignorefiles
), and apply the moodle-extra
configuration on top.
Moodle 3.10 and earlier
The easiset way to have PHP CodeSniffer pick up your preferred style, you can create a file named phpcs.xml
with the following contents:
<?xml version="1.0" encoding="UTF-8"?> <ruleset name="MoodleCore"> <rule ref="moodle"/> </ruleset>
If you wish to use the moodle-extra
coding style, then you can use the following content:
<?xml version="1.0" encoding="UTF-8"?> <ruleset name="MoodleCore"> <rule ref="moodle-extra"/> </ruleset>
Note: Third-party library code will not be ignored with these versions of Moodle.