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

Style/ClassAndModuleChildren clobbering error with multiple nested classes in compact mode #9766

Closed
dvandersluis opened this issue May 3, 2021 · 0 comments · Fixed by #9783
Labels

Comments

@dvandersluis
Copy link
Member

class Foo
  class Bar
    class Baz

    end
  end
end
$ rubocop test.rb -A --only Style/ClassAndModuleChildren
Inspecting 1 file
An error occurred while Style/ClassAndModuleChildren cop was inspecting /Users/daniel/RubymineProjects/rubocop/test.rb:2:2.
To see the complete backtrace run rubocop -d.
C

Offenses:

test.rb:1:7: C: [Corrected] Style/ClassAndModuleChildren: Use compact module/class definition instead of nested style.
class Foo
      ^^^

1 file inspected, 1 offense detected, 1 offense corrected

Backtrace:

An error occurred while Style/ClassAndModuleChildren cop was inspecting /Users/daniel/RubymineProjects/rubocop/test.rb:2:2.
Parser::Source::TreeRewriter detected clobbering
/Users/daniel/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/parser-3.0.1.1/lib/parser/source/tree_rewriter.rb:427:in `trigger_policy'
/Users/daniel/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/parser-3.0.1.1/lib/parser/source/tree_rewriter.rb:414:in `enforce_policy'
/Users/daniel/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/parser-3.0.1.1/lib/parser/source/tree_rewriter/action.rb:209:in `call'
/Users/daniel/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/parser-3.0.1.1/lib/parser/source/tree_rewriter/action.rb:209:in `block in check_fusible'
/Users/daniel/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/parser-3.0.1.1/lib/parser/source/tree_rewriter/action.rb:207:in `each'
/Users/daniel/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/parser-3.0.1.1/lib/parser/source/tree_rewriter/action.rb:207:in `check_fusible'
/Users/daniel/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/parser-3.0.1.1/lib/parser/source/tree_rewriter/action.rb:187:in `analyse_hierarchy'
/Users/daniel/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/parser-3.0.1.1/lib/parser/source/tree_rewriter/action.rb:111:in `place_in_hierarchy'
/Users/daniel/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/parser-3.0.1.1/lib/parser/source/tree_rewriter/action.rb:131:in `block in combine_children'
/Users/daniel/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/parser-3.0.1.1/lib/parser/source/tree_rewriter/action.rb:130:in `each'
/Users/daniel/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/parser-3.0.1.1/lib/parser/source/tree_rewriter/action.rb:130:in `inject'
/Users/daniel/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/parser-3.0.1.1/lib/parser/source/tree_rewriter/action.rb:130:in `combine_children'
/Users/daniel/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/parser-3.0.1.1/lib/parser/source/tree_rewriter/action.rb:221:in `merge'
/Users/daniel/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/parser-3.0.1.1/lib/parser/source/tree_rewriter/action.rb:104:in `do_combine'
/Users/daniel/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/parser-3.0.1.1/lib/parser/source/tree_rewriter/action.rb:30:in `combine'
/Users/daniel/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/parser-3.0.1.1/lib/parser/source/tree_rewriter.rb:143:in `merge!'
lib/rubocop/cop/base.rb:291:in `apply_correction'
lib/rubocop/cop/base.rb:375:in `attempt_correction'
lib/rubocop/cop/base.rb:356:in `use_corrector'
lib/rubocop/cop/base.rb:350:in `correct'
lib/rubocop/cop/base.rb:127:in `add_offense'
lib/rubocop/cop/style/class_and_module_children.rb:137:in `check_compact_style'
lib/rubocop/cop/style/class_and_module_children.rb:122:in `check_style'
lib/rubocop/cop/style/class_and_module_children.rb:35:in `on_class'

RuboCop version

master (also occurs after #9765)

tejasbubane added a commit to tejasbubane/rubocop that referenced this issue May 7, 2021
dvandersluis added a commit that referenced this issue May 7, 2021
[Fix #9766] Fix a clobbering error for `Style/ClassAndModuleChildren` with `compact` style
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
1 participant