-
Notifications
You must be signed in to change notification settings - Fork 382
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
Avoid exclamation point operator. #1826
Comments
We also have unary "-" and unary "++". I use "!" far more often than I use "-not". And outside of the unary space, we have ternary and null-coalescing operators. I would disable such a rule and personally don't like the idea. |
I can sympathize because there are aliases I like to use and whitelist. I'm fine with a rule that's not enabled by default, however |
Maybe I'm just weird but I don't like using |
On the other hand all boolean operators are "named" so it makes sense to me that way. Either way, you should be able to enforce consistent operator usage. |
Nothing forces you to use |
|
The whole point of an analyzer is to enforce consistent practices in the organization. |
The whole point behind PSScriptAnalyzer is to indicate parts of scripts which do not follow best practices. Which is why we are having the discussion as to whether your suggestion is a best practice.
So far, only three people have engaged in the discussion. Two of them like |
I write some PS code, but more I review all kinds of code, and oversee a development team. While I don't necessarily have a preference for either syntax in this particular case, I'd like my team to settle on one of them, use it consistently and have automation in place to enforce this (and all kinds of such matters). We do the same thing with the static code analysis of C#, JS, SCSS too. |
I am in the As such its a great idea for a rule but should be opt-in I think. |
Second Justins opinon. A great idea and I would absolutely turn it on, but make it opt-in. Having it as a native rule makes it easier to enforce instead of requiring writing your own rules for standards. |
Also with @JustinGrote . If we had only one of I know some people like ! and would like to have && and || too, and perhaps == instead of I think I must see hundreds or thousands of uses of The one case for having a rule is when contributing to a project. If it is my project I want |
I think there is no right and wrong since it's just about readability. PSScriptAnalyzer is not just a code analyser but also a formatter and this is the perfect scenario. I suggest to create a new formatting rule (which can either be run by Invoke-Formatter or by Invoke-ScriptAnalyzer), that lets user highlight or format the code to THEIR preference. I would not turn on the rule by default, neither in PSSA nor in the VS-Code extension but I would add a codeformatting setting for the VS-Code extension. This way, people can be optionally informed of violations of their preferred style and have the ability to have it auto-fixed (both either via command line or in the editor). Would everyone be happy with that? |
Yes, sounds perfect. |
That's excellent. |
@bergmeister Yes, that sounds ideal to me |
… the negation operator !. Fixes PowerShell#1826
…tion operator. Fixes #1826 (#1922) * Added the AvoidExclamationPointOperator rule to warn about the use of the negation operator !. Fixes #1826 * Updated license header of Rules/AvoidExclamationPointOperator.cs * Updated the description of the rule in docs Co-authored-by: Christoph Bergmeister <c.bergmeister@gmail.com> * Fix alignment Co-authored-by: Christoph Bergmeister <c.bergmeister@gmail.com> * Update Rules/Strings.resx Co-authored-by: Christoph Bergmeister <c.bergmeister@gmail.com> * Renamed rule from AvoidExclamationPointOperator to AvoidExclaimOperator * Added comment explanation of the replacement suggestion logic and renamed loop variable for clarity --------- Co-authored-by: Christoph Bergmeister <c.bergmeister@gmail.com>
Thank you! |
Summary of the new feature
While not technically an alias,
!
behaves like an alias to the-not
operator. Even "about_Logical_Operators" only mentions it in passing as "Same as-not
" Considering that PSScriptAnalyzer has other rules against aliases, and that!
looks different to pretty much all other operator, I think it should also be warned against.What is the latest version of PSScriptAnalyzer at the point of writing
1.20
The text was updated successfully, but these errors were encountered: