-
Notifications
You must be signed in to change notification settings - Fork 382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to determine when script uses language features and/or cmdlets not available in the specified minimum version of PowerShell #127
Comments
👍 |
That would be really useful. That is what PSSA should be doing in the first place, finding pitfalls like this. They are not easy to check manually, checks are time consuming, and PS documentation sometimes does not mention version changes (e.g. P.S. I should say this, sorry. I am relatively experienced in PowerShell. I tried PSScriptAnalyzer and did not find it useful. Currently it simply does not help me, it does not find issues I am interested in. Instead it adds a lot of noise which rather wastes time. The tool is supposed to save time. I am sure it is too early to judge and a lot of things will be improved and new really useful checks will be added. Like the suggested by @rkeithhill here. |
+1 I would like to see this added such that: a) PSScriptAnalyzer identifies the minimum required version according to b) PSScriptAnalyzer raises a different warning if there is an indicated *Kirk Munro * Need a PowerShell SME for a project at work? Contact me On Fri, May 22, 2015 at 1:52 AM, Roman Kuzmin [email protected]
|
Some type accelerators were added in v3, i.e. will fail in v2, for example:
P.S. I do not use PowerShell 2.0. Why do I care? I develop several tools used by other people. From questions at Stack Overflow I can periodically see that PowerShell 2.0 is still is use. So that some of my tools target v2 as well (if this is not too difficult to achieve, why not?). Hence the interest. |
Yet another class of changes difficult to check manually is enum values. Example: the error action preference values:
|
Other items added in various releases that could be used in version analysis: v3: v4: A good way to find the items specific to a particular version of PowerShell is to search help. For example: Get-Help "PowerShell 3.0" or Get-Help "PowerShell 4.0" I'm not sure those will pick up on documentation where the "PowerShell x.0" string spans more than a single line though. And of course, this is a great resouce: |
I want to avoid having a single monolithic rule for all compatibility issues. My current thinking is to create another Source (or 3) for compatibility rules targeting PSv3, PSv4,and PSv5. That way we can approach this in a more incremental manner. Thoughts? |
Multiple rules with rule sets for different versions is fine with me. |
Yup, that works for me as long as I can select such rules easily enough. Perhaps |
Or, either: a) let us pick a collection of rule sets to use; or b) apply rule sets dynamically in certain circumstances (automatically grab *Kirk Munro * Need a PowerShell SME for a project at work? Contact me On Tue, Dec 1, 2015 at 6:16 PM, Keith Hill [email protected] wrote:
|
Nearly 3 years later... |
That addresses cmdlet compatibility but not sure if it addresses feature compatibility - e.g. support for enums, classes, new operators, new parameters, etc. Perhaps we could close this issue and open a new one that is more specific to features? |
Good point. A new issue would be good summarising all the differences, especially since PSSA does not need to support v2 any more and we can focus on changes that came only in v4/5/6. |
I truly miss ISESteroids' ability to look over the script and create the requires-statement for me. I'm still working with Posh v3 and even a few v2 systems and it would be great if I could invoke something with a Posh version as argument that would tell me if the script is compatible with that version and if not, why not. |
@PowerCoder Such functionality was actually added in 1.18 last year |
I apologize. My code is so clean nowadays I have never seen a single PSScriptAnalyzer squiggly in VSCode, so I figured it didn't test for it. Now I just need to figure out how to set the PoSh extension to check for compatibility with earlier versions of PoSh, so that I get my warnings when I use PoSh5/PwSh Cmdlets. But that is for another repo to help me with... |
Those rules only run after they've been configured as the extension cannot make assumptions around against which PS version or platforms the script needs to be compatible |
This is increasingly becoming an issue as PowerShell gets new language features and cmdlets. And cmdlets get new parameters, etc. I could have a #requires -version 3.0 in my script but I'm developing on PowerShell 5.0. It is real easy to slip up and use a lang feature ("using namespace System.Diagnostics") or a cmdlet (New-TemporaryFile) or a new cmdlet parameter (PassThru added to Enable-JobTrigger in v4). It would be great if ScriptAnalyzer saw a #requires -Version X.0 and warned (or errored) when I used a feature not available on X.0. Likewise, I would like to have a parameter to ScriptAnalyzer where I could tell it the minimum version I want to target (perhaps I have several scripts written at different times that have varying levels of #requires -Version).
For bonus points, if someone specified neither the command line parameter (MinimumPowerShellVersion) or had any #requires or min version in their PSD1 file, it would be nice if ScriptAnalyzer told me that - "Scripts require at least version 4 due use of -PassThru parameter on Enable-JobTrigger and use of Get-FileHash cmdlet).
Where things get a bit more tricky is setting a minimum Windows OS version. But the need is there since I have a whole bunch of cmdlets available to me on Windows 8.1 that I know are not available on Windows 7.
The text was updated successfully, but these errors were encountered: