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
[Fix #8102] Consider class-length instead of block-length for Struct.new #8122
Conversation
I guess we should also mention this in the docs - I see we haven't done this for classes as well. Probably some examples there would also be useful. |
@tejasbubane Ping :-) |
@bbatsov Fixed. |
@tejasbubane Can you mention this in the docs? |
@tejasbubane It looks like the conflict with the |
@bkuhlmann Thanks for the reminder, this slipped between the cracks. @koic I have added documentation notes to the cops. |
@bbatsov Changed. |
af0c0b2
to
a5bc856
Compare
Rebased on master |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, looks like I forgot to review this. Got hit again by this today, went looking for it :-)
Looks great!
Can you rebase to fix the Changelog conflict?
a5bc856
to
0df2238
Compare
@marcandre Done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrote several small feedback, in any case this looks good overall :-)
…Struct.new Closes rubocop#8102
0df2238
to
14bc54e
Compare
Thank you always! |
❤️ thanks @tejasbubane, and @koic for the review! |
Follow rubocop/rubocop#8122. This commit suppresses the following RuboCop's offense. ```console % bundle exec rake (snip) Offenses: lib/rubocop/cop/mixin/index_method.rb:122:80: W: Lint/RedundantCopDisableDirective: Unnecessary disabling of Metrics/BlockLength. Autocorrection = Struct.new(:match, :block_node, :leading, :trailing) do # rubocop:disable Metrics/BlockLength ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 187 files inspected, 1 offense detected, 1 offense auto-correctable RuboCop failed! ```
Follow rubocop#8122. This PR fixes the following error for `Metrics/ClassLength` when using or assignment (`||=`). ```console % cat example.rb Constant ||= Struct.new {} % bundle exec rubocop --only Layout/ClassLength -d example.rb (snip) Inspecting 1 file Scanning /Users/koic/src/github.com/koic/rubocop-issues/8122/example.rb An error occurred while Metrics/ClassLength cop was inspecting /Users/koic/src/github.com/koic/rubocop-issues/8122/example.rb:1:0. undefined method `class_definition?' for nil:NilClass /Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/metrics/class_length.rb:43:in `on_casgn' /Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/commissioner.rb:99:in `block (2 levels) in trigger_responding_cops' /Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/commissioner.rb:152:in `with_cop_error_handling' /Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/commissioner.rb:98:in `block in trigger_responding_cops' /Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/commissioner.rb:97:in `each' /Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/commissioner.rb:97:in `trigger_responding_cops' /Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/commissioner.rb:70:in `on_casgn' /Users/koic/src/github.com/rubocop-hq/rubocop-ast/lib/rubocop/ast/traversal.rb:60:in `block in on_or_asgn' /Users/koic/src/github.com/rubocop-hq/rubocop-ast/lib/rubocop/ast/traversal.rb:60:in `each' /Users/koic/src/github.com/rubocop-hq/rubocop-ast/lib/rubocop/ast/traversal.rb:60:in `on_or_asgn' /Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/commissioner.rb:72:in `on_or_asgn' /Users/koic/src/github.com/rubocop-hq/rubocop-ast/lib/rubocop/ast/traversal.rb:14:in `walk' /Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/commissioner.rb:85:in `investigate' ``` This PR have also tweaked the highlight area of offense to more eligible location for count the class block length. Before: ```ruby Foo = Class.new do ^^^ Class has too many lines. [6/5] ``` After: ```ruby Foo = Class.new do ^^^^^^^^^^^^ Class has too many lines. [6/5] ``` I haven't added the fixing to the changelog because rubocop#8122 hasn't been released yet.
Closes #8102
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and RuboCop for itself, and generates the documentation.