Extend safe navigation docs about long `&.` chains
Closes #946.
Can you try finding confirmation that the suggested style is widespread?
At least in my company we are striving to adhere to this. I will try to investigate other codebases.
Is there a cop already to facilitate finding this ?
I am currently implementing this cop - https://github.com/rubocop/rubocop/issues/13171
Found only 1 offense in rails - https://github.com/rails/rails/blob/53ce1964f0bd6491fdc08aebc45f61275100f818/actionpack/lib/action_controller/metal/exceptions.rb#L43, so people definitely stick to it
Rails code might not be representative, I believe they are strict in code quality.
How about other repos from real-world-rails-apps and real-world-ruby in general?
We already have above the following rule:
Avoid chaining of
&.. Replace with.and an explicit check. Perhaps it just needs to be expanded and clarified a bit instead of adding a new guideline?
Perhaps it just needs to be expanded and clarified a bit instead of adding a new guideline?
Updated existing section for safe navigation. I am bad at writing docs - concrete suggestions welcome.
Probably we shouldn't mention a specific number here and just expand a bit the rationale - namely that the longer the chain is, the harder it becomes to track what on it could be returning a nil. That's always been my fundamental problem with any safe navigation chains.
Updated with a suggested rationale.