chore: update phpcs.xml from Drupal examples#670
Conversation
This will lead to many files needing to be recorrected.
1c465d7 to
4d68e5e
Compare
zeshanziya
left a comment
There was a problem hiding this comment.
@hussainweb I have added my comments. Please review.
| <exclude-pattern>*/bower_components/*</exclude-pattern> | ||
| <exclude-pattern>*/node_modules/*</exclude-pattern> | ||
| <!--Exclude third party code.--> | ||
| <exclude-pattern>./assets/vendor/*</exclude-pattern> |
There was a problem hiding this comment.
@hussainweb Exclude is mostly for use when we run phpcs directly. but again, if we don't pass include directories, it will run on whole codebase so if we plan to keep this up and allow user to run phpcs -v then we will have to exclude other directories as well and I think, this will be overkill. We can remove this as we have exclude dirs specified in grumphp conf file.
Mostly exclude all these dirs
<!-- Exclude core, vendor, and contrib directories -->
<exclude-pattern>./web/core/*</exclude-pattern>
<exclude-pattern>./vendor/*</exclude-pattern>
<exclude-pattern>./web/modules/contrib/*</exclude-pattern>
<exclude-pattern>./web/hemes/contrib/*</exclude-pattern>
<exclude-pattern>./web/profiles/contrib/*</exclude-pattern>
<exclude-pattern>./private/*</exclude-pattern>
<exclude-pattern>./config/*</exclude-pattern>
<exclude-pattern>./web/sites/*</exclude-pattern>
<exclude-pattern>./.ddev/*</exclude-pattern>
|
|
||
| <!--Allow global variables in settings file.--> | ||
| <rule ref="DrupalPractice.CodeAnalysis.VariableAnalysis.UndefinedVariable"> | ||
| <exclude-pattern>settings(\.[a-zA-Z0-9]+)?\.php</exclude-pattern> |
There was a problem hiding this comment.
If we remove this, phpcs will stop catching UndefinedVariable. Currently it did not catch it in settings.php because /web/sites/default is excluded in grumphp. So if don't want that exclude pattern, we should only keep the rule without any exclude as settings file are already excluded in grumphp.
<rule ref="DrupalPractice.CodeAnalysis.VariableAnalysis.UndefinedVariable" />
Same applies for other DrupalPractice.Commenting rules.
| <rule ref="Drupal"/> | ||
| <rule ref="Drupal.Arrays.Array"> | ||
| <!-- Sniff for these errors: CommaLastItem --> | ||
| <exclude name="Drupal.Arrays.Array.ArrayClosingIndentation"/> |
There was a problem hiding this comment.
These rules exclude were present earlier too. I removed it. It improves code readability when arrays are properly indented. So I will suggest to remove it.
| <rule ref="Drupal.Classes.FullyQualifiedNamespace"/> | ||
| <rule ref="Drupal.Classes.InterfaceName"/> | ||
| <rule ref="Drupal.Classes.UnusedUseStatement"/> | ||
| <rule ref="Drupal.Classes.UseGlobalClass"/> |
There was a problem hiding this comment.
Any specific reason for removing this? This checks the following.
You cannot use the use statement for non-namespaced classes; instead, you must reference them with a leading \, e.g., \DateTimeImmutable instead of use DateTimeImmutable;.
| <properties> | ||
| <property name="ignoreNewlines" value="true"/> | ||
| </properties> | ||
| </rule> |
There was a problem hiding this comment.
This checks operator spacing rules.
Here are few examples.
Correct: $a = $b + $c;
Incorrect: $a=$b+$c;
Correct
$abc = [
"abc3" => "dssdsd3",
"abc41" => [
"dssdsd4"
],
];
$abc = [
"abc3" => "dssdsd3",
"abc41" =>
[
"dssdsd4"
],
];Incorrect
$abc = [
"abc3"=> "dssdsd3",
"abc41" =>[
"dssdsd4"
],
];| <rule ref="Zend.Files.ClosingTag"/> | ||
|
|
||
| <!-- sniffs from https://github.com/acquia/coding-standards-php --> | ||
| <rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses" /> |
There was a problem hiding this comment.
These are from Acquia coding standards and sorts use statements in ascending order. This can be removed as sorting manually is a challenge but phpcbf can help sort it.
|
|
||
| <!-- sniffs from https://github.com/acquia/coding-standards-php --> | ||
| <rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses" /> | ||
| <rule ref="SlevomatCodingStandard.Variables.DisallowSuperGlobalVariable" /> |
There was a problem hiding this comment.
We can also keep this to discourage direct use of $_GET, $_POST, $_SERVER and $GLOBALS etc.
|
|
||
| <!-- Only include specific sniffs that pass. This ensures that, if new sniffs are added, HEAD does not fail.--> | ||
| <!-- Drupal sniffs --> | ||
| <rule ref="Drupal"/> |
There was a problem hiding this comment.
Spacing in doc comment can be achieved using <rule ref="Drupal.Commenting.DocCommentAlignment"/>.
|
@zeshanziya, can you please revert the changes as you see fit? I didn't make a deliberate effort towards these changes. I only synced it from the latest version of the example phpcs.xml. |
This will lead to many files needing to be recorrected.