Skip to content

Update PSUseCorrectCasing to enforce correct casing of automatic variables #1401

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

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

Comments

@xtqqczze
Copy link

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 commented Jan 22, 2020

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

@xtqqczze
Copy link
Author

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
Development

No branches or pull requests

3 participants