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

Highlight keyword default cmd aliases #157

Open
wesinator opened this issue Feb 6, 2019 · 1 comment
Open

Highlight keyword default cmd aliases #157

wesinator opened this issue Feb 6, 2019 · 1 comment

Comments

@wesinator
Copy link

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;
@msftrncs
Copy link
Contributor

msftrncs commented Feb 7, 2019

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants