Skip to content

Commit

Permalink
Update ruleset and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
wpscholar committed Jun 16, 2023
1 parent 5c5ef21 commit 9c50eb4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.lock
/vendor
14 changes: 11 additions & 3 deletions WPScholar/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

<arg name="colors"/>

<config name="testVersion" value="5.6-"/>
<!-- Sets the supported PHP version range. -->
<config name="testVersion" value="7.0-"/>

<!-- Sets the minimum supported WP version to 5.2, which requires PHP 5.6. -->
<config name="minimum_supported_wp_version" value="5.2"/>
<!-- Sets the minimum supported WP version to 5.8, which requires PHP 5.6+ -->
<config name="minimum_supported_wp_version" value="5.8"/>

<!-- For CI, don't fail on warnings -->
<config name="ignore_warnings_on_exit" value="1"/>
Expand Down Expand Up @@ -87,4 +88,11 @@
<!-- Loads the PHP Compatibility ruleset. -->
<rule ref="PHPCompatibilityWP"/>

<!-- Throws Warnings for TODO comments in PHP and JS -->
<rule ref="Generic.Commenting.Todo"/>
<rule ref="Generic.Commenting.Todo.CommentFound">
<message>Please review this TODO comment: %s</message>
<severity>3</severity>
</rule>

</ruleset>
12 changes: 8 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@
"email": "[email protected]"
}
],
"require": {
"require-dev": {
"squizlabs/php_codesniffer": "@stable",
"phpcompatibility/php-compatibility": "@stable",
"wp-coding-standards/wpcs": "@stable",
"dealerdirect/phpcodesniffer-composer-installer": "@stable",
"phpcompatibility/phpcompatibility-wp": "@stable"
"phpcompatibility/phpcompatibility-wp": "@stable",
"dealerdirect/phpcodesniffer-composer-installer": "@stable"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
25 changes: 20 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

An advanced configuration of the WordPress coding standards for plugin and theme development.

This ruleset is configured to support WordPress version 5.2+ and PHP version 5.6+.
This ruleset is configured to support WordPress version 5.8+ and PHP version 7.0+.

## Usage

- Install [Composer](https://getcomposer.org/)
- Run `composer init` to setup Composer for your project.
- Run `composer init` to set up Composer for your project.
- Run `composer require wpscholar/phpcs-standards-wpscholar` to install the coding standards.
- Run `vendor/bin/phpcs . --standard=WPScholar` from your project root to check your code.
- Optionally, add a script to your `composer.json` file so you can just run `composer run lint` to check your code.
Expand All @@ -16,25 +16,40 @@ This ruleset is configured to support WordPress version 5.2+ and PHP version 5.6
"scripts": {
"lint": [
"vendor/bin/phpcs . --standard=WPScholar"
],
"clean": [
"vendor/bin/phpcbf . --standard=Newfold"
]
}
```

## Additional Notes
- Append the `-s` flag to see the internal names of the rules.
- Add `--runtime-set testVersion 5.2-` to check PHP version 5.2 or greater.
- Add `--runtime-set testVersion 8.0-` to check PHP version 8.0 or greater.
- Add a custom `phpcs.xml` file to your project to customize the ruleset or your desired configuration.

```xml
<?xml version="1.0"?>
<ruleset name="Project Rules">
<rule ref="WPScholar" />
<config name="testVersion" value="5.2-"/>
<config name="minimum_supported_wp_version" value="4.7"/>
<config name="testVersion" value="7.0-"/>
<config name="minimum_supported_wp_version" value="5.8"/>
</ruleset>
```

### Additional Documentation
- https://github.com/squizlabs/PHP_CodeSniffer
- https://github.com/PHPCompatibility/PHPCompatibilityWP
- https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards

## IDE Integration

Some IDE integrations of PHPCS will fail to register your ruleset since it doesn't live in your project root. In order
to rectify this, place phpcs.xml at your project root:

```xml
<?xml version="1.0"?>
<ruleset name="Project Rules">
<rule ref="WPScholar"/>
</ruleset>
```

0 comments on commit 9c50eb4

Please sign in to comment.