| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
@microsoft-github-policy-service agree |
Sorry, something went wrong.
|
👋 Hey Dr. Skill Issue (@DrSkillIssue), thanks for putting this together; you've clearly put a lot of thought into the many ways you could try and sneak a -ComObject in 😎. Some things to look into:
I really liked your rule documentation, lots of detail and further reading links. ⭐ |
Sorry, something went wrong.
|
Dr. Skill Issue (@DrSkillIssue) There are 2 test failures, can you please look into fixing them? |
Sorry, something went wrong.
There was a problem hiding this comment.
Once my comments are being addressed, I'd be happy to approve, the most important one is that I think rule should not be enabled by default to start with
Sorry, something went wrong.
There was a problem hiding this comment.
please tidy up diff
Sorry, something went wrong.
|
|
||
| foreach (var assignment in assignments) | ||
| { | ||
| if (assignment.Right is CommandExpressionAst cmdExpr) |
There was a problem hiding this comment.
there are a few areas like this one where indentation could be reduced. Here we could e.g. negate statement and continue with next loop member so that other code can just be below at same indentation level: if (assignment.Right is not CommandExpressionAst cmdExpr) { continue; }
Sorry, something went wrong.
There was a problem hiding this comment.
this file is to replicate setting used by PSGallery to scan code when users upload new module and send email if there are violations. I don't even know whether this file is still in sync as of today but this file should only be updated by PSGallery members who know the rules used by PSGallery (and consider adding new ones).
Can you comment on whether this file is up to date and if not open separate PR to sync please alerickson ?
Sorry, something went wrong.
There was a problem hiding this comment.
I am not sure what the purpose of this settings file is but until then I'd not recommend touching it please
Sorry, something went wrong.
| #if !CORECLR | ||
| [Export(typeof(IScriptRule))] | ||
| #endif | ||
| public class AvoidUsingNewObject : IScriptRule |
There was a problem hiding this comment.
With this inheritance rule will run by default but I fear it will cause a big backlash as many people run PSSA in CI. I suggest to inherit from ConfigurableRule so that it's not enabled by default. See this PR for an example of how to: #2124
Sorry, something went wrong.
|
Despite the nice work already put in this rule, it appears to me that the PR it is stalled on a minor step:
|
Sorry, something went wrong.
|
Dr. Skill Issue (@DrSkillIssue), Reading more closely through the comments, I see that there is more behind the stall of this PR than thought initially. Please, let me know what you are planned with this pending PR. |
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks for the contribution Dr. Skill Issue (@DrSkillIssue) — and welcome! The rule itself is one we've previously said we'd accept (#2046), the documentation you wrote is genuinely good (clear examples, real rationale), and the variable-tracking work for splatting/$using: scenarios shows real care. Before this can land there's a mix of correctness, hygiene, and design things to work through.
CI is failing for two real reasons that need fixing:
Two correctness bugs — both of which Liam Peters (@liamjpeters) already pointed out and are worth fixing with tests:
Hygiene cleanup needed:
Design question — and this one I'd really like your view on, plus Christoph Bergmeister (@bergmeister)'s: the rule is currently added to both PSGallery.psd1 and ScriptFunctions.psd1, which means it would be enabled by default the moment we ship it. New-Object is still legitimately used in a lot of production code (especially for COM, for -Property splatting, and in modules that target older PowerShell versions), and turning a Warning on by default for the entire ecosystem is a different commitment than shipping the rule itself. I'd lean toward starting it disabled — either omitted from the default presets, or in a strict/opt-in preset only — and revisiting once we see how it lands. Curious what you think.
Test structure — non-blocking, but worth considering: the bulk-file-with-assertion-count style ($violations.Count | Should -Be 17) makes regressions hard to localize — a count drifting from 17 to 16 doesn't tell you which scenario broke. Splitting the cases into individual It blocks (one per scenario) would pay off the next time someone touches this rule. Up to you whether to do that here or as a follow-up.
Once the CI failures, the two bugs (with regression tests), and the hygiene items are addressed, and we settle the default-on question, I think this is in good shape. Happy to help if you hit anything weird.
— Drafted by Copilot (Claude Opus 4.7)
Sorry, something went wrong.
as previously commented I think we should not touch the settings preset files. we should just worry about defaults when running invoke-scriptanalyzer. It's up to PSGallery team to maintain this settings file, which they run when someone uploads a module to Gallery. The other file I am not sure who uses and classify it as legacy |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
PR Summary
#2046
Adds a new built-in rule PSAvoidUsingNewObject that flags usage of the New-Object cmdlet and recommends using type literals with ::new() syntax instead for better performance and more idiomatic PowerShell code.
What Changed
Key Features
PR Checklist