You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Style/FormatStringToken cop does not respect IgnoredMethods for values which are nested, e.g. into an options hash.
Suggested solution
I've investigated why that is, and the culprit seems to be FormatStringToken#use_ignored_method? where we we only check if the found node (the offending string) has a method parent (send type). In case of a value inside a hash, the parent is not the method itself.
Maybe it makes sense to allow climbing up the node tree as long as parents are pair or hash nodes (maybe others?), and only then check if the surrounding node is of type send.
Please let me know if that approach sounds reasonable and I can try implementing a fix.
Expected behavior
Given the following config,
Style/FormatStringToken:
EnforcedStyle: annotatedIgnoredMethods:
- example
The
Style/FormatStringToken
cop does not respectIgnoredMethods
for values which are nested, e.g. into an options hash.Suggested solution
I've investigated why that is, and the culprit seems to be
FormatStringToken#use_ignored_method?
where we we only check if the found node (the offending string) has a method parent (send
type). In case of a value inside a hash, the parent is not the method itself.Maybe it makes sense to allow climbing up the node tree as long as parents are
pair
orhash
nodes (maybe others?), and only then check if the surrounding node is of typesend
.Please let me know if that approach sounds reasonable and I can try implementing a fix.
Expected behavior
Given the following config,
and the following Ruby code,
both calls to
example
should be ignored.Actual behavior
example("Hello %{name}")
is ignored, butexample("Hello %{name}", bye: "Bye %{name}")
raises an offense.Steps to reproduce the problem
Run Rubocop with example config from above against a file with example Ruby code from above.
RuboCop version
The text was updated successfully, but these errors were encountered: