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 rubocop and drop support for Rubies < 2.0 #124

Merged
merged 6 commits into from
Mar 23, 2017

Conversation

hedgesky
Copy link
Contributor

@hedgesky hedgesky commented Mar 22, 2017

This PR consists of two commits. First one introduces following changes:

  • Adds rubocop as a dev dependency (use conservative version locking as official manual advises;
  • Adds .rubocop.yml config;
  • Fixes some style issues;
  • Changes default rake task;
  • Updates travis.yml to run rake instead of rspec

When first commit failed Travis checks I realized that fresh Rubocop requires only Ruby >= 2.0. Keeping in mind that there is a plan to drop support for Rubies < 2.1 in Interactor 4.0, I've decided to update this PR accordingly.

So the second commit does following:

  • removes Rubies 1.9.3, 2.0 from Travis config;
  • sets Rubocop target Ruby version to 2.1;
  • add required_ruby_version = ">= 2.1" in gemspec.

@hedgesky hedgesky force-pushed the add_rubocop branch 2 times, most recently from 1d785e0 to ccc9b89 Compare March 22, 2017 10:25
@hedgesky hedgesky changed the title add rubocop add rubocop and drop support for Rubies < 2.1 Mar 22, 2017
Copy link
Collaborator

@laserlemon laserlemon left a comment

Choose a reason for hiding this comment

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

Thank you so much for this! I didn't expect help on 4.0 so quickly! Most of this looks great; I just had a few questions. Also, could you please rebase this against the very little pending work I've done in the v4 branch? Thank you!

@@ -25,7 +25,8 @@ def build_organizer(options = {}, &block)
# └─ interactor5

let(:organizer) {
build_organizer(organize: [organizer2, interactor3, organizer4, interactor5]) do
interactors = [organizer2, interactor3, organizer4, interactor5]
build_organizer(organize: interactors) do
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are this and the similar changes below just a line length concern?

Copy link
Contributor Author

@hedgesky hedgesky Mar 22, 2017

Choose a reason for hiding this comment

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

Yep. Both ways have their benefits and downsides. Introducing intermediate variable seems a bit clumsy, but it keeps lines short. Short lines are easier to perceive and they are two-panes-friendly:
2017-03-22_15-36-32

Anyway, it's not a big issue if concentrated in a single file.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, I'm all for the 80 character limit but I typically relax that rule a bit for specs. But maybe I shouldn't!

raise "foo"
context.steps << :around_before
interactor.call
context.steps << :around_after
Copy link
Collaborator

Choose a reason for hiding this comment

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

Although it may seem obvious to Rubocop, there's some value in the assertion that these lines are not called, even after a raise. This applies to several of the changes below as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm open to discussion on this point!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I see your point. I thought about smth like this:

def unexpected_error!
  raise "foo"
end

It may be more intention-revealing (the "unexpected" nature), but plain raise is far simpler and understable. What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I like your use of unexpected_error! although we might have to define that method within the interactor's definition in the spec rather than as a helper method in the spec, which muddies the waters a little bit.

expect(Interactor::Context).to receive(:build).once.with(foo: "bar") { context }
expect(
Interactor::Context
).to receive(:build).once.with(foo: "bar") { context }
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this is a line length concern, would Rubocop accept this style:

expect(Interactor::Context).to receive(:build)
  .once.with(foo: "bar") { context }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure!

@@ -1,19 +1,24 @@
# encoding: utf-8
require "English"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thank you, I didn't know about this!

spec.test_files = spec.files.grep(/^spec/)

spec.required_ruby_version = ">= 2.1"
Copy link
Collaborator

Choose a reason for hiding this comment

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

👏 🏆 💐 🥇

spec.add_development_dependency "bundler", "~> 1.7"
spec.add_development_dependency "rake", "~> 10.3"
spec.add_development_dependency "rubocop", "~> 0.47.1"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd rather put this dependency in the Gemfile and keep the gemspec dependencies to only bundler and rake.

@@ -153,14 +153,12 @@ def run!
# each interactor class.
#
# Returns nothing.
def call
end
def call; end
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not a big fan of this, but I suppose if the community has spoken! 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rubocop default settings are easily adjustable to project's needs. I'll remove this change.

@laserlemon laserlemon added this to the v4.0.0 milestone Mar 22, 2017
@laserlemon
Copy link
Collaborator

Actually, this may need to be reopened as a PR against the v4 branch as well. 😕

@hedgesky
Copy link
Contributor Author

hedgesky commented Mar 22, 2017

I've added replies to your comments; some of them require further discussion. I'll close this PR and reopen a new one on v4 branch.

Thank you for a quick response 😄

@hedgesky hedgesky closed this Mar 22, 2017
@hedgesky hedgesky changed the base branch from master to v4 March 22, 2017 12:46
@hedgesky hedgesky reopened this Mar 22, 2017
@hedgesky
Copy link
Contributor Author

Actually, it's possible to just change base branch via github UI. Closed this too rashly 😄

@laserlemon
Copy link
Collaborator

I used the GitHub web UI to resolve conflicts with the v4 branch. I may have inadvertently removed the Ruby version restriction from the gemspec, but on second thought, I'm not sure that we want it. While we're dropping support for Rubies < 2.1, it's possible that Interactor 4.0 could work with Ruby 2.0, depending on what Ruby features we take advantage of. Dropping support for Ruby 2.0 is more of a statement that you can try to use Interactor with Ruby 2.0 but do so at your own risk. I'm open to discussion on this point though. It's certainly an option to draw a harder line with our Ruby version restriction in the gemspec.

@hedgesky
Copy link
Contributor Author

Changes in last commit:

  • I've decided to keep 80 character limit in integration_spec;
  • Added #unexpected_error! in integration_spec;
  • Changed spec/support/lint.rb:46 following your request;
  • Set spec.required_ruby_version = ">= 2.0";
  • Moved rubocop from gemspec to Gemfile;
  • Revert change with one-lined empty defs in lib/interactor.

About Ruby versions: support for required keyword arguments appeared only in 2.1. I think we'll definitely need them if we're going to implement #123.

@laserlemon
Copy link
Collaborator

laserlemon commented Mar 23, 2017

@hedgesky Your changes look really good. You said in your comment that keyword arguments appeared in Ruby 2.1, but I'm seeing otherwise. You're absolutely right though that keyword arguments will most likely be required so that would be the right reason to scope the Ruby version in the gemspec. It seems like we'll need to scope it to >= 2.0 and then only officially support non-EOL Rubies, which would be >= 2.1 as of this writing. Does that sound right to you?

@hedgesky
Copy link
Contributor Author

hedgesky commented Mar 23, 2017

Yeah, keyword arguments appeared in 2.0, but I told about required ones:

def foo(bar:)
  puts bar
end

They appeared in 2.1. Both your link and official changelog on Ruby github mentions that.
Most likely we'll need both required and non-required arguments, so maybe 2.0 support doesn't make sense in our case. Your thoughts?

@laserlemon
Copy link
Collaborator

It could be that even though required keyword arguments would be a big win for Interactor 4, they might not be strictly necessary because the structure of the keyword arguments is up to the developer when they define the call instance method. Plus, I imagine defining keyword arguments at all will be completely optional. There may be some difference between Rubies 2.0 and 2.1 as far as how we determine the nature of what keyword arguments are being requested so we can extract those from the context and send them along.

@hedgesky
Copy link
Contributor Author

I suggest delaying the decision about 2.0/2.1 until we have more information about Interactor 4 implementation details. For now we can just stick with 2.0.
Is it OK with you?

@hedgesky hedgesky changed the title add rubocop and drop support for Rubies < 2.1 add rubocop and drop support for Rubies < 2.0 Mar 23, 2017
@laserlemon
Copy link
Collaborator

@hedgesky Yes, that sounds fine, but let's make one change then. If we'll target Ruby 2.0 for now, let's add 2.0 back to .travis.yml but allow it to fail, like we do for ruby-head, since it's EOL.

@laserlemon
Copy link
Collaborator

@hedgesky Looks good. Is there anything else you want to add before I merge?

@hedgesky
Copy link
Contributor Author

Nope, that's all. Go right ahead 😄
Thanks for the discussion, it was really productive! If there is anything else I can help with, feel free to reach out to me. I'll be glad to speed up Interactor 4 release ✈️

@laserlemon
Copy link
Collaborator

@hedgesky Absolutely, I hope you don't feel like you're off the hook now! 😄 You've been a big help already and I know I'll need help to get 4.0 out the door. 🚀

@laserlemon laserlemon merged commit 6de0c22 into collectiveidea:v4 Mar 23, 2017
@hedgesky
Copy link
Contributor Author

Looks like Drop support for Rubies < 2.1 and Add and configure Rubocop to ensure consistent code style project cards can be moved to Done section now (really cool github feature, from my point of view).

I'm going to work on raise -> throw switch following #120. Would you mind if I reopen it? Probably it deserves v4.0.0 milestone, too.

@hedgesky hedgesky deleted the add_rubocop branch March 23, 2017 14:12
laserlemon pushed a commit that referenced this pull request Mar 31, 2017
taylorthurlow pushed a commit to taylorthurlow/interactor that referenced this pull request Jul 12, 2020
@hedgesky hedgesky removed their assignment Nov 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants