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

Integrated RuboCop as part of the build. #349

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dblock
Copy link

@dblock dblock commented Nov 17, 2015

Something discussed in #343.

For a contributing developer the build would fail on something like what is being added as part of feedback in #343. This also removes any conversation about style, Rubocop just enforces those automagically. I first ran rubocop -a, then rubocop --auto-gen-config and reviewed some infrequent violations and fixed them by hand.

@dblock
Copy link
Author

dblock commented Nov 17, 2015

Btw, @envygeeks @Bartuz I didn't mean to start too many debates :) I just wanted the person who made a PR, #343 to catch the style issue they were asked to fix before someone had to look at the code and waste time. So please tell me what you'd like me to change in this PR for it to be merged or whether you'd rather not, I am happy to help!

@envygeeks
Copy link
Contributor

For me, the keyword style hashes has to go, it promotes inconsistency and I am very consistent with my code in that aspect in that I always explicitly do { :key1 => :val1, "key2" => "val2" } for absolute consistency in all my hashes, def(keyword: val) so there is a very clear distinction in my code as to what it's doing. Ruby introduced code inconsistency in 1.9 with that and it's been an emacs vs. vim war ever since, I never intervene unless one is thrust upon me, meaning if you wish to do { key: val } in your code when submitted, I'll never ask it to change, as I don't ask you to ask me to change.

And the fail part.

@dblock
Copy link
Author

dblock commented Nov 18, 2015

I've merged dblock#1 from @Bartuz, so the or in the control flow is no longer flagged.

@@ -84,7 +82,7 @@ def determine_type_from_primitive(primitive)
descendants.select(&:primitive).reverse_each do |descendant|
descendant_primitive = descendant.primitive
next unless primitive <= descendant_primitive
type = descendant if type.nil? or type.primitive > descendant_primitive
type = descendant if type.nil? || type.primitive > descendant_primitive
Copy link
Author

Choose a reason for hiding this comment

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

Was this a bug?

Copy link

Choose a reason for hiding this comment

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

What do you mean? It is correct now, isn't it? || and && should be only used in conditions (like above)

Copy link
Contributor

Choose a reason for hiding this comment

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

@dblock no, or is the same as ||. Ruby programmers just choose to use or only for flow control, but at the end of the day it doesn't matter, he was choosing to be more verbose.

Copy link
Author

Choose a reason for hiding this comment

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

Nevermind, in this case it doesn't matter indeed.

Copy link
Author

Choose a reason for hiding this comment

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

@envygeeks That's incorrect, || has a higher precedence than or.

a = false or true sets a to false, and a = false || true sets a to true, since = precedence is lower than || but higher than or. SO

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I know that, but that is irrelevant in this case so I didn't feel the need to even add that bit.

@dblock
Copy link
Author

dblock commented Nov 18, 2015

@envygeeks I undid a few things in this PR:

  • Hash rockets are enforced. Most code here was hash rockets, so be it. I think we can all agree that consistency is better than inconsistency, so some places were auto-corrected from Ruby 1.9 syntax to hash rockets.
  • Raise is back instead of fail everywhere.
  • Or in control flow is allowed, thx @Bartuz.
  • Hash values in a table layout must align.

I care more about having an automatic style in Virtus than what the style is, so LMK what else needs to go for this to be merged.

@envygeeks
Copy link
Contributor

Yay, ❤️ thanks for the changes. I'm happy with it if @booch , I don't know if he's had time to review.

dblock referenced this pull request in dblock/virtus Nov 19, 2015
@dblock
Copy link
Author

dblock commented Nov 24, 2015

Bump @booch ?

@booch
Copy link
Collaborator

booch commented Nov 29, 2015

Sorry, I thought I had commented on this. Not sure if I never hit Enter, or if it got eaten.

I really like RuboCop, but I'd really prefer that we use it a bit less aggressively. For example, some of us (myself, and likely @solnic) prefer to keep extra blank lines to aid readability. And I'd prefer RSpec let to consistently use {} instead of do/end, instead of the 1-line versus multi-line rule.

I'm gonna sit on this for just a bit. I might just rework it to be a bit less aggressive, then accept it. I would prefer to keep RuboCop and most of these settings.

@@ -3,7 +3,16 @@
describe Virtus::Attribute, '#set_default_value' do
let(:object) { described_class.build(String, options.merge(:name => name, :default => default)) }

let(:model) { Class.new { def name; 'model'; end; attr_reader :test } }
Copy link
Collaborator

Choose a reason for hiding this comment

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

I find this original one-liner a lot more readable than the 9-line replacement. Ugh.

Copy link
Author

Choose a reason for hiding this comment

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

Personally I find it harder. Also very difficult to see diffs in 1-liners as code changes. Accent on "personally".

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, that onel iner is pretty hard to read.

@envygeeks
Copy link
Contributor

What is the status of this?

@dblock
Copy link
Author

dblock commented Apr 26, 2016

I think it's up to @booch but I am happy to help with whatever!

@envygeeks
Copy link
Contributor

I'm 👍 on this, we can adjust whatever we need to later. No reason to block this pull.
/cc @booch

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.

4 participants