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

Generic.WhiteSpace.ScopeIndent incorrect indent errors when self called function proceeded by comment #1777

Closed
andreolvr opened this issue Dec 11, 2017 · 7 comments
Milestone

Comments

@andreolvr
Copy link

Here is my code:

$app = new \Slim\App;

(function () use ($app) {
    require_once __DIR__ . '/../routes.php';
})();

$app->run();

When i run phpcs, here is what i get:

 37 | ERROR | [x] Line indented incorrectly; expected at least 3
    |       |     spaces, found 0

Line 37 is $app->run();

I'm using PSR2 standard, i hope this is the correct repository to report this bug 😄.

@gsherwood
Copy link
Member

I don't get any errors when I run PHPCS over that code. It is possible they only occur in the context of other code.

Have you been able to replicate on that code snippet alone? If so, which version of PHPCS are you using? If not, are you able to provide a larger code snippet (or the whole file) to help replicate the error?

@andreolvr
Copy link
Author

Yes, i replicated that code snippet alone and the error still occurs. I'm running PHP 7.1.12 with PHPCS ^3.1 on Windows 10.

@gsherwood
Copy link
Member

Thanks for getting back to me. I'm using the same PHP and PHPCS versions as you and I still can't replicate any errors.

Can you add --runtime-set scope_indent_debug 1 to your CLI command for me and post the output. This shows what the scope indent sniff is doing. Below is my output:

$ phpcs temp.php --standard=PSR2 --runtime-set scope_indent_debug 1
Start with token 0 on line 1 with indent 0
Open closure on line 4
	* first token is 14 (T_OPEN_PARENTHESIS) on line 4 *
	=> indent set to 4 by token 26 (T_OPEN_CURLY_BRACKET)
Close scope (T_CLOSURE) on line 6
	* first token is 14 (T_OPEN_PARENTHESIS) on line 4 *
	=> indent set to 0 by token 38 (T_CLOSE_CURLY_BRACKET)
Close closure on line 6
	* token has nested parenthesis 14 on line 4 *
	* using parenthesis *
	* previous token is T_SEMICOLON on line 2 *
	* first token on line 2 is 1 (T_VARIABLE) *
	=> indent set to 0 by token 1 (T_VARIABLE)
Closing parenthesis found on line 6
	* first token on line 4 is 14 (T_OPEN_PARENTHESIS) *
	=> checking indent of 0; main indent set to 0 by token 13 (T_WHITESPACE)
Closing parenthesis found on line 6
	 * ignoring single-line definition *
Closing parenthesis found on line 8
	 * ignoring single-line definition *

@andreolvr
Copy link
Author

Here it is:

E:\php-labs>"vendor/bin/phpcs" public --standard=PSR2 --runtime-set scope_indent_debug 1
Start with token 0 on line 1 with indent 0
Open closure on line 13
        * first token is 49 (T_OPEN_PARENTHESIS) on line 13 *
        => indent set to 4 by token 61 (T_OPEN_CURLY_BRACKET)
Close scope (T_CLOSURE) on line 15
        * first token is 49 (T_OPEN_PARENTHESIS) on line 13 *
        => indent set to 0 by token 73 (T_CLOSE_CURLY_BRACKET)
Close closure on line 15
        * token has nested parenthesis 49 on line 13 *
        * using parenthesis *
        * previous token is T_SEMICOLON on line 8 *
        * first token on line 8 is 22 (T_VARIABLE) *
        => indent set to 0 by token 22 (T_VARIABLE)
Closing parenthesis found on line 15
        * first token on line 13 is 49 (T_OPEN_PARENTHESIS) *
        => checking indent of 0; main indent set to 3 by token 48 (T_WHITESPACE)
Closing parenthesis found on line 15
         * ignoring single-line definition *
[Line 20] Line indented incorrectly; expected at least 3 spaces, found 0
        => Add adjustment of 3 for token 90 (T_VARIABLE) on line 20
Closing parenthesis found on line 20
         * ignoring single-line definition *

FILE: E:\php-labs\public\index.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 20 | ERROR | [x] Line indented incorrectly; expected at least 3
    |       |     spaces, found 0
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Time: 117ms; Memory: 6Mb

@andreolvr
Copy link
Author

This is me entire code:

<?php

require_once __DIR__ . '/../vendor/autoload.php';

$app = new \DI\Bridge\Slim\App;

(function () use ($app) {
    require_once __DIR__ . '/../routes.php';
})();

$app->run();

If you run phpcs with the code above, no error is found. But if i add some comments to my code, like this:

<?php

require_once __DIR__ . '/../vendor/autoload.php';

$app = new \DI\Bridge\Slim\App;

/**
 * Load the application routes
 */
(function () use ($app) {
    require_once __DIR__ . '/../routes.php';
})();

$app->run();

I get the error.

@gsherwood
Copy link
Member

If you run phpcs with the code above, no error is found. But if i add some comments to my code, like this:

Thanks. That's what I needed to replicate it.

@gsherwood gsherwood changed the title PHPCS get lost when using self called function Generic.WhiteSpace.ScopeIndent incorrect indent errors when self called function proceeded by comment Dec 12, 2017
gsherwood added a commit that referenced this issue Dec 12, 2017
…ors when self called function proceeded by comment
@gsherwood gsherwood added this to the 3.2.0 milestone Dec 12, 2017
@gsherwood
Copy link
Member

This has been fixed now. Thanks for reporting it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants