-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Indentation issues #544
Comments
If you don't have an array sniff in your standard, arrays wont be formatted to look good. For example, the PSR2 standard doesn't say how arrays should be formatted, so PHP_CodeSniffer wont report errors or try and fix the formatting. If I did, I'd get a bunch of issues from people complaining that PHPCS isn't conforming to PSR2. One thing that the indent sniff should be doing though is to maintain indentation that is already there, if it has no rules on how to fix it. So I'd be interested to see what the code originally looked like before fixing so I can make sure any existing array formatting is preserved. Are you able to provide that? Or is that what the first code block actually is? I think a really simple sniff to format arrays using one indent level would be a good idea, but you would have to explicitly add it to a custom standard if you want to use it. Right now, the only sniff that formats arrays in a consistent way is Squiz.Arrays.ArrayDeclaration, but it probably does a lot more formatting than you want and looks to have an issue with that first code block anyway. |
My existing array was like $client = new Client(
array(
'base_url' => \SproutVideo::$base_url,
'defaults' => array(
'headers' => array(
'SproutVideo-Api-Key' => \SproutVideo::$api_key,
'Content-Type', 'application/json;charset=utf-8'
),
)
)
); but with tabs. Which changed to $client = new Client(
array(
'base_url' => \SproutVideo::$base_url,
'defaults' => array(
'headers' => array(
'SproutVideo-Api-Key' => \SproutVideo::$api_key,
'Content-Type', 'application/json;charset=utf-8'
),
)
)
); |
Do you use a custom standard or one which is shipped by PHPCS? |
I used Hope that clarifies. You can see the SproutVideo/sproutvideo-php#5 and commit SproutVideo/sproutvideo-php@06211d9#diff-a0c3af6bff051809aea4bb6d7b4dcfccR77 . See arrays in the commit . |
Having a sniff, that just checks the indentation of multi-line array declarations would be great. I'm not sure though how such code will be handled considering, that tabs are used for indentation: $a = array(
'test' => 1,
); If we indent arrays based on $a = array(
'test' => 1,
); Does |
It uses spaces to line things up perfectly. But indenting to the next tab stop after the array keyword is pretty easy. PHPCS already determines the tab stops (i.e., how many spaces each tab is) and so fixing might be done in 2 steps:
Or it could be the other way; array sniff uses tabs and the sniff than bans tab indents replaces them with spaces. But that's not how the other sniffs work (they assume spaces then do tab replacement later) so it would probably be done using spaces. |
To get this formatting: $a = array(
'test' => 1,
); custom sniff can:
Won't described above approach create issues when nested arrays are found? |
on another note : Does the below code public function connect( ) need to be changed as public function connect() Please see the space between |
@harikt , what you describe isn't related to indentation. I bet there are special sniffs to validate function declaration that would do as you say. |
Sorry, just getting back to this. I tested this code: <?php
$client = new Client(
array(
'base_url' => \SproutVideo::$base_url,
'defaults' => array(
'headers' => array(
'SproutVideo-Api-Key' => \SproutVideo::$api_key,
'Content-Type', 'application/json;charset=utf-8'
),
)
)
); And ran PHPCBF over it with the PEAR and PSR2 standards, and got the same result, which was that the tabs were replaced by 4 spaces and no other formatting was changed. So I suspect something else is causing the indentation to be removed, but I have no idea what it is. The best way to find out is to get the smallest bit of code you can to replicate the problem, then run |
@gsherwood does your code have tabs and spaces ? I will run again when I get some time. Thanks. |
I only used tabs for indentation in that example. Do you have mixed indentation? |
iirc yes. Hari K T You can ring me : +91 9388 75 8821 http://harikt.com , https://github.com/harikt , Skype : kthari85 On Wed, Apr 22, 2015 at 9:05 AM, Greg Sherwood notifications@github.com
|
Probably not related, but shouldn't:
Be:
? |
@glen-84 good catch. May be. But I don't know for I could not test it now. Thanks |
I still can't replicate any problems with mixed spaces and tabs for indentation, so the above information is still something I need to try and replicate this issue. Or, a gist with the exact code causing the problem would also be fine. I may not be putting the tabs and spaces in the right locations to trigger a problem. |
ok thank you @gsherwood . I did tried once again, and I could not reproduce this again, we can close for now and open with more information when I notice next time. I will make sure next time I have the exact file attached. Thank you everyone for your valuable time. |
Hey @gsherwood I have a gist here . https://gist.github.com/harikt/7540f6a6e073e5a06a97 Anyone can try this and see if you guys can reproduce or not . Thank you. |
Thanks for the gist. That code is working for me as well (tabs are replaced by spaces but all the code remains indented to the same level) so I'll leave this closed. |
Hm. strange then why the indentation is different to me :/ . https://gist.github.com/harikt/7540f6a6e073e5a06a97#comment-1486628 |
Recently I was trying to fix via phpcbf and noticed the issue
it could have been like
I did noticed something else, but not able to get it :( . Will update when I find the same.
The text was updated successfully, but these errors were encountered: