Skip to content

Commit

Permalink
Merge branch 'feature/code-standards' into feature/code-standards-cle…
Browse files Browse the repository at this point in the history
…anup
  • Loading branch information
bradp committed Dec 5, 2023
2 parents 04bb07f + 92c02db commit 6f76277
Show file tree
Hide file tree
Showing 7 changed files with 1,852 additions and 198 deletions.
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ indent_style = space
indent_size = 4

[*.yml]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
8 changes: 7 additions & 1 deletion .phpcs.dist.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0"?>
<ruleset name="Bluehost-Plugin">
<!-- How to scan? See ./docs/coding-standards.md for instructions. -->
<!-- Usage instructions: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage -->
<!-- Annotated ruleset: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml -->

Expand Down Expand Up @@ -45,8 +44,15 @@
<!-- 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"/>
Expand Down
21 changes: 15 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,16 @@
}
},
"scripts": {
"fix": "./vendor/bin/phpcbf --standard=./.phpcs.dist.xml",
"lint": "./vendor/bin/phpcs --standard=./.phpcs.dist.xml",
"fix": "@fix:standards",
"fix:standards": [
"./vendor/bin/phpcbf --standard=./.phpcs.dist.xml",
"PHP_CS_FIXER_IGNORE_ENV=true ./vendor/bin/php-cs-fixer fix -v --diff"
],
"test": "@test:standards",
"test:standards": [
"./vendor/bin/phpcs --standard=./.phpcs.dist.xml",
"PHP_CS_FIXER_IGNORE_ENV=true ./vendor/bin/php-cs-fixer fix -v --diff --dry-run"
],
"i18n": [
"vendor/bin/wp i18n make-pot . ./languages/bluehost-wordpress-plugin.pot --headers=Report-Msgid-Bugs-To:https://github.com/bluehost/bluehost-wordpress-plugin/issues --exclude=assets,storybook,tests,src",
"vendor/bin/wp i18n make-pot . ./languages/bluehost-wordpress-plugin.pot --headers=POT-Creation-Date:null --exclude=assets,storybook,tests,src"
Expand All @@ -50,13 +58,14 @@
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "@stable",
"roave/security-advisories": "dev-latest",
"friendsofphp/php-cs-fixer": "^2.19",
"newfold-labs/wp-php-standards": "^1.2",
"phpcompatibility/phpcompatibility-wp": "@stable",
"roave/security-advisories": "dev-latest",
"squizlabs/php_codesniffer": "@stable",
"wp-cli/i18n-command": "^2.4.4",
"wp-coding-standards/wpcs": "^3.0",
"wp-phpunit/wp-phpunit": "^6.3.1",
"squizlabs/php_codesniffer": "@stable",
"phpcompatibility/phpcompatibility-wp": "@stable"
"wp-phpunit/wp-phpunit": "^6.3.1"
},
"require": {
"newfold-labs/wp-module-business-reviews": "^1.1.1",
Expand Down
Loading

0 comments on commit 6f76277

Please sign in to comment.