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 Optional PSUseConstrainedLanguageMode rule by joshcorr · Pull Request #2165 · PowerShell/PSScriptAnalyzer Conversation
Contributor
PR SummaryThis PR adds a new rule PSUseConstrainedLanguageMode that identifies PowerShell patterns incompatible with Constrained Language Mode, helping developers ensure scripts work in restricted environments. This rule is a Warning, but is optional and not enabled by default. New files: Modified files;
Features
Signature Awareness:
Array Type Support:
Configuration:
PR Checklist
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Josh Corrick (joshcorr)
requested review from
a team,
Christoph Bergmeister (bergmeister),
Mikey Lombardi (He/Him) (michaeltlombardi) and
Sean Wheeler (sdwheeler)
as code owners
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pull request overviewAdds a new optional ScriptAnalyzer rule ( Changes:
Reviewed changesCopilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsUh oh!
There was an error while loading. Please reload this page. Uh oh!
There was an error while loading. Please reload this page. Uh oh!
There was an error while loading. Please reload this page. Uh oh!
There was an error while loading. Please reload this page. Uh oh!
There was an error while loading. Please reload this page. Uh oh!
There was an error while loading. Please reload this page. Uh oh!
There was an error while loading. Please reload this page.
Contributor
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Contributor
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you please tidy away the whitespace diff please? might be easiest to just copy paste the first 58 lines from main over this
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in the latest commit.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
|
There was an error while loading. Please reload this page.
|
Wow, what a great idea and implementation Josh Corrick (@joshcorr) Build seems to be currently broken, if you could fix that would be great (maybe it's simply due to that whitespace diff in the xml file, msbuild can be picky at times. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
|
|
||
| // Only flag if COM object name was found AND it's not in the allowed list | ||
| if (!string.IsNullOrWhiteSpace(comObjectValue) && !AllowedComObjects.Contains(comObjectValue)) |
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.
minor but wouldn't it reader better as !comObjectValue.IsNullOrWhiteSpace() since comObjectValue is already typed as string? similar a bit below
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.
I looked into this and since the IsNullOrWhiteSpace() is a public static method on the string class, it can't be called from a string object., but rather from the class.
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.
ah, it's been clearly some time ago that I actively wrote a lot of C#, would have thought hoped that .NET would've improved on those things but seems not
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.
Adds a new optional ScriptAnalyzer rule to warn about PowerShell constructs that are incompatible with Constrained Language Mode (CLM), along with accompanying tests and documentation.
Changes:
PSUseConstrainedLanguageMode rule implementation (signature-aware + CLM pattern checks).Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
Rules/UseConstrainedLanguageMode.cs |
Implements the new CLM compatibility rule (AST checks + signature-aware behavior + caching). |
Tests/Rules/UseConstrainedLanguageMode.tests.ps1 |
Adds Pester coverage for the new rule, including signed/unsigned scenarios and performance-related validation. |
docs/Rules/UseConstrainedLanguageMode.md |
Documents rule purpose, configuration, and remediation guidance. |
docs/Rules/README.md |
Adds the new rule to the rules index table. |
Rules/Strings.resx |
Adds localized strings for rule name/description and diagnostic messages. |
💡 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.
| // Find all assignment statements in this scope | ||
| var assignments = scope.FindAll(testAst => testAst is AssignmentStatementAst, true); |
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Josh Corrick (@joshcorr) We merged a few other PRs that now caused a merge conflict here, can you pull latest of main into your branch and resolve conflict please? Thanks :-) |
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.
Thanks Josh Corrick (@joshcorr), hope the session goes well. I'll get this out!
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.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.