Skip to content
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

Style/ParenthesesAroundCondition correction putting right parenthesis on newline when condition ends with implicit call #548

Open
nobodywasishere opened this issue Jan 25, 2025 · 2 comments

Comments

@nobodywasishere
Copy link
Contributor

Config:

Style/ParenthesesAroundCondition:
  Description: Disallows redundant parentheses around control expressions
  ExcludeTernary: false
  AllowSafeAssignment: true
  Enabled: true
  Severity: Convention

Example:

if var = method.try &.call
  puts var
end

Is corrected to:

if (var = method.try &.call
)  puts var
 # ^^^^ error: unexpected token: "puts"
end

And should be:

if (var = method.try &.call)
  puts var
end
@Sija Sija added this to the 1.7.0 milestone Jan 25, 2025
@Sija
Copy link
Member

Sija commented Jan 28, 2025

As far as I can tell that might be a Crystal bug, since for this particular case the position reported by the ASTNode#end_location method is :2:0, which is obviously incorrect and explains the odd behavior here.

@Sija
Copy link
Member

Sija commented Jan 28, 2025

It only happens when there's a shorthand block passed without parentheses, as all the below work well:

if foo = method.try(&.call)
if foo = method.try { |x| x.call }
if foo = method.try :foo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants