[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