PSScriptAnalyzer icon indicating copy to clipboard operation
PSScriptAnalyzer copied to clipboard

psusecompatibleSyntax goes a bit too far.

Open jhoneill opened this issue 1 year ago • 7 comments

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

jhoneill avatar Nov 01 '24 18:11 jhoneill

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

iRon7 avatar Dec 16 '24 16:12 iRon7

It might also be considered to link this type of rules to the #Requires -Version x.x statement.

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.

jhoneill avatar Dec 16 '24 18:12 jhoneill

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

bergmeister avatar Mar 12 '25 21:03 bergmeister

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.

jhoneill avatar Mar 13 '25 01:03 jhoneill

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

bergmeister avatar Mar 13 '25 20:03 bergmeister

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.

jhoneill avatar Mar 14 '25 12:03 jhoneill

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 . .

LinuxOnTheDesktop avatar Aug 31 '25 13:08 LinuxOnTheDesktop