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

Update code standards, add misc dev files, make linting more good-er #851

Closed
wants to merge 16 commits into from
Closed
26 changes: 26 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# http://editorconfig.org
root = true

[*]
indent_style = tab
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 120
quote_type = single

[*.php]
indent_size = 4

[*.json]
indent_style = space
indent_size = 4

[*.yml]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:

- uses: technote-space/get-diff-action@v6
with:
SUFFIX_FILTER: .php
PATTERNS: '**.php'

- name: Get Composer cache directory
id: composer-cache
Expand All @@ -59,5 +59,5 @@ jobs:
if: "!! env.GIT_DIFF"

- name: Detecting PHP Code Standards Violations
run: vendor/bin/phpcs --standard=phpcs.xml -s ${{ env.GIT_DIFF }}
run: composer run-script lint
if: "!! env.GIT_DIFF"
89 changes: 89 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

$config = new PhpCsFixer\Config();
$finder = PhpCsFixer\Finder::create()
->exclude([
'assets',
'bin',
'dist',
'docs',
'node_modules',
'patches',
'tests/stubs',
'vendor',
])
->in(__DIR__);

return $config->setFinder( $finder )
->setRiskyAllowed( true )
->setIndent( "\t" )
->setRules([
'align_multiline_comment' => true,
'array_indentation' => true,
'array_syntax' => [ 'syntax' => 'short' ],
'backtick_to_shell_exec' => true,
'cast_spaces' => true,
'combine_consecutive_issets' => true,
'combine_consecutive_unsets' => true,
'concat_space' => [ 'spacing' => 'one'],
'constant_case' => true,
'encoding' => true,
'full_opening_tag' => true,
'increment_style' => [ 'style' => 'post' ],
'line_ending' => true,
'logical_operators' => true,
'lowercase_cast' => true,
'lowercase_keywords' => true,
'lowercase_static_reference' => true,
'magic_constant_casing' => true,
'magic_method_casing' => true,
'multiline_comment_opening_closing' => true,
'native_function_casing' => true,
'native_function_type_declaration_casing' => true,
'no_break_comment' => true,
'no_closing_tag' => true,
'no_empty_comment' => true,
'no_empty_phpdoc' => true,
'no_empty_statement' => true,
'no_extra_blank_lines' => true,
'no_homoglyph_names' => true,
'no_leading_import_slash' => true,
'no_leading_namespace_whitespace' => true,
'no_mixed_echo_print' => [ 'use' => 'echo' ],
'no_null_property_initialization' => true,
'no_short_bool_cast' => true,
'no_superfluous_elseif' => true,
'no_trailing_comma_in_singleline_array' => true,
'no_trailing_whitespace' => true,
'no_unset_cast' => true,
'no_unused_imports' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'no_whitespace_in_blank_line' => true,
'non_printable_character' => true,
'normalize_index_brace' => true,
'not_operator_with_successor_space' => true,
'operator_linebreak' => true,
'ordered_imports' => [ 'sort_algorithm' => 'alpha', 'imports_order' => [ 'class', 'const', 'function' ] ],
'phpdoc_align' => true,
'phpdoc_indent' => true,
'phpdoc_no_empty_return' => true,
'phpdoc_scalar' => true,
'phpdoc_separation' => true,
'phpdoc_summary' => true,
'phpdoc_tag_casing' => true,
'phpdoc_trim_consecutive_blank_line_separation' => true,
'phpdoc_trim' => true,
'phpdoc_order' => true,
'psr_autoloading' => true,
'short_scalar_cast' => true,
'single_blank_line_at_eof' => true,
'single_import_per_statement' => true,
'single_line_after_imports' => true,
'single_quote' => [ 'strings_containing_single_quote_chars' => false ],
'standardize_increment' => true,
'standardize_not_equals' => true,
'ternary_operator_spaces' => true,
'whitespace_after_comma_in_array' => true,
'yoda_style' => true,
]);
78 changes: 78 additions & 0 deletions .phpcs.dist.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<ruleset name="Bluehost-Plugin">
<!-- Usage instructions: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage -->
<!-- Annotated ruleset: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml -->

<!-- - - - - - - - - - -->
<!-- Files to process -->
<!-- - - - - - - - - - -->

<!-- What to scan: -->
<file>./bluehost-wordpress-plugin.php</file> <!-- Main plugin file.-->
<file>./inc</file> <!-- The rest of the plugin files. -->

<!-- What to ignore: -->
<exclude-pattern>./assets</exclude-pattern>
<exclude-pattern>./build</exclude-pattern>

<!-- - - - - - - - - - -->
<!-- Configuration -->
<!-- - - - - - - - - - -->

<!-- Show progresss & use colors. -->
<arg value="sp"/>
<arg name="colors"/>

<!-- Enables parallel processing when available for faster results. -->
<arg name="parallel" value="8"/>

<!-- Strip the file paths down to the relevant bit and only apply to .php files. -->
<arg name="basepath" value="./"/>
<arg name="extensions" value="php"/>

<!-- Minimum versions required. -->
<config name="testVersion" value="7.0-"/>
<config name="minimum_supported_wp_version" value="5.0"/>

<!-- - - - - - - - - - -->
<!-- Rules -->
<!-- - - - - - - - - - -->

<!-- No PHP syntax errors. -->
<rule ref="Generic.PHP.Syntax"/>

<!-- See https://github.com/newfold-labs/wp-php-standards for more info. -->
<rule ref="Newfold"/>

<!-- Disallow long array syntax. -->
<rule ref="Generic.Arrays.DisallowLongArraySyntax" />

<!-- Namespacing required for classes. -->
<rule ref="PSR1.Classes.ClassDeclaration" />

<!-- WordPress Coding Standards that we don't want to enforce. -->
<rule ref="WordPress-Core">
<exclude name="Universal.Arrays.DisallowShortArraySyntax.Found" />
<exclude name="WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid"/>
<exclude name="WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase"/>
<exclude name="WordPress.Files.FileName.InvalidClassFileName"/>
<exclude name="WordPress.Files.FileName.NotHyphenatedLowercase"/>
</rule>

<!-- Make sure our text is localized with the correct text domain. -->
<rule ref="WordPress.WP.I18n">
<properties>
<property name="text_domain" type="array" value="wp-plugin-bluehost" />
</properties>
</rule>

<!-- Commenting standards. -->
<rule ref="Generic.Commenting.Todo.CommentFound">
<message>Please review this TODO comment: %s</message>
<severity>3</severity>
</rule>

<!-- Gotta end those inline comments with a period. -->
<rule ref="Squiz.Commenting.InlineComment.InvalidEndChar">
<type>warning</type>
</rule>
</ruleset>
19 changes: 8 additions & 11 deletions bluehost-wordpress-plugin.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php
/**
* Bluehost WordPress Plugin
* Bluehost WordPress Plugin.
*
* @package WPPluginBluehost
*
* @author Newfold Digital
* @copyright Copyright 2024 by Newfold Digital - All rights reserved.
* @license GPL-2.0-or-later
Expand Down Expand Up @@ -36,22 +37,18 @@
define( 'BLUEHOST_PLUGIN_FILE', __FILE__ );
define( 'BLUEHOST_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'BLUEHOST_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'BLUEHOST_BUILD_DIR', BLUEHOST_PLUGIN_DIR . 'build/' . BLUEHOST_PLUGIN_VERSION );
define( 'BLUEHOST_BUILD_URL', BLUEHOST_PLUGIN_URL . 'build/' . BLUEHOST_PLUGIN_VERSION );
if ( ! defined( 'NFD_HIIVE_URL' ) ) {
define( 'NFD_HIIVE_URL', 'https://hiive.cloud/api' );
}

// Load alternate experience and short-circuit plugin functionality.
if ( defined( 'BURST_SAFETY_MODE' ) && BURST_SAFETY_MODE ) {

// Load alternate experience
require __DIR__ . '/inc/alt-experience/init.php';

// Short-circuit all plugin functionality
return;
}

define( 'BLUEHOST_BUILD_DIR', BLUEHOST_PLUGIN_DIR . 'build/' . BLUEHOST_PLUGIN_VERSION );
define( 'BLUEHOST_BUILD_URL', BLUEHOST_PLUGIN_URL . 'build/' . BLUEHOST_PLUGIN_VERSION );

global $pagenow;
if ( 'plugins.php' === $pagenow ) {

Expand All @@ -69,15 +66,15 @@
require_once BLUEHOST_PLUGIN_DIR . '/inc/plugin-nfd-compat-check.php';
$nfd_plugins_check = new NFD_Plugin_Compat_Check( BLUEHOST_PLUGIN_FILE );
// Defer to Incompatible plugin, self-deactivate
$nfd_plugins_check->incompatible_plugins = array();
$nfd_plugins_check->incompatible_plugins = [];
// Deactivate legacy plugin
$nfd_plugins_check->legacy_plugins = array(
$nfd_plugins_check->legacy_plugins = [
'The MOJO Marketplace' => 'mojo-marketplace-wp-plugin/mojo-marketplace.php',
'The MOJO Plugin' => 'wp-plugin-mojo/wp-plugin-mojo.php',
'The HostGator Plugin' => 'wp-plugin-hostgator/wp-plugin-hostgator.php',
'The Web.com Plugin' => 'wp-plugin-web/wp-plugin-web.php',
'The Crazy Domains Plugin' => 'wp-plugin-web/wp-plugin-crazy-domains.php',
);
];
// Check plugin requirements
$pass_nfd_check = $nfd_plugins_check->check_plugin_requirements();

Expand Down
Loading
Loading