Is there a way to suppress PSScriptAnalyzer
from highlighting alias
warnings? e.g.
'rm' is an alias of 'Remove-Item'. Aliases can introduce possible problems and make scripts hard to maintain. Please consider changing alias to its full content.
Aliases in PowerShell are extremely useful. I have a simple rule: I only ever use the rational built-in aliases in scripts (I ignore the strange ones). Why? Well, most of these particular aliases are now 13 years old and have never changed (PowerShell 1.0 release November 14, 2006). So, for example, %
or ls
or cd
are reliable in 99.99% of cases. I consider 99.99% reliability to be "good enough". Possibly the single-most-over-repeated comment on all PowerShell StackOverflow questions is "Note: it is not recommended to use aliases in PowerShell scripts as they can change!" (not recommended by whom I often wonder? God? ;-) )
However, PSScriptAnalyzer
in VSCode highlights all aliases as problems so that my current 7,000 line script has 488 such "problems". Is there a way to tell PSScriptAnalyzer
that I like aliases, I intend to use aliases for the vastly more concise code, clarity, and greatly improved readability that they give me, and so I do not consider them to be problems?
%
,ls
,cd
etc. I have never been one for using the more exotic (and frankly weird) aliases likervpa
(Resolve-Path),rwmi
(Remove-WmiObject),sajb
(Start-Job) etc. I use only those that are ultra-reliable - and by ultra-reliable, I mean "have never changed in 13 years" and "the kind of commands that I use very often every time I use PowerShell" (whichrvpa
never falls into the category of). – Gavottesc -> Set-Content
works in 5.1, was removed in 6.2¯\_(ツ)_/¯
regardless: yes, you can suppress individual rules. Open the Command Palette (Shift+Ctrl+P), search for "Select PSScriptAnalyzer Rules" and uncheckPSAvoidUsingCmdletAliases
– Chartiersc
is one that I have never used in any script, but good one (I'm guessing that they removed this as it might conflict with a linux command? I won't be having that problem in usingls
ormv
then!:-p
). Thanks Mathias, I'll go and look for these rules now! – GavotteForEach-Object
,GetChild-Item
(instead ofls
),Remove-Item
(instead ofrm
) everywhere. A philosophical question: why isrm
in Linux NOT freaking ugly, but is in PowerShell? ... Another philosophical question: why do people NOT feel the need to say "Note: it is not recommended to use functions in scripts as function names can change!" hmm... lol :-D – Gavottedir D:\ | more
. I bet more than a million dollars that you would be extremely hard-pressed to find even a single person with rudimentary programming ability that would find this "indecipherable". I get that you are against aliases, I just find the almost religious adherence to never using aliases (and the almost resentment projected at anyone that dares too!) to be slightly ... bewildering. I completely defend/support your right to not use aliases, I just find it somewhat "rigid". :-) – Gavotte