2
0
Fork 0
mirror of https://github.com/discourse/wp-discourse.git synced 2025-08-17 18:11:19 +08:00
wp-discourse/docs/FORMATTING.md
Simon Cossar 43bd053450
Bump version to 2.2.4 (#404)
* Add base log classes

* Return maxFiles to normal level

* Use protected class variables for folder names in folder-manager

* Add unit tests for logger classes && various logger improvements

* Add log viewer

* Fix initialization sequence in LogViewer

* Add wp-discourse settings to plugin meta

* Remove metafile comments

* Add partial coverage and annotate LogViewer

* Add code coverage reporting and a tests readme

* Tests readme xdebug section formatting

* Add logging and tests to discourse-publish

This abstracts remote post components to make it possible to add consistent error and log handling. Also adds basic tests coverage for discourse-publish.

* Add successful publication test

* Add working tests for publish_after_create and publish_after_update

* Always remove test files and database upon install

* Cleanup copy and assertions for existing tests

* Final cleanup && verbose setting

* Improve structure of publish test

* Final tests, linting, security and cleanup

* PHP 7.0 Compatibility

* PHP 5.6 Compatibility

* JSHint fixes

* Update file-handler.php

* Update log viewer title

* Use older monolog and update file_handler function signatures

* Add nonce to other view_log action

* Namespace production composer packages and define build process

* Update COMPOSER.md

* Update FORMATTING.md

* Log viewer style, naming and log-refresh improvements

* Filter out all return type declarations during scoping

* JsHint: Don't use default params

* Update COMPOSER.md

* Copy fix

* Update scoper patchers notes

* Address syntax issues

- Remove >php7 syntax from non-required files
- Add phpcs pattern exclusions to phpcs.xml
- update formatting docs

* discourse-publish: address all phpcs notices and add more tests

Note: also added dealerdirect/phpcodesniffer-composer-installer to handle local requiring of codesniffer

* Handle all phpcs warnings in lib/logs

* Add todo: review phpcs exclusions to discourse-publish

* Monolog cleanup

- Remove unused monolog handlers, processors and formatters
- Add vendor_namespaced to excluded phpcs patterns

* Update CI versions to those used in composer

* Switch to using composer directly in CI actions

* Composer is packaged in shivammathur/setup-php

* Setup PHPCS via shivammathur/setup-php

* Incorrect tools key

* Use vendor/bin version of phpcs

* Install composer dependencies via ramsey/composer-install

* Update composer.lock to composer 2 and --ignore-platform-reqs

* Install lowest version of dependencies

* Move dependency-versions key

* Move composer-options key

* Exclude vendor directory from syntax checker

* Add vendor to jshintignore

* Update phpcs.xml to properly exclude js css and config files

* Address phpcs issues in log-viewer

* Fix remaining whitespace issues created in this PR

* Remove out of date sniffs and exclude specific code where necessary

* Final cleanup

* Properly escape html in log viewer

* Remove unnecessary verbiage from documentation

* Bump plugin's version to 2.2.4

Co-authored-by: Angus McLeod <angus@mcleod.org.au>
2021-05-11 15:31:24 -07:00

2.1 KiB

WP Discourse Code Formatting

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/*" -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 .