Squiz.WhiteSpace.FunctionSpacing can remove spaces between comment and first/last method during auto-fixing #2657
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Similar to #2656
If there would be comments (or commented out code) before the first method or after the last method in an OO structure, the fixer as it was, would - depending on the various
$spacing
settings, potentially remove the space between the method and the comment which would easily conflict with other comment rules.By allowing for comments before the first method/after the last method, this is prevented.
The fix now implemented means that if there is anything between the class opener/trait import
use
and the first method, other than a function docblock/comment, the method will be treated as any method and won't get the special "first method" treatment.Similarly, when there is anything between the last method and the class closer, other than a trailing comment, the method will be treated as any method and won't get the special "last" method treatment.
Includes unit test.