GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add UseConsistentCasing by Jaykul · Pull Request #1704 · PowerShell/PSScriptAnalyzer

Conversation

@Jaykul

@Jaykul Joel Bennett (Jaykul) commented Aug 17, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Add lowercase keyword (and operator) enforcement as a separate rule.

I was thinking about adding a check for the correct case of [Types] and [Attribute()]s, but I think that should probably be in the original rule (UseCorrectCasing), which begs the question of whether we should just add that (or all of this) to the existing rule...

Originally, I made a separate rule because I thought I might need to configure the type of case ("lowercase", "UPPERCASE", "CorrectCase") ... but I quickly decided all-caps is awful, and there is no "correct" case (the C# tokenizer code just capitalizes the first letter of each token, and the documentation is inconsistent about capitalization of keywords and operators).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jkav58 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@Jaykul

Joel Bennett (Jaykul) commented Aug 17, 2021

Copy link
Copy Markdown
Contributor Author

Looks like I missed updating some docs/tests

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Jaykul
Joel Bennett (Jaykul) force-pushed the jaykul/feature/keywordcase branch from c9fe6ea to df1e30d Compare August 17, 2021 03:35
@Jaykul

Joel Bennett (Jaykul) commented Aug 17, 2021

Copy link
Copy Markdown
Contributor Author

Hold off merging this, because I have realized that it does the wrong thing for a few operators.

rjmholt reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rjmholt
Rob Holt (rjmholt) marked this pull request as draft August 17, 2021 16:43
rjmholt
Rob Holt (rjmholt) reviewed Aug 17, 2021
View reviewed changes
Comment thread RuleDocumentation/UseConsistentCasing.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Rules/Strings.resx Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Rules/UseConsistentCasing.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Rules/UseConsistentCasing.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Rules/UseConsistentCasing.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Rules/UseConsistentCasing.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Rules/UseConsistentCasing.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Rules/UseConsistentCasing.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Rules/UseConsistentCasing.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Rules/UseConsistentCasing.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

@Jaykul
Joel Bennett (Jaykul) marked this pull request as ready for review August 19, 2021 03:43
bergmeister
Christoph Bergmeister (bergmeister) reviewed Aug 24, 2021
View reviewed changes
Comment thread Rules/UseConsistentCasing.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

bergmeister
Christoph Bergmeister (bergmeister) reviewed Aug 24, 2021
View reviewed changes

@bergmeister Christoph Bergmeister (bergmeister) left a comment

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the effort, looks ok from a high level.
But we already have a UseCorrectCasing rule, which is used for cmdlet casing at the moment but I think we could just add CheckOperator and CheckKeyword as options to it and a new option for CheckCmdlet so that user can pick and choose what they prefer. Keeping it in one rule will make things easier to integrate the new settings into the VS-Code extension, which already has scaffolding for UseCorrectCasing. Also, if you wanted the rule to be usable by the formatter and the vs-code extension, you'd have to register it here.
WDYT Rob Holt (@rjmholt)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Jaykul reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@rjmholt

Rob Holt (rjmholt) commented Aug 24, 2021

Copy link
Copy Markdown
Contributor

which begs the question of whether we should just add that (or all of this) to the existing rule...

we already have a UseCorrectCasing rule, which is used for cmdlet casing at the moment but I think we could just add CheckOperator and CheckKeyword as options to it and a new option for CheckCmdlet so that user can pick and choose what they prefer

Sorry, I meant to get back to this question earlier.

I think it's better all in one rule, because:

  • We have an ongoing problem in PSScriptAnalyzer where rules that do specific things are given general names and then confusingly have competing rules next to them with a name that makes them hard to differentiate
  • We also have the opposite problem where some rules have very specific names but philosophically should do more (for example AvoidUsingInvokeExpression should also warn against [scriptblock]::Create() and maybe some other things)
  • We have a good story for rule configuration
  • In this particular case, I think the desires to case cmdlets and to case keywords/operators correctly are cohesive and really do belong in one rule
  • We unfortunately also have a bad story for formatting currently, so piggy-backing on an established formatting rule also provides a workaround there

All the code looks good and looks pretty portable at this stage, so hopefully it's just a case of sticking it inside of some conditional methods in UseCorrectCasing, rejigging the configuration and moving the tests over. But let me know if it's more complicated than that.

Jaykul reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Jaykul

Joel Bennett (Jaykul) commented Aug 26, 2021

Copy link
Copy Markdown
Contributor Author

I'm quite happy to merge them. This was a safer PR just because if you didn't want it, I could take my code and go home 😉

I did add this one to the formatter (you can see in the tests that I verified that worked).

rjmholt reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@totkeks

Norman Dankert (totkeks) commented Nov 8, 2022

Copy link
Copy Markdown

Any updates on this PR? Would be nice to have this feature in vscode so it autoformats my keywords properly.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Jaykul

Joel Bennett (Jaykul) commented Nov 9, 2022

Copy link
Copy Markdown
Contributor Author

I quite forgot about it. I'll try to look at it again this week

bergmeister and ykuijs reacted with heart emoji
All reactions
  • ❤️ 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@PrzemyslawKlys

Przemysław Kłys (PrzemyslawKlys) commented Feb 19, 2023

Copy link
Copy Markdown
Contributor

Reminder Joel Bennett (@Jaykul) that it's already next week 😂😂

bergmeister, Jaykul, and ykuijs reacted with laugh emoji
All reactions
  • 😄 3 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bergmeister Christoph Bergmeister (bergmeister) assigned Christoph Bergmeister (bergmeister) and Joel Bennett (Jaykul) and unassigned Christoph Bergmeister (bergmeister) Feb 22, 2023
@ykuijs

Yorick Kuijs (ykuijs) commented Apr 5, 2023

Copy link
Copy Markdown

Any update on this PR?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bergmeister

Christoph Bergmeister (bergmeister) commented Jan 2, 2024

Copy link
Copy Markdown
Collaborator

Last chance Joel Bennett (@Jaykul) as we are starting to wrap up for next release this month

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Jaykul
Joel Bennett (Jaykul) force-pushed the jaykul/feature/keywordcase branch from 522aa79 to 7525ff1 Compare February 16, 2024 07:10
@Jaykul

Joel Bennett (Jaykul) commented Feb 16, 2024

Copy link
Copy Markdown
Contributor Author

It's been a long, long time...
There's so much I feel that I should say
But words can wait until some other day

totkeks reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@totkeks

Norman Dankert (totkeks) commented Apr 12, 2024

Copy link
Copy Markdown

I have seen that this PR has gotten stale a bit again. Is there anything that could be done to help complete it?

I came across this again, because I noticed that I lack an auto-formatter for casing in VS Code for my PowerShell scripts. Which is why it would be really cool to have.

Jaykul reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Jaykul

Joel Bennett (Jaykul) commented Nov 25, 2024

Copy link
Copy Markdown
Contributor Author

Ping?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bergmeister
Christoph Bergmeister (bergmeister) requested review from Andy Jordan (andyleejordan), Mikey Lombardi (He/Him) (michaeltlombardi) and Sean Wheeler (sdwheeler) as code owners February 17, 2025 21:11
bergmeister
Christoph Bergmeister (bergmeister) approved these changes Feb 17, 2025
View reviewed changes

@bergmeister Christoph Bergmeister (bergmeister) left a comment

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If tests still pass, happy to finally merge it :-)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
sdwheeler
Sean Wheeler (sdwheeler) approved these changes Feb 18, 2025
View reviewed changes

@sdwheeler Sean Wheeler (sdwheeler) left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the changes include configuration options. We need to document that. I am OK with accepting the PR as is if someone will add a comment to the PR explaining the configurating with an example. I can update the docs based on that.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Jaykul
Joel Bennett (Jaykul) commented Feb 19, 2025
View reviewed changes
Comment thread Tests/Rules/UseCorrectCasing.tests.ps1
It "Does not throw when correcting certain cmdlets (issue 1516)" {
$scriptDefinition = 'Get-Content;Test-Path;Get-ChildItem;Get-Content;Test-Path;Get-ChildItem'
$settings = @{ 'Rules' = @{ 'PSUseCorrectCasing' = @{ 'Enable' = $true } } }
$settings = @{ 'Rules' = @{ 'PSUseCorrectCasing' = @{ 'Enable' = $true; CheckCommands = $true; CheckKeywords = $true; CheckOperators = $true } } }

@Jaykul Joel Bennett (Jaykul) Feb 19, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the settings for the rule

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Jaykul

Joel Bennett (Jaykul) commented Feb 19, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

That's an interesting request, Sean Wheeler (@sdwheeler) -- do we have documentation somewhere about the options?
I mean, it's not generally in the docs ...

The settings are:

'PSUseCorrectCasing' = @{ 
    Enable = $true
    CheckCommands  = $true # Require the case of all commands to match their actual casing.
    CheckKeywords  = $true # Require the case of all keywords to be lowercase.
    CheckOperators = $true # Require the case of all operators to be lowercase.
}
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sdwheeler

Sean Wheeler (sdwheeler) commented Feb 19, 2025

Copy link
Copy Markdown
Contributor

That's an interesting request, Sean Wheeler (@sdwheeler) -- do we have documentation somewhere about the options?
There are several configuration examples in the docs. Here is one: https://learn.microsoft.com/powershell/utility-modules/psscriptanalyzer/rules/alignassignmentstatement?#configuration

What are the default values?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@andyleejordan
Andy Jordan (andyleejordan) force-pushed the jaykul/feature/keywordcase branch from f949196 to 3ba33ac Compare February 19, 2025 22:45
@Jaykul

Joel Bennett (Jaykul) commented Feb 20, 2025

Copy link
Copy Markdown
Contributor Author

The default should be all $true the way I wrote it in the example.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sdwheeler

Sean Wheeler (sdwheeler) commented Feb 20, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Joel Bennett (@Jaykul)

The default should be all $true the way I wrote it in the example.

I understand the example shows them as all true. What is the default value if the user doesn't provide a configuration?

Sorry, I went back and reviewed the code again. I see where you set the default values.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@andyleejordan

Andy Jordan (andyleejordan) commented Mar 13, 2025

Copy link
Copy Markdown
Member

Christoph Bergmeister (@bergmeister) thoughts on merging this and doing a 1.3 release?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Joel Bennett (Jaykul) added 2 commits March 13, 2025 11:19
@Jaykul @andyleejordan
Correct casing for keywords and operators
fc725c5
@Jaykul @andyleejordan
Change which command I use in tests because 'more' was a function in …
3ba45d0
…PS5.1
@andyleejordan
Andy Jordan (andyleejordan) force-pushed the jaykul/feature/keywordcase branch from 3ba33ac to 3ba45d0 Compare March 13, 2025 18:19
@andyleejordan
Andy Jordan (andyleejordan) enabled auto-merge (squash) March 13, 2025 18:20
@andyleejordan
Andy Jordan (andyleejordan) merged commit 37ddc1c into PowerShell:main Mar 13, 2025
@bergmeister

Christoph Bergmeister (bergmeister) commented Mar 13, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

Christoph Bergmeister (@bergmeister) thoughts on merging this and doing a 1.3 release?

Andy Jordan (@andyleejordan) Yes to both.

I assume you meant 1.24 release though? Feel free to message me if you have question or want to plan it. I am on Slack and the PWG (PowerShell Working Group) Discord. At release time, we also sync our doc changes into msdocs repos, which is also a good time to check whether there were any changes in msdocs that weren't backported to PSSA (Sean usually does it but as it's manual, it's easy to omit some)

For consumers like PSES, we specify the rules and arguments explicitly and should set our own defaults. What I've usually done is add variable layer in PSES repo and in vscode-powershell repo, add new user setting(s) for it but don't enable them in next extension release so that people can try it and feedback before enabling by default.
Wiring in PSES is here: https://github.com/PowerShell/PowerShellEditorServices/blob/main/src/PowerShellEditorServices/Services/Workspace/LanguageServerSettings.cs

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Mar 15, 2025
v1.24.0: Thanks to all the new contributors! #2084
Merged
Document new optional parameters added to UseCorrectCasing in #1704 #2086
Merged
@andyleejordan Andy Jordan (andyleejordan) mentioned this pull request Mar 19, 2025
Backport MSDocs changes #2085
Merged
5 of 6 tasks
This was referenced Oct 31, 2025
PSUseCorrectCasing: operators casing treated differently #2136
Closed
Update docs and diagnostic message for UseCorrectCasing #2138
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@bergmeister Christoph Bergmeister (bergmeister) bergmeister approved these changes
@michaeltlombardi Mikey Lombardi (He/Him) (michaeltlombardi) Awaiting requested review from michaeltlombardi michaeltlombardi is a code owner
@andyleejordan Andy Jordan (andyleejordan) Awaiting requested review from andyleejordan
+2 more reviewers
@rjmholt Rob Holt (rjmholt) rjmholt left review comments
@sdwheeler Sean Wheeler (sdwheeler) sdwheeler approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@Jaykul Joel Bennett (Jaykul)

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

8 participants

@Jaykul @rjmholt @totkeks @PrzemyslawKlys @ykuijs @bergmeister @sdwheeler @andyleejordan
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.