Skip to content

Commit

Permalink
Update phpcs.xml rules, phpcs lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ronilaukkarinen committed Aug 9, 2024
1 parent 133b5e7 commit 4553d00
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 13 deletions.
3 changes: 1 addition & 2 deletions content/themes/dude/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,7 @@
// Restrict to only selected blocks
// Set the value to 'all' to allow all blocks everywhere
'allowed_blocks' => [
'default' => [
],
'default' => [],
'post' => [
'core/archives',
'core/audio',
Expand Down
2 changes: 1 addition & 1 deletion content/themes/dude/inc/hooks/scripts-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function add_data_attribute_to_scripts( $tag, $handle ) {
'cookieconsent',
'iframemanager',
'wpforms-generic-utils',
'video-player'
'video-player',
];

if ( ! in_array( $handle, $allowed_handles ) ) { // phpcs:ignore
Expand Down
6 changes: 2 additions & 4 deletions content/themes/dude/inc/includes/nav-walker.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ public function start_lvl( &$output, $depth = 0, $args = null ) {
} else {
$output .= "\n{$n}{$indent}<ul>{$n}";
}

}

/**
Expand Down Expand Up @@ -146,7 +145,7 @@ public function start_el( &$output, $item, $depth = 0, $args = null, $id = 0 ) {

// Updating the CSS classes of a menu item in the WordPress Customizer preview results in all classes defined
// in that particular input box to come in as one big class string.
$split_on_spaces = function ( $class ) {
$split_on_spaces = function ( $class ) { // phpcs:ignore
return preg_split( '/\s+/', $class );
};
$classes = $this->flatten( array_map( $split_on_spaces, $classes ) );
Expand Down Expand Up @@ -594,7 +593,7 @@ private function linkmod_element_close( $linkmod_type ) {
*
* @return array a simple array
*/
public function flatten( $array ) {
public function flatten( $array ) { // phpcs:ignore
$result = array();
foreach ( $array as $element ) {
if ( is_array( $element ) ) {
Expand All @@ -605,5 +604,4 @@ public function flatten( $array ) {
}
return $result;
}

}
1 change: 0 additions & 1 deletion content/themes/dude/inc/includes/post-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,4 @@ abstract protected function register();
public function register_wp_post_type( $slug, $args ) {
return register_post_type( $slug, $args );
}

}
3 changes: 1 addition & 2 deletions content/themes/dude/inc/includes/taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,10 @@ protected function register_wp_taxonomy( $slug, $object_types, $args ) {

// Remove post types that in which the taxonomy was not properly
// registered from the result array.
$registered_object_types = array_filter( $register_result, function( $result, $object_type ) {
$registered_object_types = array_filter( $register_result, function( $result, $object_type ) { // phpcs:ignore
return ( $result ) ? true : false;
}, ARRAY_FILTER_USE_BOTH );

return $registered_object_types;
}

}
1 change: 0 additions & 1 deletion content/themes/dude/inc/taxonomies/reference-category.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,4 @@ public function register( array $post_types = [] ) {

$this->register_wp_taxonomy( $this->slug, $post_types, $args );
}

}
1 change: 0 additions & 1 deletion content/themes/dude/inc/taxonomies/your-taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,4 @@ public function register( array $post_types = [] ) {

$this->register_wp_taxonomy( $this->slug, $post_types, $args );
}

}
2 changes: 1 addition & 1 deletion content/themes/dude/phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,6 @@
</rule>

<!-- Include sniffs for PHP cross-version compatibility. -->
<config name="testVersion" value="7.0-99.0"/>
<config name="testVersion" value="8.3"/>
<rule ref="PHPCompatibility"/>
</ruleset>
120 changes: 120 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?xml version="1.0"?>
<ruleset name="WordPress-Core">
<!-- See https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml -->
<!-- See https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards -->
<!-- See https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki -->
<!-- See https://github.com/wimg/PHPCompatibility -->

<!-- Set a description for this ruleset. -->
<description>A custom set of code standard rules to check for WordPress themes.</description>

<!-- Pass some flags to PHPCS:
p flag: Show progress of the run.
s flag: Show sniff codes in all reports.
v flag: Print verbose output.
n flag: Do not print warnings.
-->
<arg value="psvn"/>

<!-- Only check the PHP, CSS and SCSS files. JS files are checked separately with JSCS and JSHint. -->
<arg name="extensions" value="php,css,scss/css"/>

<!-- Check all files in this directory and the directories below it. -->
<file>.</file>

<!-- Include the WordPress ruleset, with exclusions. -->
<rule ref="WordPress">

<!-- Strict intendation rules we want to exclude -->
<exclude name="Generic.WhiteSpace.ScopeIndent.IncorrectExact" />
<exclude name="Generic.WhiteSpace.ScopeIndent.Incorrect" />
<exclude name="Generic.WhiteSpace.DisallowSpaceIndent.SpacesUsed" />
<exclude name="PEAR.Functions.FunctionCallSignature.Indent" />
<exclude name="WordPress.Arrays.ArrayIndentation.ItemNotAligned" />
<exclude name="WordPress.Arrays.ArrayIndentation.MultiLineArrayItemNotAligned" />
<exclude name="WordPress.WhiteSpace.DisallowInlineTabs.NonIndentTabsUsed" />
<exclude name="WordPress.Arrays.ArrayIndentation.CloseBraceNotAligned" />
<exclude name="PEAR.Functions.FunctionCallSignature.OpeningIndent" />

<!-- Don't require too strict inline commenting, it's a good thing to documentate, let's not make it frustrating -->
<exclude name="Squiz.Commenting.FunctionComment.WrongStyle" />
<exclude name="Squiz.Commenting.ClassComment.WrongStyle" />
<exclude name="Squiz.Commenting.InlineComment.InvalidEndChar" />
<exclude name="Squiz.Commenting.FunctionComment.Missing" />
<exclude name="Squiz.Commenting.FunctionComment.MissingParamTag" />
<exclude name="Squiz.Commenting.InlineComment.SpacingAfter" />
<exclude name="Squiz.Commenting.FileComment.Missing" />
<exclude name="Squiz.Commenting.LongConditionClosingComment.Missing" />
<exclude name="Squiz.Commenting.FunctionComment.ParamCommentFullStop" />

<!-- General code style related excludes -->
<exclude name="Squiz.PHP.DisallowMultipleAssignments.Found" />
<exclude name="Squiz.PHP.EmbeddedPhp.MultipleStatements" />
<exclude name="Squiz.PHP.EmbeddedPhp.ContentAfterOpen" />
<exclude name="Squiz.PHP.EmbeddedPhp.ContentBeforeEnd" />
<exclude name="Generic.Formatting.DisallowMultipleStatements.SameLine" />
<exclude name="WordPress.Arrays.ArrayDeclarationSpacing.AssociativeKeyFound" />
<exclude name="WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound" />
<exclude name="Squiz.ControlStructures.ControlSignature.NewlineAfterOpenBrace" />
<exclude name="PHPCompatibility.PHP.NewFunctionArrayDereferencing.Found" />
<exclude name="Generic.Arrays.DisallowShortArraySyntax" />

<!-- General WordPress stuff we like to overrule -->
<exclude name="WordPress.Files.FileName.InvalidClassFileName" />

<!-- Very strict VIP/discouraged rules that are not needed -->
<exclude name="WordPress.XSS.EscapeOutput.OutputNotEscaped" />
<exclude name="WordPress.Functions.DontExtract.extract_extract" />
<exclude name="Generic.Functions.FunctionCallArgumentSpacing.TooMuchSpaceAfterComma" />
<exclude name="Generic.Commenting.DocComment.MissingShort" />
<exclude name="Generic.Commenting.DocComment.SpacingBeforeTags" />
<exclude name="Squiz.PHP.EmbeddedPhp.NoSemicolon" />
<exclude name="PHPCompatibility.PHP.NewClosure.Found" />
<exclude name="PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket" />
<exclude name="PEAR.Functions.FunctionCallSignature.CloseBracketLine" />
<exclude name="PEAR.Functions.FunctionCallSignature.MultipleArguments" />
<exclude name="WordPress.PHP.DontExtract.extract_extract" />

<!-- Translations related, not always necessary, too strict -->
<exclude name="WordPress.WP.I18n.MissingTranslatorsComment" />

<!-- EditorConfig makes sure this happens anyway & false positives happen with this -->
<exclude name="Generic.Files.EndFileNewline.NotFound" />

<!-- Many times when developing a customer case we have placeholders for SVG includes, so unnecessary error reports happen with this rule -->
<exclude name="Squiz.PHP.EmbeddedPhp.Empty" />

<!-- Other useful excludes -->
<exclude name="WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned" />
<exclude name="WordPress.WP.GlobalVariablesOverride.Prohibited" />
<exclude name="PEAR.NamingConventions.ValidClassName.StartWithCapital" />
<exclude name="WordPress.Security.ValidatedSanitizedInput.MissingUnslash" />
<exclude name="Generic.ControlStructures.InlineControlStructure.NotAllowed" />
<exclude name="Squiz.PHP.EmbeddedPhp.ContentBeforeOpen" />
<exclude name="Generic.Formatting.MultipleStatementAlignment.NotSameWarning" />
<exclude name="PEAR.Files.IncludingFile.UseRequire" />
<exclude name="WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned" />
<exclude name="WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode" />
<exclude name="WordPress.DB.SlowDBQuery.slow_db_query_tax_query" />
<exclude name="WordPress.PHP.DisallowShortTernary.Found" />

<!-- Dudestack based -->
<exclude name="Squiz.PHP.CommentedOutCode.Found" />
<exclude name="Squiz.Commenting.FileComment.MissingPackageTag" />
<exclude name="WordPress.PHP.IniSet.display_errors_Blacklisted" />
<exclude name="WordPress.PHP.YodaConditions.NotYoda" />
<exclude name="WordPress.WP.AlternativeFunctions.parse_url_parse_url" />
<exclude name="Squiz.Commenting.ClassComment.Missing" />
<exclude name="Squiz.Commenting.VariableComment.Missing" />
<exclude name="Universal.Arrays.DisallowShortArraySyntax.Found" />
<exclude name="Universal.WhiteSpace.PrecisionAlignment.Found" />
<exclude name="WordPress.Files.FileName.NotHyphenatedLowercase" />
<exclude name="Squiz.Commenting.VariableComment.WrongStyle" />
<exclude name="PSR2.Classes.PropertyDeclaration.Underscore" />
<exclude name="Universal.Operators.DisallowShortTernary.Found" />
</rule>

<!-- Include sniffs for PHP cross-version compatibility. -->
<config name="testVersion" value="8.3"/>
<rule ref="PHPCompatibility"/>
</ruleset>

0 comments on commit 4553d00

Please sign in to comment.