Skip to content

Highlight keyword default cmd aliases #157

Description

@wesinator

Environment

  • Editor and Version (VS Code, Atom, Sublime): Atom 1.34.0
  • Your primary theme:

Issue Description

Please add highlighting of default command aliases (sal, iex, etc.)

Expected Behavior

Default cmd aliases highlighted as keywords / expressions

Code Samples

sal a New-Object;

Activity

  1. msftrncs commented on Feb 7, 2019

    @msftrncs
    Contributor

    The following is the suggestion you receive in VS Code with the PowerShell extension:

    'sal' is an alias of 'Set-Alias'. Alias can introduce possible 
    problems and make scripts hard to maintain. Please consider 
    changing alias to its full content.
    PSScriptAnalyzer(PSAvoidUsingCmdletAliases)
    

    As you stated, the alias's you know are just the default alias's. There is an alias table (dir alias:) and they can be changed or completely removed, as none of the alias's are actually keywords of the language. The alias's were merely provided to ease typing mundane command line work (or for quick adoption from other shells), where a script wouldn't be appropriate, but are not intended to be used inside script files, or meant to support directly utilizing scripts from other shells. I don't think (and its just opinion) that its a good idea to offer to highlight any of them (not even % or ? which is supported here, which causes %, the modulus operator, to not scope with the other operators).

    Here is a discussion on two particular alias that greatly make the point why alias should not be used in scripts: REDDIT: Curl author asks Microsoft to remove 'curl' and 'wget' aliases from PowerShell (it actually points back to a GitHub PR). I believe these particular alias's are now disabled on the Linux distributions of PowerShell core, among others. (actually, never existed in Core on Linux)

    On the other side, I do have a PR #156, to demonstrates an experimental statement style scoping that would cause the alias's to highlight as a function. This PR however has also removed '%' and ? as keywords, to be consistent.

    As a side note, I prefer not to use New-Object, instead using the syntax [type]::new() as it will produce a more consistent descriptive highlighting. (constructor in a class creating an arrayed instance of its base class)

    image

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions