Skip to content

Warning on assignment vs comparison in if statement #35

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

Closed
samr33 opened this issue Feb 13, 2017 · 3 comments
Closed

Warning on assignment vs comparison in if statement #35

samr33 opened this issue Feb 13, 2017 · 3 comments

Comments

@samr33
Copy link

samr33 commented Feb 13, 2017

Hello,
Really loving the syntax highlighting in combo with VSCode. I've been looking for a way to defeat my ultimate Powershell enemy:
if\s*\(.*=.*\)
Any valid uses for this? Would a warning be warranted? Any way I can extend ISE or VSCode to do this?
Thanks in advance for consideration.

@daviwil
Copy link
Contributor

daviwil commented Feb 13, 2017

Are you trying to remove whitespace from these statements? You might appreciate a new code formatting rule that is coming in the next release which allows you to control this.

PowerShell/vscode-powershell#489

@samr33
Copy link
Author

samr33 commented Aug 14, 2017

Thanks! No, I'm trying to avoid writing the statement if ($a = $b) {do something} which in Powershell doesn't generate a syntax error, just does the assignment, but is clearly meant to be if ($a -eq $b) {do something}. Too many years of that overloaded equals sign being able to do comparisons in the right context, old habits die hard. It's a pretty tough bug to find for me, would be great to have a hint that it might be wrong, or a way to easily extend the hinting or error matching with regex configs.

@vors
Copy link
Contributor

vors commented Aug 14, 2017

Please upvote corresponding issue in the script analyzer repo PowerShell/PSScriptAnalyzer#809

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants