Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to YoastCS 1.3.0 #59

Merged
merged 8 commits into from
Dec 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ grunt export-ignore
.jshintrc export-ignore
Gruntfile.js export-ignore
package.json export-ignore
phpcs.xml export-ignore
.phpcs.xml.dist export-ignore
CONTRIBUTING.md export-ignore
readme.md export-ignore
ISSUE_TEMPLATE.md export-ignore
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ node_modules/
/admin/assets/js/*.js.map
.wordpress-svn/
artifact.zip
artifact/
artifact/
.phpcs.xml
phpcs.xml
105 changes: 105 additions & 0 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="Yoast Comment Hacks"
xsi:noNamespaceSchemaLocation="./vendor/squizlabs/php_codesniffer/phpcs.xsd">

<description>Yoast Comment Hacks rules for PHP_CodeSniffer</description>

<!--
#############################################################################
COMMAND LINE ARGUMENTS
https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml
#############################################################################
-->

<file>.</file>

<!-- Only check PHP files. -->
<arg name="extensions" value="php"/>

<!-- Show progress, show the error codes for each message (source). -->
<arg value="ps"/>

<!-- Strip the filepaths down to the relevant bit. -->
<arg name="basepath" value="./"/>

<!-- Check up to 8 files simultaneously. -->
<arg name="parallel" value="8"/>


<!--
#############################################################################
USE THE YoastCS RULESET
#############################################################################
-->

<rule ref="Yoast"/>


<!--
#############################################################################
SNIFF SPECIFIC CONFIGURATION
#############################################################################
-->

<!-- Verify that all gettext calls use the correct text domain. -->
<rule ref="WordPress.WP.I18n">
<properties>
<property name="text_domain" type="array">
<element value="yoast-comment-hacks"/>
</property>
</properties>
</rule>

<rule ref="Yoast.Files.FileName">
<properties>
<!-- Don't trigger on the main file as renaming it would deactivate the plugin. -->
<property name="exclude" type="array">
<element value="yoast-comment-hacks.php"/>
</property>

<!-- Remove the following prefixes from the names of object structures. -->
<property name="prefixes" type="array">
<element value="yoast_comment"/>
</property>
</properties>

<exclude-pattern>*/deprecated/deprecated-classes\.php$</exclude-pattern>
</rule>

<!-- Verify that everything in the global namespace is prefixed with a plugin specific prefix. -->
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<properties>
<!-- Provide the prefixes to look for. -->
<property name="prefixes" type="array">
<!-- Temporarily allowed until the prefixes are fixed. -->
<element value="yoast_ch"/>
<element value="yst_comment"/>

<!-- These are the new prefixes which all code should comply with in the future. -->
<element value="yoast_comment"/>
<element value="Yoast\WP\Comment"/>
</property>
</properties>

<exclude-pattern>*/deprecated/*\.php$</exclude-pattern>
</rule>


<!--
#############################################################################
TEMPORARY ADJUSTMENTS
Adjustments which should be removed once the associated issue has been resolved.
#############################################################################
-->

<!-- Direct database queries need careful review.
Ticket: https://github.com/Yoast/comment-hacks/issues/50
-->
<rule ref="WordPress.DB.DirectDatabaseQuery">
<exclude-pattern>/admin/comment-parent\.php$</exclude-pattern>
<exclude-pattern>/inc/clean-emails\.php$</exclude-pattern>
<exclude-pattern>/inc/email-links\.php$</exclude-pattern>
</rule>

</ruleset>
2 changes: 1 addition & 1 deletion .removeable-files
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
phpcs.xml
.phpcs.xml.dist
readme.md
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
fast_finish: true
include:
- php: 7.3
env: PHPLINT=1 CHECK=1 TRAVIS_NODE_VERSION=node
env: PHPLINT=1 CHECK=1 PHPCS=1 TRAVIS_NODE_VERSION=node
- php: 5.6
env: PHPLINT=1
- php: "7.4snapshot"
Expand Down Expand Up @@ -40,7 +40,7 @@ before_install:

install:
- |
if [[ "$CHECK" == "1" ]]; then
if [[ "$CHECK" == "1" || "$PHPCS" == "1" ]]; then
composer install --no-interaction
fi
- |
Expand Down Expand Up @@ -70,13 +70,15 @@ script:
find -L . -path ./vendor -prune -o -path ./node_modules -prune -o -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l
travis_time_finish && travis_fold end "PHP.check"
fi
# PHP CS
# GRUNT Tasks
- |
if [[ "$CHECK" == "1" ]]; then
travis_fold start "Grunt.check" && travis_time_start
grunt check
travis_time_finish && travis_fold end "Grunt.check"
fi
# PHPCS
- if [[ "$PHPCS" == "1" ]]; then composer check-cs;fi
# Validate the composer.json file.
# @link https://getcomposer.org/doc/03-cli.md#validate
- if [[ $TRAVIS_PHP_VERSION == "5.6" || $TRAVIS_PHP_VERSION == "7.3" ]]; then composer validate --no-check-all; fi
11 changes: 8 additions & 3 deletions admin/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,14 @@ public function config_page() {
if ( \defined( 'WP_DEBUG' ) && \WP_DEBUG ) {
echo '<h4>', \esc_html__( 'Options debug', 'yoast-comment-hacks' ), '</h4>';
echo '<div style="border: 1px solid #aaa; padding: 20px;">';
// @codingStandardsIgnoreStart
echo str_replace( '<code>', '<code style="background-color: #eee; margin: 0; padding: 0;">', highlight_string( "<?php\n\$this->options = " . var_export( $this->options, true ) . ';', true ), $num );
// @codingStandardsIgnoreEnd
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Debug output.
echo \str_replace(
'<code>',
'<code style="background-color: #eee; margin: 0; padding: 0;">',
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export -- This is only shown in debug mode.
\highlight_string( "<?php\n\$this->options = " . \var_export( $this->options, true ) . ';', true ),
$num
);
echo '</div>';
}
}
Expand Down
2 changes: 1 addition & 1 deletion admin/comment-parent.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct() {
*
* @param object $comment The comment object.
*/
public function comment_parent_box( $comment ) {
public function comment_parent_box( $comment ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found -- Param used in included file.
require_once \YST_COMMENT_HACKS_PATH . 'admin/views/comment-parent-box.php';
}

Expand Down
3 changes: 2 additions & 1 deletion admin/views/config-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@
array(
'depth' => 0,
'id' => 'redirect_page',
'name' => $yoast_comment_option_name . '[redirect_page]', // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
// phpcs:ignore WordPress.Security.EscapeOutput -- This is a hard-coded string, just passed around as a variable.
'name' => $yoast_comment_option_name . '[redirect_page]',
'option_none_value' => 0,
'selected' => ( isset( $this->options['redirect_page'] ) ? (int) $this->options['redirect_page'] : 0 ),
'show_option_none' => esc_html__( 'Don\'t redirect first time commenters', 'yoast-comment-hacks' ),
Expand Down
14 changes: 10 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"yoast/i18n-module": "^3.1.1"
},
"require-dev": {
"yoast/yoastcs": "^1.2.1"
"yoast/yoastcs": "^1.3.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand All @@ -40,9 +40,15 @@
]
},
"scripts": {
"config-yoastcs": [
"\"vendor/bin/phpcs\" --config-set installed_paths ../../../vendor/wp-coding-standards/wpcs,../../../vendor/yoast/yoastcs",
"\"vendor/bin/phpcs\" --config-set default_standard Yoast"
"config-yoastcs" : [
"Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run",
"@php ./vendor/squizlabs/php_codesniffer/bin/phpcs --config-set default_standard Yoast"
],
"check-cs": [
"@php ./vendor/squizlabs/php_codesniffer/bin/phpcs --runtime-set testVersion 5.6-"
],
"fix-cs": [
"@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf"
]
}
}
Loading