Skip to content

Enforce exact scope indentation in PHPCS#13140

Open
faisalahammad wants to merge 2 commits into
google:developfrom
faisalahammad:fix/12934-phpcs-exact-indent
Open

Enforce exact scope indentation in PHPCS#13140
faisalahammad wants to merge 2 commits into
google:developfrom
faisalahammad:fix/12934-phpcs-exact-indent

Conversation

@faisalahammad

Copy link
Copy Markdown

Summary

Addresses issue:

Relevant technical choices

Set Generic.WhiteSpace.ScopeIndent to exact=true in phpcs.xml. The default exact=false (inherited from WordPress-Core) only checks the lower bound of indentation, so lines indented deeper than the expected scope slip through CI. Flipping to exact=true makes the sniff enforce the full range: under- and over-indented lines both fail.

This also turned up 189 pre-existing over-indent violations across 52 PHP files, all auto-fixed by phpcbf. One real bug was uncovered: tests/phpunit/integration/Core/Tags/Guards/Tag_Environment_Type_GuardTest.php had two use statements indented at file scope.

Repro to confirm the rule works:

<?php
class Test {
	public function test() {
		$a = true;
		$b = true;

			return $a === $b; // over-indented, must fail
	}
}

Running composer run lint -- /tmp/test_indent.php now reports Generic.WhiteSpace.ScopeIndent.IncorrectExact. Clean code keeps passing.

PR Author Checklist

  • My code is tested and passes existing unit tests.
  • My code has an appropriate set of unit tests which all pass.
  • My code is backward-compatible with WordPress 5.2 and PHP 7.4.
  • My code follows the WordPress coding standards.
  • My code has proper inline documentation.
  • I have added a QA Brief on the issue linked above.
  • I have signed the Contributor License Agreement (see https://cla.developers.google.com/).

Do not alter or remove anything below. The following sections will be managed by moderators only.

Code Reviewer Checklist

  • Run the code.
  • Ensure the acceptance criteria are satisfied.
  • Reassess the implementation with the IB.
  • Ensure no unrelated changes are included.
  • Ensure CI checks pass.
  • Check Storybook where applicable.
  • Ensure there is a QA Brief.
  • Ensure there are no unexpected significant changes to file sizes.

Merge Reviewer Checklist

  • Ensure the PR has the correct target branch.
  • Double-check that the PR is okay to be merged.
  • Ensure the corresponding issue has a ZenHub release assigned.
  • Add a changelog message to the issue.

…ication

The component is shown for any initial setup error, not only Analytics
activation, so the new name describes its purpose better.

- Rename component and stories file.
- Update import, component name, constant, notification ID, and CSS
  class in SetupUsingProxyWithSignIn/index.js.
- Update story usage and test descriptions.
- Rename 6 Backstop reference PNGs (pixels unchanged).
Set Generic.WhiteSpace.ScopeIndent to exact=true in phpcs.xml so the sniff
flags lines indented deeper than the expected scope, not just lines indented
less. The default exact=false inherits from WordPress-Core and only checks
the lower bound, which lets over-indented code slip through CI.

Auto-fixed 189 pre-existing over-indent violations across 52 PHP files using
phpcbf. All changes are whitespace-only except one real over-indent bug in
tests/phpunit/integration/Core/Tags/Guards/Tag_Environment_Type_GuardTest.php
where two use statements were indented at file scope.

Fixes google#12934.
@google-cla

google-cla Bot commented Jul 19, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant