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 #725] Fix an incorrect autocorrect for Rails/DotSeparatedKeys #726

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#725](https://github.com/rubocop/rubocop-rails/issues/725): Fix an incorrect autocorrect for `Rails/DotSeparatedKeys` when a key starts with dot. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rails/dot_separated_keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def should_convert_scope?(scope_node)
end

def new_key(key_node, scope_node)
"'#{scopes(scope_node).map(&:value).join('.')}.#{key_node.value}'"
"'#{scopes(scope_node).map(&:value).join('.')}.#{key_node.value}'".squeeze('.')
end

def scopes(scope_node)
Expand Down
3 changes: 3 additions & 0 deletions spec/rubocop/cop/rails/dot_separated_keys_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
^^^^^^^^^^^^^^^^^^^ Use the dot-separated keys instead of specifying the `:scope` option.
I18n.t :key, scope: :one
^^^^^^^^^^^ Use the dot-separated keys instead of specifying the `:scope` option.
I18n.t '.key', scope: :one
^^^^^^^^^^^ Use the dot-separated keys instead of specifying the `:scope` option.
RUBY

expect_correction(<<~RUBY)
Expand All @@ -30,6 +32,7 @@
I18n.t 'one.two.key'
I18n.t 'one.two.key'
I18n.t 'one.key'
I18n.t 'one.key'
RUBY
end

Expand Down