Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ gemspec
group :development do
gem 'rake', '>= 13'
gem 'rspec', '~> 3.13.0'
gem 'rubocop', '~> 1.75.0'
gem 'rubocop', '~> 1.76.1'
gem 'rubocop-performance', '~> 1.25.0'
gem 'rubocop-rake', '~> 0.7.1'
gem 'rubocop-rspec', '~> 3.6.0'
Expand Down
2 changes: 1 addition & 1 deletion lib/sass/value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def to_a
end

# @return [::Boolean]
def to_bool
def to_bool # rubocop:disable Naming/PredicateMethod
true
end

Expand Down
32 changes: 16 additions & 16 deletions lib/sass/value/color.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,21 +318,21 @@ def ==(other)

if legacy?
return false unless other.legacy?
return false unless FuzzyMath.equals_nilable(other.alpha_or_nil, alpha_or_nil)
return false unless FuzzyMath.equals_nilable?(other.alpha_or_nil, alpha_or_nil)

if _space == other._space
FuzzyMath.equals_nilable(other.channel0_or_nil, channel0_or_nil) &&
FuzzyMath.equals_nilable(other.channel1_or_nil, channel1_or_nil) &&
FuzzyMath.equals_nilable(other.channel2_or_nil, channel2_or_nil)
FuzzyMath.equals_nilable?(other.channel0_or_nil, channel0_or_nil) &&
FuzzyMath.equals_nilable?(other.channel1_or_nil, channel1_or_nil) &&
FuzzyMath.equals_nilable?(other.channel2_or_nil, channel2_or_nil)
else
_to_space(Space::RGB) == other._to_space(Space::RGB)
end
else
other._space == _space &&
FuzzyMath.equals_nilable(other.channel0_or_nil, channel0_or_nil) &&
FuzzyMath.equals_nilable(other.channel1_or_nil, channel1_or_nil) &&
FuzzyMath.equals_nilable(other.channel2_or_nil, channel2_or_nil) &&
FuzzyMath.equals_nilable(other.alpha_or_nil, alpha_or_nil)
FuzzyMath.equals_nilable?(other.channel0_or_nil, channel0_or_nil) &&
FuzzyMath.equals_nilable?(other.channel1_or_nil, channel1_or_nil) &&
FuzzyMath.equals_nilable?(other.channel2_or_nil, channel2_or_nil) &&
FuzzyMath.equals_nilable?(other.alpha_or_nil, alpha_or_nil)
end
end

Expand Down Expand Up @@ -367,9 +367,9 @@ def channel0_missing?
def channel0_powerless?
case _space
when Space::HSL
FuzzyMath.equals(channel1, 0)
FuzzyMath.equals?(channel1, 0)
when Space::HWB
FuzzyMath.greater_than_or_equals(channel1 + channel2, 100)
FuzzyMath.greater_than_or_equals?(channel1 + channel2, 100)
else
false
end
Expand Down Expand Up @@ -398,7 +398,7 @@ def channel2_missing?
def channel2_powerless?
case _space
when Space::LCH, Space::OKLCH
FuzzyMath.equals(channel1, 0)
FuzzyMath.equals?(channel1, 0)
else
false
end
Expand Down Expand Up @@ -449,7 +449,7 @@ def _initialize_for_space_internal(space, channel0, channel1, channel2, alpha =
when Space::HSL
_initialize_for_space(
space,
_normalize_hue(channel0, invert: !channel1.nil? && FuzzyMath.less_than(channel1, 0)),
_normalize_hue(channel0, invert: !channel1.nil? && FuzzyMath.less_than?(channel1, 0)),
channel1&.abs,
channel2,
alpha
Expand All @@ -461,7 +461,7 @@ def _initialize_for_space_internal(space, channel0, channel1, channel2, alpha =
space,
channel0,
channel1&.abs,
_normalize_hue(channel2, invert: !channel1.nil? && FuzzyMath.less_than(channel1, 0)),
_normalize_hue(channel2, invert: !channel1.nil? && FuzzyMath.less_than?(channel1, 0)),
alpha
)
else
Expand All @@ -488,7 +488,7 @@ def _normalize_hue(hue, invert:)
def _is_channel_in_gamut(value, channel)
case channel
when LinearChannel
FuzzyMath.less_than_or_equals(value, channel.max) && FuzzyMath.greater_than_or_equals(value, channel.min)
FuzzyMath.less_than_or_equals?(value, channel.max) && FuzzyMath.greater_than_or_equals?(value, channel.min)
else
true
end
Expand All @@ -500,8 +500,8 @@ def _interpolate(other, method, weight: nil)
raise Sass::ScriptError.new("Expected #{wieght} to be within 0 and 1.", 'weight')
end

return other if FuzzyMath.equals(weight, 0)
return self if FuzzyMath.equals(weight, 1)
return other if FuzzyMath.equals?(weight, 0)
return self if FuzzyMath.equals?(weight, 1)

color1 = _to_space(method.space)
color2 = other._to_space(method.space)
Expand Down
4 changes: 2 additions & 2 deletions lib/sass/value/color/gamut_map_method/local_minde.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def map(color)
hue = original_oklch.send(:channel2_or_nil)
alpha = original_oklch.send(:alpha_or_nil)

if FuzzyMath.greater_than_or_equals(lightness.nil? ? 0 : lightness, 1)
if FuzzyMath.greater_than_or_equals?(lightness.nil? ? 0 : lightness, 1)
if color.legacy?
return Color.send(:_for_space,
Space::RGB, 255, 255, 255, color.send(:alpha_or_nil))
Expand All @@ -37,7 +37,7 @@ def map(color)
return Color.send(:for_space_internal,
color.send(:_space), 1, 1, 1, color.send(:alpha_or_nil))
end
elsif FuzzyMath.less_than_or_equals(lightness.nil? ? 0 : lightness, 0)
elsif FuzzyMath.less_than_or_equals?(lightness.nil? ? 0 : lightness, 0)
return Color.send(:_for_space,
Space::RGB, 0, 0, 0, color.send(:alpha_or_nil))
.send(:_to_space, color.send(:_space))
Expand Down
2 changes: 1 addition & 1 deletion lib/sass/value/color/space/lab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def convert(dest, lightness, a, b, alpha, # rubocop:disable Naming/MethodParamet
missing_chroma: false, missing_hue: false)
case dest
when LAB
powerless_ab = lightness.nil? || FuzzyMath.equals(lightness, 0)
powerless_ab = lightness.nil? || FuzzyMath.equals?(lightness, 0)
Color.send(
:_for_space,
dest,
Expand Down
4 changes: 2 additions & 2 deletions lib/sass/value/color/space/srgb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def convert(dest, red, green, blue, alpha,
Color.send(
:for_space_internal,
dest,
missing_hue || FuzzyMath.equals(saturation, 0) ? nil : hue % 360,
missing_hue || FuzzyMath.equals?(saturation, 0) ? nil : hue % 360,
missing_chroma ? nil : saturation,
missing_lightness ? nil : lightness * 100,
alpha
Expand All @@ -67,7 +67,7 @@ def convert(dest, red, green, blue, alpha,
Color.send(
:for_space_internal,
dest,
missing_hue || FuzzyMath.greater_than_or_equals(whiteness + blackness, 100) ? nil : hue % 360,
missing_hue || FuzzyMath.greater_than_or_equals?(whiteness + blackness, 100) ? nil : hue % 360,
whiteness,
blackness,
alpha
Expand Down
2 changes: 1 addition & 1 deletion lib/sass/value/color/space/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def srgb_and_display_p3_from_linear(channel)
def lab_to_lch(dest, lightness, a, b, alpha, # rubocop:disable Naming/MethodParameterName
missing_chroma: false, missing_hue: false)
chroma = Math.sqrt(((a.nil? ? 0 : a)**2) + ((b.nil? ? 0 : b)**2))
hue = if missing_hue || FuzzyMath.equals(chroma, 0)
hue = if missing_hue || FuzzyMath.equals?(chroma, 0)
nil
else
Math.atan2(b.nil? ? 0 : b, a.nil? ? 0 : a) * 180 / Math::PI
Expand Down
26 changes: 13 additions & 13 deletions lib/sass/value/fuzzy_math.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ module FuzzyMath

module_function

def equals(number1, number2)
def equals?(number1, number2)
return true if number1 == number2

(number1 - number2).abs <= EPSILON &&
(number1 * INVERSE_EPSILON).round ==
(number2 * INVERSE_EPSILON).round
end

def equals_nilable(number1, number2)
def equals_nilable?(number1, number2)
return true if number1 == number2
return false if number1.nil? || number2.nil?

Expand All @@ -29,35 +29,35 @@ def equals_nilable(number1, number2)
(number2 * INVERSE_EPSILON).round
end

def less_than(number1, number2)
number1 < number2 && !equals(number1, number2)
def less_than?(number1, number2)
number1 < number2 && !equals?(number1, number2)
end

def less_than_or_equals(number1, number2)
number1 < number2 || equals(number1, number2)
def less_than_or_equals?(number1, number2)
number1 < number2 || equals?(number1, number2)
end

def greater_than(number1, number2)
number1 > number2 && !equals(number1, number2)
def greater_than?(number1, number2)
number1 > number2 && !equals?(number1, number2)
end

def greater_than_or_equals(number1, number2)
number1 > number2 || equals(number1, number2)
def greater_than_or_equals?(number1, number2)
number1 > number2 || equals?(number1, number2)
end

def integer?(number)
return false unless number.finite?

equals(number, number.round)
equals?(number, number.round)
end

def to_i(number)
integer?(number) ? number.round : nil
end

def between(number, min, max)
return min if equals(number, min)
return max if equals(number, max)
return min if equals?(number, min)
return max if equals?(number, max)
return number if number > min && number < max

nil
Expand Down
2 changes: 1 addition & 1 deletion lib/sass/value/null.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def hash
end

# @return [::Boolean]
def to_bool
def to_bool # rubocop:disable Naming/PredicateMethod
false
end

Expand Down
6 changes: 3 additions & 3 deletions lib/sass/value/number.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ def ==(other)
return false if numerator_units.length != other.numerator_units.length ||
denominator_units.length != other.denominator_units.length

return FuzzyMath.equals(value, other.value) if unitless?
return FuzzyMath.equals?(value, other.value) if unitless?

if Unit.canonicalize_units(numerator_units) != Unit.canonicalize_units(other.numerator_units) &&
Unit.canonicalize_units(denominator_units) != Unit.canonicalize_units(other.denominator_units)
return false
end

FuzzyMath.equals(
FuzzyMath.equals?(
value *
Unit.canonical_multiplier(numerator_units) /
Unit.canonical_multiplier(denominator_units),
Expand Down Expand Up @@ -306,7 +306,7 @@ def coerce_or_convert_value(new_numerator_units, new_denominator_units,

unit_length = new_numerator_units.length + new_denominator_units.length
units = unit_string(new_numerator_units, new_denominator_units)
Sass::ScriptError.new("Expected #{self} to have unit#{unit_length > 1 ? 's' : ''} #{units}", name)
Sass::ScriptError.new("Expected #{self} to have unit#{'s' if unit_length > 1} #{units}", name)
}

result = value
Expand Down
2 changes: 1 addition & 1 deletion spec/sandbox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def chdir(...)
private

def file_uri(path)
URI::File.build([nil, "#{path.start_with?('/') ? '' : '/'}#{URI::DEFAULT_PARSER.escape(path)}"])
URI::File.build([nil, "#{'/' unless path.start_with?('/')}#{URI::DEFAULT_PARSER.escape(path)}"])
end
end
end