Problem/Motivation
Save this as broken.php and run ./vendor/bin/phpcs --standard=core/phpcs.xml.dist --sniffs=Drupal.WhiteSpace.ScopeIndent broken.php:
<?php
#[X]
public function test() {
}
Observe no errors.
Save this one as correct.php and run ./vendor/bin/phpcs --standard=core/phpcs.xml.dist --sniffs=Drupal.WhiteSpace.ScopeIndent correct.php
<?php
# [X]
public function test() {
}
The only change is I changed the attribute to be a comment. Observe two fixable errors found.
Proposed resolution
if ($tokenIndent > $checkIndent) {
// Ignore multi line statements.
$before = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($checkToken - 1), null, true);
if ($before !== false && in_array(
$tokens[$before]['code'],
[
T_SEMICOLON,
T_CLOSE_CURLY_BRACKET,
T_OPEN_CURLY_BRACKET,
T_COLON,
T_OPEN_TAG,
T_ATTRIBUTE_END
]
) === false
) {
continue;
}
}
Remaining tasks
This works great at fixing indentation for attributes on methods.
This breaks stories attributes (7 in core) ul add examples later.
public function __construct(
Settings $settings,
#[AutowireLocator('queue_factory')]
protected ContainerInterface $container,
) {/lib
User interface changes
API changes
Data model changes
Comments
Comment #2
nicxvan commentedIs there an upstream issue for this? I can't find one.
Comment #3
nicxvan commentedComment #5
nicxvan commentedComment #6
nicxvan commentedComment #7
nicxvan commentedComment #8
nicxvan commentedComment #9
nicxvan commentedComment #10
ghost of drupal pastComment #11
ghost of drupal pastComment #12
ghost of drupal pastComment #13
ghost of drupal pastComment #14
ghost of drupal pastComment #15
nicxvan commentedComment #16
nicxvan commentedComment #17
nicxvan commentedComment #18
nicxvan commentedComment #20
klausiThanks, please create pull requests at https://github.com/pfrenssen/coder/pulls so that we see tests run there.
Comment #21
nicxvan commentedDone! I'm not sure what is needed for tests here, but I just moved it over.
Also not sure if I should still use statuses here.
Comment #22
klausiThanks a lot! Yes, we use statuses here and assign credits here.
Approach makes sense, only the test case needs to be moved to the right place.
Comment #23
nicxvan commentedComment #26
klausiMerged, thanks! Tests were failing, fixed them in a small follow-up.
Please always run the test cases to verify they are correct.
Comment #28
klausiTurns out that this broke Drupal core testing. I need to really wait for full green tests on Github before merging next time.
Fixed this by updating the sniff from upstream in https://github.com/pfrenssen/coder/pull/245
Comment #29
nicxvan commentedOh sorry about that! Great catch!
Comment #31
nicxvan commented