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

Squiz.WhiteSpace.FunctionSpacing is removing indents from the start of functions when fixing #2110

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Aug 3, 2018

When too many blank lines are found before a function, the Before/BeforeFirst fixer would unnecessarily also remove the indentation of the $nextContent line, meaning that this sniff would always need to be accompanied by one or more sniffs to fix the indentation again.

As this sniff is about blank lines between functions, not about indentation, I consider this a bug.

This minor change fixes it.

Includes unit tests demonstrating the issue.

When too many blank lines are found before a function, the `Before/BeforeFirst` fixer would unnecessarily also remove the indentation of the `$nextContent` line, meaning that this sniff would **always** need to be accompanied by one or more sniffs to fix the indentation again.

As this sniff is about blank lines between functions, not about indentation, I consider this a bug.

This minor change fixes it.

Includes unit tests demonstrating the issue.
When too few blank lines are found before a function, the `Before/BeforeFirst` fixer would unnecessarily also remove the indentation of the `$nextContent` line and leave the indentation on the newly added blank line, meaning that this sniff would **always** need to be accompanied by one or more sniffs to fix the indentation again and to remove trailing whitespace.

As this sniff is about blank lines between functions, not about indentation, I consider this a bug.

This minor change fixes it.

Includes unit tests demonstrating the issue.
@jrfnl
Copy link
Contributor Author

jrfnl commented Aug 6, 2018

Just realized that the same problem existed when there would be too few blank lines before a function.
The fixer would remove the indentation for the $nextContent line and leave trailing indentation on the first added "blank" line. I've added a new fix for this in a separate commit, including unit tests.

This new fix also documents how this sniff handles PHPCS annotations found before a function - which may not be as desired -, but I haven't changed the behaviour regarding this.

@gsherwood gsherwood added this to the 3.3.2 milestone Aug 12, 2018
@gsherwood gsherwood changed the title Squiz/FunctionSpacing: don't remove indentation before start of function Squiz.WhiteSpace.FunctionSpacing is removing indents from the start of functions when fixing Aug 12, 2018
@gsherwood gsherwood merged commit 5d1e7b2 into squizlabs:master Aug 12, 2018
gsherwood added a commit that referenced this pull request Aug 12, 2018
@gsherwood
Copy link
Member

100% agree. Thanks for fixing this.

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.

2 participants