intellij-powershell
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
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' ...
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.
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.
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.
BTW, it seems this issue duplicates #36 in both questions :)
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.
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.
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).