ParsedConstantDefinitions doesn’t support fully qualified constants
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 1.9k
- Forks
- 121
- Avg merge
- 2m
- Merged PRs (30d)
- 1
Description
RuboCop::AST::Node#const_name doesn’t reveal whether a constant is fully qualified (e.g. ::HELLO) or not:
>> RuboCop::ProcessedSource.new('::HELLO', 2.6).ast.const_name
=> "HELLO"
>> RuboCop::ProcessedSource.new('HELLO', 2.6).ast.const_name
=> "HELLO"
As a result, the implementation of ParsedConstantDefinitions#collect_local_definitions is unaware of whether a constant is fully qualified, so it’s unable to put it in the correct namespace:
>> definitions = ParsedConstantDefinitions.new(
root_node: parse_code('module Sales; ::HELLO = "World"; end')
)
=> #<Packwerk::ParsedConstantDefinitions
@local_definitions=
{"::Sales"=>#<Parser::Source::Range (string) 7...12>,
"::Sales::HELLO"=>#<Parser::Source::Range (string) 16...21>}>
>> definitions.local_reference?('HELLO')
=> false # should be true
>> definitions.local_reference?('Sales::HELLO')
=> true # should be false
I’m not going to fix this right now because I’m trying to make progress on a different task, but I think it’s a bug that’s going to affect users.
cc: @tomstuart
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with ParsedConstantDefinitions#collect_local_definitions and reproduce the two fully qualified and unqualified constant examples from the issue. Trace how RuboCop::AST::Node#const_name is used, then verify that local_reference?('HELLO') and local_reference?('Sales::HELLO') produce the expected results for the module example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100