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

Issue fork coder-3461148

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Ghost of Drupal Past created an issue. See original summary.

nicxvan’s picture

Is there an upstream issue for this? I can't find one.

nicxvan’s picture

Issue summary: View changes

nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
ghost of drupal past’s picture

Issue summary: View changes
ghost of drupal past’s picture

Title: Incorrect indent in fixed up Rector generated file » Drupal.WhiteSpace.ScopeIndent gets confused by attributes on a function.
Issue summary: View changes
ghost of drupal past’s picture

Issue summary: View changes
ghost of drupal past’s picture

Issue summary: View changes
ghost of drupal past’s picture

Issue summary: View changes
nicxvan’s picture

StatusFileSize
new1.26 KB
nicxvan’s picture

Status: Active » Needs review
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes

klausi’s picture

Status: Needs review » Needs work

Thanks, please create pull requests at https://github.com/pfrenssen/coder/pulls so that we see tests run there.

nicxvan’s picture

Status: Needs work » Needs review

Done! 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.

klausi’s picture

Status: Needs review » Needs work

Thanks 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.

nicxvan’s picture

Status: Needs work » Needs review

  • klausi committed 8339bd5b on 8.3.x
    test(ScopeIndent): Fix PHP attribute error lines (#3461148)
    

  • acc55a98 committed on 8.3.x
    fix(ScopeIndent): Support PHP attributes (#3461148 by nicxvan)
    
    
klausi’s picture

Version: 8.3.24 » 8.3.x-dev
Status: Needs review » Fixed

Merged, thanks! Tests were failing, fixed them in a small follow-up.

Please always run the test cases to verify they are correct.

  • klausi authored bf0dc2f5 on 8.3.x
    fix(ScopeIndent): Fix test fails on attributes on constructor promotion...
klausi’s picture

Turns 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

nicxvan’s picture

Oh sorry about that! Great catch!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

nicxvan’s picture