Captains Log - WebDevStudios/php-coding-standards GitHub Wiki
@see
#wdscodingstandards Follow along on Twitter.
09.29.2020
TLDR
- Finding our options for using Prettier with PHP are slim, may have to look into maybe using
php-cs-fixer
instead
Notes
Okay, now that I have JS out of the way, time to start doing the same with PHP...
- https://github.com/prettier/plugin-php is an NPM package, not a composer one, which makes this tricky as I don't want to give DEVs another package to install
- Created a new NPM package intended to be a config for
*.php
files, only to find out that in yourprettier
setting, it can't be anarray
, so I can't do e.g.[ "@webdevstudios/prettier-config-js-coding-standards", "@webdevstudios/prettier-config-php-coding-standards" ]
to load JS and PHP- There are a couple ways to fix this issue, one is to have combo-packages, e.g.
@webdevstudios/prettier-config-js-php-coding-standards
which will, e.g. inindex.js
do something like:
- There are a couple ways to fix this issue, one is to have combo-packages, e.g.
module.exports = {
require( '@webdevstudios/prettier-config-js-coding-standards' ),
require( '@webdevstudios/prettier-config-php-coding-standards' ),
};
...which will load both JS and PHP configs... But that requires up to four combo packages for:
- js+php
- css+php
- css+js+php (all)
- css+js
The other way to handle this is to have an all package, essentially @webdevstudios/prettier-config-coding-standards
which will:
module.exports = {
require( '@webdevstudios/prettier-config-js-coding-standards' ),
require( '@webdevstudios/prettier-config-php-coding-standards' ),
require( '@webdevstudios/prettier-config-css-coding-standards' ),
};
...require and load all configs.
The other option is to instruct someone to NOT use the package.json:prettier
option and instead create a .prettierrc.js
file that will have:
module.exports = {
require( '@webdevstudios/prettier-config-js-coding-standards' ),
require( '@webdevstudios/prettier-config-php-coding-standards' ),
require( '@webdevstudios/prettier-config-css-coding-standards' ),
};
...and you can pick and choose which one's you want to have loaded.
I think the best option is the 2nd one, where we have an all package, @webdevstudios/prettier-config-coding-standards
and maybe in index.js
we can do some conditional module loading depending on what you have installed, e.g.
If you installed @webdevstudios/js-coding-standards
we would have:
module.exports = {
require.resolve( '@webdevstudios/prettier-config-js-coding-standards' ),
require.resolve( '@webdevstudios/prettier-config-php-coding-standards' ),
};
So, if you had @webdevstudios/prettier-config-js-coding-standards
installed, because you installed @webdevstudios/js-coding-standards
it would load that config.
Of course I do not know if require.resolve will work that way but because index.js
is a JS file, I can write some functions maybe...
- Okay, this package now exists: https://www.npmjs.com/package/@webdevstudios/prettier-config-coding-standards and is now on js-coding-standards: https://www.npmjs.com/package/@webdevstudios/js-coding-standards#121
I'm finding that the Prettier for PHP options are slim, and that we might not be able to use it, may need to look into php-cs-fixer
instead.
See https://github.com/WebDevStudios/js-coding-standards/wiki/Captains-Log#09292020 for more details