Skip to content

Commit e9a043d

Browse files
authored
Merge pull request #726 from koic/fix_an_incorrect_autocorrect_for_rails_dot_separated_keys
[Fix #725] Fix an incorrect autocorrect for `Rails/DotSeparatedKeys`
2 parents b671caa + d085218 commit e9a043d

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#725](https://github.com/rubocop/rubocop-rails/issues/725): Fix an incorrect autocorrect for `Rails/DotSeparatedKeys` when a key starts with dot. ([@koic][])

lib/rubocop/cop/rails/dot_separated_keys.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def should_convert_scope?(scope_node)
5353
end
5454

5555
def new_key(key_node, scope_node)
56-
"'#{scopes(scope_node).map(&:value).join('.')}.#{key_node.value}'"
56+
"'#{scopes(scope_node).map(&:value).join('.')}.#{key_node.value}'".squeeze('.')
5757
end
5858

5959
def scopes(scope_node)

spec/rubocop/cop/rails/dot_separated_keys_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
^^^^^^^^^^^^^^^^^^^ Use the dot-separated keys instead of specifying the `:scope` option.
2020
I18n.t :key, scope: :one
2121
^^^^^^^^^^^ Use the dot-separated keys instead of specifying the `:scope` option.
22+
I18n.t '.key', scope: :one
23+
^^^^^^^^^^^ Use the dot-separated keys instead of specifying the `:scope` option.
2224
RUBY
2325

2426
expect_correction(<<~RUBY)
@@ -30,6 +32,7 @@
3032
I18n.t 'one.two.key'
3133
I18n.t 'one.two.key'
3234
I18n.t 'one.key'
35+
I18n.t 'one.key'
3336
RUBY
3437
end
3538

0 commit comments

Comments
 (0)