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 #7534] Fix an incorrect autocorrect for Layout/SpaceBeforeBlockBraces #7535

Conversation

koic
Copy link
Member

@koic koic commented Nov 28, 2019

Fixes #7534.

Fix an incorrect autocorrect for Style/BlockDelimiters cop and Layout/SpaceBeforeBlockBraces cop with EnforcedStyle: no_space when using multiline braces.


Before submitting the PR make sure the following are checked:

  • 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.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

@koic koic force-pushed the fix_an_incorrect_autocorrect_for_space_before_block_braces branch from f7852cf to 9709601 Compare November 28, 2019 18:14
EnforcedStyle: no_space
YAML

expect(cli.run(%w[--auto-correct])).to eq(0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please don't let this example depend on other cops than --only Style/BlockDelimiters,Layout/SpaceBeforeBlockBraces. This is to prevent unnecessary work in the future if any of the unrelated cops changes. I remember 8d071f0 all to well …

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the review. I updated it.

@koic koic force-pushed the fix_an_incorrect_autocorrect_for_space_before_block_braces branch from 9709601 to e12736e Compare November 29, 2019 05:25
…reBlockBraces`

Fixes rubocop#7534.

Fix an incorrect autocorrect for `Style/BlockDelimiters` cop and
`Layout/SpaceBeforeBlockBraces` cop with `EnforcedStyle: no_space`
when using multiline braces.
@koic koic force-pushed the fix_an_incorrect_autocorrect_for_space_before_block_braces branch from e12736e to e61357e Compare November 29, 2019 15:37
@koic koic merged commit b281caf into rubocop:master Nov 29, 2019
@koic koic deleted the fix_an_incorrect_autocorrect_for_space_before_block_braces branch November 29, 2019 15:49
@@ -1653,6 +1653,32 @@ def self.some_method(foo, bar: 1)
RUBY
end

it 'corrects Style/BlockDelimiters offenses when specifing' \

Choose a reason for hiding this comment

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

small typo here (if you care): "specifying" instead of "specifing"

Thanks so much for posting the bugfix in such a timely manner! I am amazed at how quickly you did so! You're awesome!

Copy link
Member Author

Choose a reason for hiding this comment

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

This typo fixed by e97eb5c. Thanks!

koic added a commit that referenced this pull request Nov 30, 2019
@@ -110,6 +118,15 @@ def style_for_empty_braces
end
end

def conflict_with_block_delimiters?
block_delimiters_style == 'line_count_based' &&
style == :no_space && node.multiline?
Copy link
Contributor

Choose a reason for hiding this comment

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

@koic
With rubocop-0.78.0 I got the below error. Do you have any idea?

An error occurred while Layout/SpaceBeforeBlockBraces cop was inspecting /webapp/spec/my_spec.rb:697:6.
undefined local variable or method `node' for #<RuboCop::Cop::Layout::SpaceBeforeBlockBraces:0x0000560a675e42d8>
/usr/local/bundle/gems/rubocop-0.78.0/lib/rubocop/cop/layout/space_before_block_braces.rb:123:in `conflict_with_block_delimiters?'

Copy link
Member Author

Choose a reason for hiding this comment

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

@johnny-miyake Thanks for your feedback. Can you open the issue with the reproduction code?
https://github.com/rubocop-hq/rubocop/issues

Copy link
Contributor

Choose a reason for hiding this comment

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

@koic Sure. I opened the issue here: #7590

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.

Bug: curly brace converting to do WITHOUT SPACE breaks code block (changes field_set_tag { to field_set_tagdo)
5 participants