Skip to content

-Mode parameter for Set-StrictMode #16388

Closed

Description

@iRon7

Summary of the new feature / enhancement

Setting Set-StrictMode to a specific -Version level automatically implies that all prior prohibitors are enabled. Meaning that there is no way just select for a recent prohibitor (e.g. "out of bounds or unresolvable array indexes") without also selecting a earlier prohibitor (e.g. "references to uninitialized variables").

A -Modes parameter that supports certain prohibit flags, e.g.:

[Flags()] enum StrictModes {
    ProhibitReferencesToUninitializedVariables = 1
    ProhibitReferencesToNonExistentProperties = 2
    ProhibitUseOfCallingMethodSyntax = 4
    ProhibitUnresolvableArrayIndexes = 8
    ProhibitOmittingWriteOutput = 16
}

will avoid that.
The lack of selective prohibitors also holds back the future extensions of the Set-StrictMode cmdlet as e.g. #15781Strict Write-Output.

Proposed technical implementation details (optional)

No response

Activity

  1. added
    Issue-Enhancement
    Needs-Triage
    on Nov 7, 2021
  2. added
    WG-Security
    on Nov 8, 2021
  3. iRon7 commented on Nov 10, 2021

    @iRon7
    Author

    Also possible (false positive) bugs in specific Set-StrictMode modes as in #16427 Set-StrictMode -Version Latest: False positive for references to non-existent properties of an object could be excluded/suppressed while still being able to as strict as possible with the rest of the prohibitors, using a command as e.g.: Set-StrictMode -Mode 29

  4. added
    WG-Language
    and removed
    WG-Security
    Needs-Triage
    on Nov 15, 2021
  5. iRon7 commented on Nov 29, 2021

    @iRon7
    Author

    Michael Klement (@mklement0),

    Even if lexical scoping were to be introduced, the dynamic scoping of the existing strict modes would have to be retained for backward compatibility, which would invite confusion and subtle bugs.

    A different way to implement lexical scoping is by excluding using SuppressMessageAttribute Class in the cmdlet binding similar to the approach of PSScriptAnalyzer.

  6. added
    Resolution-No Activity
    on Nov 15, 2023
  7. iRon7 commented on Nov 15, 2023

    @iRon7
    Author

    I have closed this issue in favor of issue #20432

  8. removed
    Resolution-No Activity
    on Nov 15, 2023
  9. added
    Resolution-No Activity
    on May 13, 2024
  10. microsoft-github-policy-service commented on May 13, 2024

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if there is no further activity in 7 days, the issue will be closed automatically.

    Activity in this case refers only to comments on the issue. If the issue is closed and you are the author, you can re-open the issue using the button below. Please add more information to be considered during retriage. If you are not the author but the issue is impacting you after it has been closed, please submit a new issue with updated details and a link to this issue and the original.

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

    Issue-EnhancementResolution-No ActivityWG-Language

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions