-
Notifications
You must be signed in to change notification settings - Fork 4
Add export(typed: false) to ParamProxy and rewrite_signature to MethodProxy #9
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
Open
obsidiannnn
wants to merge
6
commits into
low-rb:main
Choose a base branch
from
obsidiannnn:feature/export-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fe89079
Add export(typed:) to ParamProxy and rewrite_signature to MethodProxy
obsidiannnn 4406112
Address review feedback: start_index, indentation via sig_lines, rena…
obsidiannnn 48c5041
Use lines= setter for indentation, delegate lines= through Proxy, han…
obsidiannnn ee3e09f
Rename original to old_line in rewrite_signature
obsidiannnn 866b565
Remove empty private block from Source
obsidiannnn 6cefcc2
Fix rewrite_signature to use direct lines[start_index] instead of lin…
obsidiannnn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,8 +38,6 @@ def export | |
| lines[start_index..end_index].join | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def start_index | ||
| start_line - 1 | ||
| end | ||
|
|
||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'prism' | ||
| require_relative '../../lib/lowkey' | ||
|
|
||
| RSpec.describe Lowkey::MethodProxy do | ||
| subject(:file_proxy) { Lowkey.load('spec/fixtures/mock_node.rbx') } | ||
|
|
||
| let(:method_proxy) { file_proxy['Lowkey::MockNode'][:render] } | ||
|
|
||
| describe '#rewrite_signature' do | ||
| it 'replaces the signature line in the shared lines array' do | ||
| original_line = method_proxy.lines[method_proxy.start_index].dup | ||
| method_proxy.rewrite_signature | ||
| rewritten = method_proxy.lines[method_proxy.start_index] | ||
| expect(rewritten).not_to eq(original_line) | ||
| end | ||
|
|
||
| it 'removes type annotations from the signature' do | ||
| method_proxy.rewrite_signature | ||
| rewritten = method_proxy.lines[method_proxy.start_index] | ||
| expect(rewritten).not_to match(/String|Integer|Symbol/) | ||
| end | ||
|
|
||
| it 'preserves the method name' do | ||
| method_proxy.rewrite_signature | ||
| rewritten = method_proxy.lines[method_proxy.start_index] | ||
| expect(rewritten).to include('def render') | ||
| end | ||
|
|
||
| it 'is reflected in file_proxy.export since lines are shared' do | ||
| method_proxy.rewrite_signature | ||
| expect(file_proxy.export).to include(method_proxy.lines[method_proxy.start_index].strip) | ||
| end | ||
| end | ||
| end |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'prism' | ||
| require_relative '../../lib/lowkey' | ||
|
|
||
| RSpec.describe Lowkey::ParamProxy do | ||
| subject(:file_proxy) { Lowkey.load('spec/fixtures/mock_node.rbx') } | ||
|
|
||
| let(:method_proxy) { file_proxy['Lowkey::MockNode'][:render] } | ||
|
|
||
| describe '#export' do | ||
| context 'typed: true (default)' do | ||
| it 'returns the raw source for a positional param' do | ||
| param = method_proxy[:one] | ||
| expect(param.export).to eq(param.export(typed: true)) | ||
| end | ||
|
|
||
| it 'returns the raw source for a keyword param' do | ||
| param = method_proxy[:three] | ||
| expect(param.export).to eq(param.export(typed: true)) | ||
| end | ||
| end | ||
|
|
||
| context 'typed: false with no expression set' do | ||
| it 'returns plain name for a required positional param' do | ||
| param = method_proxy[:one] | ||
| expect(param.export(typed: false)).to eq('one') | ||
| end | ||
|
|
||
| it 'returns plain name for a required keyword param' do | ||
| param = method_proxy[:three] | ||
| expect(param.export(typed: false)).to eq('three:') | ||
| end | ||
|
|
||
| it 'returns name with default for an optional positional param' do | ||
| param = method_proxy[:two] | ||
| expect(param.export(typed: false)).to eq("two = 'mock value'") | ||
| end | ||
|
|
||
| it 'returns name with default for an optional keyword param' do | ||
| param = method_proxy[:four] | ||
| expect(param.export(typed: false)).to eq("four: 'mock value'") | ||
| end | ||
| end | ||
| end | ||
| end |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a blocker but I wonder if a method proxy already has info on whether it's a class method or not