-
-
Notifications
You must be signed in to change notification settings - Fork 68
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] PSR12 - Control Structure Spacing #182
Merged
jrfnl
merged 21 commits into
PHPCSStandards:master
from
dingo-d:documentation/PSR12-control-structures-control-structure-spacing
Jan 26, 2024
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
5a0186f
Add the documentation for the PSR12 Control Structure Spacing sniff
dingo-d f4fabf1
Update src/Standards/PSR12/Docs/ControlStructures/ControlStructureSpa…
dingo-d 62cd376
Update src/Standards/PSR12/Docs/ControlStructures/ControlStructureSpa…
dingo-d baf28e9
Update src/Standards/PSR12/Docs/ControlStructures/ControlStructureSpa…
dingo-d 5961ed8
Update src/Standards/PSR12/Docs/ControlStructures/ControlStructureSpa…
dingo-d e2f79ab
Update src/Standards/PSR12/Docs/ControlStructures/ControlStructureSpa…
dingo-d 4ac58b1
Update src/Standards/PSR12/Docs/ControlStructures/ControlStructureSpa…
dingo-d c14c5dd
Update src/Standards/PSR12/Docs/ControlStructures/ControlStructureSpa…
dingo-d 8041c8b
Update src/Standards/PSR12/Docs/ControlStructures/ControlStructureSpa…
dingo-d a57752b
Update src/Standards/PSR12/Docs/ControlStructures/ControlStructureSpa…
dingo-d 0b63cb0
Update src/Standards/PSR12/Docs/ControlStructures/ControlStructureSpa…
dingo-d 1bf2c27
Update src/Standards/PSR12/Docs/ControlStructures/ControlStructureSpa…
dingo-d f6ec02b
Update src/Standards/PSR12/Docs/ControlStructures/ControlStructureSpa…
dingo-d 383618b
Update src/Standards/PSR12/Docs/ControlStructures/ControlStructureSpa…
dingo-d cdeef4d
Update src/Standards/PSR12/Docs/ControlStructures/ControlStructureSpa…
dingo-d c62e10f
Update src/Standards/PSR12/Docs/ControlStructures/ControlStructureSpa…
dingo-d a1795c1
Improve readability of the documentation
dingo-d b38b4b7
Update src/Standards/PSR12/Docs/ControlStructures/ControlStructureSpa…
dingo-d f593a53
Fix suggestions from the PR
dingo-d 6a22d05
Update the standard description for single line control structures
dingo-d 77366bb
Update src/Standards/PSR12/Docs/ControlStructures/ControlStructureSpa…
dingo-d File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
124 changes: 124 additions & 0 deletions
124
src/Standards/PSR12/Docs/ControlStructures/ControlStructureSpacingStandard.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<documentation title="Control Structure Spacing"> | ||
<standard> | ||
<![CDATA[ | ||
Single line control structures must have no spaces after the condition opening parenthesis and before the condition closing parenthesis. | ||
]]> | ||
</standard> | ||
<code_comparison> | ||
<code title="Valid: No space after the opening parenthesis in a single-line condition."> | ||
<![CDATA[ | ||
if <em>(</em>$expr) { | ||
} | ||
]]> | ||
</code> | ||
<code title="Invalid: Space after the opening parenthesis in a single-line condition."> | ||
<![CDATA[ | ||
if <em>( </em>$expr) { | ||
} | ||
]]> | ||
</code> | ||
</code_comparison> | ||
<code_comparison> | ||
<code title="Valid: No space before the closing parenthesis in a single-line condition."> | ||
<![CDATA[ | ||
if <em>(</em>$expr) { | ||
} | ||
]]> | ||
</code> | ||
<code title="Invalid: Space before the closing parenthesis in a single-line condition."> | ||
<![CDATA[ | ||
if ($expr<em> )</em> { | ||
} | ||
]]> | ||
</code> | ||
</code_comparison> | ||
<standard> | ||
<![CDATA[ | ||
The condition of the multi-line control structure must be indented once, placing the first expression on the next line after the opening parenthesis. | ||
]]> | ||
</standard> | ||
<code_comparison> | ||
dingo-d marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<code title="Valid: First expression of a multi-line control structure condition block is on the line after the opening parenthesis."> | ||
<![CDATA[ | ||
while ( | ||
<em>$expr1</em> | ||
&& $expr2 | ||
) { | ||
} | ||
]]> | ||
</code> | ||
<code title="Invalid: First expression of a multi-line control structure condition block is on the same line as the opening parenthesis."> | ||
<![CDATA[ | ||
while <em>($expr1</em> | ||
&& $expr2 | ||
) { | ||
} | ||
]]> | ||
</code> | ||
</code_comparison> | ||
<code_comparison> | ||
dingo-d marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<code title="Valid: Each line in a multi-line control structure condition block indented at least once. Default indentation is 4 spaces."> | ||
<![CDATA[ | ||
dingo-d marked this conversation as resolved.
Show resolved
Hide resolved
|
||
while ( | ||
<em> </em>$expr1 | ||
<em> </em>&& $expr2 | ||
) { | ||
} | ||
]]> | ||
</code> | ||
<code title="Invalid: Some lines in a multi-line control structure condition block not indented correctly."> | ||
<![CDATA[ | ||
while ( | ||
<em>$expr1</em> | ||
&& $expr2 | ||
<em> && $expr3</em> | ||
) { | ||
} | ||
]]> | ||
</code> | ||
</code_comparison> | ||
<standard> | ||
<![CDATA[ | ||
The closing parenthesis of the multi-line control structure must be on the next line after the last condition, indented to the same level as the start of the control structure. | ||
]]> | ||
</standard> | ||
<code_comparison> | ||
<code title="Valid: The closing parenthesis of a multi-line control structure condition block is on the line after the last expression."> | ||
<![CDATA[ | ||
while ( | ||
$expr1 | ||
&& $expr2 | ||
<em>)</em> { | ||
} | ||
]]> | ||
</code> | ||
<code title="Invalid: The closing parenthesis of a multi-line control structure condition block is on the same line as the last expression."> | ||
<![CDATA[ | ||
while ( | ||
$expr1 | ||
<em>&& $expr2)</em> { | ||
} | ||
]]> | ||
</code> | ||
</code_comparison> | ||
<code_comparison> | ||
<code title="Valid: The closing parenthesis of a multi-line control structure condition block is indented to the same level as start of the control structure."> | ||
<![CDATA[ | ||
dingo-d marked this conversation as resolved.
Show resolved
Hide resolved
|
||
while ( | ||
$expr1 | ||
&& $expr2 | ||
<em>)</em> { | ||
} | ||
]]> | ||
</code> | ||
<code title="Invalid: The closing parenthesis of a multi-line control structure condition block is not indented to the same level as start of the control structure."> | ||
<![CDATA[ | ||
while ( | ||
$expr1 | ||
&& $expr2 | ||
<em> )</em> { | ||
} | ||
]]> | ||
</code> | ||
</code_comparison> | ||
</documentation> |
Oops, something went wrong.
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.
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.
Should the "no space after the keyword" rule get its own code sample ? Or could this be included in this invalid code sample ?
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.
Technically, this sniff doesn't check for the space after the keyword. This is covered by the
Squiz.ControlStructures.ControlSignature.SpaceAfterKeyword
sniff, so I'm not sure if we should include it in the documentation for this sniff.I'm all for removing squiz rules from the PSR12 ruleset, and just modifying the
ControlStructuresSpacing
sniff to include all the checks as in the PSR-12 documentation for control structures, but I think that would be something for PHPCS v4.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.
You are 100% correct! I thought this sniff was checking that too, but you are right, it does not. The updated standards description from commit a1795c1 confused me as that _does_mention the space after the control structure keyword.
In other words: No, there should not be a code sample for space after keyword, but the first
<standard>
block will need to be updated to remove the mention of the spacing after the keyword.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.
And this bit ", and one space between the closing parenthesis and the opening brace" will also need to be removed as that is also not checked via this sniff.
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.
Yes, you're right about these. Will fix them now 👍🏼