Match ::I18n.t call just like I18n.t does - #752
Open
sato11 wants to merge 1 commit into
Open
Conversation
Given this model definition;
```ruby
class Post < ApplicationRecord
def hello
I18n.t("hello")
end
def world
::I18n.t("world")
end
end
```
and this dictionary;
```yml
en:
hello: "Hello"
world: "World"
```
the `unused` task used to falsely flag the `I18n.t` instance
with the scope resolution operator (`::`) prepended.
```
% i18n-tasks unused
#StandWithUkraine
Unused keys (1) | i18n-tasks v1.1.2
+--------+-------+-------+
| Locale | Key | Value |
+--------+-------+-------+
| en | world | World |
+--------+-------+-------+
```
This change fixes it, and also adds a test suite that covers `#scan_file`
which directly consumes the enhanced matcher.
Below is how one test case out of two fails without the fix:
```
Failures:
1) I18n::Tasks::Scanners::RubyScanner #scan_file when source contains ::I18n.t calls is expected to be present
Failure/Error: it { is_expected.to be_present }
expected `[].present?` to be truthy, got false
# ./spec/ruby_scanner_spec.rb:36:in 'block (4 levels) in <top (required)>'
Finished in 0.04819 seconds (files took 0.2276 seconds to load)
2 examples, 1 failure
```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #751.
Given this model definition;
and this dictionary;
the
unusedtask used to falsely flag theI18n.tinstance with the scope resolution operator (::) prepended.This change fixes it, and also adds a test suite that covers
#scan_filewhich directly consumes the enhanced matcher.Below is how one test case out of two fails without the fix: