mongoose-marketplace / facebook-page-feed-graph-api

It's time to upgrade from your old like box! Display the Facebook Page Plugin from the Graph API using a shortcode or widget.
GNU General Public License v2.0
4 stars 1 forks source link

Add CI with WP-Core code sniffs. #37

Open peterwilsoncc opened 7 years ago

peterwilsoncc commented 7 years ago

Add either Travis CI or Circle CI with code sniffs against the WP-Core coding standards.

Running phpcs the WP coding standards produces a number of errors, most of which can be fixed automatically with phpcbf.

I've got both Travis and Cirlce set up in my theme repo with a phpcs config file. You'll need to swap out the HM styles in my config with the WP-Core standards.

cameronjonesweb commented 7 years ago

Thanks for that @peterwilsoncc.

I've done a bit of research into Travis but I'm not sure where to start. Is there some sort of tutorial or resource you could point me to? There's a few things I'm uncertain on, like for instance if phpcbf is meant to fix some things automatically, how do they get back into the repo? Does it just give me a report or can it commit back in

peterwilsoncc commented 7 years ago

There's some documentation to run the sniffs on Travis CI in the project.

To use phpcbf to automatically fix what you can, you need to run the code locally. The easiest way to get set up is to install composer and use the guide for installing via composer.

Doing some tests, I found the custom ruleset that follows to get best results. It needs to be saved as phpcs.xml in your root directory.

To code sniff run: wpcs/vendor/bin/phpcs . -v --standard=phpcs.xml

To fix: wpcs/vendor/bin/phpcbf . -v --standard=phpcs.xml

On travis CI, replace the suggested line with the custom ruleset.

Feel free to reach out to me or @bronsonquick on the wpaus slack if you have any questions.

<?xml version="1.0"?>
<ruleset name="Example Project">
    <description>A custom set of rules to check for a WPized WordPress project</description>

    <!-- Exclude the Composer Vendor directory. -->
    <exclude-pattern>/wpcs/*</exclude-pattern>

    <!-- Exclude the Node Modules directory. -->
    <exclude-pattern>/node_modules/*</exclude-pattern>

    <!-- Exclude minified Javascript files. -->
    <exclude-pattern>*.min.js</exclude-pattern>

    <!-- Include the WordPress-Extra standard. -->
    <rule ref="WordPress-Core">
    </rule>

    <!-- Check for PHP cross-version compatibility. -->
    <!--
    To enable this, the PHPCompatibility standard needs
    to be installed.
    See the readme for installation instructions:
    https://github.com/wimg/PHPCompatibility
    -->
    <!--
    <config name="testVersion" value="5.2-99.0"/>
    <rule ref="PHPCompatibility"/>
    -->

    <!--
    To get the optimal benefits of using WPCS, we should add a couple of
    custom properties.
    Adjust the values of these properties to fit our needs.

    For information on additional custom properties available, check out
    the wiki:
    https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties
    -->
    <rule ref="WordPress.WP.I18n">
        <properties>
            <property name="text_domain" type="array" value="facebook-page-feed-graph-api,library-facebook-page-feed-graph-api"/>
        </properties>
    </rule>

    <rule ref="WordPress.NamingConventions.PrefixAllGlobals">
        <properties>
            <property name="prefixes" type="array" value="cameronjonesweb_facebook_page_plugin,facebook_page_plugin,CJW_FBPP_PLUGIN"/>
        </properties>
    </rule>
</ruleset>