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 Fatsoma:fix/cond_assign_const_namespace branch from 470d676 to ffd33c2 Jul 14, 2020
@biinari biinari marked this pull request as ready for review Jul 14, 2020
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 Fatsoma:fix/cond_assign_const_namespace branch from ffd33c2 to e3bcf91 Jul 14, 2020
@bbatsov bbatsov merged commit 1fc1981 into rubocop-hq:master Aug 5, 2020
5 of 19 checks passed
5 of 19 checks passed
windows 2.4
Details
windows 2.5
Details
windows 2.6
Details
windows 2.7
Details
windows mingw
Details
ci/circleci: cc-setup Your tests are queued behind your running builds
Details
ci/circleci: documentation-checks Your tests are queued behind your running builds
Details
ci/circleci: jruby-9.2-ascii_spec Your tests are queued behind your running builds
Details
ci/circleci: jruby-9.2-rubocop Your tests are queued behind your running builds
Details
ci/circleci: ruby-2.4-ascii_spec Your tests are queued behind your running builds
Details
ci/circleci: ruby-2.4-rubocop Your tests are queued behind your running builds
Details
ci/circleci: ruby-2.5-ascii_spec Your tests are queued behind your running builds
Details
ci/circleci: ruby-2.5-rubocop Your tests are queued behind your running builds
Details
ci/circleci: ruby-2.6-ascii_spec Your tests are queued behind your running builds
Details
ci/circleci: ruby-2.6-rubocop Your tests are queued behind your running builds
Details
ci/circleci: ruby-2.7-ascii_spec Your tests are queued behind your running builds
Details
ci/circleci: ruby-2.7-rubocop Your tests are queued behind your running builds
Details
ci/circleci: ruby-head-ascii_spec Your tests are queued behind your running builds
Details
ci/circleci: ruby-head-rubocop Your tests are queued behind your running builds
Details
@bbatsov
Copy link
Collaborator

@bbatsov bbatsov commented Aug 5, 2020

Thanks!

@biinari biinari deleted the Fatsoma:fix/cond_assign_const_namespace branch Aug 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.