Skip to content

Disallow turning a conditional into a ternary if there's a Not node without parentheses in the predicate #72

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

Conversation

bbuchalter
Copy link
Contributor

fixes #58

@@ -35,3 +35,9 @@
%
if foo {}
end
%
Copy link
Contributor Author

@bbuchalter bbuchalter May 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surprised this new fixture doesn't result in a test failure in CI. I get one locally:

  1) Failure:
SyntaxTree::FormattingTest#test_formatted_if_9 [/Users/brian.buchalter/workspace/syntax_tree/test/formatting_test.rb:9]:
--- expected
+++ actual
@@ -1,6 +1,2 @@
-"if not a
-  b
-else
-  c
-end
+"not a ? b : c
 "

@bbuchalter bbuchalter force-pushed the issue-58-disallow-ternary-with-not-node branch from ef7463b to 74379e5 Compare May 10, 2022 17:33
@@ -5192,7 +5192,7 @@ def call(q, node)
else
# Otherwise, we're going to check the conditional for certain cases.
case node
in predicate: Assign | Command | CommandCall | MAssign | OpAssign
in predicate: Assign | Command | CommandCall | MAssign | Not | OpAssign
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this isn't quite everything, as we want to allow:

if not(a)
  b
else
  c
end

-->

not(a) ? b : c

@kddnewton kddnewton merged commit a0bb8da into ruby-syntax-tree:main May 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disallow turning a conditional into a ternary if there's a Not node without parentheses in the predicate
2 participants