Skip to content

Commit

Permalink
Add new RangeNode extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Drenmi authored and bbatsov committed Jan 8, 2019
1 parent 7cf76ff commit 743ca45
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 8 deletions.
16 changes: 8 additions & 8 deletions .rubocop_todo.yml
@@ -1,12 +1,12 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-12-27 11:29:54 +0800 using RuboCop version 0.61.1.
# on 2019-01-03 17:29:56 +0800 using RuboCop version 0.62.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 75
# Offense count: 77
Metrics/AbcSize:
Max: 17

Expand All @@ -15,31 +15,31 @@ Metrics/AbcSize:
Metrics/ClassLength:
Max: 181

# Offense count: 220
# Offense count: 222
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/MethodLength:
Max: 14

# Offense count: 5
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 139
Max: 141

# Offense count: 10
# Offense count: 12
RSpec/AnyInstance:
Exclude:
- 'spec/rubocop/cli_spec.rb'
- 'spec/rubocop/cop/lint/duplicate_methods_spec.rb'
- 'spec/rubocop/runner_spec.rb'
- 'spec/rubocop/target_finder_spec.rb'

# Offense count: 1067
# Offense count: 1071
# Configuration parameters: Prefixes.
# Prefixes: when, with, without
RSpec/ContextWording:
Enabled: false

# Offense count: 3304
# Offense count: 3313
# Configuration parameters: Max.
RSpec/ExampleLength:
Enabled: false
Expand All @@ -60,7 +60,7 @@ RSpec/ExpectOutput:
- 'spec/rubocop/target_finder_spec.rb'
- 'spec/support/cli_spec_behavior.rb'

# Offense count: 525
# Offense count: 528
# Configuration parameters: AggregateFailuresByDefault.
RSpec/MultipleExpectations:
Max: 25
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop.rb
Expand Up @@ -48,6 +48,7 @@
require_relative 'rubocop/ast/node/keyword_splat_node'
require_relative 'rubocop/ast/node/or_node'
require_relative 'rubocop/ast/node/pair_node'
require_relative 'rubocop/ast/node/range_node'
require_relative 'rubocop/ast/node/regexp_node'
require_relative 'rubocop/ast/node/resbody_node'
require_relative 'rubocop/ast/node/send_node'
Expand Down
2 changes: 2 additions & 0 deletions lib/rubocop/ast/builder.rb
Expand Up @@ -27,6 +27,8 @@ class Builder < Parser::Builders::Default
for: ForNode,
hash: HashNode,
if: IfNode,
irange: RangeNode,
erange: RangeNode,
kwsplat: KeywordSplatNode,
or: OrNode,
pair: PairNode,
Expand Down
11 changes: 11 additions & 0 deletions lib/rubocop/ast/node/range_node.rb
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module RuboCop
module AST
# A node extension for `irange` and `erange` nodes. This will be used in
# place of a plain node when the builder constructs the AST, making its
# methods available to all `irange` and `erange` nodes within RuboCop.
class RangeNode < Node
end
end
end
32 changes: 32 additions & 0 deletions spec/rubocop/ast/range_node_spec.rb
@@ -0,0 +1,32 @@
# frozen_string_literal: true

RSpec.describe RuboCop::AST::RangeNode do
let(:range_node) { parse_source(source).ast }

describe '.new' do
context 'with an inclusive range' do
let(:source) do
'1..2'
end

it { expect(range_node.is_a?(described_class)).to be(true) }
end

context 'with an exclusive range' do
let(:source) do
'1...2'
end

it { expect(range_node.is_a?(described_class)).to be(true) }
end

context 'with an infinite range' do
let(:ruby_version) { 2.6 }
let(:source) do
'1..'
end

it { expect(range_node.is_a?(described_class)).to be(true) }
end
end
end

0 comments on commit 743ca45

Please sign in to comment.