WPBP / WordPress-Plugin-Boilerplate-Powered

Wordpress Plugin Boilerplate but Powered with examples and a generator!
https://wpbp.github.io/
GNU General Public License v3.0
782 stars 116 forks source link

Strongly typed js - updates wp-packages - babel, prettier and eslint configuration enhancements #232

Closed erikyo closed 1 year ago

erikyo commented 1 year ago

This pull request enables strongly typed JavaScript, updates the NPM dependencies used in the WordPress Plugin Boilerplate Powered project to their latest versions and, in addition, adds the configurations of eslint, stylelint, prettier to the package.json (and applies it).

The following packages were changed/updated, some have been removed because already part of other packages and would only risk conflicting dependencies: ➖ @babel/core ➕ @types/jquery: 3.5.16 ➖ @wordpress/browserslist-config: 4.1.2 ➖ @wordpress/eslint-plugin: 12.5.0 ⬆️ @wordpress/scripts: 23.2.0 -> 24.6.0 ➖ @wordpress/blocks: 11.10.0 ⬆️ @wordpress/block-editor: 9.8.0 ➕ typescript: 5.0.4

➕ Babel, Stylelint and Prettier configuration were added to the package.json

➕ 2 additional scripts publish (a shortcut to build and prepare the plugin zip) and wp-env which starts the plugin in a local WordPress environment for creating and testing plugins.

The code changes were tested locally and confirmed to be working as expected. Please review and merge this Pull Request if everything looks good.

erikyo commented 1 year ago

I can revert the package.json back be formatted with spaces but I think the current .editorconfig is conflicting with the wordpress-dev one, my suggestion is to update it to something like:

# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

# WordPress Coding Standards
# https://make.wordpress.org/core/handbook/coding-standards/

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab

[{*.yml,*.neon}]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false

[{*.txt,wp-config-sample.php}]
end_of_line = crlf

[{LICENSE.txt,README.txt}]
indent_style = space
end_of_line = lf

@Mte90 what do you think?

Mte90 commented 1 year ago

Maybe we can do an exception just for the .json file as there is already for neon/yml.

Right now already has that exception https://github.com/WPBP/WordPress-Plugin-Boilerplate-Powered/blob/master/plugin-name/.editorconfig#L37 probably I did to avoid issues with CI so can be updated for those needs.

erikyo commented 1 year ago

I guess the exception for .json files isn't even needed since the rule would fallback to the {*} (the main one to be clear), and that rule will cover all the other files like the newer tsconfig.json. So it would suffice to delete the rules for "composer.json,composer.lock,package.json" that are currently forcing spaces for jsons that are not convenient in that context.

I would also suggest to remove the code below because isn't part of the .editorconfig specification

block_comment_start = /*
block_comment = *
block_comment_end = */

Furthermore I suggest to remove also this one, isn't useful for a plugin

[{wp-config-sample.php}]
end_of_line = crlf

Last but not the least I advice to remove "/assets/build/*,/assets/src/block/.json" from the rules below, because the generated files usually aren't checked/testes with the ci (but i may be wrong)

[{/tests/_data/*.sql,/tests/_support/_generated/**}]
charset = unset
end_of_line = unset
insert_final_newline = unset
trim_trailing_whitespace = unset
indent_style = space
indent_size = unset
Mte90 commented 1 year ago

So just do those changes in this pr and let's see the editorconfig validation what says about it.

Mte90 commented 1 year ago

So now codacy reports the missing use of doublequote, just fix that and we can go.

For editorconfig I need a pr to understand the effect on the whole codebase.