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

Upgrade rubocop #1566

Merged
merged 41 commits into from
Nov 17, 2021
Merged

Upgrade rubocop #1566

merged 41 commits into from
Nov 17, 2021

Conversation

aurelien-reeves
Copy link
Contributor

@aurelien-reeves aurelien-reeves commented Aug 4, 2021

Description

Rubocop is fixed to a pretty old version.
The purpose of this PR is to try upgrading it step by step.

Type of change

Please delete options that are not relevant.

  • Refactoring (improvements to code design or tooling that don't change behaviour)

Note to other contributors

One of the first offense to be fixed with a new version is done in lib/cucumber/glue/dsl.rb. Before we just had the extend(Cucumber::Glue::Dsl) instruction to extend the global Object class. This triggered an offense. I've fixed it by explicitly replacing it with the following:

class Object
  # TODO: can we avoid adding methods to the global namespace (Kernel)
  prepend(Cucumber::Glue::Dsl)
end

That way the extension of the global Object class is made explicit. Tests seems to be passing. Does that looks good to advanced ruby developers?

Checklist:

Your PR is ready for review once the following checklist is
complete. You can also add some checks if you want to.

  • New and existing tests are passing locally and on CI
  • bundle exec rubocop reports no offenses

lib/cucumber/glue/dsl.rb Outdated Show resolved Hide resolved
@aurelien-reeves aurelien-reeves marked this pull request as ready for review November 3, 2021 13:28
@aurelien-reeves
Copy link
Contributor Author

aurelien-reeves commented Nov 3, 2021

Rubocop has been bumped to the latest version, and offenses have been fixed.

To review this PR, I think it would be easier to look at the commits rather than the diff.

@luke-hill What do you think? I removed all inline magic comment I had added before except for one that I have documented.

Copy link
Contributor

@luke-hill luke-hill left a comment

Choose a reason for hiding this comment

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

So yeh reviewing this was hell! Please don't give me a PR with 158 things again to review 😓

We should use the todo file to partially fix things up and then just click them off in the todo file.

lib/cucumber/cli/main.rb Show resolved Hide resolved
lib/cucumber/configuration.rb Show resolved Hide resolved
lib/cucumber/events/step_activated.rb Outdated Show resolved Hide resolved
lib/cucumber/events/step_definition_registered.rb Outdated Show resolved Hide resolved
lib/cucumber/formatter/ansicolor.rb Show resolved Hide resolved
spec/cucumber/cli/configuration_spec.rb Show resolved Hide resolved
spec/cucumber/formatter/http_io_spec.rb Show resolved Hide resolved
spec/cucumber/formatter/junit_spec.rb Show resolved Hide resolved
spec/support/fake_objects.rb Outdated Show resolved Hide resolved
spec/support/fake_objects.rb Show resolved Hide resolved
@aurelien-reeves
Copy link
Contributor Author

aurelien-reeves commented Nov 4, 2021

So yeh reviewing this was hell! Please don't give me a PR with 158 things again to review 😓

We should use the todo file to partially fix things up and then just click them off in the todo file.

Yeah, sorry for that 😓
I hate big PR myself.

I'll summarize all your comments and plan some specific actions.

@aurelien-reeves
Copy link
Contributor Author

aurelien-reeves commented Nov 4, 2021

So, to summarize:

What we could do as part of dedicated PR (I would open dedicated issues to make sure we do not forget those):

To merge the current PR:

  • make sure that calling super in the events initialize methods is safe as part of the actual PR (lib/cucumber/events/step_activated.rb and lib/cucumber/events/step_definition_registered.rb)
  • can we safely delete some code from proto_world.rb? I am still confused with this. It seems to be useless. What would make it useful? Cucumber::Glue#steps and Cucumber::Glue#inspect are just calling super without any other code.

Did I missed something? Does that look like a plan?

@luke-hill
Copy link
Contributor

Yep sounds great. I've attached a couple of additional comments where needed.

The initializer of Core::Event already generates sub-classes with
attribute readers.

Refs. https://github.com/cucumber/cucumber-ruby-core/blob/main/lib/cucumber/core/event.rb
@aurelien-reeves
Copy link
Contributor Author

make sure that calling super in the events initialize methods is safe as part of the actual PR (lib/cucumber/events/step_activated.rb and lib/cucumber/events/step_definition_registered.rb)

Actually, Cucumber::Core::Event generates sub-classes with initializers dedicated to generate attribute readers.

So in derived classes as StepDefinitionRegistered or StepActivated, writing an initializer to initialize the attribute readers is doing what already does the base class.

Calling superis doing it twice.

Removing the initializer is removing duplicated code.

And this is actually covered with tests: when not properly initializing attribute readers for those two classes, some tests broke.

@aurelien-reeves
Copy link
Contributor Author

can we safely delete some code from proto_world.rb? I am still confused with this. It seems to be useless. What would make it useful? Cucumber::Glue#steps and Cucumber::Glue#inspect are just calling super without any other code.

I have restored the deleted methods. There purpose is actually documentation.

@aurelien-reeves
Copy link
Contributor Author

@luke-hill I guess I answer all your questions. Can we merge?

@aurelien-reeves aurelien-reeves merged commit 9777e60 into main Nov 17, 2021
@luke-hill luke-hill deleted the upgrade-rubocop branch March 29, 2023 08:24
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.

2 participants