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

Add Style/TrailingConditional #581

Open
nobodywasishere opened this issue Feb 20, 2025 · 2 comments
Open

Add Style/TrailingConditional #581

nobodywasishere opened this issue Feb 20, 2025 · 2 comments
Labels

Comments

@nobodywasishere
Copy link
Contributor

This rule would encourage the use of normal if statements over trailing ones. Trailing if can be hard to use when line debugging via gbd or codelldb. For example:

   def foo(bar)
*    bar.baz if bar
   end

When using CodeLLDB and the code stops here, it's very hard to know where on the line the break point stops at. This is in comparison to:

   def foo(bar)
     if bar
*      bar.baz
     end
   end

Which is a lot more clear.

I intend for this rule to be disabled by default.

@Sija Sija added the rule label Feb 20, 2025
@straight-shoota
Copy link
Contributor

straight-shoota commented Feb 20, 2025

This would be a general problem with debugging though. Other languages, even C, have single-line conditions. So it might be interesting to see if there are some ideas to improve this?

It feels a bit odd to introduce a linter rule just to address limitations of the debugging process. Even if it's disabled by default.

I suppose it might also be useful if you want to disallow trailing conditionals entirely in your codebase for stylistic reasons.
Or if you want to automatically rewrite them into multi-liners, as this should be easy to auto-fix.

Note that unless should be treated equally.

@nobodywasishere nobodywasishere changed the title Add Style/TrailingIf Add Style/TrailingConditional Feb 20, 2025
@nobodywasishere
Copy link
Contributor Author

That's a fair point. My reasoning for this rule does stem beyond just debugging reasons, into general style, but I thought debugging was the most compelling.

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

No branches or pull requests

3 participants