intellij-powershell icon indicating copy to clipboard operation
intellij-powershell copied to clipboard

Fomatter destroys correctness of code: Formatter removes white space after '-Not', and always adds space around = even when not a powershell-assignment

Open arberg opened this issue 2 years ago • 5 comments

Using plugin version 2.0.10. If I disable the plugin, the problem disappears.

It replaces if (-Not $DryRun) {} with if (-Not$DryRun) {}
regardless what comes after -Not it seems to just remove the spacing.

Also it adds white-space around =, which fails for lines like these git log --pretty=format:'%Cred' ... becomes git log --pretty = format:'%Cred' ...

arberg avatar May 05 '23 09:05 arberg

Space between -Not and the following element is configured with SPACE_AROUND_UNARY_OPERATOR setting, in the UI it's shown as Spaces :: Around operators :: Unary operators (!, -, +, ++, --), and it's unchecked by default.

VladRassokhin avatar Sep 03 '23 17:09 VladRassokhin

Thank you Vlad. Indeed enabling that setting does help. Interestingly the code in the example is broken when this is off. I don't know why this setting is even there.

image

image

I suppose it might be something IntelliJ adds that we cannot avoid... If the setting could be deleted, that would be optimal I would say.

arberg avatar Sep 04 '23 09:09 arberg

BTW, it seems this issue duplicates #36 in both questions :)

VladRassokhin avatar Sep 06 '23 08:09 VladRassokhin

I am still at the very beginning of the issue tracker grooming session, but still, let's mark that one as a duplicate of this (since this one has a more focused name).

I hope we'll get here eventually and provide some fix.

ForNeVeR avatar Sep 06 '23 21:09 ForNeVeR

Here another example that gets "destroyed": & msbuild ".\solution.sln" -t:Restore,Rebuild -p:RestorePackagesConfig=true -p:Configuration=$configuration -p:Deterministic=True which gets & msbuild ".\solution.sln" -t:Restore, Rebuild -p:RestorePackagesConfig = true -p:Configuration = $configuration -p:Deterministic = True it added spaces around = and a space after comma.

To work around that I'm using no spaces around "=" and also no space after "," in my formatting settings.

daniatic avatar Dec 11 '23 09:12 daniatic

Thanks for the discussion, everyone. I have added all your examples to the plugin tests, and fixed them all (hopefully without affecting any useful formatting).

ForNeVeR avatar Mar 10 '24 17:03 ForNeVeR