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

CS: start using YoastCS 0.5 #69

Merged
merged 12 commits into from
Jun 7, 2018
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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/vendor/
/composer.lock
.phpcs.xml
phpcs.xml
129 changes: 129 additions & 0 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?xml version="1.0"?>
<ruleset name="Yoast WHIP">
<description>Yoast WHIP rules for PHP_CodeSniffer</description>

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

<file>.</file>

<exclude-pattern>vendor/*</exclude-pattern>

<!-- 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 simultanously. -->
<arg name="parallel" value="8"/>


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

<rule ref="Yoast">
<!-- Historically, this library has used camelCaps not snakecase for variable and function names. -->
<exclude name="WordPress.NamingConventions.ValidVariableName"/>
<exclude name="WordPress.NamingConventions.ValidFunctionName"/>

<!-- Historically, this library uses camelCaps file names. -->
<exclude name="Yoast.Files.FileName"/>
</rule>

<!-- Check that variable names are in camelCaps. -->
<rule ref="Squiz.NamingConventions.ValidVariableName">
<!-- Private properties should, however, *not* start with an underscore. -->
<exclude name="Squiz.NamingConventions.ValidVariableName.PrivateNoUnderscore"/>
</rule>

<!-- Check that function and method names are in camelCaps. -->
<rule ref="Generic.NamingConventions.CamelCapsFunctionName">
<properties>
<!-- Allow for two adjacent capital letters for acronyms. -->
<property name="strict" value="false"/>
</properties>

<!-- Exclude WordPress example function. -->
<exclude-pattern>/src/facades/wordpress\.php$</exclude-pattern>

<!-- Exclude mocks of WP Core functions which comply with the WP function name rules instead. -->
<exclude-pattern>/tests/doubles/WpCoreFunctionsMock\.php$</exclude-pattern>
</rule>


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

<!-- Set the minimum supported WP version. This is used by several sniffs. -->
<config name="minimum_supported_wp_version" value="3.0"/>

<!-- 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" value="whip"/>
</properties>

<!-- Valid usage: For testing purposes, allow non-prefixed globals. -->
<exclude-pattern>/tests/doubles/WPCoreFunctionsMock\.php$</exclude-pattern>
</rule>


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

<!-- Textdomain is passed in dynamically which will not work correctly with gettext().
Ticket: https://github.com/Yoast/whip/issues/2 -->
<rule ref="WordPress.WP.I18n.NonSingularStringLiteralDomain">
<type>warning</type>
</rule>

<rule ref="WordPress.WP.I18n.NonSingularStringLiteralText">
<!-- False positive. This has already been fixed in WPCS.
The fix will be included in WPCS 1.0.0.
Once this repo moves up to using WPCS 1.0.0, this exclusion can be removed.
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/pull/1267
-->
<exclude-pattern>/tests/doubles/WPCoreFunctionsMock\.php$</exclude-pattern>
</rule>

<rule ref="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound">
<!-- These hook setups should be reviewed.
Ticket: https://github.com/Yoast/whip/issues/67 -->
<exclude-pattern>/src/Whip_Host\.php$</exclude-pattern>
</rule>

<!-- Tests should be documented too.
Ticket: https://github.com/Yoast/whip/issues/66 -->
<rule ref="Generic.Commenting.DocComment.MissingShort">
<exclude-pattern>/tests/*\.php$</exclude-pattern>
</rule>
<rule ref="Generic.Commenting.DocComment.SpacingBeforeTags">
<exclude-pattern>/tests/*\.php$</exclude-pattern>
</rule>
<rule ref="Squiz.Commenting.FunctionComment.Missing">
<exclude-pattern>/tests/*\.php$</exclude-pattern>
</rule>
<rule ref="Squiz.Commenting.FunctionComment.MissingParamTag">
<exclude-pattern>/tests/*\.php$</exclude-pattern>
</rule>

</ruleset>
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ matrix:
fast_finish: true
include:
- php: 7.2
env: PHPCS=1
- php: 5.2
dist: precise
- php: 5.3
Expand All @@ -35,7 +36,8 @@ before_install:

install:
- if [[ $TRAVIS_PHP_VERSION == "5.2" || $TRAVIS_PHP_VERSION == "5.3" ]]; then phpenv local 5.3.29; fi
- if [[ "$TRAVIS_PHP_VERSION" == "5.2" ]]; then composer remove --dev phpunit/phpunit; fi
- if [[ $TRAVIS_PHP_VERSION == "5.2" || $TRAVIS_PHP_VERSION == "5.3" ]]; then composer remove --dev yoast/yoastcs dealerdirect/phpcodesniffer-composer-installer; fi
- if [[ $TRAVIS_PHP_VERSION == "5.2" ]]; then composer remove --dev phpunit/phpunit; fi
- composer install --prefer-dist --no-interaction
- if [[ $TRAVIS_PHP_VERSION == "5.2" || $TRAVIS_PHP_VERSION == "5.3" ]]; then phpenv local --unset; fi

Expand All @@ -44,3 +46,4 @@ script:
- find -L . -path ./vendor -prune -o -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l
- if [[ "$TRAVIS_PHP_VERSION" == "5.2" ]]; then phpunit; else ./vendor/bin/phpunit; fi
- if [[ "$TRAVIS_PHP_VERSION" != "5.2" ]]; then composer validate --no-check-all; fi
- if [[ $PHPCS == "1" ]]; then vendor/bin/phpcs --runtime-set ignore_warnings_on_exit 1; fi
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
"name": "yoast/whip",
"description": "A WordPress package to nudge users to upgrade their software versions (starting with PHP)",
"type": "library",
"require-dev": {
"phpunit/phpunit": "^3.6.12 | ^4.5 | ^5.7",
"roave/security-advisories": "dev-master"
},
"license": "GPL-3.0-or-later",
"authors": [
{
Expand All @@ -24,6 +20,12 @@
"require": {
"xrstf/composer-php52": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^3.6.12 | ^4.5 | ^5.7",
"roave/security-advisories": "dev-master",
"yoast/yoastcs": "~0.5.0",
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.3"
},
"scripts": {
"post-install-cmd": [
"xrstf\\Composer52\\Generator::onPostInstallCmd"
Expand Down