Skip to content

Add check for capitalization for reserved powershell words #767

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
dchristian3188 opened this issue May 30, 2017 · 2 comments
Open

Add check for capitalization for reserved powershell words #767

dchristian3188 opened this issue May 30, 2017 · 2 comments

Comments

@dchristian3188
Copy link

One thing i would like to see is rules that check case of reserved powershell words like function, if, switch, class, etc.

A setting should be available to enforce all lower, upper and proper case. Ideally this would drive a correction that could be used by VSCode to auto correct.

@krissmilne
Copy link

As Powershell isn't a case sensitive language, it would be good to provide the case formatting options for the developers preference.

Something along the lines of:

//Changes the case for powershell reserved words (if, else, elseif, function, switch, param etc...) to either UPPER, lower or First (capitalises the first letter)
"powershell.codeFormatting.reservedWordCase": "lower", "upper", "first"

//Changes the case for powershell variables declared in the global or script scope to either UPPER, lower or FirstUpper (PascalCase) or firstLower (camelCase)
"powershell.codeFormatting.globalVariableCase": "lower", "upper", "FirstUpper", "firstLower"

//Changes the case for powershell variables declared in the local or private scope (within functions) to either UPPER, lower or FirstUpper (PascalCase) or firstLower (camelCase)
"powershell.codeFormatting.privateVariableCase": "lower", "upper", "FirstUpper", "firstLower"

//Autocorrects the case for recognised cmdlets and functions
"powershell.codeFormatting.cmdletCase": true, false

//Autocorrects the case for recognised parameters of cmdlets and functions
"powershell.codeFormatting.parameterCase": true, false

@Jaykul
Copy link
Contributor

Jaykul commented Nov 17, 2020

My 2c: I think "lower" should be the default, and "pascal" (or "proper") should be the only other option for keywords (and only because of the C# programmers who write the documentation). PSScriptAnalyzer is the defacto standard-bearer for PowerShell best practices, and I am reasonably sure the community wants to discourage the use of ALL CAPS or camelCase keywords in PowerShell. Honestly, I'm not even sure about PascalCase; newbies will discover some annoyed veterans if they start capitalizing keywords such as ForEach...

I also really like the idea of fixing the case on variables, but perhaps that should be a separate issue? I think you'd need to separate not just "global" but "constant" and "parameter" variables -- and you don't have a good way of doing that. I think a good first step would be to have the current capitalization fixer fix the variables based on "follow first use" -- make the case of each variable consistent throughout the file, without worrying about what kind of variable it is.

If we fix variable case, should we consider also enforcing the use of ALL_CAPS for environment variables, for compatibility reasons?

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

5 participants