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

Layout/ClassStructure crashes when constant with inline comment precedes 'extend' #9848

Closed
gongfarmer opened this issue Jun 2, 2021 · 0 comments
Labels

Comments

@gongfarmer
Copy link

Layout/ClassStructure class gets an internal error on the minimal code example provided below.

Expected behavior

Layout/ClassStructure cop should not encounter internal error when checking this code example.

Actual behavior

$ cat .rubocop.yml
AllCops:
  NewCops: enable

Layout/ClassStructure:
  Enabled: true

$ cat grid_task.rb 
# frozen_string_literal: true

class GridTask
  DESC = 'Grid Task' # grid task name OID, subclasses should set this
  extend Helpers::MakeFromFile
end

$ rubocop  -d grid_task.rb 
For $DIR: configuration from $DIR/.rubocop.yml
Default configuration from /var/lib/gems/2.5.0/gems/rubocop-1.16.0/config/default.yml
Inspecting 1 file
Scanning $DIR/grid_task.rb
An error occurred while Layout/ClassStructure cop was inspecting $DIR/grid_task.rb:4:0.
Parser::Source::TreeRewriter detected clobbering
/var/lib/gems/2.5.0/gems/parser-3.0.1.1/lib/parser/source/tree_rewriter.rb:427:in `trigger_policy'
/var/lib/gems/2.5.0/gems/parser-3.0.1.1/lib/parser/source/tree_rewriter.rb:414:in `enforce_policy'
/var/lib/gems/2.5.0/gems/parser-3.0.1.1/lib/parser/source/tree_rewriter/action.rb:233:in `call'
/var/lib/gems/2.5.0/gems/parser-3.0.1.1/lib/parser/source/tree_rewriter/action.rb:233:in `swallow'
/var/lib/gems/2.5.0/gems/parser-3.0.1.1/lib/parser/source/tree_rewriter/action.rb:97:in `with'
/var/lib/gems/2.5.0/gems/parser-3.0.1.1/lib/parser/source/tree_rewriter/action.rb:119:in `place_in_hierarchy'
/var/lib/gems/2.5.0/gems/parser-3.0.1.1/lib/parser/source/tree_rewriter/action.rb:106:in `do_combine'
/var/lib/gems/2.5.0/gems/parser-3.0.1.1/lib/parser/source/tree_rewriter/action.rb:30:in `combine'
/var/lib/gems/2.5.0/gems/parser-3.0.1.1/lib/parser/source/tree_rewriter.rb:400:in `combine'
/var/lib/gems/2.5.0/gems/parser-3.0.1.1/lib/parser/source/tree_rewriter.rb:194:in `replace'
/var/lib/gems/2.5.0/gems/parser-3.0.1.1/lib/parser/source/tree_rewriter.rb:218:in `remove'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/cop/layout/class_structure.rb:181:in `autocorrect'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/cop/layout/class_structure.rb:162:in `block (2 levels) in on_class'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/cop/base.rb:342:in `correct'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/cop/base.rb:127:in `add_offense'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/cop/layout/class_structure.rb:162:in `block in on_class'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/cop/layout/class_structure.rb:227:in `block in walk_over_nested_class_definition'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/cop/layout/class_structure.rb:223:in `each'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/cop/layout/class_structure.rb:223:in `walk_over_nested_class_definition'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/cop/layout/class_structure.rb:158:in `on_class'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/cop/commissioner.rb:100:in `public_send'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/cop/commissioner.rb:100:in `block (2 levels) in trigger_responding_cops'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/cop/commissioner.rb:160:in `with_cop_error_handling'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/cop/commissioner.rb:99:in `block in trigger_responding_cops'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/cop/commissioner.rb:98:in `each'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/cop/commissioner.rb:98:in `trigger_responding_cops'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/cop/commissioner.rb:69:in `on_class'
/var/lib/gems/2.5.0/gems/rubocop-ast-1.7.0/lib/rubocop/ast/traversal.rb:20:in `walk'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/cop/commissioner.rb:86:in `investigate'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/cop/team.rb:155:in `investigate_partial'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/cop/team.rb:83:in `investigate'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/runner.rb:310:in `inspect_file'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/runner.rb:254:in `block in do_inspection_loop'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/runner.rb:288:in `block in iterate_until_no_changes'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/runner.rb:281:in `loop'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/runner.rb:281:in `iterate_until_no_changes'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/runner.rb:250:in `do_inspection_loop'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/runner.rb:130:in `block in file_offenses'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/runner.rb:155:in `file_offense_cache'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/runner.rb:129:in `file_offenses'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/runner.rb:120:in `process_file'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/runner.rb:101:in `block in each_inspected_file'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/runner.rb:100:in `each'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/runner.rb:100:in `reduce'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/runner.rb:100:in `each_inspected_file'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/runner.rb:86:in `inspect_files'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/runner.rb:47:in `run'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/cli/command.rb:11:in `run'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/cli/environment.rb:18:in `run'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/cli.rb:65:in `run_command'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/cli.rb:72:in `execute_runners'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/lib/rubocop/cli.rb:41:in `run'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/exe/rubocop:12:in `block in <top (required)>'
/usr/lib/ruby/2.5.0/benchmark.rb:308:in `realtime'
/var/lib/gems/2.5.0/gems/rubocop-1.16.0/exe/rubocop:12:in `<top (required)>'
/usr/local/bin/rubocop:23:in `load'
/usr/local/bin/rubocop:23:in `<main>'
.

1 file inspected, no offenses detected

1 error occurred:
An error occurred while Layout/ClassStructure cop was inspecting $DIR/grid_task.rb:4:0.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop/rubocop/issues

Mention the following information in the issue report:
1.16.0 (using Parser 3.0.1.1, rubocop-ast 1.7.0, running on ruby 2.5.5 x86_64-linux-gnu)
Finished in 0.23941434547305107 seconds

Steps to reproduce the problem

  • update rubocop config to enable Layout/ClassStructure (see dump of minimal .rubocop.yml above)
  • copy the code from the file grid_task.rb above
  • run rubocop on grid_task.rb

RuboCop version

$ rubocop -V
1.16.0 (using Parser 3.0.1.1, rubocop-ast 1.7.0, running on ruby 2.5.5 x86_64-linux-gnu)
@koic koic added the bug label Jun 17, 2021
@koic koic closed this as completed in caf12fa Jul 7, 2021
koic added a commit that referenced this issue Jul 7, 2021
[Fix #9848] Handle EOL comments in ClassStructure auto-correct
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants