Skip to content

Commit

Permalink
Add a new moodle-extra coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Sep 14, 2023
1 parent 57bd4db commit aff8985
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ The format of this change log follows the advice given at [Keep a CHANGELOG](htt

## [Unreleased]

### Added

- A new moodle-extra coding standard which moves towards a more PSR-12 compliant coding style

## [v3.3.5] - 2023-08-28
### Changed
- Update composer dependencies to current versions, notably PHPCompatibility (0a17f9ed).
Expand Down
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@
{
"name": "Andrew Lyons",
"email": "[email protected]"
},
{
"name": "Eloy Lafuente",
"email": "[email protected]"
}
],
"require": {
"dealerdirect/phpcodesniffer-composer-installer": "^1.0.0",
"squizlabs/php_codesniffer": "^3.7.2",
"phpcsstandards/phpcsextra": "^1.1.0",
"phpcompatibility/php-compatibility": "dev-develop#0a17f9ed"
},
"config": {
Expand Down
73 changes: 73 additions & 0 deletions moodle-extra/ruleset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd"
name="moodle-strict"
namespace="MoodleHQ\MoodleCS\MoodleExtra">

<description>Best Practices for Moodle development beyond the core Coding Standards</description>

<!-- Extend the standard Moodle coding style -->
<rule ref="moodle"/>

<!-- Include the PSR-12 ruleset with relevant Moodle exclusions -->
<rule ref="PSR12">

<!-- Moodle has a header manager and places its copyright on the first line after the opening tag -->
<exclude name="PSR12.Files.FileHeader.SpacingAfterBlock"/>

<!-- Moodle already defines its own line length, so remove this from the PSR-12 standard -->
<exclude name="Generic.Files.LineLength.TooLong"/>

<!-- Moodle has its own custom sniff for side effects -->
<exclude name="PSR1.Files.SideEffects.FoundWithSymbols"/>

<!-- Moodle does not support camel case at all -->
<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps"/>

<!-- Moodle contains a lot of code which pre-dates PHP 7.1 and did not support constant visibility -->
<exclude name="PSR12.Properties.ConstantVisibility.NotFound"/>

<!-- Moodle does not place the opening brace on a new line -->
<exclude name="PSR2.Classes.ClassDeclaration.OpenBraceNewLine"/>

<!-- Moodle allows use of else if-->
<exclude name="PSR2.ControlStructures.ElseIfDeclaration.NotAllowed"/>

<!-- Moodle casing rules do not allow camel case at all -->
<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps"/>

<!-- Moodle casing currently places the brace in the same line -->
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine"/>
</rule>

<!-- Detect duplicate array keys -->
<rule ref="Universal.Arrays.DuplicateArrayKey"/>

<!-- Require a comma after the last element in a multi-line array, but prevent in a single-line array definition -->
<rule ref="NormalizedArrays.Arrays.CommaAfterLast"/>

<!-- Disallow use of list() instead of [] -->
<rule ref="Universal.Lists.DisallowLongListSyntax"/>

<!-- Enusre that ::class is lower-cased -->
<rule ref="Universal.Constants.LowercaseClassResolutionKeyword"/>

<!-- Require a consistent modifier keyword order for OO constant declarations -->
<rule ref="Universal.Constants.ModifierKeywordOrder"/>

<!-- Enforce that the names used in a class/enum "implements" statement or an interface "extends" statement are listed in alphabetic order -->
<rule ref="Universal.OOStructures.AlphabeticExtendsImplements"/>

<!-- Enforce the use of a single space after the use, function, const keywords and both before and after the as keyword in import use statements -->
<rule ref="Universal.UseStatements.KeywordSpacing"/>

<!-- Enforce lowercase function/const -->
<rule ref="Universal.UseStatements.LowercaseFunctionConst"/>

<!-- Detect useless class imports (aliases) -->
<rule ref="Universal.UseStatements.NoUselessAliases"/>

<!-- Enfore comma, spacing, like, this -->
<rule ref="Universal.WhiteSpace.CommaSpacing"/>

</ruleset>
10 changes: 0 additions & 10 deletions moodle/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,6 @@
<rule ref="Squiz.Scope.MethodScope"/>
<rule ref="Squiz.Scope.StaticThisUsage"/>

<rule ref="Squiz.WhiteSpace.OperatorSpacing">
<properties>
<property name="ignoreNewlines" value="true"/>
</properties>
</rule>
<rule ref="Squiz.WhiteSpace.ObjectOperatorSpacing">
<properties>
<property name="ignoreNewlines" value="true"/>
</properties>
</rule>
<rule ref="PEAR.WhiteSpace.ObjectOperatorIndent"/>
<rule ref="Squiz.WhiteSpace.ScopeClosingBrace"/>
<rule ref="Squiz.WhiteSpace.ScopeKeywordSpacing"/>
Expand Down

0 comments on commit aff8985

Please sign in to comment.