Skip to content

Update sniff to improve whitespace consistency#2768

Merged
Crabcyborg merged 1 commit into
masterfrom
update_sniff_to_improve_whitespace_consistency
Jan 10, 2026
Merged

Update sniff to improve whitespace consistency#2768
Crabcyborg merged 1 commit into
masterfrom
update_sniff_to_improve_whitespace_consistency

Conversation

@Crabcyborg
Copy link
Copy Markdown
Contributor

No description provided.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 10, 2026

Walkthrough

This PR updates a PHPCS whitespace sniff to enforce blank lines after closing braces and function calls, then applies resulting formatting improvements across multiple files in the codebase and test suite.

Changes

Cohort / File(s) Summary
PHPCS Sniff Update
phpcs-sniffs/Formidable/Sniffs/WhiteSpace/BlankLineAfterClosingBraceSniff.php
Enhanced sniff to register both T_VARIABLE and T_STRING tokens; added logic to differentiate between variable assignments and function calls; introduces context-aware checks for containing functions and existing blank lines before applying the rule.
Application Controllers
classes/controllers/FrmFormsController.php, classes/controllers/FrmSettingsController.php, square/controllers/FrmSquareLiteEventsController.php, stripe/controllers/FrmStrpLiteEventsController.php
Blank line formatting added in methods: menu(), load_settings_tab(), process_events(), maybe_cancel_subscription(), and process_connect_events().
Application Helpers
classes/helpers/FrmAppHelper.php, classes/helpers/FrmFormsHelper.php, square/helpers/FrmSquareLiteConnectHelper.php, stripe/helpers/FrmStrpLiteConnectHelper.php
Blank line formatting added in permission_check(), set_current_screen_and_hook_suffix(), get_unsafe_params(), verify(), and handle_reauth() methods.
Application Models
classes/models/FrmMigrate.php, classes/models/fields/FrmFieldCombo.php
Blank line formatting added in revert_widget_field_size(), adjust_widget_size(), and print_input_atts() methods.
Test Updates
tests/phpunit/misc/test_FrmSpamCheckDenylist.php
Minor blank line spacing adjustment in test file.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

run analysis, run tests

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Description check ❓ Inconclusive No pull request description was provided by the author, making it impossible to evaluate whether the description relates to the changeset. Add a pull request description explaining the purpose and scope of the sniff changes and how they improve whitespace consistency.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Update sniff to improve whitespace consistency' directly relates to the main change: updating the BlankLineAfterClosingBraceSniff to enforce blank lines more consistently across the codebase.
Docstring Coverage ✅ Passed Docstring coverage is 84.21% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
phpcs-sniffs/Formidable/Sniffs/WhiteSpace/BlankLineAfterClosingBraceSniff.php (2)

172-191: Potential cross-platform issue with newline detection.

The check for blank lines uses $tokens[ $i ]['content'] === "\n" which may not match "\r\n" on Windows or in files with Windows line endings.

Consider using a more robust newline check
-		for ( $i = $functionStart + 1; $i < $functionEnd; $i++ ) {
-			if ( $tokens[ $i ]['code'] === T_WHITESPACE && $tokens[ $i ]['content'] === "\n" ) {
+		for ( $i = $functionStart + 1; $i < $functionEnd; $i++ ) {
+			if ( $tokens[ $i ]['code'] === T_WHITESPACE && preg_match( '/\r?\n/', $tokens[ $i ]['content'] ) ) {

Alternatively, you could check if the content contains only whitespace and spans multiple lines by comparing line numbers of adjacent tokens.


193-199: Error message doesn't reflect expanded scope.

The error message still says "variable assignment" but the sniff now also handles function calls. Consider updating for clarity.

Suggested update
 		$fix = $phpcsFile->addFixableError(
-			'Expected blank line after closing brace before variable assignment',
+			'Expected blank line after closing brace before statement',
 			$stackPtr,
 			'MissingBlankLine'
 		);
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 46ab757 and aab799d.

📒 Files selected for processing (12)
  • classes/controllers/FrmFormsController.php
  • classes/controllers/FrmSettingsController.php
  • classes/helpers/FrmAppHelper.php
  • classes/helpers/FrmFormsHelper.php
  • classes/models/FrmMigrate.php
  • classes/models/fields/FrmFieldCombo.php
  • phpcs-sniffs/Formidable/Sniffs/WhiteSpace/BlankLineAfterClosingBraceSniff.php
  • square/controllers/FrmSquareLiteEventsController.php
  • square/helpers/FrmSquareLiteConnectHelper.php
  • stripe/controllers/FrmStrpLiteEventsController.php
  • stripe/helpers/FrmStrpLiteConnectHelper.php
  • tests/phpunit/misc/test_FrmSpamCheckDenylist.php
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Cypress
  • GitHub Check: PHP 7.4 tests in WP 6.9
  • GitHub Check: PHP 8 tests in WP 6.9
  • GitHub Check: Cypress
  • GitHub Check: PHP 8 tests in WP 6.9
  • GitHub Check: PHP 7.4 tests in WP 6.9
🔇 Additional comments (18)
classes/controllers/FrmSettingsController.php (1)

266-267: Formatting improvement to enhance code clarity.

The addition of a blank line between the function call and the final wp_die() improves code readability by visually separating the main logic from the exit statement.

classes/models/FrmMigrate.php (2)

651-652: Formatting improvement to enhance code clarity.

The blank line between the loop processing and the update_option() call improves readability by clearly separating the data processing from the final save operation.


769-770: Formatting improvement to enhance code clarity.

The blank line between the loop processing and the update_option() call improves readability and maintains consistency with the similar pattern in revert_widget_field_size().

classes/helpers/FrmFormsHelper.php (1)

1843-1844: Formatting improvement to separate early-return logic from main processing.

The blank line visually separates the early return guard clause from the subsequent logic, improving code clarity without changing any behavior.

classes/models/fields/FrmFieldCombo.php (1)

404-408: Formatting change aligns with sniff goals.

The added blank line before the do_action() call follows the PR objective to enforce whitespace consistency after logical code segments. No functional changes detected.

stripe/controllers/FrmStrpLiteEventsController.php (2)

315-324: Formatting improvement for blank line after conditional block.

The added blank line at line 323 before the remove_filter() call improves readability after the subscription cancellation conditional block. Functional behavior is unchanged.


454-463: Formatting change maintains existing behavior.

The blank line added before wp_send_json_success() follows the sniff enforcement for spacing after conditional logic. Event processing logic remains unaffected.

square/controllers/FrmSquareLiteEventsController.php (1)

50-59: Whitespace consistency applied to event processing method.

The blank line added before wp_send_json_success() follows the sniff's enforcement pattern for spacing after conditional blocks. The change is formatting-only and preserves all functional behavior.

classes/helpers/FrmAppHelper.php (2)

2366-2376: Whitespace-only change in FrmAppHelper::permission_check() looks safe.
The added blank line improves readability without affecting the wp_die() path.


4651-4660: Whitespace-only change in FrmAppHelper::set_current_screen_and_hook_suffix() looks safe.
The blank line separation before set_current_screen() is purely formatting; behavior is unchanged.

square/helpers/FrmSquareLiteConnectHelper.php (1)

786-805: Whitespace-only change in FrmSquareLiteConnectHelper::verify() looks safe.
Adds a blank line after the success response; no control-flow change.

classes/controllers/FrmFormsController.php (1)

28-38: Whitespace-only change in FrmFormsController::menu() looks safe.
Improves visual separation between conditional label tweak and add_submenu_page() call.

tests/phpunit/misc/test_FrmSpamCheckDenylist.php (1)

307-336: LGTM - Formatting changes applied correctly.

The blank lines added after the inline filter functions (lines 313 and 333) align with the updated sniff rules for blank lines after closing braces.

Note: Defining functions at the global scope inside a test method is unconventional and could cause "cannot redeclare function" errors if the test runs multiple times in the same process. Consider using anonymous functions or class methods instead. However, this is existing code and not part of the current changes.

stripe/helpers/FrmStrpLiteConnectHelper.php (2)

336-343: LGTM - Formatting change applied correctly.

The added blank line after the success path's closing brace (where wp_send_json_success() is called) follows the updated whitespace rules. The control flow is correct since wp_send_json_success() terminates execution, making wp_send_json_error() on line 342 only reachable when the condition on line 338 is false.


960-964: LGTM - Formatting change applied correctly.

The blank line added after the success conditional block aligns with the updated sniff rules. The logic remains correct: wp_send_json_success() terminates, so wp_send_json_error() is only reached when the identifier check fails.

phpcs-sniffs/Formidable/Sniffs/WhiteSpace/BlankLineAfterClosingBraceSniff.php (3)

38-40: LGTM - Registration expanded to handle function calls.

Good addition of T_STRING to catch function calls in addition to variable assignments, broadening the sniff's coverage.


60-87: LGTM - Clean differentiation between variable assignments and function calls.

The logic correctly handles both cases:

  • Variables require a following assignment operator
  • Strings (function names) require a following opening parenthesis

The comprehensive list of assignment operators ensures all assignment patterns are covered.


139-167: Scope detection logic is sound.

The backward search for containing function/closure with scope boundary validation is well-implemented. Decrementing $searchPtr after each iteration ensures all potential containing scopes are checked.

@Crabcyborg Crabcyborg merged commit 0a1a156 into master Jan 10, 2026
35 of 36 checks passed
@Crabcyborg Crabcyborg deleted the update_sniff_to_improve_whitespace_consistency branch January 10, 2026 02:32
stephywells pushed a commit that referenced this pull request Apr 4, 2026
…espace_consistency

Update sniff to improve whitespace consistency
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant