Skip to content
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

Add ragexp_dot? method to RuboCop::AST::Token. #235

Merged
merged 2 commits into from Jul 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/new_add_regexp_dot_p_to_token.md
@@ -0,0 +1 @@
* [#235](https://github.com/rubocop-hq/rubocop-ast/pull/235): Add `regexp_dot?` method to `RuboCop::AST::Token`. ([@koic][])
4 changes: 4 additions & 0 deletions lib/rubocop/ast/token.rb
Expand Up @@ -100,6 +100,10 @@ def comma?
type == :tCOMMA
end

def regexp_dot?
%i[tDOT2 tDOT3].include?(type)
end

def rescue_modifier?
type == :kRESCUE_MOD
end
Expand Down
22 changes: 19 additions & 3 deletions spec/rubocop/ast/token_spec.rb
Expand Up @@ -8,6 +8,8 @@
def some_method
[ 1, 2 ];
foo[0] = 3
1..42
1...42
end
RUBY

Expand All @@ -22,6 +24,8 @@ def some_method
processed_source.find_token { |t| t.text == '[' && t.line == 3 }
end
let(:comma_token) { processed_source.find_token { |t| t.text == ',' } }
let(:irange_token) { processed_source.find_token { |t| t.text == '..' } }
let(:erange_token) { processed_source.find_token { |t| t.text == '...' } }
let(:right_array_bracket_token) do
processed_source.find_token { |t| t.text == ']' && t.line == 3 }
end
Expand Down Expand Up @@ -69,7 +73,7 @@ def some_method
it 'returns line of token' do
expect(first_token.line).to eq 1
expect(zero_token.line).to eq 4
expect(end_token.line).to eq 5
expect(end_token.line).to eq 7
end
end

Expand All @@ -85,15 +89,15 @@ def some_method
it 'returns index of first char in token range of entire source' do
expect(first_token.begin_pos).to eq 0
expect(zero_token.begin_pos).to eq 44
expect(end_token.begin_pos).to eq 51
expect(end_token.begin_pos).to eq 68
end
end

describe '#end_pos' do
it 'returns index of last char in token range of entire source' do
expect(first_token.end_pos).to eq 9
expect(zero_token.end_pos).to eq 45
expect(end_token.end_pos).to eq 54
expect(end_token.end_pos).to eq 71
end
end

Expand Down Expand Up @@ -232,6 +236,18 @@ def some_method
end
end

describe '#regexp_dot?' do
it 'returns true for regexp tokens' do
expect(irange_token).to be_regexp_dot
expect(erange_token).to be_regexp_dot
end

it 'returns false for non comma tokens' do
expect(semicolon_token).not_to be_regexp_dot
expect(right_ref_bracket_token).not_to be_regexp_dot
end
end

describe '#rescue_modifier?' do
let(:source) { <<~RUBY }
def foo
Expand Down