Posted in Editor, Powershell, vscode

Let you IDE dress it up

I am re-posting something I posted in a small Slack group.

I started with showing how easy it can be to let your editor (in this case VSCode which personally I can’t see why you would be using anything else but …) come in and make your code look right. Let’s face it, we have an idea for what we are coding, and we want to stay focused on that. Between interruptions, writing, testing, writing again just focus on the task at hand is ideal. One thing that can help with that is the code formatting capabilities of your Editor/IDE.

So in the first video I have a simple scratchpad script where I am testing an If\ElseIf statement versus a Switch statement. There is nothing special in the code, matter of fact it just might be flawed, hence why it is a “scratchpad” script. The point is I was working through and then used Format Document to dress up the code (I believe there is also the use of “Trim Trailing Whitespaces” involved as well).

So as you see the format did dress up my sloppy code but I was not thrilled on how that destroyed my concise switch statement elements. Yes it formatted according to the settings in my settings.json file but…

I kept thinking about that scenario and then I remembered the setting that would probably work through this. In the following video I show the same code, format and the destruction, I mean expansion of my switch elements, Ctrl-Z, change the setting and the Format Document works to my liking…

So I stay in OTSB but because they are simple elements my Switch statement stays just a few lines.

This applies to other languages in Visual Studio Code but this is a PowerShell blog so… If you are using Visual Studio Code for PowerShell work, go into your Settings file (Use the ⚙ icon and select settings and then search for “PowerShell Code Format” .  When you get to the Code Formatting: Preset check here for a great reference when you select the formatting style.

Again, I welcome any questions or feedback you might have. Now back to work.

 

 

Author:

USMC, CVID, Technology, PowerShell... just general ramblings

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s