2
0
Fork 0
mirror of https://github.com/discourse/wp-discourse.git synced 2025-10-03 08:59:21 +08:00
wp-discourse/docs/FORMATTING.md
Angus McLeod deacab2662
Update and improve webhooks (#519)
* Update and improve webhooks

Changes:
- Add email matching as an identification basis for Update Userdata webhook.
- Standardise webhook data processing and responses.
- Add get_discourse_webhook_data utility method.
- Improve Webhook admin panel UX and descriptions.

Misc:
- Update phpcs usage

* Fix php 5.6 and 7.0 syntax checks

* Fix phpcs issues arising from update

* Remove ineffective nbsp from admin page
2024-06-19 09:08:22 -07:00

2.2 KiB

WP Discourse Code Formatting Guide

WP Discourse uses

  • PHP_CodeSniffer to handle code formatting (phpcs);
  • the native PHP syntax checker; and
  • jshint for javascript.

These formatters will be applied on each pull request in Github Actions (via .github/workflows/ci.yml), so make sure you run them locally before making your PR.

PHPCS

The phpcs configuration is handled in the .phpcs.xml file, a type of Annotated Ruleset. Install the development composer packages by running composer install prior to using phpcs, and run it using vendor/bin/phpcs, for example

vendor/bin/phpcs lib/discourse-publish.php

All errors must be addressed, and all warnings should be addressed as far as possible. You can attempt to fix any issues automatically using phpcbf. If using phpcbf

  1. Make sure your working tree is clean as you may wish to revert the results (in some cases it can create more issues than it solves)

  2. Only use phpcbf on a file by file basis.

Native Syntax Check

The .github/workflows/ci.yml applies a syntax check for each supported version of PHP by searching for all .php files in the repository, running the relevant version of the PHP interpreter, and catching syntax errors via xargs:

find -L . -name '*.php' -not -path "./vendor/*" -not -path "./tests/*" -print0 | xargs -0 -n 1 -P 4 php -l

To perform this locally:

  1. First, check the PHP version "matrix" in .github/workflows/ci.yml to see which versions we are currently testing.

  2. Then you'll need a local build of each PHP version. You can install different PHP versions using phpbrew or phpenv (we may include a phpenv setup in the project in the future).

  3. Finally run the above command using each PHP version in the matrix.

All errors must be fixed, even if they are not in a file required in production, and all warnings must be addressed as far as possible.

JSHint

First, install jshint globally on your machine

npm install -g jshint

Then run it in the wp-discourse directory

jshint .