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 new Minitest/LifecycleHooksOrder cop #232

Merged
merged 1 commit into from
Jan 31, 2023

Conversation

fatkodima
Copy link
Contributor

Closes #214.

Tested on rails/rails - 5 valid offenses.

@@ -32,6 +32,6 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.add_runtime_dependency 'rubocop', '>= 0.90', '< 2.0'
spec.add_runtime_dependency 'rubocop', '>= 1.43', '< 2.0'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Upgraded rubocop because I need range_with_comments_and_lines from RangeHelp module.
Probably better done as a separate PR?

Copy link
Member

Choose a reason for hiding this comment

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

It's a big jump, but let's still include it in this PR. By the way, it looks like this was introduced in 1.39, not 1.43.
rubocop/rubocop@0d6b0d1

Suggested change
spec.add_runtime_dependency 'rubocop', '>= 1.43', '< 2.0'
spec.add_runtime_dependency 'rubocop', '>= 1.39', '< 2.0'

MSG = '`%<current>s` is supposed to appear before `%<previous>s`.'

HOOKS_ORDER_MAP = Hash.new do |hash, hook|
hash[hook] = LIFECYCLE_HOOK_METHODS_IN_ORDER.index(hook) || 100
Copy link
Member

Choose a reason for hiding this comment

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

Can you make the magic number 100 a constant and add an explanation of what it is?

@fatkodima
Copy link
Contributor Author

Updated.


MSG = '`%<current>s` is supposed to appear before `%<previous>s`.'

REGULAR_METHOD_POSITION = 100
Copy link
Member

Choose a reason for hiding this comment

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

It would be better if source commented why the value of 100 was chosen and set :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

@koic koic merged commit a469a0a into rubocop:master Jan 31, 2023
@koic
Copy link
Member

koic commented Jan 31, 2023

Thanks!

@fatkodima fatkodima deleted the lifecycle_hooks_order-cop branch January 31, 2023 12:45
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.

New cop: Minitest/HooksGrouping
2 participants