-
Notifications
You must be signed in to change notification settings - Fork 400
Add PSAvoidUsingNewObject Rule #2109
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
base: main
Are you sure you want to change the base?
Conversation
@microsoft-github-policy-service agree |
👋 Hey @DrSkillIssue, thanks for putting this together; you've clearly put a lot of thought into the many ways you could try and sneak a Some things to look into:
I really liked your rule documentation, lots of detail and further reading links. ⭐ |
PR Summary
#2046
Adds a new built-in rule
PSAvoidUsingNewObject
that flags usage of theNew-Object
cmdlet and recommends using type literals with::new()
syntax instead for better performance and more idiomatic PowerShell code.What Changed
AvoidUsingNewObject
New-Object -TypeName
usage while preservingNew-Object -ComObject
(COM objects cannot use type literals)Key Features
New-Object -ComObject
calls since they cannot be replaced with type literalsNew-Object @params
)$using:
variablesPR Checklist
.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
to the beginning of the title and remove the prefix when the PR is ready.