Skip to content

Commit

Permalink
Merge pull request rubocop#1916 from jonas054/reduce_abc_size
Browse files Browse the repository at this point in the history
Reduce ABC size
  • Loading branch information
bbatsov committed May 23, 2015
2 parents 6fbcb28 + 7f7b61b commit 34f4a64
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 30 deletions.
12 changes: 6 additions & 6 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
# This configuration was generated by `rubocop --auto-gen-config`
# on 2015-05-17 17:49:50 +0200 using RuboCop version 0.31.0.
# on 2015-05-23 07:26:48 +0200 using RuboCop version 0.31.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: 159
# Offense count: 160
Metrics/AbcSize:
Max: 38
Max: 32

# Offense count: 13
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 141

# Offense count: 43
# Offense count: 42
Metrics/CyclomaticComplexity:
Max: 10

# Offense count: 159
# Offense count: 160
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 19
Max: 18

# Offense count: 7
# Configuration parameters: CountComments.
Expand Down
10 changes: 10 additions & 0 deletions lib/rubocop/cop/mixin/if_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ def elsif?(node)
def if_else?(node)
node.loc.respond_to?(:else) && node.loc.else
end

def if_node_parts(node)
case node.loc.keyword.source
when 'if', 'elsif' then condition, body, else_clause = *node
when 'unless' then condition, else_clause, body = *node
else condition, body = *node
end

[condition, body, else_clause]
end
end
end
end
6 changes: 1 addition & 5 deletions lib/rubocop/cop/mixin/statement_modifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ module StatementModifier
include IfNode

def fit_within_line_as_modifier_form?(node)
case node.loc.keyword.source
when 'if' then cond, body, _else = *node
when 'unless' then cond, _else, body = *node
else cond, body = *node
end
cond, body, _else = if_node_parts(node)

return false if length(node) > 3
return false if body && body.begin_type? # multiple statements
Expand Down
6 changes: 1 addition & 5 deletions lib/rubocop/cop/style/if_unless_modifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ def on_if(node)
end

def autocorrect(node)
if node.loc.keyword.is?('if')
cond, body = *node
else
cond, _else, body = *node
end
cond, body, _else = if_node_parts(node)

oneline =
"#{body.loc.expression.source} #{node.loc.keyword.source} " +
Expand Down
6 changes: 1 addition & 5 deletions lib/rubocop/cop/style/indentation_width.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,7 @@ def on_if(node, base = node)
return if ternary_op?(node)
return if modifier_if?(node)

case node.loc.keyword.source
when 'if', 'elsif' then _condition, body, else_clause = *node
when 'unless' then _condition, else_clause, body = *node
else _condition, body = *node
end
_condition, body, else_clause = if_node_parts(node)

check_if(node, body, else_clause, base.loc) if body
end
Expand Down
20 changes: 11 additions & 9 deletions lib/rubocop/cop/style/multiline_operation_indentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,17 @@ def right_hand_side(send_node)
_, method_name, *args = *send_node
if operator?(method_name) && args.any?
args.first.loc.expression
elsif send_node.loc.dot &&
send_node.loc.selector &&
send_node.loc.dot.line == send_node.loc.selector.line
send_node.loc.dot.join(send_node.loc.selector)
elsif send_node.loc.selector
send_node.loc.selector
elsif send_node.loc.dot.line == send_node.loc.begin.line
# lambda.(args)
send_node.loc.dot.join(send_node.loc.begin)
else
dot = send_node.loc.dot
selector = send_node.loc.selector
if dot && selector && dot.line == selector.line
dot.join(selector)
elsif selector
selector
elsif dot.line == send_node.loc.begin.line
# lambda.(args)
dot.join(send_node.loc.begin)
end
end
end

Expand Down
8 changes: 8 additions & 0 deletions lib/rubocop/cop/style/trailing_blank_lines.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ def investigate(processed_source)

return unless blank_lines != wanted_blank_lines

offense_detected(sb, wanted_blank_lines, blank_lines,
whitespace_at_end)
end

private

def offense_detected(sb, wanted_blank_lines, blank_lines,
whitespace_at_end)
begin_pos = sb.source.length - whitespace_at_end.length
autocorrect_range = Parser::Source::Range.new(sb, begin_pos,
sb.source.length)
Expand Down

0 comments on commit 34f4a64

Please sign in to comment.