[Resolved] PSSCriptAnalyzer warnings in VSCode

Has anyone figured out how to make VSCode ignore these warnings?

PSSCriptAnalyzer(PSUseDeclaredVarsMoreThanAssignments)

I’ve searched the wide webs and found that they can be suppressed by adding line on top of script, but I had no luck.
A lot of my files are dot sourced and I know these variables are used.

Hey raymix,
I use a PSScriptAnalyzerSettings.psd1 file in the root of my workspace (although you can change the path in your settings json to point a particular location).
You should be able to configure it there.

Feel free to take from mine what you want: https://github.com/insomniacc/Misc/blob/master/PSScriptAnalyzerSettings.psd1

You can include/exclude rules and apply settings/config to each that allow. The rule definitions can be read here:

1 Like

@insomniacc this works better than expected, thank you!

All I had to do is add your example to the root, comment out stuff I don’t care about from include section and restart VSCode.

Cheers

No Problem, Glad I could help.

Also if you weren’t aware, as a VSCode hotkey ALT + SHIFT + E will auto fix all aliases in your script.

You can also use:

Invoke-ScriptAnalyzer -Path "scriptpath.ps1" -Settings "PSScriptAnalyzerSettings.psd1" -fix

Which will auto fix everything it can including aligning hashtables etc.

:+1:

1 Like

My apologies for reviving this almost ancient thread, but would you perhaps be able to share this again?
The current url 404’s, but I’m very keen to have a look at it :smiley:

Hey!
Unfortunately it looks like I removed that quite some time back I’m afraid, I was doing a clean up and didn’t realise it was still linked here! I had a poke around and didn’t find a backup either.
I guess I figured that it was so well documented that I wouldn’t need it.

There’s plenty of examples out there if you search for ‘PSScriptAnalyzerSettings.psd1’
Here’s one I found nested in a PSGallery module:
https://www.powershellgallery.com/packages/Cluster/0.1.3/Content/PSScriptAnalyzerSettings.psd1

Further docs:

Yep!
Thanks a bunch :slight_smile:

I was already able to configure something myself based on the docs you also referenced. My brain just reached out for a shortcut to get me started haha

Thanks for your time and efforts nonetheless!