Skip to content
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

psusecompatibleSyntax goes a bit too far. #2041

Open
jhoneill opened this issue Nov 1, 2024 · 6 comments
Open

psusecompatibleSyntax goes a bit too far. #2041

jhoneill opened this issue Nov 1, 2024 · 6 comments

Comments

@jhoneill
Copy link

jhoneill commented Nov 1, 2024

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

@iRon7
Copy link

iRon7 commented Dec 16, 2024

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)

@jhoneill
Copy link
Author

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.

@bergmeister
Copy link
Collaborator

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

@jhoneill
Copy link
Author

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.

@bergmeister
Copy link
Collaborator

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

@jhoneill
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants