question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Avoid exclamation point operator.

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:4
  • Comments:16

github_iconTop GitHub Comments

7reactions
bergmeistercommented, Aug 30, 2022

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?

2reactions
JustinGrotecommented, Aug 18, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found