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 PHPCS default rule set #161

Merged
merged 10 commits into from
Jul 29, 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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ The following files are also included unless the `--skip-tests` is used:
* `bin/install-wp-tests.sh` configures the WordPress test suite and a test database.
* `tests/bootstrap.php` is the file that makes the current plugin active when running the test suite.
* `tests/test-sample.php` is a sample file containing test cases.
* `phpcs.xml.dist` is a collection of PHP_CodeSniffer rules.
* `.phpcs.xml.dist` is a collection of PHP_CodeSniffer rules.

**OPTIONS**

Expand Down Expand Up @@ -288,7 +288,7 @@ The following files are generated by default:
* `bin/install-wp-tests.sh` configures the WordPress test suite and a test database.
* `tests/bootstrap.php` is the file that makes the current plugin active when running the test suite.
* `tests/test-sample.php` is a sample file containing the actual tests.
* `phpcs.xml.dist` is a collection of PHP_CodeSniffer rules.
* `.phpcs.xml.dist` is a collection of PHP_CodeSniffer rules.

Learn more from the [plugin unit tests documentation](https://make.wordpress.org/cli/handbook/plugin-unit-tests/).

Expand Down Expand Up @@ -426,7 +426,7 @@ The following files are generated by default:
* `bin/install-wp-tests.sh` configures the WordPress test suite and a test database.
* `tests/bootstrap.php` is the file that makes the current theme active when running the test suite.
* `tests/test-sample.php` is a sample file containing the actual tests.
* `phpcs.xml.dist` is a collection of PHP_CodeSniffer rules.
* `.phpcs.xml.dist` is a collection of PHP_CodeSniffer rules.

Learn more from the [plugin unit tests documentation](https://make.wordpress.org/cli/handbook/plugin-unit-tests/).

Expand Down
2 changes: 1 addition & 1 deletion features/scaffold-plugin-tests.feature
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Feature: Scaffold plugin unit tests
"""
<exclude>./tests/test-sample.php</exclude>
"""
And the {PLUGIN_DIR}/hello-world/phpcs.xml.dist file should exist
And the {PLUGIN_DIR}/hello-world/.phpcs.xml.dist file should exist
And the {PLUGIN_DIR}/hello-world/circle.yml file should not exist
And the {PLUGIN_DIR}/hello-world/.circleci directory should not exist
And the {PLUGIN_DIR}/hello-world/bitbucket-pipelines.yml file should not exist
Expand Down
2 changes: 1 addition & 1 deletion features/scaffold-theme-tests.feature
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Feature: Scaffold theme unit tests
"""
<exclude>./tests/test-sample.php</exclude>
"""
And the {THEME_DIR}/p2child/phpcs.xml.dist file should exist
And the {THEME_DIR}/p2child/.phpcs.xml.dist file should exist
And the {THEME_DIR}/p2child/circle.yml file should not exist
And the {THEME_DIR}/p2child/.circleci directory should not exist
And the {THEME_DIR}/p2child/bitbucket-pipelines.yml file should not exist
Expand Down
7 changes: 5 additions & 2 deletions features/scaffold.feature
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,12 @@ Feature: WordPress code scaffolding
.git
.gitignore
"""
And the {PLUGIN_DIR}/hello-world/phpcs.xml.dist file should contain:
And the {PLUGIN_DIR}/hello-world/.phpcs.xml.dist file should contain:
"""
<rule ref="PHPCompatibilityWP"/>
"""
And the {PLUGIN_DIR}/hello-world/.phpcs.xml.dist file should contain:
"""
<rule ref="PHPCompatibility"/>
<config name="testVersion" value="5.3-"/>
"""
And the {PLUGIN_DIR}/hello-world/hello-world.php file should contain:
Expand Down
8 changes: 4 additions & 4 deletions src/Scaffold_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ private function get_output_path( $assoc_args, $subdir ) {
* * `bin/install-wp-tests.sh` configures the WordPress test suite and a test database.
* * `tests/bootstrap.php` is the file that makes the current plugin active when running the test suite.
* * `tests/test-sample.php` is a sample file containing test cases.
* * `phpcs.xml.dist` is a collection of PHP_CodeSniffer rules.
* * `.phpcs.xml.dist` is a collection of PHP_CodeSniffer rules.
*
* ## OPTIONS
*
Expand Down Expand Up @@ -706,7 +706,7 @@ function plugin( $args, $assoc_args ) {
* * `bin/install-wp-tests.sh` configures the WordPress test suite and a test database.
* * `tests/bootstrap.php` is the file that makes the current plugin active when running the test suite.
* * `tests/test-sample.php` is a sample file containing the actual tests.
* * `phpcs.xml.dist` is a collection of PHP_CodeSniffer rules.
* * `.phpcs.xml.dist` is a collection of PHP_CodeSniffer rules.
*
* Learn more from the [plugin unit tests documentation](https://make.wordpress.org/cli/handbook/plugin-unit-tests/).
*
Expand Down Expand Up @@ -759,7 +759,7 @@ public function plugin_tests( $args, $assoc_args ) {
* * `bin/install-wp-tests.sh` configures the WordPress test suite and a test database.
* * `tests/bootstrap.php` is the file that makes the current theme active when running the test suite.
* * `tests/test-sample.php` is a sample file containing the actual tests.
* * `phpcs.xml.dist` is a collection of PHP_CodeSniffer rules.
* * `.phpcs.xml.dist` is a collection of PHP_CodeSniffer rules.
*
* Learn more from the [plugin unit tests documentation](https://make.wordpress.org/cli/handbook/plugin-unit-tests/).
*
Expand Down Expand Up @@ -889,7 +889,7 @@ private function scaffold_plugin_theme_tests( $args, $assoc_args, $type ) {
$to_copy = array(
'install-wp-tests.sh' => $bin_dir,
'phpunit.xml.dist' => $target_dir,
'phpcs.xml.dist' => $target_dir,
'.phpcs.xml.dist' => $target_dir,
);

foreach ( $to_copy as $file => $dir ) {
Expand Down
48 changes: 48 additions & 0 deletions templates/.phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0"?>
<ruleset name="WordPress Coding Standards based custom ruleset for your plugin">
<description>Generally-applicable sniffs for WordPress plugins.</description>

<!-- What to scan -->
<file>.</file>
<exclude-pattern>/vendor/</exclude-pattern>

<!-- How to scan -->
<!-- Usage instructions: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage -->
<!-- Annotated ruleset: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml -->
<arg value="sp"/> <!-- Show sniff and progress -->
<arg name="basepath" value="./"/><!-- Strip the file paths down to the relevant bit -->
<arg name="colors"/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="8"/><!-- Enables parallel processing when available for faster results. -->

<!-- Rules: Check PHP version compatibility -->
<!-- https://github.com/PHPCompatibility/PHPCompatibility#sniffing-your-code-for-compatibility-with-specific-php-versions -->
<config name="testVersion" value="5.3-"/>
<!-- https://github.com/PHPCompatibility/PHPCompatibilityWP -->
<rule ref="PHPCompatibilityWP"/>

<!-- Rules: WordPress Coding Standards -->
<!-- https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards
<!-- https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties -->
<config name="minimum_supported_wp_version" value="4.6"/>
<rule ref="WordPress">
<exclude name="WordPress.VIP"/>
</rule>
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<properties>
<!-- Value: replace the function, class, and variable prefixes used. Separate multiple prefixes with a comma. -->
<property name="prefixes" type="array" value="my-plugin"/>
</properties>
</rule>
<rule ref="WordPress.WP.I18n">
<properties>
<!-- Value: replace the text domain used. -->
<property name="text_domain" type="array" value="my-plugin"/>
</properties>
</rule>
<rule ref="WordPress.WhiteSpace.ControlStructureSpacing">
<properties>
<property name="blank_line_check" value="true"/>
</properties>
</rule>
</ruleset>
20 changes: 0 additions & 20 deletions templates/phpcs.xml.dist

This file was deleted.

2 changes: 2 additions & 0 deletions templates/plugin-distignore.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ phpunit.xml
phpunit.xml.dist
multisite.xml
multisite.xml.dist
.phpcs.xml
phpcs.xml
.phpcs.xml.dist
phpcs.xml.dist
README.md
wp-cli.local.yml
Expand Down