Skip to content

Update PSUseCorrectCasing to enforce correct casing of automatic variables #1401

Open

Description

@xtqqczze

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

Activity

  1. bergmeister commented on Jan 22, 2020

    @bergmeister
    Collaborator

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

  2. xtqqczze commented on Jan 23, 2020

    @xtqqczze
    ContributorAuthor

    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

  3. iRon7 commented on Apr 21, 2026

    @iRon7
    Contributor

    I think this should also cover preference variables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions