Avoid exclamation point operator.
See original GitHub issueSummary 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
Issue Analytics
- State:
- Created a year ago
- Reactions:4
- Comments:16
Top Results From Across the Web
tslint - In TypeScript, what is the ! (exclamation mark / bang) ...
It is a way to tell the compiler "this expression cannot be null or undefined here, so don't complain about the possibility of...
Read more >Use of the Exclamation Mark in TypeScript
The exclamation mark in TypeScript. In many scripting languages, developers use the exclamation mark as a not operator.
Read more >Understanding the exclamation mark in TypeScript
The exclamation mark ! is known as the non-null assertion operator in TypeScript. We will be using these terms interchangeably in this ...
Read more >In Typescript, what is the ! (exclamation mark / bang) ...
operator to assert that the said value is not null or undefined . Personal take: avoid doing this wherever possible. What is the...
Read more >Jeremy Bytes: Null Forgiving Operator in C# - !
We do this by using an exclamation point. In the following example, the analyzer thinks that the "Exception" property on task may be...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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?
I am in the
-not
camp, despite it being a terrible syntax in if statements. I would definitely turn on this rule on my project styles but this is one of those where there isn’t a predominant style unfortunately. Similar to $_ vs $psitem.As such its a great idea for a rule but should be opt-in I think.