The ternary operator should support inline comments but not blank lines
See original GitHub issueSteps 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:
- Created 4 years ago
- Comments:7 (1 by maintainers)
Top 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 >
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
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:
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:
As well as:
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!