★ wanayoo — archive 1999 https://github.com/PowerShell/PSScriptAnalyzer/issues/1401Nouvelle recherche | Portail wanayoo
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

Update PSUseCorrectCasing to enforce correct casing of automatic variables #1401

Open
xtqqczze opened this issue Jan 22, 2020 · 2 comments
Open

Comments

@xtqqczze
Copy link

@xtqqczze xtqqczze commented Jan 22, 2020 •

Summary of the new feature

Incorrect case of automatic variables should result in a PSUseCorrectCasing rule violation.

Proposed technical implementation details (optional)

Code using $error should result in a rule violation

Replacement with $Error should be suggested as a fix.

What is the latest version of PSScriptAnalyzer at the point of writing

1.18.3

@bergmeister
Copy link
Collaborator

@bergmeister bergmeister commented Jan 22, 2020 •

Certainly possible. Would we take the union of automatic variables from Windows PowerShell and PowerShell Core?

@xtqqczze
Copy link
Author

@xtqqczze xtqqczze commented Jan 23, 2020

There should only be rule violations for automatic variables present in the test environment. We can access a list of special variables at runtime by reflection:

[ref].
Assembly.
GetType('System.Management.Automation.SpecialVariables').
DeclaredFields.
Where{ $PSItem.FieldType -eq [string] }.
ForEach{ $PSItem.GetValue($null) }

https://github.com/SeeminglyScience/EditorServicesCommandSuite/blob/master/module/Classes/Utility.ps1

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

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.