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 more automatic variables to PSAvoidAssignmentToAutomaticVariables that are not read-only but should still not be assigned to in most cases by bergmeister · Pull Request #1394 · PowerShell/PSScriptAnalyzer

Conversation

@bergmeister

@bergmeister Christoph Bergmeister (bergmeister) commented Jan 13, 2020 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Collaborator

PR Summary

Closes #712
Closes #1183

The list of variables was extracted from #712 and it i s the union of non-readonly automatic variables in Windows PowerShell and PowerShell Core. Some of those variables can be assigned to in very special cases but the point of this rule is to rather warn that assignment to automatic variables happens and if the author knows what he/she/they are doing then they can/should suppress the rule

PR Checklist

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • Change is not breaking
  • Make sure all .cs, .ps1 and .psm1 files have the correct copyright header
  • Make sure you've added a new test if existing tests do not effectively test the code changed and/or updated documentation
  • This PR is ready to merge and is not Work in Progress.
    • If the PR is work in progress, please add the prefix WIP: to the beginning of the title and remove the prefix when the PR is ready.

Sorry, something went wrong.

Uh oh!

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

All reactions
Christoph Bergmeister added 2 commits January 13, 2020 08:31
Christoph Bergmeister
Add more automatic variables to PSAvoidAssignmentToAutomaticVariables…
72e0dac
… that are not read-only but should still not be assigned to in most cases
Christoph Bergmeister
Merge branch 'master' of https://github.com/powershell/psscriptanalyzer…
af5734d
… into automaticVariables

# Conflicts:
#	Rules/Strings.resx
@bergmeister Christoph Bergmeister (bergmeister) added the Issue - Enhancement label Jan 13, 2020
@bergmeister
Christoph Bergmeister (bergmeister) marked this pull request as ready for review January 13, 2020 09:30
@bergmeister
Christoph Bergmeister (bergmeister) requested review from James Truher (JamesWTruher) and Rob Holt (rjmholt) January 14, 2020 00:01
rjmholt
Rob Holt (rjmholt) approved these changes Jan 14, 2020
View reviewed changes
Comment thread Rules/AvoidAssignmentToAutomaticVariable.cs Resolved

Uh oh!

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

Comment thread Rules/AvoidAssignmentToAutomaticVariable.cs Outdated
"IsCoreCLR", "IsLinux", "IsMacOS", "IsWindows"
};

private static readonly IList<string> _automaticVariablesThatCouldBeProblematicToAssignTo = new List<string>()

@rjmholt Rob Holt (rjmholt) Jan 14, 2020 •
edited
Loading

Uh oh!

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

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.

I feel we should avoid embedding clausal descriptions in variable names if we can -- and also I can't think of an automatic variable that's not problematic to assign to (since, being automatic, they could be reassigned unexpectedly)

Suggested change
private static readonly IList<string> _automaticVariablesThatCouldBeProblematicToAssignTo = new List<string>()
private static readonly IList<string> _automaticVariables = new List<string>()

Sorry, something went wrong.

Uh oh!

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

All reactions

@bergmeister Christoph Bergmeister (bergmeister) Jan 14, 2020

Copy link
Copy Markdown
Collaborator 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.

I wanted to differentiate from the _readOnlyAutomaticVariables variable above where PowerShell actually itself throws an error when trying to assign, those variables don't.

Sorry, something went wrong.

Uh oh!

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

All reactions

@rjmholt Rob Holt (rjmholt) Jan 14, 2020

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.

Well one is readonly variables and the other is just automatic variables, no? So _readonlyVariables and _automaticVariables or _writeableAutomaticVariables maybe?

Sorry, something went wrong.

Uh oh!

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

All reactions

@rjmholt Rob Holt (rjmholt) Jan 14, 2020

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.

I'd just prefer not to call the variable something that embeds a sentence

Sorry, something went wrong.

Uh oh!

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

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

@bergmeister Christoph Bergmeister (bergmeister) Jan 14, 2020

Copy link
Copy Markdown
Collaborator 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.

How about _writeableAutomaticVariables and _readonlyAutomaticVariables?

Sorry, something went wrong.

Uh oh!

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

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

@rjmholt Rob Holt (rjmholt) Jan 14, 2020

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.

👌

Sorry, something went wrong.

Uh oh!

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

bergmeister reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Christoph Bergmeister (bergmeister) and others added 2 commits January 14, 2020 09:09
@bergmeister @rjmholt
Update Rules/AvoidAssignmentToAutomaticVariable.cs
2a91c87
Co-Authored-By: Robert Holt <[email protected]>
Christoph Bergmeister
rename variable to _writableAutomaticVariables
09ec140
JamesWTruher
James Truher (JamesWTruher) approved these changes Jan 16, 2020
View reviewed changes
@bergmeister
Christoph Bergmeister (bergmeister) merged commit 5d529a3 into PowerShell:master Jan 16, 2020
@coderabbitai coderabbitai Bot mentioned this pull request Apr 26, 2026
Added Nuke Build Project VolkmarR/Nuke-Cake#2
Merged
@coderabbitai coderabbitai Bot mentioned this pull request May 8, 2026
Add RDS 90-day logon report script DTC-Inc/msp-script-library#52
Merged
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

2 more reviewers
@rjmholt Rob Holt (rjmholt) rjmholt approved these changes
@JamesWTruher James Truher (JamesWTruher) JamesWTruher approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

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

Assignees

No one assigned

Labels

Issue - Enhancement

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Update PSAvoidAssignmentToAutomaticVariable to detect more automatic variables New Rule Suggestion: AvoidReuseOfAutomaticVariables

Uh oh!

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

3 participants

@bergmeister @rjmholt @JamesWTruher
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.