-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
[Documentation] Squiz: Scope Closing Brace #353
[Documentation] Squiz: Scope Closing Brace #353
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jonmcp Thank you for taking on this sniff !
Aside from the inline notes, I wonder if the code samples could be made more varied ? The sniff is not just about the close brace for function declarations, but also about OO structures and all control structures.
Nitpick: it looks like the CDATA close tag for all code samples is not indented ?
src/Standards/Squiz/Docs/WhiteSpace/ScopeClosingBraceStandard.xml
Outdated
Show resolved
Hide resolved
src/Standards/Squiz/Docs/WhiteSpace/ScopeClosingBraceStandard.xml
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jonmcp Thanks for making those updates!
Regarding the first section: as the code samples are now quite wordy, I'm not sure they each need their own <code_comparison>
block. They could possibly be combined in one <code_comparison>
block. What do you think ?
Regarding my comments about the second section: The mention of "newline" in the code sample descriptions is misleading as the close brace could be indented.
if ($something) {
echo 'close brace is on its own line, but not directly preceded by a new line char';
}
And the sniff also allows for a mix of PHP and HTML, so the below would also be valid (but not comply with the description as currently in the docs):
<?php if ($something) { ?>
<div>sniff regards this as the close brace being on its own line, but the close brace is not directly preceded by a new line char';
<?php } ?>
Sorry to be a pain, but being precise is kind of important for these things for sniffs.
src/Standards/Squiz/Docs/WhiteSpace/ScopeClosingBraceStandard.xml
Outdated
Show resolved
Hide resolved
src/Standards/Squiz/Docs/WhiteSpace/ScopeClosingBraceStandard.xml
Outdated
Show resolved
Hide resolved
I tried this out locally, and it does look a lot cleaner. I've combined them in 9cd4fd2.
That's a very good point. I've combined the conditional with the class declaration in d3e4068 to better illustrate that statements can be indented. I also removed some of the related code comments, not only because they were syntactically invalid, but because I felt that they were making the code block quite messy. I've instead indented the invalid closing braces enough that it should be clear that they are misaligned, rather than relying upon the comments to describe it. I'm not 100% confident that that was the correct decision, so please let me know if you'd like me to work on it further.
I think I've reworded it to be more clear now. I've also added an example illustrating your code example above in 9cd4fd2. <?php if ($something) { ?>
<p>additional whitespace before closing brace</p>
<?php } ?>
Not at all. I agree that it's very important, and I appreciate the time you're taking to thoroughly explain where I have fallen short in my descriptions. |
Good observation. For the above, the sniff does not actually check the indentation of the close brace, but the indentation of the PHP open tag preceding the close tag. It would flag the code if the PHP open tag preceding the close curly would be indented differently from the start of the line containing the <?php if ($something) { ?>
<p>additional whitespace before closing brace</p>
<?php } ?> Might be an idea to add an additional check to this sniff to verify that, if a PHP open tag is used to determine whether the indentation is correct, there is only one space between the PHP open tag and the close brace. If you think that is a good idea, you may want to open an issue for it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also removed some of the related code comments, not only because they were syntactically invalid, but because I felt that they were making the code block quite messy. I've instead indented the invalid closing braces enough that it should be clear that they are misaligned, rather than relying upon the comments to describe it. I'm not 100% confident that that was the correct decision, so please let me know if you'd like me to work on it further.
@jonmcp I definitely think that was the right decision. I even think some of the remaining wordiness in the code samples could be trimmed down, as the code samples are clear enough as they are IMO, but I'm fine with leaving those as they are. Up to you.
One thing I did notice was that all examples have too much indentation for the close brace, while the sniff would also flag too little indentation. Was that intentional ?
I'm okay with merging the PR as-is, but will give you a little time to think the above over. Let me know how you want to proceed.
where I have fallen short in my descriptions.
Please don't take code reviews personally. You are new to this codebase, so give yourself some leeway. I'm happy to provide guidance and/or answer questions to help you find your feet.
I do think that it would be useful; in fact, I think it would be good to catch it either side of the closing brace, but that would perhaps be outside the scope of this sniff. I'll open an issue anyway, to avoid getting too far off topic in this PR. 🙂
Re the latter part - that's an oversight on my part. I will modify the code comparisons to also include an example of too little indentation, and I'll also take another look at the wordiness whilst I'm working on that.
Thank you so much! 😊 |
@jrfnl apologies for the delay in actioning the feedback here. I am only able to devote time on Mondays and Fridays due to work commitments. |
@jonmcp Just a thought: what about removing the Like this: if (!class_exists('Foo')) {
class Foo {
}
} You could even consider reversing the expected indents: if (!class_exists('Foo')) {
class Foo {
}
} Re: the |
Thanks @jrfnl, it looks a lot better that way, I think, in both cases. As an aside: after this PR is complete, I'll be updating my committer name from |
Whatever works for you and makes you feel most comfortable. Be yourself, whomever that may be. I can't rewrite history for any earlier commits to the repo (of course), but I'll make sure to update my draft changelog notes to use Jay instead of Jon. Is that okay for you ? |
- Fixup CDATA indentation - Improve wording in code examples - Add more varied code examples
Better illustrates that statements can be indented, and that their closing braces still should align with the start of the statement.
- Reduces wordiness - Adds an example of too little whitespace
- Combine too little with too much whitespace - Adjust emphasis on example containing PHP tags - Change example paragraph to span for better HTML formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jonmcp Jay, thank you for your work on this. Looking good.
I'll rebase the PR and will merge once the build has passed.
444fb8a
to
b5cd72f
Compare
That's perfect, and appreciated. Thank you 💜 |
* Docs: add documentation for Squiz.WhiteSpace.ScopeClosingBrace * Docs: improve documentation for Squiz.WhiteSpace.ScopeClosingBrace - Fixup CDATA indentation - Improve wording in code examples - Add more varied code examples * Docs: clarify wording and code samples for Squiz.WhiteSpace.ScopeClosingBrace * Docs: combine code examples in Squiz.WhiteSpace.ScopeClosingBrace Better illustrates that statements can be indented, and that their closing braces still should align with the start of the statement. * Docs: improve examples for Squiz.WhiteSpace.ScopeClosingBrace - Reduces wordiness - Adds an example of too little whitespace * Docs: add missing emphasis in Squiz.WhiteSpace.ScopeClosingBrace * Docs: improve code examples for Squiz.WhiteSpace.ScopeClosingBrace - Combine too little with too much whitespace - Adjust emphasis on example containing PHP tags - Change example paragraph to span for better HTML formatting
Description
This PR adds documentation for the
Squiz.WhiteSpace.ScopeClosingBrace
sniff.Suggested changelog entry
Add documentation for the Squiz Scope Closing Brace sniff
Related issues/external references
Part of #148
Types of changes
PR checklist