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

Fix find_end_line for block nodes. #11858

Merged
merged 1 commit into from
May 7, 2023
Merged

Conversation

reitermarkus
Copy link
Contributor

@reitermarkus reitermarkus commented May 6, 2023

When two block nodes are in the root, e.g.

block1 do
  # ...
end

block2 do
  # ...
end

calling find_end_line on the second will return 1 instead of 7.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@reitermarkus reitermarkus changed the title Fix find_end_line when parent does not have an end. Fix find_end_line for block nodes. May 7, 2023
@koic
Copy link
Member

koic commented May 7, 2023

Can you add a test case and a changelog entry?

@reitermarkus
Copy link
Contributor Author

Are there any existing tests for CommentsHelp? I only ran into this issue while implementing a custom cop, so not sure about the best way to test this here.

@koic
Copy link
Member

koic commented May 7, 2023

It would be better to add a reproducible test case in any cop that mixin CommentsHelp:

$ git grep 'include CommentsHelp'
lib/rubocop/cop/layout/class_structure.rb:137:        include CommentsHelp
lib/rubocop/cop/lint/empty_conditional_body.rb:65:        include CommentsHelp
lib/rubocop/cop/lint/empty_in_pattern.rb:47:        include CommentsHelp
lib/rubocop/cop/lint/empty_when.rb:48:        include CommentsHelp
lib/rubocop/cop/style/class_methods_definitions.rb:63:        include CommentsHelp
lib/rubocop/cop/style/if_unless_modifier.rb:68:        include CommentsHelp
lib/rubocop/cop/style/multiline_ternary_operator.rb:37:        include CommentsHelp
lib/rubocop/cop/style/redundant_initialize.rb:98:        include CommentsHelp
lib/rubocop/cop/style/symbol_proc.rb:88:        include CommentsHelp

It may not be the best, but having regression tests is essential.

@reitermarkus reitermarkus force-pushed the patch-2 branch 3 times, most recently from b6fdef6 to 5668fb1 Compare May 7, 2023 06:16
@reitermarkus reitermarkus requested a review from koic May 7, 2023 06:17
@reitermarkus
Copy link
Contributor Author

Thanks, I found a cop that runs on blocks which actually has this problem.

@koic
Copy link
Member

koic commented May 7, 2023

I left two comments. Finally, please squash the commits into one.

@reitermarkus reitermarkus force-pushed the patch-2 branch 2 times, most recently from e6d273f to 40b3a31 Compare May 7, 2023 08:16
@reitermarkus reitermarkus requested a review from koic May 7, 2023 08:29
@koic koic merged commit df6b797 into rubocop:master May 7, 2023
28 checks passed
@koic
Copy link
Member

koic commented May 7, 2023

Thanks!

@reitermarkus reitermarkus deleted the patch-2 branch May 7, 2023 20:00
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.

None yet

2 participants