Closed okuramasafumi closed 8 months ago
I don't think this is the right solution.
This should just skip interpolated strings for const_get
. In addition it's easily analyzable if the string literal contains double-colons to prevent a false positive.
From testing, this also applies to:
const_source_location
const_defined?
These don't:
public_const
/private_const
don't accept nested constantsdeprecate_constant
as wellremove_const
and set_const
@Earlopain You are right. At least this change must cover all affected methods. One concern is that the rule will be a little complex. Some might be confused about why it's not applied for some cases. We need to have a good documentation to explain.
@Earlopain What about this case:
const_get("#{process(name)}Resource")
Here, process
method returns a string that MIGHT contain ::
. Is it analyzable?
Perhaps in some trivial cases but generally no. I would just ignore those.
I'll close this PR in favor of #430, which proposals a better resolution. Thank you.
[Fix #425]
const_get
doesn't accept symbols that are something like:"Foo::Bar"
, and that's intended according to this issue. https://bugs.ruby-lang.org/issues/12319 Therefore, changing String to Symbol might not work as expected. As far as I know that's related toconst_get
only so we can remove it from the target ofStringIdentifierArgument
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.