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

Rails/DotSeparatedKeys autofix seems to keep all dots when combining the scope with the key. #725

Closed
danieldiekmeier opened this issue Jun 21, 2022 · 0 comments · Fixed by #726
Labels
bug Something isn't working

Comments

@danieldiekmeier
Copy link

When running the new Rails/DotSeparatedKeys cop, I noticed that it generates some invalid keys.

Expected behavior

I18n.t("world", scope: ["hello", "hello"])
I18n.t(".world", scope: ["hello", "hello"])

should both be transformed into:

I18n.t("hello.hello.world")

Actual behavior

I18n.t("world", scope: ["hello", "hello"])  -> I18n.t("hello.hello.world")
I18n.t(".world", scope: ["hello", "hello"]) -> I18n.t("hello.hello..world")

It looks like the Autofix smooshes together the different parts, instead of making sure to remove redundant dots.

Steps to reproduce the problem

$ echo "def x\n  I18n.t('.world', scope: ['hello', 'hello'])\nend" > example.rb
$ rubocop --auto-correct ./example.rb
$ cat example.rb

RuboCop version

$ bundle exec rubocop -V
1.29.1 (using Parser 3.1.2.0, rubocop-ast 1.18.0, running on ruby 3.0.3 arm64-darwin21)
  - rubocop-performance 1.13.3
  - rubocop-rails 2.15.0
  - rubocop-rspec 2.11.1
@koic koic added the bug Something isn't working label Jun 21, 2022
koic added a commit to koic/rubocop-rails that referenced this issue Jun 21, 2022
…dKeys`

Fixes rubocop#725.

This PR fixes an incorrect autocorrect for `Rails/DotSeparatedKeys`
when a key starts with dot.
@koic koic closed this as completed in #726 Jun 25, 2022
koic added a commit that referenced this issue Jun 25, 2022
…ils_dot_separated_keys

[Fix #725] Fix an incorrect autocorrect for `Rails/DotSeparatedKeys`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants