forked from moodlehq/moodle-cs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the phpcs.xml dist file and some small adjustments
Here we are introducing the phpcs.xml.dist file that will guide our coding style within moodle-cs. - It scans all the code but vendor and fixtures directories. - It's the complete PSR12 standard but allowing multi line function declarations to have the opening curly bracket in the same line. - With line length adjusted to 132 / 180. - And a few more sniffs, not part of the PSR12, but good for readability (hopefully non-controversial): - && and || logical operators. - Short array syntax. - Space after commas. - Comma at the end of multi-line arrays. - PHPCompatibility standard to check for >=7.4 (with an exception about T_ENUM false positives). And that's it! Then, apart of the above, small adjustments to the composer.json and .gitignore files.
- Loading branch information
Showing
3 changed files
with
61 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,20 @@ | ||
vendor | ||
# Composer stuff | ||
composer.lock | ||
phpcs.xml | ||
composer.phar | ||
|
||
# PHP_CodeSniffer | ||
.phpcs.xml | ||
phpcs.xml | ||
!phpcs.xml.dist | ||
|
||
# PHPUnit | ||
.phpunit.result.cache | ||
phpunit.xml | ||
.phplint-cache | ||
clover.xml | ||
.phpunit.cache | ||
|
||
# PHPlin | ||
phplint.cache | ||
|
||
# IDEs and editors | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ruleset> | ||
<description>The coding rules configuration for the moodle-cs project.</description> | ||
|
||
<!-- We don't want to analyse these --> | ||
<exclude-pattern>*/vendor/*</exclude-pattern> | ||
<exclude-pattern>*/Tests/fixtures/*</exclude-pattern> | ||
<exclude-pattern>*/Tests/*/fixtures/*</exclude-pattern> | ||
|
||
<!-- PSR12 with a few exceptions and adjustments --> | ||
<rule ref="PSR12"> | ||
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine"/> | ||
</rule> | ||
|
||
<!-- Some more chars don't hurt too much --> | ||
<rule ref="Generic.Files.LineLength"> | ||
<properties> | ||
<property name="lineLimit" value="132"/> | ||
<property name="absoluteLineLimit" value="180"/> | ||
</properties> | ||
</rule> | ||
|
||
<!-- We want to enforce && and || instead of and and or --> | ||
<rule ref="Squiz.Operators.ValidLogicalOperators"/> | ||
|
||
<!-- We want to use always the short array syntax --> | ||
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/> | ||
|
||
<!-- We went better commas managing --> | ||
<!-- Space after comma --> | ||
<rule ref="moodle.WhiteSpace.SpaceAfterComma"/> | ||
<!-- Comma at the end of multi-line arrays --> | ||
<rule ref="NormalizedArrays.Arrays.CommaAfterLast"> | ||
<exclude name="NormalizedArrays.Arrays.CommaAfterLast.MissingMultiLineCloserSameLine" /> | ||
</rule> | ||
|
||
<!--PHPCompetibility configuration--> | ||
<rule ref="./vendor/phpcompatibility/php-compatibility/PHPCompatibility/ruleset.xml"/> | ||
<config name="testVersion" value="7.4-"/> | ||
|
||
<!-- These are false positives because CodeSniffer creates them when needed. | ||
TODO: Delete this once we raise minimum requirements to PHP 8.0. --> | ||
<rule ref="PHPCompatibility.Constants.NewConstants"> | ||
<exclude name="PHPCompatibility.Constants.NewConstants.newConstants.t_enumFound"/> | ||
</rule> | ||
</ruleset> |