code
stringlengths
26
124k
docstring
stringlengths
23
125k
func_name
stringlengths
1
98
language
stringclasses
1 value
repo
stringlengths
5
53
path
stringlengths
7
151
url
stringlengths
50
211
license
stringclasses
7 values
def default? optarg_type? || kwoptarg_type? end
Checks whether the argument has a default value @return [Boolean] whether the argument has a default value
default?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/arg_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/arg_node.rb
Apache-2.0
def each_value(&block) return to_enum(__method__) unless block values.each(&block) self end
@deprecated Use `values.each` (a.k.a. `children.each`)
each_value
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/array_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/array_node.rb
Apache-2.0
def arguments if numblock_type? [].freeze # Numbered parameters have no block arguments. else node_parts[1] end end
The arguments of this block. Note that if the block has destructured arguments, `arguments` will return a `mlhs` node, whereas `argument_list` will return only actual argument nodes. @return [Array<Node>]
arguments
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/block_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/block_node.rb
Apache-2.0
def argument_list if numblock_type? numbered_arguments else arguments.argument_list end end
Returns a collection of all descendants of this node that are argument type nodes. See `ArgsNode#argument_list` for details. @return [Array<Node>]
argument_list
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/block_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/block_node.rb
Apache-2.0
def single_line? loc.begin.line == loc.end.line end
Checks whether this is a single line block. This is overridden here because the general version in `Node` does not work for `block` nodes. @return [Boolean] whether the `block` literal is on a single line
single_line?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/block_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/block_node.rb
Apache-2.0
def branches bodies = in_pattern_branches.map(&:body) if else? # `empty-else` node sets nil because it has no body. else_branch.empty_else_type? ? bodies.push(nil) : bodies.push(else_branch) end bodies end
Returns an array of all the when branches in the `case` statement. @return [Array<Node, nil>] an array of the bodies of the `in` branches and the `else` (if any). Note that these bodies could be nil.
branches
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/case_match_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/case_match_node.rb
Apache-2.0
def branches bodies = when_branches.map(&:body) bodies.push(else_branch) if else? bodies end
Returns an array of all the when branches in the `case` statement. @return [Array<Node, nil>] an array of the bodies of the when branches and the else (if any). Note that these bodies could be nil.
branches
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/case_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/case_node.rb
Apache-2.0
def absolute? return false unless namespace each_path.first.cbase_type? end
@return [Boolean] if the constant starts with `::` (aka s(:cbase))
absolute?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/const_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/const_node.rb
Apache-2.0
def each_path(&block) return to_enum(__method__) unless block descendants = [] last = self loop do last = last.children.first break if last.nil? descendants << last break unless last.const_type? end descendants.reverse_each(&block) self end
Yield nodes for the namespace For `::Foo::Bar::BAZ` => yields: s(:cbase), then s(:const, :Foo), then s(:const, s(:const, :Foo), :Bar)
each_path
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/const_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/const_node.rb
Apache-2.0
def void_context? method?(:initialize) || assignment_method? end
Checks whether this node body is a void context. @return [Boolean] whether the `def` node body is a void context
void_context?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/def_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/def_node.rb
Apache-2.0
def argument_forwarding? arguments.any?(&:forward_args_type?) || arguments.any?(&:forward_arg_type?) end
Checks whether this method definition node forwards its arguments as per the feature added in Ruby 2.7. @note This is written in a way that may support lead arguments which are rumored to be added in a later version of Ruby. @return [Boolean] whether the `def` node uses argument forwarding
argument_forwarding?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/def_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/def_node.rb
Apache-2.0
def each_pair return each_child_node(:pair).to_enum unless block_given? each_child_node(:pair) do |pair| yield(*pair) end self end
Calls the given block for each `pair` node in the `hash` literal. If no block is given, an `Enumerator` is returned. @note `kwsplat` nodes are ignored. @return [self] if a block is given @return [Enumerator] if no block is given
each_pair
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/hash_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/hash_node.rb
Apache-2.0
def each_key(&block) return pairs.map(&:key).to_enum unless block pairs.map(&:key).each(&block) self end
Calls the given block for each `key` node in the `hash` literal. If no block is given, an `Enumerator` is returned. @note `kwsplat` nodes are ignored. @return [self] if a block is given @return [Enumerator] if no block is given
each_key
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/hash_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/hash_node.rb
Apache-2.0
def each_value(&block) return pairs.map(&:value).to_enum unless block pairs.map(&:value).each(&block) self end
Calls the given block for each `value` node in the `hash` literal. If no block is given, an `Enumerator` is returned. @note `kwsplat` nodes are ignored. @return [self] if a block is given @return [Enumerator] if no block is given
each_value
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/hash_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/hash_node.rb
Apache-2.0
def pairs_on_same_line? pairs.each_cons(2).any? { |first, second| first.same_line?(second) } end
Checks whether any of the key value pairs in the `hash` literal are on the same line. @note A multiline `pair` is considered to be on the same line if it shares any of its lines with another `pair` @note `kwsplat` nodes are ignored. @return [Boolean] whether any `pair` nodes are on the same line
pairs_on_same_line?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/hash_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/hash_node.rb
Apache-2.0
def if? keyword == 'if' end
Checks whether this node is an `if` statement. (This is not true of ternary operators and `unless` statements.) @return [Boolean] whether the node is an `if` statement
if?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/if_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/if_node.rb
Apache-2.0
def unless? keyword == 'unless' end
Checks whether this node is an `unless` statement. (This is not true of ternary operators and `if` statements.) @return [Boolean] whether the node is an `unless` statement
unless?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/if_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/if_node.rb
Apache-2.0
def elsif? keyword == 'elsif' end
Checks whether the `if` is an `elsif`. Parser handles these by nesting `if` nodes in the `else` branch. @return [Boolean] whether the node is an `elsif`
elsif?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/if_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/if_node.rb
Apache-2.0
def else? loc.respond_to?(:else) && loc.else end
Checks whether the `if` node has an `else` clause. @note This returns `true` for nodes containing an `elsif` clause. This is legacy behavior, and many cops rely on it. @return [Boolean] whether the node has an `else` clause
else?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/if_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/if_node.rb
Apache-2.0
def keyword ternary? ? '' : loc.keyword.source end
Returns the keyword of the `if` statement as a string. Returns an empty string for ternary operators. @return [String] the keyword of the `if` statement
keyword
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/if_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/if_node.rb
Apache-2.0
def inverse_keyword case keyword when 'if' then 'unless' when 'unless' then 'if' else '' end end
Returns the inverse keyword of the `if` node as a string. Returns `if` for `unless` nodes and vice versa. Returns an empty string for ternary operators. @return [String] the inverse keyword of the `if` statement
inverse_keyword
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/if_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/if_node.rb
Apache-2.0
def modifier_form? (if? || unless?) && super end
Checks whether the `if` node is in a modifier form, i.e. a condition trailing behind an expression. Only `if` and `unless` nodes without other branches can be modifiers. @return [Boolean] whether the `if` node is a modifier
modifier_form?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/if_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/if_node.rb
Apache-2.0
def nested_conditional? node_parts[1..2].compact.each do |branch| branch.each_node(:if) do |nested| return true unless nested.elsif? end end false end
Chacks whether the `if` node has nested `if` nodes in any of its branches. @note This performs a shallow search. @return [Boolean] whether the `if` node contains nested conditionals
nested_conditional?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/if_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/if_node.rb
Apache-2.0
def elsif_conditional? else_branch&.if_type? && else_branch&.elsif? end
Checks whether the `if` node has at least one `elsif` branch. Returns true if this `if` node itself is an `elsif`. @return [Boolean] whether the `if` node has at least one `elsif` branch
elsif_conditional?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/if_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/if_node.rb
Apache-2.0
def node_parts if unless? condition, false_branch, true_branch = *self else condition, true_branch, false_branch = *self end [condition, true_branch, false_branch] end
Custom destructuring method. This is used to normalize the branches for `if` and `unless` nodes, to aid comparisons and conversions. @return [Array<Node>] the different parts of the `if` statement
node_parts
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/if_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/if_node.rb
Apache-2.0
def branches if ternary? [if_branch, else_branch] elsif !else? [if_branch] else branches = [if_branch] other_branches = if elsif_conditional? else_branch.branches else [else_branch] end branches.concat(other_branches) end end
Returns an array of all the branches in the conditional statement. @return [Array<Node>] an array of branch nodes
branches
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/if_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/if_node.rb
Apache-2.0
def node_parts [self, self] end
Custom destructuring method. This is used to normalize the branches for `pair` and `kwsplat` nodes, to add duck typing to `hash` elements. @return [Array<KeywordSplatNode>] the different parts of the `kwsplat`
node_parts
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/keyword_splat_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/keyword_splat_node.rb
Apache-2.0
def alternate_operator logical_operator? ? SEMANTIC_OR : LOGICAL_OR end
Returns the alternate operator of the `or` as a string. Returns `or` for `||` and vice versa. @return [String] the alternate of the `or` operator
alternate_operator
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/or_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/or_node.rb
Apache-2.0
def inverse_operator logical_operator? ? LOGICAL_AND : SEMANTIC_AND end
Returns the inverse keyword of the `or` node as a string. Returns `and` for `or` and `&&` for `||`. @return [String] the inverse of the `or` operator
inverse_operator
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/or_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/or_node.rb
Apache-2.0
def value_on_new_line? key.loc.line != value.loc.line end
Checks whether the value starts on its own line. @return [Boolean] whether the value in the `pair` starts its own line
value_on_new_line?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/pair_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/pair_node.rb
Apache-2.0
def to_regexp Regexp.new(content, options) end
@return [Regexp] a regexp of this node
to_regexp
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/regexp_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/regexp_node.rb
Apache-2.0
def options regopt.children.map { |opt| OPTIONS.fetch(opt) }.inject(0, :|) end
NOTE: The 'o' option is ignored. @return [Integer] the Regexp option bits as returned by Regexp#options
options
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/regexp_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/regexp_node.rb
Apache-2.0
def slash_literal? loc.begin.source == '/' end
@return [Bool] if the regexp is a /.../ literal
slash_literal?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/regexp_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/regexp_node.rb
Apache-2.0
def exceptions exceptions_node = node_parts[0] if exceptions_node.nil? [] elsif exceptions_node.array_type? exceptions_node.values else [exceptions_node] end end
Returns an array of all the exceptions in the `rescue` clause. @return [Array<Node>] an array of exception nodes
exceptions
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/resbody_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/resbody_node.rb
Apache-2.0
def branches bodies = resbody_branches.map(&:body) bodies.push(else_branch) if else? bodies end
Returns an array of all the rescue branches in the exception handling statement. @return [Array<Node, nil>] an array of the bodies of the rescue branches and the else (if any). Note that these bodies could be nil.
branches
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/rescue_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/rescue_node.rb
Apache-2.0
def node_parts [nil, :super, *to_a] end
Custom destructuring method. This can be used to normalize destructuring for different variations of the node. @return [Array] the different parts of the `super` node
node_parts
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/super_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/super_node.rb
Apache-2.0
def node_parts [nil, :yield, *to_a] end
Custom destructuring method. This can be used to normalize destructuring for different variations of the node. @return [Array] the different parts of the `send` node
node_parts
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/yield_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/yield_node.rb
Apache-2.0
def conditions lhs, rhs = *self lhs = lhs.children.first if lhs.begin_type? rhs = rhs.children.first if rhs.begin_type? [lhs, rhs].each_with_object([]) do |side, collection| if side.operator_keyword? collection.concat(side.conditions) else collection << side end end end
Returns all of the conditions, including nested conditions, of the binary operation. @return [Array<Node>] the left and right hand side of the binary operation and the let and right hand side of any nested binary operators
conditions
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/binary_operator_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/binary_operator_node.rb
Apache-2.0
def single_line_condition? loc.keyword.line == condition.source_range.line end
Checks whether the condition of the node is written on a single line. @return [Boolean] whether the condition is on a single line
single_line_condition?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/conditional_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/conditional_node.rb
Apache-2.0
def each_child_node(*types) return to_enum(__method__, *types) unless block_given? children.each do |child| next unless child.is_a?(::AST::Node) yield child if types.empty? || types.include?(child.type) end self end
Calls the given block for each child node. If no block is given, an `Enumerator` is returned. Note that this is different from `node.children.each { |child| ... }` which yields all children including non-node elements. @overload each_child_node Yield all nodes. @overload each_child_node(type, ...) Yield only nodes matching any of the types. @param [Symbol] type a node type @yieldparam [Node] node each child node @return [self] if a block is given @return [Enumerator] if no block is given
each_child_node
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/descendence.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/descendence.rb
Apache-2.0
def child_nodes # Iterate child nodes directly to avoid allocating an Enumerator. nodes = [] each_child_node { |node| nodes << node } nodes end
Returns an array of child nodes. This is a shorthand for `node.each_child_node.to_a`. @return [Array<Node>] an array of child nodes
child_nodes
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/descendence.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/descendence.rb
Apache-2.0
def each_descendant(*types, &block) return to_enum(__method__, *types) unless block visit_descendants(types, &block) self end
Calls the given block for each descendant node with depth first order. If no block is given, an `Enumerator` is returned. @overload each_descendant Yield all nodes. @overload each_descendant(type) Yield only nodes matching the type. @param [Symbol] type a node type @overload each_descendant(type_a, type_b, ...) Yield only nodes matching any of the types. @param [Symbol] type_a a node type @param [Symbol] type_b a node type @yieldparam [Node] node each descendant node @return [self] if a block is given @return [Enumerator] if no block is given
each_descendant
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/descendence.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/descendence.rb
Apache-2.0
def each_node(*types, &block) return to_enum(__method__, *types) unless block yield self if types.empty? || types.include?(type) visit_descendants(types, &block) self end
Calls the given block for the receiver and each descendant node in depth-first order. If no block is given, an `Enumerator` is returned. This method would be useful when you treat the receiver node as the root of a tree and want to iterate over all nodes in the tree. @overload each_node Yield all nodes. @overload each_node(type) Yield only nodes matching the type. @param [Symbol] type a node type @overload each_node(type_a, type_b, ...) Yield only nodes matching any of the types. @param [Symbol] type_a a node type @param [Symbol] type_b a node type @yieldparam [Node] node each node @return [self] if a block is given @return [Enumerator] if no block is given
each_node
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/descendence.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/descendence.rb
Apache-2.0
def same_line?(other) loc.last_line == other.loc.line || loc.line == other.loc.last_line end
Checks whether this `hash` element is on the same line as `other`. @note A multiline element is considered to be on the same line if it shares any of its lines with `other` @return [Boolean] whether this element is on the same line as `other`
same_line?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/hash_element_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/hash_element_node.rb
Apache-2.0
def key_delta(other, alignment = :left) HashElementDelta.new(self, other).key_delta(alignment) end
Returns the delta between this pair's key and the argument pair's. @note Keys on the same line always return a delta of 0 @note Keyword splats always return a delta of 0 for right alignment @param [Symbol] alignment whether to check the left or right side @return [Integer] the delta between the two keys
key_delta
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/hash_element_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/hash_element_node.rb
Apache-2.0
def value_delta(other) HashElementDelta.new(self, other).value_delta end
Returns the delta between this element's value and the argument's. @note Keyword splats always return a delta of 0 @return [Integer] the delta between the two values
value_delta
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/hash_element_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/hash_element_node.rb
Apache-2.0
def block_node parent if block_literal? end
The `block` or `numblock` node associated with this method dispatch, if any. @return [BlockNode, nil] the `block` or `numblock` node associated with this method call or `nil`
block_node
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
Apache-2.0
def macro? !receiver && in_macro_scope? end
Checks whether the dispatched method is a macro method. A macro method is defined as a method that sits in a class, module, or block body and has an implicit receiver. @note This does not include DSLs that use nested blocks, like RSpec @return [Boolean] whether the dispatched method is a macro method
macro?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
Apache-2.0
def access_modifier? bare_access_modifier? || non_bare_access_modifier? end
Checks whether the dispatched method is an access modifier. @return [Boolean] whether the dispatched method is an access modifier
access_modifier?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
Apache-2.0
def bare_access_modifier? macro? && bare_access_modifier_declaration? end
Checks whether the dispatched method is a bare access modifier that affects all methods defined after the macro. @return [Boolean] whether the dispatched method is a bare access modifier
bare_access_modifier?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
Apache-2.0
def non_bare_access_modifier? macro? && non_bare_access_modifier_declaration? end
Checks whether the dispatched method is a non-bare access modifier that affects only the method it receives. @return [Boolean] whether the dispatched method is a non-bare access modifier
non_bare_access_modifier?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
Apache-2.0
def special_modifier? bare_access_modifier? && SPECIAL_MODIFIERS.include?(source) end
Checks whether the dispatched method is a bare `private` or `protected` access modifier that affects all methods defined after the macro. @return [Boolean] whether the dispatched method is a bare `private` or `protected` access modifier
special_modifier?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
Apache-2.0
def command?(name) !receiver && method?(name) end
Checks whether the name of the dispatched method matches the argument and has an implicit receiver. @param [Symbol, String] name the method name to check for @return [Boolean] whether the method name matches the argument
command?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
Apache-2.0
def setter_method? loc.respond_to?(:operator) && loc.operator end
Checks whether the dispatched method is a setter method. @return [Boolean] whether the dispatched method is a setter
setter_method?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
Apache-2.0
def dot? loc.respond_to?(:dot) && loc.dot && loc.dot.is?('.') end
Checks whether the dispatched method uses a dot to connect the receiver and the method name. This is useful for comparison operators, which can be called either with or without a dot, i.e. `foo == bar` or `foo.== bar`. @return [Boolean] whether the method was called with a connecting dot
dot?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
Apache-2.0
def double_colon? loc.respond_to?(:dot) && loc.dot && loc.dot.is?('::') end
Checks whether the dispatched method uses a double colon to connect the receiver and the method name. @return [Boolean] whether the method was called with a connecting dot
double_colon?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
Apache-2.0
def safe_navigation? loc.respond_to?(:dot) && loc.dot && loc.dot.is?('&.') end
Checks whether the dispatched method uses a safe navigation operator to connect the receiver and the method name. @return [Boolean] whether the method was called with a connecting dot
safe_navigation?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
Apache-2.0
def implicit_call? method?(:call) && !loc.selector end
Checks whether the method dispatch is the implicit form of `#call`, e.g. `foo.(bar)`. @return [Boolean] whether the method is the implicit form of `#call`
implicit_call?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
Apache-2.0
def block_literal? (parent&.block_type? || parent&.numblock_type?) && eql?(parent.send_node) end
Whether this method dispatch has an explicit block. @return [Boolean] whether the dispatched method has a block
block_literal?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
Apache-2.0
def def_modifier(node = self) arg = node.children[2] return unless node.send_type? && node.receiver.nil? && arg.is_a?(::AST::Node) return arg if arg.def_type? || arg.defs_type? def_modifier(arg) end
Checks if this node is part of a chain of `def` or `defs` modifiers. @example private def foo; end @return [Node | nil] returns the `def|defs` node this is a modifier for, or `nil` if it isn't a def modifier
def_modifier
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
Apache-2.0
def lambda? block_literal? && command?(:lambda) end
Checks whether this is a lambda. Some versions of parser parses non-literal lambdas as a method send. @return [Boolean] whether this method is a lambda
lambda?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
Apache-2.0
def lambda_literal? loc.expression.source == '->' && block_literal? end
Checks whether this is a lambda literal (stabby lambda.) @example -> (foo) { bar } @return [Boolean] whether this method is a lambda literal
lambda_literal?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
Apache-2.0
def unary_operation? return false unless loc.selector operator_method? && loc.expression.begin_pos == loc.selector.begin_pos end
Checks whether this is a unary operation. @example -foo @return [Boolean] whether this method is a unary operation
unary_operation?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
Apache-2.0
def binary_operation? return false unless loc.selector operator_method? && loc.expression.begin_pos != loc.selector.begin_pos end
Checks whether this is a binary operation. @example foo + bar @return [Boolean] whether this method is a binary operation
binary_operation?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_dispatch_node.rb
Apache-2.0
def method?(name) method_name == name.to_sym end
Checks whether the method name matches the argument. @param [Symbol, String] name the method name to check for @return [Boolean] whether the method name matches the argument
method?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb
Apache-2.0
def assignment_method? !comparison_method? && method_name.to_s.end_with?('=') end
Checks whether the method is an assignment method. @return [Boolean] whether the method is an assignment
assignment_method?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb
Apache-2.0
def enumerator_method? ENUMERATOR_METHODS.include?(method_name) || method_name.to_s.start_with?('each_') end
Checks whether the method is an enumerator method. @return [Boolean] whether the method is an enumerator
enumerator_method?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb
Apache-2.0
def camel_case_method? method_name.to_s =~ /\A[A-Z]/ end
Checks whether the method is a camel case method, e.g. `Integer()`. @return [Boolean] whether the method is a camel case method
camel_case_method?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb
Apache-2.0
def negation_method? receiver && method_name == :! end
Checks whether this is a negation method, i.e. `!` or keyword `not`. @return [Boolean] whether this method is a negation method
negation_method?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb
Apache-2.0
def prefix_not? negation_method? && loc.selector.is?('not') end
Checks whether this is a prefix not method, e.g. `not foo`. @return [Boolean] whether this method is a prefix not
prefix_not?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb
Apache-2.0
def prefix_bang? negation_method? && loc.selector.is?('!') end
Checks whether this is a prefix bang method, e.g. `!foo`. @return [Boolean] whether this method is a prefix bang
prefix_bang?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb
Apache-2.0
def splat_argument? arguments? && (arguments.any?(&:splat_type?) || arguments.any?(&:restarg_type?)) end
Checks whether any argument of the node is a splat argument, i.e. `*splat`. @return [Boolean] whether the node is a splat argument
splat_argument?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/parameterized_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/parameterized_node.rb
Apache-2.0
def block_argument? arguments? && (last_argument.block_pass_type? || last_argument.blockarg_type?) end
Whether the last argument of the node is a block pass, i.e. `&block`. @return [Boolean] whether the last argument of the node is a block pass
block_argument?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/parameterized_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/parameterized_node.rb
Apache-2.0
def arguments first = children.first if first&.begin_type? first.children else children end end
@return [Array] The arguments of the node.
arguments
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/parameterized_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/parameterized_node.rb
Apache-2.0
def arguments if arguments? children.drop(first_argument_index).freeze else # Skip unneeded Array allocation. EMPTY_ARGUMENTS end end
@return [Array<Node>] arguments, if any
arguments
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/parameterized_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/parameterized_node.rb
Apache-2.0
def last_argument children[-1] if arguments? end
A shorthand for getting the last argument of the node. Equivalent to `arguments.last`. @return [Node, nil] the last argument of the node, or `nil` if there are no arguments
last_argument
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/parameterized_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/parameterized_node.rb
Apache-2.0
def arguments? children.size > first_argument_index end
Checks whether this node has any arguments. @return [Boolean] whether this node has any arguments
arguments?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/parameterized_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/parameterized_node.rb
Apache-2.0
def logical_operator? operator == LOGICAL_AND || operator == LOGICAL_OR end
Checks whether this is a logical operator. @return [Boolean] whether this is a logical operator
logical_operator?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/predicate_operator_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/predicate_operator_node.rb
Apache-2.0
def semantic_operator? operator == SEMANTIC_AND || operator == SEMANTIC_OR end
Checks whether this is a semantic operator. @return [Boolean] whether this is a semantic operator
semantic_operator?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/predicate_operator_node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node/mixin/predicate_operator_node.rb
Apache-2.0
def inspect "#<NodePattern::Comment #{@location.expression} #{text.inspect}>" end
# @return [String] a human-readable representation of this comment
inspect
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/comment.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/comment.rb
Apache-2.0
def each_union(enum, &block) enforce_same_captures(binding.union_bind(enum), &block) end
Enumerates `enum` while keeping track of state across union branches (captures and unification).
each_union
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/compiler.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/compiler.rb
Apache-2.0
def matches m = (1..9).map { |i| ss[i] } m.pop until m[-1] or m.empty? m end
# The match groups for the current scan.
matches
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/lexer.rex.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/lexer.rex.rb
Apache-2.0
def parse_file path self.filename = path open path do |f| parse f.read end end
# Read in and parse the file at +path+.
parse_file
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/lexer.rex.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/lexer.rex.rb
Apache-2.0
def location [ (filename || "<input>"), ].compact.join(":") end
# The current location in the parse.
location
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/lexer.rex.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/lexer.rex.rb
Apache-2.0
def wrapping_block(method_name, **defaults) proc do |*args, **values| send method_name, *args, **defaults, **values end end
This method minimizes the closure for our method
wrapping_block
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/method_definer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/method_definer.rb
Apache-2.0
def parse(source) @lexer = self.class::Lexer.new(source) do_parse rescue Lexer::Error => e raise NodePattern::Invalid, e.message ensure @lexer = nil # Don't keep references end
# (Similar API to `parser` gem) Parses a source and returns the AST. @param [Parser::Source::Buffer, String] source_buffer The source buffer to parse. @return [NodePattern::Node]
parse
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/parser.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/parser.rb
Apache-2.0
def pos ::Parser::Source::Range.new(source_buffer, ss.pos - ss.matched_size, ss.pos) end
@return [::Parser::Source::Range] last match's position
pos
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/with_meta.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/with_meta.rb
Apache-2.0
def visit_other_type compiler.with_temp_variables do |compare| code = compiler.compile_as_node_pattern(node, var: compare) "->(#{compare}) { #{code} }" end end
Assumes other types are node patterns.
visit_other_type
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/compiler/atom_subcompiler.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/compiler/atom_subcompiler.rb
Apache-2.0
def bind(name) var = @bound.fetch(name) do yield n = @bound[name] = "unify_#{name.gsub('-', '__')}" n end if var == :forbidden_unification raise Invalid, "Wildcard #{name} was first seen in a subset of a " \ "union and can't be used outside that union" end var end
Yields the first time a given name is bound @return [String] bound variable name
bind
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/compiler/binding.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/compiler/binding.rb
Apache-2.0
def union_bind(enum) # We need to reset @bound before each branch is processed. # Moreover we need to keep track of newly encountered wildcards. # Var `newly_bound_intersection` will hold those that are encountered # in all branches; these are not a problem. # Var `partially_bound` will hold those encountered in only a subset # of the branches; these can't be used outside of the union. return to_enum __method__, enum unless block_given? newly_bound_intersection = nil partially_bound = [] bound_before = @bound.dup result = enum.each do |e| @bound = bound_before.dup if newly_bound_intersection yield e newly_bound = @bound.keys - bound_before.keys if newly_bound_intersection.nil? # First iteration newly_bound_intersection = newly_bound else union = newly_bound_intersection | newly_bound newly_bound_intersection &= newly_bound partially_bound |= union - newly_bound_intersection end end # At this point, all members of `newly_bound_intersection` can be used # for unification outside of the union, but partially_bound may not forbid(partially_bound) result end
rubocop:disable Metrics/MethodLength, Metrics/AbcSize
union_bind
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/compiler/binding.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/compiler/binding.rb
Apache-2.0
def colorize(color_scheme = COLOR_SCHEME) map = color_map(color_scheme) ast.source_range.source_buffer.source.chars.map.with_index do |char, i| Rainbow(char).color(map[i]) end.join end
@return [String] a Rainbow colorized version of ruby
colorize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/compiler/debug.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/compiler/debug.rb
Apache-2.0
def match_map @match_map ||= ast .each_node .to_h { |node| [node, matched?(node)] } end
@return [Hash] a map for {node => matched?}, depth-first
match_map
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/compiler/debug.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/compiler/debug.rb
Apache-2.0
def matched?(node) id = colorizer.compiler.node_ids.fetch(node) { return :not_visitable } trace.matched?(id) end
@return a value of `Trace#matched?` or `:not_visitable`
matched?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/compiler/debug.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/compiler/debug.rb
Apache-2.0
def compile_args(arg_list, first: nil) args = arg_list&.map { |arg| compiler.compile_as_atom(arg) } args = [first, *args] if first "(#{args.join(', ')})" if args end
@param [Array<Node>, nil] @return [String, nil]
compile_args
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/compiler/node_pattern_subcompiler.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/compiler/node_pattern_subcompiler.rb
Apache-2.0
def initialize(compiler, sequence:, var:) @seq = sequence # The node to be compiled @seq_var = var # Holds the name of the variable holding the AST::Node we are matching super(compiler) end
Calls `compile_sequence`; the actual `compile` method will be used for the different terms of the sequence. The only case of re-entrant call to `compile` is `visit_capture`
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/compiler/sequence_subcompiler.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/compiler/sequence_subcompiler.rb
Apache-2.0
def visit_other_type access = case @cur_index when :seq_head { var: @seq_var, seq_head: true } when :variadic_mode { var: @cur_child_var } else idx = @cur_index + (@cur_index.negative? ? DELTA : 0) { access: "#{@seq_var}.children[#{idx}]" } end term = compiler.compile_as_node_pattern(node, **access) compile_and_advance(term) end
Single node patterns are all handled here
visit_other_type
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/compiler/sequence_subcompiler.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/compiler/sequence_subcompiler.rb
Apache-2.0
def compile_any_order_else rest = node.rest_node if !rest 'false' elsif rest.capture? capture_rest = compiler.next_capture init = "#{capture_rest} = [];" ["#{capture_rest} << #{@cur_child_var}", init] else 'true' end end
@return [Array<String>] Else code, and init code (if any)
compile_any_order_else
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/compiler/sequence_subcompiler.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/compiler/sequence_subcompiler.rb
Apache-2.0
def sync return if @in_sync code = compile_loop_advance("= #{compile_cur_index}") @in_sync = true yield code end
yield `sync_code` iff not already in sync
sync
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/compiler/sequence_subcompiler.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/compiler/sequence_subcompiler.rb
Apache-2.0
def remaining_arities(children, last_arity) last = last_arity arities = children .reverse .map(&:arity_range) .map { |r| last = last.begin + r.begin..last.max + r.max } .reverse! arities.push last_arity end
@return [Array<Range>] total arities (as Ranges) of remaining children nodes E.g. For sequence `(_ _? <_ _>)`, arities are: 1, 0..1, 2 and remaining arities are: 3..4, 2..3, 2..2, 0..0
remaining_arities
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/compiler/sequence_subcompiler.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/compiler/sequence_subcompiler.rb
Apache-2.0
def compile_min_check return 'false' unless node.variadic? unless @remaining_arity.end.infinite? not_too_much_remaining = "#{compile_remaining} <= #{@remaining_arity.max}" end min_to_match = node.arity_range.begin if min_to_match.positive? enough_matched = "#{compile_matched(:length)} >= #{min_to_match}" end return 'true' unless not_too_much_remaining || enough_matched [not_too_much_remaining, enough_matched].compact.join(' && ') end
@return [String] code that evaluates to `false` if the matched arity is too small
compile_min_check
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/compiler/sequence_subcompiler.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rubocop-ast-1.28.1/lib/rubocop/ast/node_pattern/compiler/sequence_subcompiler.rb
Apache-2.0