GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Add new AvoidUsingNewObject rule by iRon7 · Pull Request #2186 · PowerShell/PSScriptAnalyzer Conversation
|
| File | Description |
|---|---|
| docs/Rules/README.md | Registers the new rule in the documentation rules table. |
| docs/Rules/AvoidUsingNewObject.md | Adds rule reference documentation and examples. |
| Tests/Rules/AvoidUsingNewObject.tests.ps1 | Adds Pester coverage for rule behavior, suppression, and -fix. |
| Rules/Strings.resx | Adds localized strings for rule name/description/message/correction. |
| Rules/AvoidUsingNewObject.cs | Implements the rule logic and suggested corrections. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| else if (boundResult.ConstantValue != null) | ||
| { | ||
| string valueText = boundResult.Value.Extent.Text; | ||
| if ( | ||
| boundResult.Value is StringConstantExpressionAst stringConstant && | ||
| stringConstant.StringConstantType == StringConstantType.BareWord | ||
| ) | ||
| { | ||
| valueText = '"' + valueText.Replace("\"", string.Empty) + '"'; // Test""123 --> "Test123" | ||
| } | ||
| correction = "[" + typeName + "]" + valueText; | ||
| } |
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think I got this right, if the -ArgumentList contains a constant value, I might use a shorter (preferred) syntax by simply casting the value expression.
For the given example: New-Object DateTime 0 vs [DateTime]0, both return the same results:
Monday, January 1, 0001 12:00:00 AM
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Andy Jordan (@andyleejordan), thanks for trying to push this one through. I am currently on holidays, I will check next week on why it failed the workflow. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Apparently I was behind with my fork which caused all kind of errors. All local tests (PowerShell 5.1 and 7) have a green light now... |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Christoph Bergmeister (@bergmeister), can I get your approval (or feedback) on this one? I realy would like to see this rule going in to the next PSScriptAnalyzer release. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
iRon7 Thanks for the reminder (always good). I think given it's an optional rule, should be OK to add it, nothing I have against it. Kicked off CI tests now |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Automated corrections can alter executable PowerShell semantics across varied constructor and conversion forms, requiring final human validation.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Happy to take this change. There are minor Copilot comments around also alerting in other scenarios and potential edge cases but what the rule does at the moment is good enough for an optional rule, it doesn't need to be perfect
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sean Wheeler (@sdwheeler), Mikey Lombardi (He/Him) (@michaeltlombardi), Apparently, I need an additional review/approval. Can you take a look at this rule PR? Thanks in advance, |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
iRon7 We have a new format for rule documentation. Please see the attatched files for a template and instructions.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Hello Sean Wheeler (@sdwheeler), I am probably missing something but there are no files attached (aka, the two links are broken)... |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
iRon7 The links work for me. However, these files need to be added to the repository. You can get them from this PR: #2215. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
iRon7 can you please resolve the merge conflict? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Christoph Bergmeister (@bergmeister), Sean Wheeler (@sdwheeler) Not sure how to resolve this conflict... My change (new rule) should appear some where on line 45: And probably need to be changed to: But what about the 50 following rules and their related reference list? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Copilot resolve the merge conflicts in this pull request (it seems Copilot cannot do it) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Automatic corrections can change runtime behavior, discard side effects and redirections, or generate invalid PowerShell syntax.
[Type]value) for any constant argument, but PowerShell…Review effort: Balanced
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| // But not both, as that would mean there isn't a simple | ||
| // type initializer available as a replacement. | ||
| if ( | ||
| bindingResult.BoundParameters.Count <= 2 && |
| } | ||
| else if (isProperty) | ||
| { | ||
| correction = "[" + typeName + "]" + boundResult.Value.Extent.Text; |
| stringConstant.StringConstantType == StringConstantType.BareWord | ||
| ) | ||
| { | ||
| valueText = '"' + valueText.Replace("\"", string.Empty) + '"'; // Test""123 --> "Test123" |
| { | ||
| valueText = '"' + valueText.Replace("\"", string.Empty) + '"'; // Test""123 --> "Test123" | ||
| } | ||
| correction = "[" + typeName + "]" + valueText; |
| !parenExpressionAst.Pipeline.Extent.Text.StartsWith(",") | ||
| ) | ||
| { | ||
| correction = "[" +typeName + "]::new" + parenExpressionAst.Extent.Text; |
| typeName | ||
| ); | ||
|
|
||
| if (correction != null) |
There was an error while loading. Please reload this page.
AI's could be worse than humans in a meeting: they are programmed to give an opinion even it isn't related to the issue concerned. For the new suggestions: unfortunately I haven't the time to go over them in depth (again) this weekend and after that, I will be on holidays (without access to a computer). Besides, most of the suggestions are trivial cornercases that open a new door to a rabbithole with another cornercase at the bottom. In general, I wouldn't make the rule too complex and generally push for the PowerShell Anyways, for resolving the actual merge conflict issue, I would ask Copilot to review the change in PR2196 where it proposed the new format. Note here that any solution to a specific new-rule PR merge conflict, will unlikely resolve any new-rule merge requests that follow in the future (see also issue #2220). My recommendation (also to Sean Wheeler (@sdwheeler) ) is to go back to the original README format that doesn't use references. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
At least 1 approving review is required to merge this pull request.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Rule request:AvoidNewObjectCmdlet
There was an error while loading. Please reload this page.