mirror of
https://github.com/usetrmnl/trmnl-liquid.git
synced 2026-04-29 13:43:18 -07:00
Fixed Reek issues
Added configuration, fixes issues where possible, and left code comments for addressing later when time allows. Milestone: patch
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
exclude_paths:
|
||||
- tmp
|
||||
- vendor
|
||||
|
||||
detectors:
|
||||
LongParameterList:
|
||||
enabled: false
|
||||
ManualDispatch:
|
||||
exclude:
|
||||
- TRMNL::Liquid::Filters
|
||||
UtilityFunction:
|
||||
exclude:
|
||||
- TRMNL::Liquid::Filters
|
||||
@@ -6,12 +6,14 @@ require "trmnl/liquid/memory_system"
|
||||
require "trmnl/liquid/template_tag"
|
||||
|
||||
module TRMNL
|
||||
# Main namespace.
|
||||
module Liquid
|
||||
def self.build_environment(...)
|
||||
warn "`#{self.class}##{__method__}` is deprecated, use `new` instead.", category: :deprecated
|
||||
new(...)
|
||||
end
|
||||
|
||||
# :reek:TooManyStatements
|
||||
def self.load key
|
||||
case key
|
||||
when :rails
|
||||
|
||||
@@ -6,6 +6,7 @@ module TRMNL
|
||||
module Fallback
|
||||
module_function
|
||||
|
||||
# :reek:TooManyStatements
|
||||
# rubocop:todo Metrics/MethodLength
|
||||
def number_with_delimiter number, delimiter, separator
|
||||
value = number.to_s
|
||||
@@ -42,6 +43,7 @@ module TRMNL
|
||||
end
|
||||
# rubocop:enable Metrics/ParameterLists
|
||||
|
||||
# :reek:TooManyStatements
|
||||
def ordinalize number
|
||||
return "#{number}th" if (11..13).cover? number % 100
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ module TRMNL
|
||||
|
||||
def group_by(collection, key) = collection.group_by { it[key] }
|
||||
|
||||
# :reek:ControlParameter
|
||||
# rubocop:todo Metrics/ParameterLists
|
||||
def find_by collection, key, value, fallback = nil
|
||||
collection.find { |obj| obj[key] == value } || fallback
|
||||
@@ -43,6 +44,7 @@ module TRMNL
|
||||
end
|
||||
end
|
||||
|
||||
# :reek:TooManyStatements
|
||||
# rubocop:todo Metrics/ParameterLists
|
||||
def number_to_currency number,
|
||||
unit_or_locale = "$",
|
||||
@@ -76,6 +78,7 @@ module TRMNL
|
||||
|
||||
def map_to_i(collection) = collection.map(&:to_i)
|
||||
|
||||
# :reek:FeatureEnvy
|
||||
# rubocop:todo Style/OptionHash
|
||||
def pluralize singular, count, options = {}
|
||||
plural = options["plural"]
|
||||
@@ -95,6 +98,7 @@ module TRMNL
|
||||
|
||||
def sample(array) = array.sample
|
||||
|
||||
# :reek:TooManyStatements
|
||||
# source: https://github.com/jekyll/jekyll/blob/40ac06ed3e95325a07868dd2ac419e409af823b6/lib/jekyll/filters.rb#L209
|
||||
def where_exp input, variable, expression
|
||||
return input unless input.respond_to? :select
|
||||
@@ -112,12 +116,8 @@ module TRMNL
|
||||
|
||||
def ordinalize date_str, strftime_exp
|
||||
date = Date.parse date_str
|
||||
|
||||
ordinal_day = if date.day.respond_to? :ordinalize
|
||||
date.day.ordinalize
|
||||
else
|
||||
Fallback.ordinalize date.day
|
||||
end
|
||||
day = date.day
|
||||
ordinal_day = day.respond_to?(:ordinalize) ? day.ordinalize : Fallback.ordinalize(day)
|
||||
|
||||
date.strftime strftime_exp.gsub("<<ordinal_day>>", ordinal_day)
|
||||
end
|
||||
@@ -168,6 +168,8 @@ module TRMNL
|
||||
condition
|
||||
end
|
||||
|
||||
# :reek:TooManyStatements
|
||||
# :reek:DuplicateMethodCall
|
||||
def parse_binary_comparison parser
|
||||
condition = parse_comparison parser
|
||||
first_condition = condition
|
||||
@@ -181,6 +183,7 @@ module TRMNL
|
||||
first_condition
|
||||
end
|
||||
|
||||
# :reek:DuplicateMethodCall
|
||||
def parse_comparison parser
|
||||
left_operand = ::Liquid::Expression.parse parser.expression
|
||||
operator = parser.consume? :comparison
|
||||
|
||||
@@ -4,6 +4,7 @@ require "action_view"
|
||||
|
||||
module TRMNL
|
||||
module Liquid
|
||||
# Defines Rails helpers for use in filters.
|
||||
module RailsHelpers
|
||||
extend ActionView::Helpers::TextHelper
|
||||
extend ActionView::Helpers::NumberHelper
|
||||
|
||||
Reference in New Issue
Block a user