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
feat: Add statement_indentation
config not_for_comments
#7963
base: master
Are you sure you want to change the base?
Changes from 3 commits
481ba4d
e06a26e
8cbd995
081423b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,18 @@ | |
', | ||
['stick_comment_to_next_continuous_control_statement' => true] | ||
), | ||
new CodeSample( | ||
'<?php | ||
if ($foo) { | ||
// Comment stays where it is | ||
echo "foo"; // Code is indented | ||
// Comment stays where it is | ||
} else { | ||
$aaa = 1; | ||
} | ||
', | ||
['not_for_comments' => true] | ||
Check warning on line 102 in src/Fixer/Whitespace/StatementIndentationFixer.php GitHub Actions / PHP 8.3 mutation tests
Check warning on line 102 in src/Fixer/Whitespace/StatementIndentationFixer.php GitHub Actions / PHP 8.3 mutation tests
|
||
), | ||
] | ||
); | ||
} | ||
|
@@ -116,6 +128,10 @@ | |
->setAllowedTypes(['bool']) | ||
->setDefault(false) | ||
->getOption(), | ||
(new FixerOptionBuilder('not_for_comments', 'Leave commented lines alone.')) | ||
->setAllowedTypes(['bool']) | ||
Check warning on line 132 in src/Fixer/Whitespace/StatementIndentationFixer.php GitHub Actions / PHP 8.3 mutation tests
|
||
->setDefault(false) | ||
->getOption(), | ||
]); | ||
} | ||
|
||
|
@@ -437,6 +453,13 @@ | |
} | ||
} | ||
|
||
if (true === $this->configuration['not_for_comments']) { | ||
$lineIsCommented = $tokens[$firstNonWhitespaceTokenIndex]->isGivenKind([T_COMMENT]); | ||
Check warning on line 457 in src/Fixer/Whitespace/StatementIndentationFixer.php GitHub Actions / PHP 8.3 mutation tests
|
||
if ($lineIsCommented) { | ||
Check warning on line 458 in src/Fixer/Whitespace/StatementIndentationFixer.php GitHub Actions / PHP 8.3 mutation tests
|
||
continue; | ||
} | ||
} | ||
|
||
$endIndex = $scopes[$currentScope]['end_index']; | ||
|
||
if (!$scopes[$currentScope]['end_index_inclusive']) { | ||
|
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.
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 like
allow_zero_indented_comments
better, because that's what it does. I have the occasional two lines of// \PHPStan\dumpType()
at line start.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 like it. Make sure it is only for single line comments starting with
//
.