From 490a89737c7f9aaedebaad0bdbb6042f48f3bd5f Mon Sep 17 00:00:00 2001 From: Brooke Kuhlmann Date: Thu, 29 Jan 2026 14:52:43 -0700 Subject: [PATCH] Fixed Reek issues Added configuration, fixes issues where possible, and left code comments for addressing later when time allows. Milestone: patch --- .reek.yml | 13 +++++++++++++ lib/trmnl/liquid.rb | 2 ++ lib/trmnl/liquid/fallback.rb | 2 ++ lib/trmnl/liquid/filters.rb | 15 +++++++++------ lib/trmnl/liquid/rails_helpers.rb | 1 + 5 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 .reek.yml diff --git a/.reek.yml b/.reek.yml new file mode 100644 index 0000000..95bb2c1 --- /dev/null +++ b/.reek.yml @@ -0,0 +1,13 @@ +exclude_paths: + - tmp + - vendor + +detectors: + LongParameterList: + enabled: false + ManualDispatch: + exclude: + - TRMNL::Liquid::Filters + UtilityFunction: + exclude: + - TRMNL::Liquid::Filters diff --git a/lib/trmnl/liquid.rb b/lib/trmnl/liquid.rb index 96cd0a2..7ece4ae 100644 --- a/lib/trmnl/liquid.rb +++ b/lib/trmnl/liquid.rb @@ -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 diff --git a/lib/trmnl/liquid/fallback.rb b/lib/trmnl/liquid/fallback.rb index b5d6999..26d9d0d 100644 --- a/lib/trmnl/liquid/fallback.rb +++ b/lib/trmnl/liquid/fallback.rb @@ -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 diff --git a/lib/trmnl/liquid/filters.rb b/lib/trmnl/liquid/filters.rb index b769f6a..066b945 100644 --- a/lib/trmnl/liquid/filters.rb +++ b/lib/trmnl/liquid/filters.rb @@ -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) 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 diff --git a/lib/trmnl/liquid/rails_helpers.rb b/lib/trmnl/liquid/rails_helpers.rb index 3b67c34..cce3bd1 100644 --- a/lib/trmnl/liquid/rails_helpers.rb +++ b/lib/trmnl/liquid/rails_helpers.rb @@ -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