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 move namespaced constant in Style/ConditionalAssignment #8332

Merged
merged 2 commits into from Aug 5, 2020

Conversation

biinari
Copy link
Contributor

@biinari biinari commented Jul 14, 2020

Fix autocorrect for moving constant assignment outside the condition
when the constant is in a namespace, e.g. from:

condition ? FOO::BAR = 1 : FOO::BAR = 2

if condition
  ::FOO = 1
else
  ::FOO = 2
end

to keep the namespace Foo:: and the top-level :: in correction:

FOO::BAR = cond? ? 1 : 2

::FOO = if condition
  1
else
  2
end

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.

@biinari biinari force-pushed the fix/cond_assign_const_namespace branch from 470d676 to ffd33c2 Compare July 14, 2020 00:23
@biinari biinari marked this pull request as ready for review July 14, 2020 01:56
Fix autocorrect for moving constant assignment outside the condition
when the constant is in a namespace, e.g. from:

```ruby
condition ? FOO::BAR = 1 : FOO::BAR = 2

if condition
  ::FOO = 1
else
  ::FOO = 2
end
```

to keep the namespace `Foo::` and the top-level `::` in correction:

```ruby
FOO::BAR = cond? ? 1 : 2

::FOO = if condition
  1
else
  2
end
```
@biinari biinari force-pushed the fix/cond_assign_const_namespace branch from ffd33c2 to e3bcf91 Compare July 14, 2020 01:57
@bbatsov bbatsov merged commit 1fc1981 into rubocop:master Aug 5, 2020
@bbatsov
Copy link
Collaborator

bbatsov commented Aug 5, 2020

Thanks!

@biinari biinari deleted the fix/cond_assign_const_namespace branch August 6, 2020 03:21
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