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

Add CI with WP-Core code sniffs. #37

Open
peterwilsoncc opened this issue Sep 1, 2017 · 2 comments
Open

Add CI with WP-Core code sniffs. #37

peterwilsoncc opened this issue Sep 1, 2017 · 2 comments
Assignees
Milestone

Comments

@peterwilsoncc
Copy link

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 cameronjonesweb self-assigned this Sep 6, 2017
@cameronjonesweb
Copy link
Member

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
Copy link
Author

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants