psusecompatibleSyntax goes a bit too far.
Not sure if something has changed but I've noticed this recently, and it the hadn't registered before
Summary of the new feature
I'm seeing this
The constructor syntax '[type]::new()' is not available by default in PowerShell versions 3,4
I got the same with class We're trying to get people to move on from Windows PowerShell 5, but that has been around for 8 yeas or so and it might be time to review the pre-PowerShell 5 features people are told to avoid
Proposed technical implementation details (optional)
Drop checks for PowerShell 3 compatibility.
What is the latest version of PSScriptAnalyzer at the point of writing 1.22.0
It might also be considered to link this type of rules to the #Requires -Version x.x statement.
Originally posted by @iRon7 in https://github.com/PowerShell/PSScriptAnalyzer/issues/2046#issuecomment-2546082319
It might also be considered to link this type of rules to the
#Requires -Version x.xstatement.Originally posted by @iRon7 in #2046 (comment)
YES . If the solution were "Put a requires statement in if your code uses feature only in XX" (which only appeared if there was no such statement) that would be ideal.
You can specify the target versions to not get errors for older versions
https://learn.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/rules/usecompatiblesyntax?view=ps-modules
You can specify the target versions to not get errors for older versions
https://learn.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/rules/usecompatiblesyntax?view=ps-modules
Good to know, but it would be still be better if V3/4 checks were off by default, and/or there was check for requires.
You can specify the target versions to not get errors for older versions https://learn.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/rules/usecompatiblesyntax?view=ps-modules
Good to know, but it would be still be better if V3/4 checks were off by default, and/or there was check for requires.
I think because the rule is off by default, intent was to start with most versions and if people want they can overide. Defaults will also be debatable but I agree with original offer to offer the most analysis by default because the reality is that a lot of people use defaults and thus would never benefit from it
You can specify the target versions to not get errors for older versions https://learn.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/rules/usecompatiblesyntax?view=ps-modules
Good to know, but it would be still be better if V3/4 checks were off by default, and/or there was check for requires.
I think because the rule is off by default, intent was to start with most versions and if people want they can overide. Defaults will also be debatable but I agree with original offer to offer the most analysis by default because the reality is that a lot of people use defaults and thus would never benefit from it
I think I created this because on some system I was on after an update it started complaining that I'd used classes or ::new or something of that kind. I'm sure cases can be made for every possible default value :-) The best thing to come out of this for me I now that I don't need to turn the rule off, I can tell to it warn me if my V7 code will break on V5. But if the presence of requires silenced that, we'd be in the best place.
How does one get the compatibility doogit to work, please? Does the following suffice?
$ Install-Module -Name WindowsCompatibility -Scope CurrentUser
It seems not to suffice . .