Skip to content

Make compatible with latest RuboCop - #448

Merged
colszowka merged 3 commits into
simplecov-ruby:masterfrom
craiglittle:rubocop-update
Jan 25, 2016
Merged

colszowka merged 3 commits into
simplecov-ruby:masterfrom
craiglittle:rubocop-update

Conversation

@craiglittle

Copy link
Copy Markdown
Contributor

Comment thread lib/simplecov.rb Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I like the approach, but this changes the logic, you're missing an else SimpleCov::ResultMerger.merged_result case here to keep it in line with the previous version, no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Whoops, I think the right move is to get rid of the now-redundant if defined? @result. On the way.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reading this method makes me dizzy, maybe we get to untangle this a bit:

def result
  # Ensure the variable is defined to avoid ruby warnings
  @result = nil unless defined?(@result)

  # Collect our coverage result
  if running and not result?
    @result = SimpleCov::Result.new add_not_loaded_files(Coverage.result)
  end

  # If we're using merging of results, store the current result
  # first, then merge the results and return those
  if use_merging
    if result?
      SimpleCov::ResultMerger.store_result @result
    end
    SimpleCov::ResultMerger.merged_result
  else
    @result
  end
ensure
  self.running = false
end

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I know this is not applied to all of the code base and this especially is "just" our test sample code, but personally I prefer the actual if/else form because it's easier to parse the control flow of the method

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure. Would you like me to disable that cop completely or special case this file?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Which one is it and what is it complaining about? Can't see anything in the build log :(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That would be the Style::GuardClause cop, which says:

Use a guard clause instead of wrapping the code inside a conditional expression.

@craiglittle
craiglittle force-pushed the rubocop-update branch 2 times, most recently from 7683485 to 241de7f Compare January 20, 2016 18:20
@craiglittle

Copy link
Copy Markdown
Contributor Author

I've added the refactor of the result method with a few tweaks to continue to make RuboCop happy. Now, all we need to resolve is what to do with the guard clause.

@craiglittle

Copy link
Copy Markdown
Contributor Author

Also, I think it'd be prudent to consider locking rubocop to a minor version so it doesn't randomly break the build whenever a new version is released. Then, it could be updated when it's convenient instead of blocking other PRs.

Would you be open to me making that change?

@colszowka colszowka mentioned this pull request Jan 22, 2016
@craiglittle

Copy link
Copy Markdown
Contributor Author

@colszowka When you get a chance, I'm waiting on feedback on two points in order to proceed:

@colszowka

Copy link
Copy Markdown
Collaborator

Thanks for keeping up on this thing!

  • As I mentioned before, nowadays I personally prefer explicit conditionals over guard clauses because imho they're easier to read. But that also requires you to make your conditionals clean. I think in this case that is true, but its my personal opinion. Maybe you could create a follow-up issue where we bring in the rest of the contributors team to figure this out, and disable it for now to resolve the PR?
  • yes please, I was thinking about this myself. Please lock it at patch level since we're currently at 0.36 if I remember correctly, so ~>0.36 wouldnt fix the problem :)

Thanks again

On Fri, Jan 22, 2016 at 2:14 PM -0800, "Craig Little" [email protected] wrote:

@colszowka When you get a chance, I'm waiting on feedback on two points in order to proceed:

What should we do about the Style/GuardClause cop?
Should we lock down rubocop to avoid unexpected build failures in the future?

—
Reply to this email directly or view it on GitHub.

Since `rubocop` is pre-1.0, breaking changes are often introduced with
each minor version release. By locking to a minor version series, we
can update to the latest on our own schedule and avoid unexpected build
failures in the meantime.
This gets the build to green for now. An issue will be opened to
discuss what to do with this cop going forward.
@craiglittle

Copy link
Copy Markdown
Contributor Author

As I mentioned before, nowadays I personally prefer explicit conditionals over guard clauses because imho they're easier to read. But that also requires you to make your conditionals clean. I think in this case that is true, but its my personal opinion. Maybe you could create a follow-up issue where we bring in the rest of the contributors team to figure this out, and disable it for now to resolve the PR?

Done and done!

yes please, I was thinking about this myself. Please lock it at patch level since we're currently at 0.36 if I remember correctly, so ~>0.36 wouldnt fix the problem :)

Locked to the v0.36.x series.

And the build's 💚!

colszowka added a commit that referenced this pull request Jan 25, 2016
Make compatible with latest RuboCop
@colszowka
colszowka merged commit b08b8d9 into simplecov-ruby:master Jan 25, 2016
@colszowka

Copy link
Copy Markdown
Collaborator

Perfect, thanks @craiglittle

@craiglittle
craiglittle deleted the rubocop-update branch January 25, 2016 17:57
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.

3 participants