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.

The ternary operator should support inline comments but not blank lines

See original GitHub issue

Steps to reproduce

$true ?




'It is true.'




:





'Nope, it''s false!'

Expected behavior

A parser error should be raised. Comments should be supported, but there is no need to allow blank lines in ternary. That just opens the door for sloppy code.

Actual behavior

It is true.

Environment data

Name                           Value
----                           -----
PSVersion                      7.0.0-preview.4
PSEdition                      Core
GitCommitId                    7.0.0-preview.4
OS                             Microsoft Windows 10.0.17763
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
rkeithhillcommented, Oct 6, 2019

But PowerShell is a “whitespace insignificant” language (unlike Python), well, except for newlines. Someone could do the following too and like you, I would not recommend that folks use this style:

>> if ($true) {
>>                                                                                                                      
>>
>>
>> 'It is true.'
>>                                                                                                                      
>>
>>
>> } else {
>>                                                                                                                      
>>
>>
>> 'Nope, it''s false!'
>> }                                                                                                                    
It is true.

But I would not go so far as to want to change the language’s whitespace handling. This is why we have style guidelines and tools like PSScriptAnalyzer to help folks enforce their chosen style.

Also, what exactly do you mean by inline comments? Comments like this work:

image

As well as:

image

1reaction
vexx32commented, Oct 6, 2019

Interesting. Filed issue on PSRL to see if we can get to the bottom of it one way or another: https://github.com/PowerShell/PSReadLine/issues/1088

Thanks for the workaround!

Read more comments on GitHub >

github_iconTop Results From Across the Web

There must be no blank line following an inline comment [# ...
There must be no blank line following an inline comment Remove that blank line which are not as per coding standard.
Read more >
if statement - Javascript Ternary operator with empty else
Answer to your real question in the comments: all2.forEach(function (e) { e.getAttribute("class") && only.push(e.
Read more >
Java static code analysis: The ternary operator should not ...
While the ternary operator is pleasingly compact, its use can make code more difficult to read. It should therefore be avoided in favor...
Read more >
Ternary operator support · Issue #236 · Shopify/liquid
Hello! I think it would be awesome to implement ternary operator support like Twig does: {{ foo ? 'yes' : 'no' }} {{...
Read more >
Ternary conditional operator
In computer programming, the ternary conditional operator is a ternary operator that is part of the syntax for basic conditional expressions in several ......
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