Skip to content

Commit a897a54

Browse files
authored
Merge pull request #161 from NicktheGeek/update-phpcs-rules
change to .phpcs.xml.dist and update rules
2 parents 02b57c7 + 64920e5 commit a897a54

File tree

8 files changed

+64
-31
lines changed

8 files changed

+64
-31
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ The following files are also included unless the `--skip-tests` is used:
218218
* `bin/install-wp-tests.sh` configures the WordPress test suite and a test database.
219219
* `tests/bootstrap.php` is the file that makes the current plugin active when running the test suite.
220220
* `tests/test-sample.php` is a sample file containing test cases.
221-
* `phpcs.xml.dist` is a collection of PHP_CodeSniffer rules.
221+
* `.phpcs.xml.dist` is a collection of PHP_CodeSniffer rules.
222222

223223
**OPTIONS**
224224

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

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

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

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

features/scaffold-plugin-tests.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Feature: Scaffold plugin unit tests
3939
"""
4040
<exclude>./tests/test-sample.php</exclude>
4141
"""
42-
And the {PLUGIN_DIR}/hello-world/phpcs.xml.dist file should exist
42+
And the {PLUGIN_DIR}/hello-world/.phpcs.xml.dist file should exist
4343
And the {PLUGIN_DIR}/hello-world/circle.yml file should not exist
4444
And the {PLUGIN_DIR}/hello-world/.circleci directory should not exist
4545
And the {PLUGIN_DIR}/hello-world/bitbucket-pipelines.yml file should not exist

features/scaffold-theme-tests.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Feature: Scaffold theme unit tests
3737
"""
3838
<exclude>./tests/test-sample.php</exclude>
3939
"""
40-
And the {THEME_DIR}/p2child/phpcs.xml.dist file should exist
40+
And the {THEME_DIR}/p2child/.phpcs.xml.dist file should exist
4141
And the {THEME_DIR}/p2child/circle.yml file should not exist
4242
And the {THEME_DIR}/p2child/.circleci directory should not exist
4343
And the {THEME_DIR}/p2child/bitbucket-pipelines.yml file should not exist

features/scaffold.feature

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,12 @@ Feature: WordPress code scaffolding
224224
.git
225225
.gitignore
226226
"""
227-
And the {PLUGIN_DIR}/hello-world/phpcs.xml.dist file should contain:
227+
And the {PLUGIN_DIR}/hello-world/.phpcs.xml.dist file should contain:
228+
"""
229+
<rule ref="PHPCompatibilityWP"/>
230+
"""
231+
And the {PLUGIN_DIR}/hello-world/.phpcs.xml.dist file should contain:
228232
"""
229-
<rule ref="PHPCompatibility"/>
230233
<config name="testVersion" value="5.3-"/>
231234
"""
232235
And the {PLUGIN_DIR}/hello-world/hello-world.php file should contain:

src/Scaffold_Command.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ private function get_output_path( $assoc_args, $subdir ) {
575575
* * `bin/install-wp-tests.sh` configures the WordPress test suite and a test database.
576576
* * `tests/bootstrap.php` is the file that makes the current plugin active when running the test suite.
577577
* * `tests/test-sample.php` is a sample file containing test cases.
578-
* * `phpcs.xml.dist` is a collection of PHP_CodeSniffer rules.
578+
* * `.phpcs.xml.dist` is a collection of PHP_CodeSniffer rules.
579579
*
580580
* ## OPTIONS
581581
*
@@ -706,7 +706,7 @@ function plugin( $args, $assoc_args ) {
706706
* * `bin/install-wp-tests.sh` configures the WordPress test suite and a test database.
707707
* * `tests/bootstrap.php` is the file that makes the current plugin active when running the test suite.
708708
* * `tests/test-sample.php` is a sample file containing the actual tests.
709-
* * `phpcs.xml.dist` is a collection of PHP_CodeSniffer rules.
709+
* * `.phpcs.xml.dist` is a collection of PHP_CodeSniffer rules.
710710
*
711711
* Learn more from the [plugin unit tests documentation](https://make.wordpress.org/cli/handbook/plugin-unit-tests/).
712712
*
@@ -759,7 +759,7 @@ public function plugin_tests( $args, $assoc_args ) {
759759
* * `bin/install-wp-tests.sh` configures the WordPress test suite and a test database.
760760
* * `tests/bootstrap.php` is the file that makes the current theme active when running the test suite.
761761
* * `tests/test-sample.php` is a sample file containing the actual tests.
762-
* * `phpcs.xml.dist` is a collection of PHP_CodeSniffer rules.
762+
* * `.phpcs.xml.dist` is a collection of PHP_CodeSniffer rules.
763763
*
764764
* Learn more from the [plugin unit tests documentation](https://make.wordpress.org/cli/handbook/plugin-unit-tests/).
765765
*
@@ -889,7 +889,7 @@ private function scaffold_plugin_theme_tests( $args, $assoc_args, $type ) {
889889
$to_copy = array(
890890
'install-wp-tests.sh' => $bin_dir,
891891
'phpunit.xml.dist' => $target_dir,
892-
'phpcs.xml.dist' => $target_dir,
892+
'.phpcs.xml.dist' => $target_dir,
893893
);
894894

895895
foreach ( $to_copy as $file => $dir ) {

templates/.phpcs.xml.dist

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="WordPress Coding Standards based custom ruleset for your plugin">
3+
<description>Generally-applicable sniffs for WordPress plugins.</description>
4+
5+
<!-- What to scan -->
6+
<file>.</file>
7+
<exclude-pattern>/vendor/</exclude-pattern>
8+
9+
<!-- How to scan -->
10+
<!-- Usage instructions: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage -->
11+
<!-- Annotated ruleset: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml -->
12+
<arg value="sp"/> <!-- Show sniff and progress -->
13+
<arg name="basepath" value="./"/><!-- Strip the file paths down to the relevant bit -->
14+
<arg name="colors"/>
15+
<arg name="extensions" value="php"/>
16+
<arg name="parallel" value="8"/><!-- Enables parallel processing when available for faster results. -->
17+
18+
<!-- Rules: Check PHP version compatibility -->
19+
<!-- https://github.com/PHPCompatibility/PHPCompatibility#sniffing-your-code-for-compatibility-with-specific-php-versions -->
20+
<config name="testVersion" value="5.3-"/>
21+
<!-- https://github.com/PHPCompatibility/PHPCompatibilityWP -->
22+
<rule ref="PHPCompatibilityWP"/>
23+
24+
<!-- Rules: WordPress Coding Standards -->
25+
<!-- https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards
26+
<!-- https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties -->
27+
<config name="minimum_supported_wp_version" value="4.6"/>
28+
<rule ref="WordPress">
29+
<exclude name="WordPress.VIP"/>
30+
</rule>
31+
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
32+
<properties>
33+
<!-- Value: replace the function, class, and variable prefixes used. Separate multiple prefixes with a comma. -->
34+
<property name="prefixes" type="array" value="my-plugin"/>
35+
</properties>
36+
</rule>
37+
<rule ref="WordPress.WP.I18n">
38+
<properties>
39+
<!-- Value: replace the text domain used. -->
40+
<property name="text_domain" type="array" value="my-plugin"/>
41+
</properties>
42+
</rule>
43+
<rule ref="WordPress.WhiteSpace.ControlStructureSpacing">
44+
<properties>
45+
<property name="blank_line_check" value="true"/>
46+
</properties>
47+
</rule>
48+
</ruleset>

templates/phpcs.xml.dist

Lines changed: 0 additions & 20 deletions
This file was deleted.

templates/plugin-distignore.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ phpunit.xml
2020
phpunit.xml.dist
2121
multisite.xml
2222
multisite.xml.dist
23+
.phpcs.xml
2324
phpcs.xml
25+
.phpcs.xml.dist
2426
phpcs.xml.dist
2527
README.md
2628
wp-cli.local.yml

0 commit comments

Comments
 (0)