Skip to content

Commit

Permalink
[Refactor] Move common logic from on_percent_literal to caller
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas054 committed Jul 12, 2014
1 parent 8330aa3 commit 6bf924a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
3 changes: 2 additions & 1 deletion lib/rubocop/cop/mixin/percent_literal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ def percent_literal?(node)
end

def process(node, *types)
on_percent_literal(node, types) if percent_literal?(node)
return unless percent_literal?(node) && types.include?(type(node))
on_percent_literal(node)
end

def begin_source(node)
Expand Down
7 changes: 3 additions & 4 deletions lib/rubocop/cop/style/percent_literal_delimiters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,10 @@ def autocorrect(node)
end
end

def on_percent_literal(node, types)
def on_percent_literal(node)
type = type(node)
return unless types.include?(type) &&
!uses_preferred_delimiter?(node, type) &&
!contains_preferred_delimiter?(node, type)
return if uses_preferred_delimiter?(node, type) ||
contains_preferred_delimiter?(node, type)

add_offense(node, :expression)
end
Expand Down
3 changes: 1 addition & 2 deletions lib/rubocop/cop/style/percent_q_literals.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ def on_str(node)

private

def on_percent_literal(node, types)
return unless types.include?(type(node))
def on_percent_literal(node)
if style == :lower_case_q
if type(node) == '%Q'
check(node,
Expand Down
6 changes: 2 additions & 4 deletions lib/rubocop/cop/style/unneeded_capital_w.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ def on_array(node)

private

def on_percent_literal(node, types)
type = type(node)
return unless types.include?(type) &&
node.children.none? { |x| x.type == :dstr }
def on_percent_literal(node)
return unless node.children.none? { |x| x.type == :dstr }

add_offense(node, :expression)
end
Expand Down

0 comments on commit 6bf924a

Please sign in to comment.