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

[PHP] Fix indentation rules #3880

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions PHP/Indentation Rules.tmPreferences
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
\s* [}\])] # optionally followed by whitespace, followed by a closing: curly brace, square bracket or paren
| # OR
\s* (<\?(php)?\s+)? # an optional PHP open tag
(else(\s*if)?\b.*:\s*($|//|/\*|\?>)|(end(if|for(each)?|switch|while))\b) # followed by an keyword that ends a control flow block
(else(\s*if)?\b.*:\s*($|//|/\*|\?>)|(end(if|for(each)?|switch|while))\b) # followed by an keyword that ends a control flow block
)
]]></string>

Expand All @@ -46,17 +46,14 @@
| # OR
^\s* (<\?(php)?\s+)? # the beginning of the line followed by any amount of whitespace and an optional PHP open tag
( (?:
(?:else)?if\s*\g<balanced_paren>|else # PHP "if" related statements
(?:else\s*)?if\s*\g<balanced_paren>|else # PHP "if" related statements
)\s*:(?!.*\bendif\b) # followed by a colon, not followed by an "endif" anywhere on the line
|
(?<php_control_word>foreach|for|switch|while)\s*\g<balanced_paren> # PHP control keywords, followed by balanced parens
\s*:(?!.*\bend\k<php_control_word>\b) # followed by a colon, and where the control structures don't end themselves on the same line
)
]]></string>

<key>indentNextLinePattern</key>
<string><![CDATA[^(?!.*(#|//|\*/|<\?))(?!.*[};:]\s*(//|/\*.*\*/\s*$)).*[^\s;:{}]\s*$|<\?php.+?\b(if|else(?:if)?|for(?:each)?|while)\b.*:(?!.*end\1)]]></string>

<key>bracketIndentNextLinePattern</key>
<string>(?x)
^ \s* \b(if|while|else|elseif|foreach)\b [^;]* $
Expand Down
2 changes: 2 additions & 0 deletions PHP/tests/syntax_test_indentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
asdfadf
<?php elseif(false): ?>
asdf
<?php else if(true):?>
asdf
<?php else: ?>
qwfpg
<?php endif;?>
Expand Down