Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Warn when using += on array objects #933

Closed

Conversation

bergmeister
Copy link
Collaborator

@bergmeister bergmeister commented Mar 14, 2018

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.
…nalyzer into WarnPlusEquals

resolved by taking both
# Conflicts:
#	Rules/Strings.resx
…nalyzer into WarnPlusEquals

Resolved by taking both.
# Conflicts:
#	Rules/Strings.resx
…nalyzer into WarnPlusEquals

# Conflicts:
#	Rules/Strings.resx
…nalyzer into WarnPlusEquals

# Conflicts:
#	Rules/Strings.resx
@rjmholt rjmholt marked this pull request as draft April 21, 2021 21:14
@homotechsual
Copy link

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

@bergmeister
Copy link
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
Collaborator Author

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

@bergmeister bergmeister closed this Jan 2, 2024
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