Skip to content

WIP Warn when using += on array objects - #933

Closed
Christoph Bergmeister (bergmeister) wants to merge 8 commits into
PowerShell:developmentfrom
bergmeister:WarnPlusEquals
Closed

Christoph Bergmeister (bergmeister) wants to merge 8 commits into
PowerShell:developmentfrom
bergmeister:WarnPlusEquals

Conversation

@bergmeister

@bergmeister Christoph Bergmeister (bergmeister) commented Mar 14, 2018 •

Copy link
Copy Markdown
Collaborator

PR Summary

Fixes #806 and #904
It is well know that PowerShell's += operator always creates a new array under the hood even if the array type is not of fixed size.
Because SSA (single statement analysis) is not fully implemented at the moment, the detection for the object type can not catch all cases. For example it does not work inside function definitions or cannot determine if the object is of type string at the moment or cases like $a=@(); $a+=$foo.
The rule documentation includes all possible info even if strings cannot be caught at the moment.

PR Checklist

Note: Tick the boxes below that apply to this pull request by putting an x between the square brackets. Please mark anything not applicable to this PR NA.

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • User facing documentation needed
  • Change is not breaking
  • Make sure you've added a new test if existing tests do not effectively test the code changed
  • 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

…s because SSA is not fully implemented (i.e. $a=@();$a+=$foo does not get caught or determining that the type is of type string.
@rjmholt
Rob Holt (rjmholt) marked this pull request as draft April 21, 2021 21:14
@homotechsual

Copy link
Copy Markdown

Is there any chance of progressing this so it's included?

@bergmeister

Copy link
Copy Markdown
Collaborator Author

Is there any chance of progressing this so it's included?

I don't think so because of the issues encountered that are fundamental due to limitation of variable analysis framework in PSSA, which was a fork of PowerShell code in the first place anyway. It only works for simple cases where the += isn't in a function, etc.

@bergmeister

Copy link
Copy Markdown
Collaborator Author

Closing as there is no path to get this working as-is and therefore no point in keeping open

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rule to recommend against Lists when using += with Array objects

2 participants