Is there a “strict” case-sensitive syntax mode?

Welcome Forums General PowerShell Q&A Is there a “strict” case-sensitive syntax mode?

Viewing 2 reply threads
  • Author
    Posts
    • #215949
      Participant
      Topics: 1
      Replies: 0
      Points: 11
      Rank: Member

      I sort of understand the reasoning behind the decision to make the powershell syntax case-insensitive but when writing serious and complex scripts it is a terrible problem. Everybody is writing in his own style and reading and comprehending all that mess becomes mission impossible. Is there a way to turn on a “strict” mode which would require to use exact casing and ideally the long versions of the commands like Select-Object, Push-Location and so on?

      If there is no such feature, is possible to request implementing it?

    • #215955
      Participant
      Topics: 4
      Replies: 82
      Points: 251
      Helping Hand
      Rank: Contributor

      I don’t think there is any quick easy way to make PS globally case sensitive.  You can force case sensitivity in certain situations like using comparison operators such as -ceq instead of -eq.  Also, you might want to look at Set-StrictMode to eliminate what some (myself included) might consider bad coding practices that PS lets you get away with.

    • #215961
      Participant
      Topics: 12
      Replies: 1623
      Points: 2,565
      Helping Hand
      Rank: Community Hero

      There is a Strict Mode (https://redmondmag.com/articles/2017/12/28/understanding-powershell-strictmode.aspx). Strict mode is more for strongly-typed code, but not the case of the letters. It checks things like Gci (alias) should be Get-ChildItem. get-childitem would most likely be fine as long as it’s not an alias. Where should be Where-Object, but where-object is fine.

      Editors can have preferences like brackets, if everyone is using Visual Studio Code, you can force some settings. In general, I don’t think you can force Title case or something specific like this.

Viewing 2 reply threads
  • You must be logged in to reply to this topic.