fix a few more rubocop offenses

This commit is contained in:
Florian Weingarten
2015-06-04 13:09:58 -04:00
parent b347fac3c0
commit 82269e2509
10 changed files with 31 additions and 37 deletions
+8
View File
@@ -5,6 +5,11 @@ AllCops:
- 'performance/shopify/*' - 'performance/shopify/*'
- 'pkg/**' - 'pkg/**'
Metrics/BlockNesting:
Max: 3
Exclude:
- 'lib/liquid/block_body.rb'
Lint/AssignmentInCondition: Lint/AssignmentInCondition:
Enabled: false Enabled: false
@@ -26,6 +31,9 @@ Lint/EndAlignment:
Style/SingleLineBlockParams: Style/SingleLineBlockParams:
Enabled: false Enabled: false
Style/DoubleNegation:
Enabled: false
Style/StringLiteralsInInterpolation: Style/StringLiteralsInInterpolation:
Enabled: false Enabled: false
+12 -21
View File
@@ -1,5 +1,5 @@
# This configuration was generated by `rubocop --auto-gen-config` # This configuration was generated by `rubocop --auto-gen-config`
# on 2015-06-04 12:55:39 -0400 using RuboCop version 0.31.0. # on 2015-06-04 13:07:29 -0400 using RuboCop version 0.31.0.
# The point is for the user to remove these configuration records # The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base. # one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new # Note that changes in the inspected code, or installation of new
@@ -10,22 +10,10 @@
Lint/UnusedMethodArgument: Lint/UnusedMethodArgument:
Enabled: false Enabled: false
# Offense count: 1
Lint/UselessAccessModifier:
Enabled: false
# Offense count: 6
Lint/UselessAssignment:
Enabled: false
# Offense count: 51 # Offense count: 51
Metrics/AbcSize: Metrics/AbcSize:
Max: 58 Max: 58
# Offense count: 2
Metrics/BlockNesting:
Max: 6
# Offense count: 16 # Offense count: 16
# Configuration parameters: CountComments. # Configuration parameters: CountComments.
Metrics/ClassLength: Metrics/ClassLength:
@@ -48,7 +36,7 @@ Metrics/MethodLength:
# Offense count: 1 # Offense count: 1
# Configuration parameters: CountComments. # Configuration parameters: CountComments.
Metrics/ModuleLength: Metrics/ModuleLength:
Max: 235 Max: 234
# Offense count: 6 # Offense count: 6
Metrics/PerceivedComplexity: Metrics/PerceivedComplexity:
@@ -58,8 +46,9 @@ Metrics/PerceivedComplexity:
Style/AccessorMethodName: Style/AccessorMethodName:
Enabled: false Enabled: false
# Offense count: 2 # Offense count: 1
Style/DoubleNegation: # Cop supports --auto-correct.
Style/ClosingParenthesisIndentation:
Enabled: false Enabled: false
# Offense count: 3 # Offense count: 3
@@ -76,7 +65,7 @@ Style/MethodName:
Style/MultilineBlockChain: Style/MultilineBlockChain:
Enabled: false Enabled: false
# Offense count: 3 # Offense count: 2
# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles. # Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles.
Style/Next: Style/Next:
Enabled: false Enabled: false
@@ -86,12 +75,14 @@ Style/Next:
Style/PredicateName: Style/PredicateName:
Enabled: false Enabled: false
# Offense count: 1
Style/RescueModifier:
Enabled: false
# Offense count: 7 # Offense count: 7
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: AllowAsExpressionSeparator. # Configuration parameters: AllowAsExpressionSeparator.
Style/Semicolon: Style/Semicolon:
Enabled: false Enabled: false
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: MaxLineLength.
Style/WhileUntilModifier:
Enabled: false
+1 -1
View File
@@ -7,7 +7,7 @@ module Liquid
def parse(tokens) def parse(tokens)
@body = BlockBody.new @body = BlockBody.new
while more = parse_body(@body, tokens) while parse_body(@body, tokens)
end end
end end
-2
View File
@@ -57,8 +57,6 @@ module Liquid
alias_method :[], :invoke_drop alias_method :[], :invoke_drop
private
# Check for method existence without invoking respond_to?, which creates symbols # Check for method existence without invoking respond_to?, which creates symbols
def self.invokable?(method_name) def self.invokable?(method_name)
invokable_methods.include?(method_name.to_s) invokable_methods.include?(method_name.to_s)
-1
View File
@@ -138,7 +138,6 @@ module Liquid
# Remove duplicate elements from an array # Remove duplicate elements from an array
# provide optional property with which to determine uniqueness # provide optional property with which to determine uniqueness
def uniq(input, property = nil) def uniq(input, property = nil)
ary = InputIterator.new(input)
if property.nil? if property.nil?
input.uniq input.uniq
elsif input.first.respond_to?(:[]) elsif input.first.respond_to?(:[])
+1 -1
View File
@@ -16,7 +16,7 @@ module Liquid
def parse(tokens) def parse(tokens)
body = BlockBody.new body = BlockBody.new
while more = parse_body(body, tokens) while parse_body(body, tokens)
body = @blocks.last.attachment body = @blocks.last.attachment
end end
end end
+5 -6
View File
@@ -41,11 +41,10 @@ module Liquid
if filter_markup =~ /#{FilterSeparator}\s*(.*)/om if filter_markup =~ /#{FilterSeparator}\s*(.*)/om
filters = $1.scan(FilterParser) filters = $1.scan(FilterParser)
filters.each do |f| filters.each do |f|
if f =~ /\w+/ next unless f =~ /\w+/
filtername = Regexp.last_match(0) filtername = Regexp.last_match(0)
filterargs = f.scan(/(?:#{FilterArgumentSeparator}|#{ArgumentSeparator})\s*((?:\w+\s*\:\s*)?#{QuotedFragment})/o).flatten filterargs = f.scan(/(?:#{FilterArgumentSeparator}|#{ArgumentSeparator})\s*((?:\w+\s*\:\s*)?#{QuotedFragment})/o).flatten
@filters << parse_filter_expressions(filtername, filterargs) @filters << parse_filter_expressions(filtername, filterargs)
end
end end
end end
end end
@@ -74,7 +73,7 @@ module Liquid
def render(context) def render(context)
@filters.inject(context.evaluate(@name)) do |output, (filter_name, filter_args, filter_kwargs)| @filters.inject(context.evaluate(@name)) do |output, (filter_name, filter_args, filter_kwargs)|
filter_args = evaluate_filter_expressions(context, filter_args, filter_kwargs) filter_args = evaluate_filter_expressions(context, filter_args, filter_kwargs)
output = context.invoke(filter_name, output, *filter_args) context.invoke(filter_name, output, *filter_args)
end.tap{ |obj| taint_check(obj) } end.tap{ |obj| taint_check(obj) }
end end
+1 -1
View File
@@ -1,4 +1,4 @@
require 'stackprof' rescue fail("install stackprof extension/gem") require 'stackprof'
require_relative 'theme_runner' require_relative 'theme_runner'
Liquid::Template.error_mode = ARGV.first.to_sym if ARGV.first Liquid::Template.error_mode = ARGV.first.to_sym if ARGV.first
+3 -3
View File
@@ -83,15 +83,15 @@ class ErrorHandlingTest < Minitest::Test
def test_with_line_numbers_adds_numbers_to_parser_errors def test_with_line_numbers_adds_numbers_to_parser_errors
err = assert_raises(SyntaxError) do err = assert_raises(SyntaxError) do
template = Liquid::Template.parse(%q( Liquid::Template.parse(%q(
foobar foobar
{% "cat" | foobar %} {% "cat" | foobar %}
bla bla
), ),
line_numbers: true line_numbers: true
) )
end end
assert_match /Liquid syntax error \(line 4\)/, err.message assert_match /Liquid syntax error \(line 4\)/, err.message
-1
View File
@@ -453,7 +453,6 @@ class ContextUnitTest < Minitest::Test
def test_use_empty_instead_of_any_in_interrupt_handling_to_avoid_lots_of_unnecessary_object_allocations def test_use_empty_instead_of_any_in_interrupt_handling_to_avoid_lots_of_unnecessary_object_allocations
mock_any = Spy.on_instance_method(Array, :any?) mock_any = Spy.on_instance_method(Array, :any?)
mock_empty = Spy.on_instance_method(Array, :empty?) mock_empty = Spy.on_instance_method(Array, :empty?)
mock_has_interrupt = Spy.on(@context, :has_interrupt?).and_call_through
@context.has_interrupt? @context.has_interrupt?