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
Implemented Layout/SpaceInsideParens with EnforcedStyle: compact #10025
Conversation
I'm not sure I understand why it'd be desired to compact only right parens? If this is a style that people use, should it not apply on both sides? Or else, the style should probably be called Also you'd need to update |
The code style we enforce at Clustermarket is a bit odd, although everyone approves it. The idea is put spaces around important words, and to decrease the emphasis (by decreasing whitespace) around language grammar, which is always there and is expected. Long story short we believe it improves readability and allows us to scan through code diagonally faster. Also compact left doesn't really make sense, because you don't really do: |
I'm not convinced that this is a style that makes sense for RuboCop as a whole. You could implement it as a custom cop for your codebase/company and just disable @bbatsov what do you think? |
RubCop is a collection of rules, configurable to suit different projects and different teams with different views. The objective of the project is internal consistency, with a healthy set of defaults. If there was one style that was suitable for everyone - there wouldn't be any need for configuration. But that's not the case and there is configuration. All is good until you miss the one option you need, in which case you either disable that corresponding cop, or if you want to be better than that - you spend the time to reverse-engineer how Rubocop works and modify it to include your use case. And I did exactly that, I wrote tests, documentation, and followed your particular style and recommendations as close as I can. Saying that this style doesn't makes sense for RuboCop as a whole, kind of violates the spirit of Rubocop, doesn't it? It adds too much personal opinion, in a project where personal opinion should be no more than a default, albeit configurable option. |
@itay-grudev I'm not suggesting that there should only be a single allowed style -- in fact this cop is already configurable as you have seen, and we support opposing styles on many cops. That being said, we cannot guarantee that every single style that a company uses makes sense for the RuboCop userbase as a whole. I'm also not saying that this definitely doesn't fit, I'm interested what others on the team think. We often recommend niche rules be implemented as custom cops (in fact, we have our own custom cops at my workplace that don't necessarily make sense for the tool as a whole). It is simple to create your own cop, and the effort you have put in for this PR would not go to waste, because it could be repurposed as such. |
Indeed. We can't possibly support any style that exists (that would mean an epic overhead in the RuboCop codebase), that's why we focused only on those that are common within the community. I'm leaning towards rejecting the proposed addition. |
@bbatsov @dvandersluis We have compact for the following:
array = [ a, [ b, c ]]
array = [[ a ],
[ b, c ]]
h = { a: { b: 2 }}
foo = {{ a: 1 } => { b: { c: 2 }}} The g( f( x ))
g( f( x( 3 )), 5 ) Also I plan to write an article about why this may be better from a neuroscience perspective and information theory perspective. |
Hmm, I don't recall when those were added. I'll have to dig up the relevant tickets.
I guess now I'm more receptive to accepting this, but I first have to recall what exactly was I thinking back in the day for those other cops. Perhaps back then I still wasn't as afraid of complexity. :D |
Looking at this ticket things started from the |
@bbatsov In any way - while not as popular, this pattern actually improves readability. We put spaces around content important for humans. Here is an excerpt from our internal guidelines:
|
Exactly, and it is possible to write custom cops for your team for exactly this reason. People submit custom cops here all the time. Sometimes they get added, sometimes they don't. |
I'd suggest taking a look here https://docs.rubocop.org/rubocop/1.19/index.html#philosophy
"common" is the key word here. Anyways, I'll admit I've not always thought enough about some of the things I've accepted, plus over time, as the project grew I became significantly more concerned about the overhead of maintaining some niche styles. Again, I'm not rejecting this particular proposal (I'll likely merge it if this has existed in similar cops), I just want everyone to know what we're aiming for in general. |
This is a perspective on the keyword "common". IMHO, I've never encountered this style in well-known programming books and OSS of Ruby. (I may have seen it in Perl...?, but I don't remember it well.) Of course this is my personal perspective. I know that each programmer encounters different styles. OTOH, I agree with @dvandersluis as a maintainer. I also have several niche custom cops at my workplace. |
@koic I think we're all in agreement here, but as @itay-grudev pointed out somehow this style got added to two other existing cops ( |
@bbatsov Thank you for your explanation. My understanding has caught up. But this is certainly a difficult issue to choose. I haven't come up with a better answer yet. |
True. At some point we'll have to evaluate all cops/supported styles and remove uncommon stuff to improve the long-term maintainability of the project. |
I just want to point out again that the style on the other cops are symmetrical (applies to both left and right parens) whereas this one is not (only applying to right parens). If we add this I still think it should also be symmetrical to match? |
@dvandersluis Well, if you agree to merge it then I'll spend the extra time to make those changes and test them, so it's consistent with the other two cops. |
Up to @bbatsov if we want to continue with this or deprecate the style from the other cops I guess. |
I've decided to continue with adding |
Alright @itay-grudev please update to make this symmetrical then! |
@dvandersluis I will finish it later this week and I will ping you when it's ready. Thanks a lot guys! |
@dvandersluis Implemented left side compaction. I also moved the correction code inside each respective style processor because I started tripping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, apart from my small remark.
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.