PhpStorm formats multiline array with double tab
Answered
I've posted my question on stackoverflow but didn't get solution.
The problem is that PhpStorm(10) formats array with double indentation instead of single. So I expect this
public function behaviors ()
{
return [
[
'class' => NestedSetsBehavior::className()
]
];
}
but get this
public function behaviors ()
{
return [
[
'class' => NestedSetsBehavior::className()
]
];
}
I've tried to change different settings for indentation including 'Continuation indent' but still get the same.
Please sign in to leave a comment.
Hi there,
Please share you Code Style ("File | Export Settings") so it can be downloaded and checked locally.
https://www.dropbox.com/s/jiw9gybpwxfmmqw/PhpStormSettings.jar?dl=0
Thanks. So your code style schema is called "Default (1)", right?
Can you please also share some sample file (before reformatting) that has such issue.
I've tried it on a code you have provided (in a .php file -- I've only surrounded it with a class {} ) .. but it all works just fine. This is what I'm getting:
The only thing that I have changed is unchecked "Indent code in PHP tags" from "Code Style | PHP | Other" (otherwise "class" is indented too much ) but that does not have any affect on actual array indenting (I've checked reformatting results before and after).
P.S.
BTW -- do you use EditorConfig plugin .. and do you have .editorconfig files in this project? Settings from there will override whatever you will have in Code Style.
I've 3 installations of PhpStorm on different computers and the same thing happens for all. I look for EditorConfig plugin and have not found it.
So the file before reformatting (the way I want it to be)
https://www.dropbox.com/s/8m9zf8b3d8k55lm/TagBeforeFomat.php?dl=0
And after
https://www.dropbox.com/s/seb9vlz110f4dzy/TagAfterFormat.php?dl=0
There must be something else .. as it reformats arrays just fine here on my 2 computers (PhpStorm 10.0.3 on Windows 7 x64) -- I've tried again with your original non-modified code style.
Could you please disable ALL 3rd party plugins (not bundled by default); restart IDE and try again.
Another thing to check -- maybe that code style that you have provided is not what is actually used? Maybe you have and use project-specific code style ("Project") and not global one ("Default (1)")?
If disabling plugins does not do any different .. could you please: create brand new empty project; copy that file into it; try to reformat -- any difference?
I tried all that propose and nothing helped. Then I thought 'Wait!' and delete all my config directory. That helped. Though I need to restore all my configs from memory (to avoid this thing with double tab) now I am really happy with arrays.
Also, why does PHPStorm indent shorthand array brackets!?
I expect this:
But I get this:
It doesn't match with function formatting which I find jarring:
Any reason? Or just an omission?
@Dave
1) Please create separate thread for your issue
2) Please provide sample file (that can be downloaded and opened as is and not just copy-pasted from browser) + your code style
I've been having the same problem recently. Here's my Code Style settings:
https://www.dropbox.com/s/3pxludzbbhh5lut/phpstorm_code-style.jar?dl=0
As far as I can see above, the only solution offered is deleting all settings and setting everything again from memory. Obviously not ideal - has anything else come to light in the meantime? It would be useful to know which setting controls this, to just go and change it, but I can't find anything that changes it.
@Steve
No ideas.
I've activated your Code Style (named "Steve") and used it on this code (spaces used for indent):
After invoking "Code | Reformat Code" I've got the following (tabs in use):
I personally have no ideas why you see different results. Maybe it depends on the file it is used on?.. Maybe some 3rd party plugin affects this?..
I hope devs or tech support guys will have something to tell here.
This has been driving me absolutely crazy, and I think I just figured it out. If you have mixed content HTML/PHP in the same file, the array shorthand for some reason uses the HTML setting for continuation indent as you type, rather than the PHP one. HTML's continuation indent defaults to 8. I changed it to 4 and now my bracket array declarations look correct.
@Josh my God, that could be it. It did always seem to be erratic, and I have some dim awareness that this may have related to whether I'm working in (WordPress) functions files or template files that include HTML. Will try this out and see, but I'm optimistic. Thanks!
@Josh C, that's what the fix was for me. HTML's `Continuation indent` was the issue for m.
That fixed it for me as well. How annoying that was!
@Josh C, that's it! Thank you so much! This issue frustrating me a lot, even in 2020.
Just wanted to add that this fixed it for me too, even working in a PHP file with no mixed content!