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 #8470] Do not try to autocorrect Style/StringConcatenation if any of the parts are too complex #8634

Merged

Conversation

dvandersluis
Copy link
Member

Fixes #8470.

If any of the parts in the expression are too complex, an offense will be registered but autocorrection will not take place (ideally the complex expression should be replaced with a variable or method call that could then be interpolated more simply).

The following disable autocorrection:

  • multiline statements
  • heredocs (which otherwise were autocorrecting into a syntax error)
  • nested interpolation
  • expressions with blocks (block braces inside interpolation 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.

@dvandersluis
Copy link
Member Author

Ping @marcandre.

@dvandersluis dvandersluis force-pushed the fix-string-concatenation-autocorrect branch 2 times, most recently from e0e1d54 to ec69673 Compare September 2, 2020 18:36
Copy link
Contributor

@marcandre marcandre left a comment

Choose a reason for hiding this comment

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

Great PR 👏
Would it be worthwhile to state in the cop's doc that overly complex expressions will not be auto-corrected?

@dvandersluis dvandersluis force-pushed the fix-string-concatenation-autocorrect branch from ec69673 to aaf9b21 Compare September 3, 2020 14:42
…n if any of the parts are too complex.

Complex includes multiline statements, heredocs, nested interpolations and expressions with blocks.
@dvandersluis dvandersluis force-pushed the fix-string-concatenation-autocorrect branch from aaf9b21 to eebceb0 Compare September 3, 2020 14:43
@dvandersluis
Copy link
Member Author

@marcandre I added a note in the doc, please let me know if you want me to reword anything!

Copy link
Contributor

@marcandre marcandre left a comment

Choose a reason for hiding this comment

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

Awesome!

@mergify mergify bot merged commit 5b93f78 into rubocop:master Sep 3, 2020
@dvandersluis dvandersluis deleted the fix-string-concatenation-autocorrect branch January 18, 2021 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Style/StringConcatenation: flexibility settings
2 participants