Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
6de99d4
Add PHPCS linting for PHP blocks in feature files
swissspidy Jul 23, 2026
1f954c8
Add PHPCBF support for feature files
swissspidy Jul 23, 2026
af59387
Fix PHP code style violations in feature files
swissspidy Jul 23, 2026
c8b2dd1
Preserve relative PHP code indentation during PHPCBF update
swissspidy Jul 23, 2026
f7e89ee
Preserve empty lines inside feature PHP blocks during extraction
swissspidy Jul 23, 2026
9d3728c
Enforce standard tab indentation inside feature PHP snippets
swissspidy Jul 23, 2026
d6304a3
Exclude WordPress.NamingConventions.PrefixAllGlobals from feature fil…
swissspidy Jul 23, 2026
780a76b
Exclude OO structure and global override rules from feature file sniffs
swissspidy Jul 23, 2026
b32a615
Exclude YodaConditions, empty catch, unnamed namespaces, and file hea…
swissspidy Jul 23, 2026
6a3fbc8
Address review feedback on feature file PHP checks
claude Aug 4, 2026
979fa28
Merge branch 'main' into try/phpcs-in-feature-files
swissspidy Aug 6, 2026
2c962f3
Address some code review feedback
swissspidy Aug 6, 2026
9c79335
Address code review feedback
swissspidy Aug 6, 2026
0328764
Merge branch 'main' into try/phpcs-in-feature-files
swissspidy Aug 26, 2026
3c60271
Keep the feature file round trip lossless
swissspidy Aug 26, 2026
94222b2
Make the feature file code style check work outside this package
swissspidy Aug 26, 2026
8b6fc76
Document the code style check of the PHP blocks in feature files
swissspidy Aug 26, 2026
6b61bd4
Share the parts both feature file tools agree on
swissspidy Aug 26, 2026
4ceb8a4
Share how the blocks of a feature file are found
swissspidy Aug 26, 2026
49d2f81
Share how much indentation comes off a block
swissspidy Aug 26, 2026
736b3c0
Share the scaffolding around the feature file script tests
swissspidy Aug 26, 2026
77737d8
Annotate the return types of the test scaffolding hooks
swissspidy Aug 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions bin/run-phpcbf-cleanup
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
#!/bin/sh

# Run the code style check only if a configuration file exists.
EXIT_CODE=0

# 1. Run standard PHPCBF if configuration file exists.
if [ -f ".phpcs.xml" ] || [ -f "phpcs.xml" ] || [ -f ".phpcs.xml.dist" ] || [ -f "phpcs.xml.dist" ]
then
vendor/bin/phpcbf "$@"
vendor/bin/phpcbf "$@" || EXIT_CODE=$?
fi

# 2. Run PHPCBF over extracted PHP blocks in .feature files and sync back fixes.
DIR="$(cd "$(dirname "$0")/.." && pwd)"
if [ -d "features" ] && [ -f "$DIR/utils/extract-feature-php.php" ]
then
TEMP_DIR=$(mktemp -d 2>/dev/null || mktemp -d -t 'feature_phpcbf')
trap 'rm -rf "$TEMP_DIR"' EXIT HUP INT TERM

# Fixes are only synced back when the extraction they are based on succeeded.
if php "$DIR/utils/extract-feature-php.php" extract features "$TEMP_DIR" >/dev/null
then
if [ -d "$TEMP_DIR" ] && [ "$(ls -A "$TEMP_DIR" 2>/dev/null)" ]
then
vendor/bin/phpcbf --standard=WP_CLI_CS \
--exclude=Generic.Files.InlineHTML,Generic.Files.LineEndings,WordPress.Files.FileName,Squiz.Commenting.FileComment,Universal.WhiteSpace.PrecisionAlignment,PSR2.Files.EndFileNewline,PSR2.Methods.FunctionClosingBrace,Generic.PHP.CharacterBeforePHPOpenTag,Generic.PHP.RequireStrictTypes,Squiz.WhiteSpace.SuperfluousWhitespace,WordPress.NamingConventions.PrefixAllGlobals,Universal.Files.SeparateFunctionsFromOO,Generic.Files.OneObjectStructurePerFile,WordPress.WP.GlobalVariablesOverride,Universal.Namespaces.OneDeclarationPerFile,Universal.Namespaces.DisallowCurlyBraceSyntax,WordPress.PHP.YodaConditions,Universal.Namespaces.DisallowDeclarationWithoutName,PSR12.Files.FileHeader,Generic.CodeAnalysis.EmptyStatement \
"$TEMP_DIR" >/dev/null || EXIT_CODE=$?

php "$DIR/utils/extract-feature-php.php" update features "$TEMP_DIR" >/dev/null || EXIT_CODE=$?
fi
else
EXIT_CODE=1
fi
fi

exit $EXIT_CODE
40 changes: 38 additions & 2 deletions bin/run-phpcs-tests
Original file line number Diff line number Diff line change
@@ -1,7 +1,43 @@
#!/bin/sh

# Run the code style check only if a configuration file exists.
EXIT_CODE=0

# 1. Run standard PHP code style check if a configuration file exists.
if [ -f ".phpcs.xml" ] || [ -f "phpcs.xml" ] || [ -f ".phpcs.xml.dist" ] || [ -f "phpcs.xml.dist" ]
then
vendor/bin/phpcs "$@"
vendor/bin/phpcs "$@" || EXIT_CODE=$?
fi

# 2. Run PHPCS over extracted PHP blocks in .feature files if features/ directory exists.
DIR="$(cd "$(dirname "$0")/.." && pwd)"
if [ -d "features" ] && [ -f "$DIR/utils/extract-feature-php.php" ]
then
TEMP_DIR=$(mktemp -d 2>/dev/null || mktemp -d -t 'feature_phpcs')
PHPCS_OUTPUT=$(mktemp 2>/dev/null || mktemp -t 'feature_phpcs_output')
trap 'rm -rf "$TEMP_DIR" "$PHPCS_OUTPUT"' EXIT HUP INT TERM

if php "$DIR/utils/extract-feature-php.php" extract features "$TEMP_DIR" >/dev/null
then
if [ -d "$TEMP_DIR" ] && [ "$(ls -A "$TEMP_DIR" 2>/dev/null)" ]
then
# The report is written to a file so that the status of PHPCS itself
# is preserved instead of the status of the commands rewriting it.
vendor/bin/phpcs --standard=WP_CLI_CS --warning-severity=0 \
--exclude=Generic.Files.InlineHTML,Generic.Files.LineEndings,WordPress.Files.FileName,Squiz.Commenting.FileComment,Universal.WhiteSpace.PrecisionAlignment,PSR2.Files.EndFileNewline,PSR2.Methods.FunctionClosingBrace,Generic.PHP.CharacterBeforePHPOpenTag,Generic.PHP.RequireStrictTypes,Squiz.WhiteSpace.SuperfluousWhitespace,WordPress.NamingConventions.PrefixAllGlobals,Universal.Files.SeparateFunctionsFromOO,Generic.Files.OneObjectStructurePerFile,WordPress.WP.GlobalVariablesOverride,Universal.Namespaces.OneDeclarationPerFile,Universal.Namespaces.DisallowCurlyBraceSyntax,WordPress.PHP.YodaConditions,Universal.Namespaces.DisallowDeclarationWithoutName,PSR12.Files.FileHeader,Generic.CodeAnalysis.EmptyStatement \
"$TEMP_DIR" >"$PHPCS_OUTPUT" 2>&1 || EXIT_CODE=$?

# The temporary directory is reported through its resolved path.
TEMP_DIR_REAL=$(cd "$TEMP_DIR" && pwd -P)

sed -E \
-e 's/\.feature_L[0-9]+_E[0-9]+_(HASPHP|NOPHP)\.php/.feature/g' \
-e "s|$TEMP_DIR_REAL/|features/|g" \
-e "s|$TEMP_DIR/|features/|g" \
"$PHPCS_OUTPUT"
fi
else
EXIT_CODE=1
fi
fi

exit $EXIT_CODE
2 changes: 1 addition & 1 deletion features/behat-steps.feature
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ Feature: Test that WP-CLI Behat steps work as expected
And a send-email.php file:
"""
<?php
wp_mail('test@example.com', 'Test', 'Body');
wp_mail( 'test@example.com', 'Test', 'Body' );
"""
When I run `wp eval-file send-email.php`
Then an email should be sent
Expand Down
2 changes: 1 addition & 1 deletion features/testing.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Feature: Test that WP-CLI loads.
And a test_cron.php file:
"""
<?php
$cron_disabled = defined( "DISABLE_WP_CRON" ) ? DISABLE_WP_CRON : false;
$cron_disabled = defined( 'DISABLE_WP_CRON' ) ? DISABLE_WP_CRON : false;
echo 'DISABLE_WP_CRON is: ' . ( $cron_disabled ? 'true' : 'false' );
"""

Expand Down
Loading
Loading