Skip to content
Snippets Groups Projects
Verified Commit 6ef6ffcf authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3135933 by Spokje, jungle, ravi.shankar, quietone, jonathan1055,...

Issue #3135933 by Spokje, jungle, ravi.shankar, quietone, jonathan1055, longwave, phenaproxima: Sort sniffs/rules in phpcs.xml.dist and write test to keep them sorted
parent b957382d
No related branches found
No related tags found
38 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!54479.5.x SF update,!5014Issue #3071143: Table Render Array Example Is Incorrect,!4868Issue #1428520: Improve menu parent link selection,!4289Issue #1344552 by marcingy, Niklas Fiekas, Ravi.J, aleevas, Eduardo Morales...,!4114Issue #2707291: Disable body-level scrolling when a dialog is open as a modal,!4100Issue #3249600: Add support for PHP 8.1 Enums as allowed values for list_* data types,!3630Issue #2815301 by Chi, DanielVeza, kostyashupenko, smustgrave: Allow to create...,!3600Issue #3344629: Passing null to parameter #1 ($haystack) of type string is deprecated,!3291Issue #3336463: Rewrite rules for gzipped CSS and JavaScript aggregates never match,!3102Issue #3164428 by DonAtt, longwave, sahil.goyal, Anchal_gupta, alexpott: Use...,!2853#3274419 Makes BaseFieldOverride inherit the internal property from the base field.,!2661Issue #3295972 by Munavijayalakshmi, nitin_lama, arunkumark, cilefen,...,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2334Issue #3228209: Add hasRole() method to AccountInterface,!2074Issue #2707689: NodeForm::actions() checks for delete access on new entities,!2062Issue #3246454: Add weekly granularity to views date sort,!1591Issue #3199697: Add JSON:API Translation experimental module,!1484Exposed filters get values from URL when Ajax is on,!1255Issue #3238922: Refactor (if feasible) uses of the jQuery serialize function to use vanillaJS,!1254Issue #3238915: Refactor (if feasible) uses of the jQuery ready function to use VanillaJS,!1162Issue #3100350: Unable to save '/' root path alias,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!957Added throwing of InvalidPluginDefinitionException from getDefinition().,!925Issue #2339235: Remove taxonomy hard dependency on node module,!877Issue #2708101: Default value for link text is not saved,!873Issue #2875228: Site install not using batch API service,!872Draft: Issue #3221319: Race condition when creating menu links and editing content deletes menu links,!844Resolve #3036010 "Updaters",!712Issue #2909128: Autocomplete intermittent on Chrome Android,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!485Sets the autocomplete attribute for username/password input field on login form.,!30Issue #3182188: Updates composer usage to point at ./vendor/bin/composer
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="drupal_core">
<description>Default PHP CodeSniffer configuration for Drupal core.</description>
<file>.</file>
<file>../composer</file>
<file>scripts/drupal.sh</file>
<file>scripts/password-hash.sh</file>
<file>scripts/rebuild_token_calculator.sh</file>
<file>scripts/run-tests.sh</file>
<file>scripts/update-countries.sh</file>
<arg name="extensions" value="inc,install,module,php,profile,test,theme,yml"/>
<description>Default PHP CodeSniffer configuration for Drupal core.</description>
<!--Exclude folders used by common frontend tools. These folders match the file_scan_ignore_directories setting in default.settings.php-->
<exclude-pattern>*/bower_components/*</exclude-pattern>
<exclude-pattern>*/node_modules/*</exclude-pattern>
<!--Exclude third party code.-->
<exclude-pattern>./assets/vendor/*</exclude-pattern>
<!-- Exclude third-party code maintained within core that does not follow our standards. -->
<!-- @todo This rule may be removed when https://www.drupal.org/node/1848264 is resolved. -->
<exclude-pattern>./core/lib/Drupal/Component/Diff/</exclude-pattern>
<exclude-pattern>./core/tests/Drupal/Tests/Component/Annotation/Doctrine/</exclude-pattern>
<!--Exclude folders used by common frontend tools. These folders match the file_scan_ignore_directories setting in default.settings.php-->
<exclude-pattern>*/node_modules/*</exclude-pattern>
<exclude-pattern>*/bower_components/*</exclude-pattern>
<!--Exclude test files that are intentionally empty, or intentionally violate coding standards.-->
<exclude-pattern>./modules/system/tests/fixtures/HtaccessTest</exclude-pattern>
<!-- Exclude third-party code maintained within core that does not follow our standards. -->
<!-- @todo This rule may be removed when https://www.drupal.org/node/1848264 is resolved. -->
<exclude-pattern>./core/lib/Drupal/Component/Diff/</exclude-pattern>
<file>.</file>
<file>../composer</file>
<file>scripts/drupal.sh</file>
<file>scripts/password-hash.sh</file>
<file>scripts/rebuild_token_calculator.sh</file>
<file>scripts/run-tests.sh</file>
<file>scripts/update-countries.sh</file>
<!-- Only include specific sniffs that pass. This ensures that, if new sniffs are added, HEAD does not fail.-->
<!-- Drupal sniffs -->
<rule ref="Drupal.Arrays.Array">
<!-- Sniff for these errors: CommaLastItem -->
......@@ -33,6 +33,8 @@
<exclude name="Drupal.Arrays.Array.ArrayIndentation"/>
<exclude name="Drupal.Arrays.Array.LongLineDeclaration"/>
</rule>
<rule ref="Drupal.CSS.ClassDefinitionNameSpacing"/>
<rule ref="Drupal.CSS.ColourDefinition"/>
<rule ref="Drupal.Classes.ClassCreateInstance"/>
<rule ref="Drupal.Classes.ClassDeclaration"/>
<rule ref="Drupal.Classes.ClassFileName"/>
......@@ -42,8 +44,6 @@
<rule ref="Drupal.Classes.UnusedUseStatement"/>
<rule ref="Drupal.Classes.UseGlobalClass"/>
<rule ref="Drupal.Classes.UseLeadingBackslash"/>
<rule ref="Drupal.CSS.ClassDefinitionNameSpacing"/>
<rule ref="Drupal.CSS.ColourDefinition"/>
<rule ref="Drupal.Commenting.ClassComment">
<exclude name="Drupal.Commenting.ClassComment.Missing"/>
</rule>
......@@ -56,12 +56,12 @@
TagsNotGrouped, ParamGroup -->
<!-- ParamNotFirst still not decided for PHPUnit-based tests.
@see https://www.drupal.org/node/2253915 -->
<exclude name="Drupal.Commenting.DocComment.ParamNotFirst"/>
<exclude name="Drupal.Commenting.DocComment.SpacingBeforeTags"/>
<exclude name="Drupal.Commenting.DocComment.LongFullStop"/>
<exclude name="Drupal.Commenting.DocComment.MissingShort"/>
<exclude name="Drupal.Commenting.DocComment.ParamNotFirst"/>
<exclude name="Drupal.Commenting.DocComment.ShortNotCapital"/>
<exclude name="Drupal.Commenting.DocComment.ShortSingleLine"/>
<exclude name="Drupal.Commenting.DocComment.MissingShort"/>
<exclude name="Drupal.Commenting.DocComment.SpacingBeforeTags"/>
</rule>
<rule ref="Drupal.Commenting.DocCommentAlignment"/>
<rule ref="Drupal.Commenting.DocCommentStar"/>
......@@ -75,15 +75,8 @@
<exclude name="Drupal.Commenting.FunctionComment.ParamCommentFullStop"/>
<exclude name="Drupal.Commenting.FunctionComment.TypeHintMissing"/>
</rule>
<rule ref="Drupal.Commenting.HookComment"/>
<rule ref="Drupal.Commenting.GenderNeutralComment"/>
<rule ref="Drupal.Commenting.InlineVariableComment"/>
<rule ref="Drupal.Commenting.VariableComment">
<!-- Sniff for: DuplicateVar, EmptyVar, IncorrectVarType, InlineVariableName, WrongStyle -->
<exclude name="Drupal.Commenting.VariableComment.Missing"/>
<exclude name="Drupal.Commenting.VariableComment.MissingVar"/>
<exclude name="Drupal.Commenting.VariableComment.VarOrder"/>
</rule>
<rule ref="Drupal.Commenting.HookComment"/>
<rule ref="Drupal.Commenting.InlineComment">
<!-- Sniff for: NoSpaceBefore, SpacingBefore, WrongStyle -->
<exclude name="Drupal.Commenting.InlineComment.DocBlock"/>
......@@ -91,9 +84,17 @@
<exclude name="Drupal.Commenting.InlineComment.NotCapital"/>
<exclude name="Drupal.Commenting.InlineComment.SpacingAfter"/>
</rule>
<rule ref="Drupal.Commenting.InlineVariableComment"/>
<rule ref="Drupal.Commenting.PostStatementComment"/>
<rule ref="Drupal.ControlStructures.ElseIf"/>
<rule ref="Drupal.Commenting.VariableComment">
<!-- Sniff for: DuplicateVar, EmptyVar, InlineVariableName, WrongStyle -->
<exclude name="Drupal.Commenting.VariableComment.IncorrectVarType"/>
<exclude name="Drupal.Commenting.VariableComment.Missing"/>
<exclude name="Drupal.Commenting.VariableComment.MissingVar"/>
<exclude name="Drupal.Commenting.VariableComment.VarOrder"/>
</rule>
<rule ref="Drupal.ControlStructures.ControlSignature"/>
<rule ref="Drupal.ControlStructures.ElseIf"/>
<rule ref="Drupal.ControlStructures.InlineControlStructure"/>
<rule ref="Drupal.Files.EndFileNewline"/>
<rule ref="Drupal.Files.FileEncoding"/>
......@@ -113,6 +114,8 @@
Drupal.NamingConventions.ValidFunctionName.ScopeNotCamelCaps. -->
<exclude name="Drupal.Methods.MethodDeclaration.Underscore"/>
</rule>
<rule ref="Drupal.NamingConventions.ValidClassName"/>
<rule ref="Drupal.NamingConventions.ValidGlobal"/>
<rule ref="Drupal.NamingConventions.ValidVariableName">
<!-- Sniff for: LowerStart -->
<exclude name="Drupal.NamingConventions.ValidVariableName.LowerCamelName"/>
......@@ -143,9 +146,6 @@
<rule ref="Drupal.WhiteSpace.ScopeIndent"/>
<!-- Drupal Practice sniffs -->
<rule ref="DrupalPractice.Commenting.ExpectedException"/>
<rule ref="DrupalPractice.General.ExceptionT"/>
<rule ref="DrupalPractice.InfoFiles.NamespacedDependency"/>
<rule ref="DrupalPractice.CodeAnalysis.VariableAnalysis">
<!-- @todo exclude tests -->
<exclude-pattern>*/tests/*</exclude-pattern>
......@@ -156,14 +156,17 @@
<property name="allowUnusedFunctionParameters" value="true"/>
</properties>
</rule>
<rule ref="DrupalPractice.CodeAnalysis.VariableAnalysis.UndefinedUnsetVariable">
<severity>0</severity>
</rule>
<rule ref="DrupalPractice.CodeAnalysis.VariableAnalysis.UndefinedVariable">
<!-- Setting severity to 0 to completely disable an error message in this sniff, without excluding the whole sniff -->
<!-- See https://github.com/squizlabs/PHP_CodeSniffer/wiki/Configuration-Options#changing-the-default-severity-levels -->
<severity>0</severity>
</rule>
<rule ref="DrupalPractice.CodeAnalysis.VariableAnalysis.UndefinedUnsetVariable">
<severity>0</severity>
</rule>
<rule ref="DrupalPractice.Commenting.ExpectedException"/>
<rule ref="DrupalPractice.General.ExceptionT"/>
<rule ref="DrupalPractice.InfoFiles.NamespacedDependency"/>
<!-- Generic sniffs -->
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
......@@ -178,8 +181,6 @@
<property name="checkClosures" value="true"/>
</properties>
</rule>
<rule ref="Drupal.NamingConventions.ValidClassName"/>
<rule ref="Drupal.NamingConventions.ValidGlobal"/>
<rule ref="Generic.NamingConventions.ConstructorName"/>
<rule ref="Generic.NamingConventions.UpperCaseConstantName"/>
<rule ref="Generic.PHP.DeprecatedFunctions"/>
......@@ -200,30 +201,29 @@
<!-- PEAR sniffs -->
<rule ref="PEAR.Files.IncludingFile"/>
<!-- Disable some error messages that we do not want. -->
<rule ref="PEAR.Files.IncludingFile.UseIncludeOnce">
<severity>0</severity>
</rule>
<rule ref="PEAR.Files.IncludingFile.UseInclude">
<severity>0</severity>
</rule>
<rule ref="PEAR.Files.IncludingFile.UseRequireOnce">
<rule ref="PEAR.Files.IncludingFile.UseIncludeOnce">
<severity>0</severity>
</rule>
<rule ref="PEAR.Files.IncludingFile.UseRequire">
<severity>0</severity>
</rule>
<rule ref="PEAR.Functions.ValidDefaultValue"/>
<!-- PEAR sniffs -->
<rule ref="PEAR.Files.IncludingFile.UseRequireOnce">
<severity>0</severity>
</rule>
<rule ref="PEAR.Functions.FunctionCallSignature"/>
<!-- The sniffs inside PEAR.Functions.FunctionCallSignature silenced below are
also silenced in Drupal CS' ruleset.xml. The code below is a 1-on-1 copy
from that file. -->
<!-- Disable some error messages that we already cover. -->
<rule ref="PEAR.Functions.FunctionCallSignature.SpaceAfterOpenBracket">
<rule ref="PEAR.Functions.FunctionCallSignature.CloseBracketLine">
<severity>0</severity>
</rule>
<rule ref="PEAR.Functions.FunctionCallSignature.SpaceBeforeCloseBracket">
<rule ref="PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket">
<severity>0</severity>
</rule>
<rule ref="PEAR.Functions.FunctionCallSignature.EmptyLine">
<severity>0</severity>
</rule>
<!-- Disable some error messages that we do not want. -->
......@@ -233,15 +233,14 @@
<rule ref="PEAR.Functions.FunctionCallSignature.OpeningIndent">
<severity>0</severity>
</rule>
<rule ref="PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket">
<severity>0</severity>
</rule>
<rule ref="PEAR.Functions.FunctionCallSignature.CloseBracketLine">
<!-- Disable some error messages that we already cover. -->
<rule ref="PEAR.Functions.FunctionCallSignature.SpaceAfterOpenBracket">
<severity>0</severity>
</rule>
<rule ref="PEAR.Functions.FunctionCallSignature.EmptyLine">
<rule ref="PEAR.Functions.FunctionCallSignature.SpaceBeforeCloseBracket">
<severity>0</severity>
</rule>
<rule ref="PEAR.Functions.ValidDefaultValue"/>
<!-- PSR-2 sniffs -->
<rule ref="PSR2.Classes.PropertyDeclaration">
......@@ -255,8 +254,8 @@
<!-- Squiz sniffs -->
<rule ref="Squiz.Arrays.ArrayBracketSpacing"/>
<rule ref="Squiz.Arrays.ArrayDeclaration">
<exclude name="Squiz.Arrays.ArrayDeclaration.NoKeySpecified"/>
<exclude name="Squiz.Arrays.ArrayDeclaration.KeySpecified"/>
<exclude name="Squiz.Arrays.ArrayDeclaration.NoKeySpecified"/>
</rule>
<!-- Disable some error messages that we do not want. -->
<rule ref="Squiz.Arrays.ArrayDeclaration.CloseBraceNotAligned">
......@@ -286,10 +285,10 @@
<rule ref="Squiz.Arrays.ArrayDeclaration.SingleLineNotAllowed">
<severity>0</severity>
</rule>
<rule ref="Squiz.Arrays.ArrayDeclaration.ValueNotAligned">
<rule ref="Squiz.Arrays.ArrayDeclaration.ValueNoNewline">
<severity>0</severity>
</rule>
<rule ref="Squiz.Arrays.ArrayDeclaration.ValueNoNewline">
<rule ref="Squiz.Arrays.ArrayDeclaration.ValueNotAligned">
<severity>0</severity>
</rule>
<rule ref="Squiz.ControlStructures.ForEachLoopDeclaration"/>
......@@ -346,10 +345,21 @@
<rule ref="Squiz.ControlStructures.SwitchDeclaration.SpacingBeforeBreak">
<severity>0</severity>
</rule>
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing">
<properties>
<property name="equalsSpacing" value="1"/>
</properties>
</rule>
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing.NoSpaceBeforeArg">
<severity>0</severity>
</rule>
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration"/>
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine">
<severity>0</severity>
</rule>
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.CloseBracketLine">
<severity>0</severity>
</rule>
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.ContentAfterBrace">
<severity>0</severity>
</rule>
......@@ -360,17 +370,6 @@
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.Indent">
<severity>0</severity>
</rule>
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.CloseBracketLine">
<severity>0</severity>
</rule>
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing">
<properties>
<property name="equalsSpacing" value="1"/>
</properties>
</rule>
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing.NoSpaceBeforeArg">
<severity>0</severity>
</rule>
<rule ref="Squiz.PHP.LowercasePHPFunctions"/>
<rule ref="Squiz.PHP.NonExecutableCode"/>
<rule ref="Squiz.Strings.ConcatenationSpacing">
......
<?php
namespace Drupal\Tests\PhpCs;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
/**
* Tests that phpcs.xml.dist is properly sorted.
*
* @group phpcs
*/
class SortTest extends TestCase {
/**
* The path of phpcs.xml.dist file.
*
* @var string
*/
private $filePath;
/**
* {@inheritdoc}
*/
protected function setUp(): void {
$this->filePath = __DIR__ . '/../../../../../core/phpcs.xml.dist';
}
/**
* Tests that the phpcs.xml.dist file exists.
*/
public function testFileExists() {
$this->assertFileExists($this->filePath);
}
/**
* Tests that the phpcs.xml.dist file is properly sorted.
*/
public function testSorted() {
$content = file_get_contents($this->filePath);
$xml_encoder = new XmlEncoder();
$xml_encoded = $xml_encoder->decode($content, 'xml');
$this->assertIsArray($xml_encoded);
$top_level_keys = array_keys($xml_encoded);
$this->assertSorted($top_level_keys);
$this->assertArrayHasKey('file', $xml_encoded);
$files = $xml_encoded['file'];
$this->assertSorted($files);
$this->assertArrayHasKey('exclude-pattern', $xml_encoded);
$excluded_patterns = $xml_encoded['exclude-pattern'];
$this->assertSorted($excluded_patterns);
$this->assertArrayHasKey('rule', $xml_encoded);
$rules = $xml_encoded['rule'];
$this->assertSorted($rules, '@ref');
foreach ($rules as $item) {
if (array_key_exists('exclude', $item)) {
$excluded = $item['exclude'];
$excluded = array_filter($excluded, static function ($item) {
return is_array($item) && array_key_exists('@name', $item);
});
$this->assertSorted($excluded, '@name');
}
}
}
/**
* A helper method to assert that an input array is sorted.
*
* Compared by values, if the $column is not null, the column of the value is
* used for comparing.
*
* @param array $input
* The input array.
* @param null|string $column
* The column of the value or NULL.
*/
private function assertSorted(array $input, string $column = NULL) {
$input_sorted = $input;
if ($column === NULL) {
usort($input_sorted, static function ($a, $b) {
return strcmp($a, $b);
});
}
else {
usort($input_sorted, static function ($a, $b) use ($column) {
return strcmp($a[$column], $b[$column]);
});
}
$this->assertEquals($input, $input_sorted);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment