Skip to content

Commit 727bd86

Browse files
authored
Rubocop config updates (#384)
1 parent 2fe9e34 commit 727bd86

10 files changed

Lines changed: 316 additions & 326 deletions

File tree

.rubocop.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ Metrics/PerceivedComplexity:
3030
Enabled: false
3131
Metrics/AbcSize:
3232
Enabled: false
33+
Layout/ExtraSpacing:
34+
AllowForAlignment: false

.rubocop_todo.yml

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2024-09-01 18:40:26 UTC using RuboCop version 1.66.0.
3+
# on 2025-12-28 23:46:28 UTC using RuboCop version 1.82.1.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 2
9+
# Offense count: 1
1010
Lint/BinaryOperatorWithIdenticalOperands:
1111
Exclude:
1212
- 'spec/ruby_units/unit_spec.rb'
1313

1414
# Offense count: 2
1515
# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
1616
# SupportedStyles: snake_case, normalcase, non_integer
17-
# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
17+
# AllowedIdentifiers: TLS1_1, TLS1_2, capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
1818
Naming/VariableNumber:
1919
Exclude:
2020
- 'spec/ruby_units/unit_spec.rb'
@@ -33,7 +33,7 @@ RSpec/BeforeAfterAll:
3333
- '**/spec/support/**/*.rb'
3434
- 'spec/ruby_units/temperature_spec.rb'
3535

36-
# Offense count: 95
36+
# Offense count: 79
3737
# Configuration parameters: Prefixes, AllowedPatterns.
3838
# Prefixes: when, with, without
3939
RSpec/ContextWording:
@@ -42,7 +42,7 @@ RSpec/ContextWording:
4242
- 'spec/ruby_units/unit_spec.rb'
4343
- 'spec/ruby_units/utf-8/unit_spec.rb'
4444

45-
# Offense count: 12
45+
# Offense count: 13
4646
# Configuration parameters: IgnoredMetadata.
4747
RSpec/DescribeClass:
4848
Exclude:
@@ -53,6 +53,7 @@ RSpec/DescribeClass:
5353
- '**/spec/views/**/*'
5454
- 'spec/ruby_units/bugs_spec.rb'
5555
- 'spec/ruby_units/definition_spec.rb'
56+
- 'spec/ruby_units/initialization_spec.rb'
5657
- 'spec/ruby_units/temperature_spec.rb'
5758
- 'spec/ruby_units/unit_spec.rb'
5859

@@ -92,11 +93,11 @@ RSpec/MultipleDescribes:
9293
Exclude:
9394
- 'spec/ruby_units/unit_spec.rb'
9495

95-
# Offense count: 10
96+
# Offense count: 30
9697
RSpec/MultipleExpectations:
9798
Max: 6
9899

99-
# Offense count: 59
100+
# Offense count: 60
100101
# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
101102
# SupportedStyles: always, named_only
102103
RSpec/NamedSubject:
@@ -134,29 +135,23 @@ RSpec/RepeatedExampleGroupDescription:
134135
- 'spec/ruby_units/unit_spec.rb'
135136

136137
# Offense count: 1
137-
# Configuration parameters: Include, CustomTransform, IgnoreMethods, IgnoreMetadata.
138-
# Include: **/*_spec.rb
138+
# Configuration parameters: CustomTransform, IgnoreMethods, IgnoreMetadata, InflectorPath, EnforcedInflector.
139+
# SupportedInflectors: default, active_support
139140
RSpec/SpecFilePathFormat:
140141
Exclude:
141142
- '**/spec/routing/**/*'
142143
- 'spec/ruby_units/utf-8/unit_spec.rb'
143144

144145
# Offense count: 1
145146
# This cop supports unsafe autocorrection (--autocorrect-all).
146-
# Configuration parameters: EnforcedStyle.
147+
# Configuration parameters: EnforcedStyle, EnforcedStyleForClasses, EnforcedStyleForModules.
147148
# SupportedStyles: nested, compact
149+
# SupportedStylesForClasses: ~, nested, compact
150+
# SupportedStylesForModules: ~, nested, compact
148151
Style/ClassAndModuleChildren:
149152
Exclude:
150153
- 'lib/ruby_units/definition.rb'
151154

152-
# Offense count: 1
153-
# Configuration parameters: AllowedConstants.
154-
Style/Documentation:
155-
Exclude:
156-
- 'spec/**/*'
157-
- 'test/**/*'
158-
- 'lib/ruby_units/configuration.rb'
159-
160155
# Offense count: 5
161156
# This cop supports unsafe autocorrection (--autocorrect-all).
162157
Style/GlobalStdStream:
@@ -169,13 +164,6 @@ Style/OpenStructUse:
169164
Exclude:
170165
- 'Guardfile'
171166

172-
# Offense count: 1
173-
# Configuration parameters: AllowedMethods.
174-
# AllowedMethods: respond_to_missing?
175-
Style/OptionalBooleanParameter:
176-
Exclude:
177-
- 'lib/ruby_units/date.rb'
178-
179167
# Offense count: 1
180168
# This cop supports unsafe autocorrection (--autocorrect-all).
181169
# Configuration parameters: AllowSend.

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ GEM
179179
rubocop-ast (>= 1.48.0, < 2.0)
180180
ruby-progressbar (~> 1.7)
181181
unicode-display_width (>= 2.4.0, < 4.0)
182-
rubocop-ast (1.48.0)
182+
rubocop-ast (1.49.0)
183183
parser (>= 3.3.7.2)
184-
prism (~> 1.4)
184+
prism (~> 1.7)
185185
rubocop-rake (0.7.1)
186186
lint_roller (~> 1.1)
187187
rubocop (>= 1.72.1)

Guardfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ guard :rspec, cmd: "bundle exec rspec" do
2828
rspec.spec_helper = "spec/spec_helper.rb"
2929

3030
watch(%r{^spec/.+_spec\.rb$})
31-
watch(%r{^lib/(.+)\.rb$}) { |m| rspec.spec.call(m[1]) }
32-
watch(rspec.spec_helper) { rspec.spec_dir }
31+
watch(%r{^lib/(.+)\.rb$}) { |m| rspec.spec.call(m[1]) }
32+
watch(rspec.spec_helper) { rspec.spec_dir }
3333
end

lib/ruby_units/unit.rb

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ class << self
5555
self.unit_values = {}
5656
@unit_regex = nil
5757
@unit_match_regex = nil
58-
UNITY = "<1>"
59-
UNITY_ARRAY = [UNITY].freeze
58+
UNITY = "<1>"
59+
UNITY_ARRAY = [UNITY].freeze
6060

6161
SIGN_REGEX = /(?:[+-])?/ # +, -, or nothing
6262

@@ -75,36 +75,36 @@ class << self
7575
# and 'inches', but they aren't defined at the point in the code where we
7676
# need this regex.
7777
FEET_INCH_UNITS_REGEX = /(?:'|ft|feet)\s*(?<inches>#{RATIONAL_NUMBER}|#{SCI_NUMBER})\s*(?:"|in|inch(?:es)?)/
78-
FEET_INCH_REGEX = /(?<feet>#{INTEGER_REGEX})\s*#{FEET_INCH_UNITS_REGEX}/
78+
FEET_INCH_REGEX = /(?<feet>#{INTEGER_REGEX})\s*#{FEET_INCH_UNITS_REGEX}/
7979
# ideally we would like to generate this regex from the alias for a 'pound'
8080
# and 'ounce', but they aren't defined at the point in the code where we
8181
# need this regex.
82-
LBS_OZ_UNIT_REGEX = /(?:#|lbs?|pounds?|pound-mass)+[\s,]*(?<oz>#{RATIONAL_NUMBER}|#{UNSIGNED_INTEGER_REGEX})\s*(?:ozs?|ounces?)/
83-
LBS_OZ_REGEX = /(?<pounds>#{INTEGER_REGEX})\s*#{LBS_OZ_UNIT_REGEX}/
82+
LBS_OZ_UNIT_REGEX = /(?:#|lbs?|pounds?|pound-mass)+[\s,]*(?<oz>#{RATIONAL_NUMBER}|#{UNSIGNED_INTEGER_REGEX})\s*(?:ozs?|ounces?)/
83+
LBS_OZ_REGEX = /(?<pounds>#{INTEGER_REGEX})\s*#{LBS_OZ_UNIT_REGEX}/
8484
# ideally we would like to generate this regex from the alias for a 'stone'
8585
# and 'pound', but they aren't defined at the point in the code where we
8686
# need this regex. also note that the plural of 'stone' is still 'stone',
8787
# but we accept 'stones' anyway.
8888
STONE_LB_UNIT_REGEX = /(?:sts?|stones?)+[\s,]*(?<pounds>#{RATIONAL_NUMBER}|#{UNSIGNED_INTEGER_REGEX})\s*(?:#|lbs?|pounds?|pound-mass)*/
89-
STONE_LB_REGEX = /(?<stone>#{INTEGER_REGEX})\s*#{STONE_LB_UNIT_REGEX}/
89+
STONE_LB_REGEX = /(?<stone>#{INTEGER_REGEX})\s*#{STONE_LB_UNIT_REGEX}/
9090
# Time formats: 12:34:56,78, (hh:mm:ss,msec) etc.
91-
TIME_REGEX = /(?<hour>\d+):(?<min>\d+):?(?:(?<sec>\d+))?(?:[.](?<msec>\d+))?/
91+
TIME_REGEX = /(?<hour>\d+):(?<min>\d+):?(?:(?<sec>\d+))?(?:[.](?<msec>\d+))?/
9292
# Complex numbers: 1+2i, 1.0+2.0i, -1-1i, etc.
93-
COMPLEX_NUMBER = /(?<real>#{SCI_NUMBER})?(?<imaginary>#{SCI_NUMBER})i\b/
93+
COMPLEX_NUMBER = /(?<real>#{SCI_NUMBER})?(?<imaginary>#{SCI_NUMBER})i\b/
9494
# Any Complex, Rational, or scientific number
95-
ANY_NUMBER = /(#{COMPLEX_NUMBER}|#{RATIONAL_NUMBER}|#{SCI_NUMBER})/
96-
ANY_NUMBER_REGEX = /(?:#{ANY_NUMBER})?\s?([^-\d.].*)?/
97-
NUMBER_REGEX = /(?<scalar>#{SCI_NUMBER}*)\s*(?<unit>.+)?/ # a number followed by a unit
98-
UNIT_STRING_REGEX = %r{#{SCI_NUMBER}*\s*([^/]*)/*(.+)*}
99-
TOP_REGEX = /(?<unit_part>[^ *]+)(?:\^|\*\*)(?<exponent>[\d-]+)/
100-
BOTTOM_REGEX = /(?<unit_part>[^* ]+)(?:\^|\*\*)(?<exponent>\d+)/
101-
NUMBER_UNIT_REGEX = /#{SCI_NUMBER}?(.*)/
102-
COMPLEX_REGEX = /#{COMPLEX_NUMBER}\s?(?<unit>.+)?/
103-
RATIONAL_REGEX = /#{RATIONAL_NUMBER}\s?(?<unit>.+)?/
104-
KELVIN = ["<kelvin>"].freeze
105-
FAHRENHEIT = ["<fahrenheit>"].freeze
106-
RANKINE = ["<rankine>"].freeze
107-
CELSIUS = ["<celsius>"].freeze
95+
ANY_NUMBER = /(#{COMPLEX_NUMBER}|#{RATIONAL_NUMBER}|#{SCI_NUMBER})/
96+
ANY_NUMBER_REGEX = /(?:#{ANY_NUMBER})?\s?([^-\d.].*)?/
97+
NUMBER_REGEX = /(?<scalar>#{SCI_NUMBER}*)\s*(?<unit>.+)?/ # a number followed by a unit
98+
UNIT_STRING_REGEX = %r{#{SCI_NUMBER}*\s*([^/]*)/*(.+)*}
99+
TOP_REGEX = /(?<unit_part>[^ *]+)(?:\^|\*\*)(?<exponent>[\d-]+)/
100+
BOTTOM_REGEX = /(?<unit_part>[^* ]+)(?:\^|\*\*)(?<exponent>\d+)/
101+
NUMBER_UNIT_REGEX = /#{SCI_NUMBER}?(.*)/
102+
COMPLEX_REGEX = /#{COMPLEX_NUMBER}\s?(?<unit>.+)?/
103+
RATIONAL_REGEX = /#{RATIONAL_NUMBER}\s?(?<unit>.+)?/
104+
KELVIN = ["<kelvin>"].freeze
105+
FAHRENHEIT = ["<fahrenheit>"].freeze
106+
RANKINE = ["<rankine>"].freeze
107+
CELSIUS = ["<celsius>"].freeze
108108

109109
# Temperature conversion constants
110110
CELSIUS_OFFSET_TO_KELVIN = 273.15 # offset to convert Celsius to Kelvin
@@ -1229,9 +1229,9 @@ def convert_to(other)
12291229

12301230
target_num = target.numerator
12311231
target_den = target.denominator
1232-
source_numerator_values = to_scalar.call(@numerator)
1232+
source_numerator_values = to_scalar.call(@numerator)
12331233
source_denominator_values = to_scalar.call(@denominator)
1234-
target_numerator_values = to_scalar.call(target_num)
1234+
target_numerator_values = to_scalar.call(target_num)
12351235
target_denominator_values = to_scalar.call(target_den)
12361236
# @type [Rational, Numeric]
12371237
scalar_is_integer = @scalar.is_a?(Integer)
@@ -1295,10 +1295,10 @@ def as_json(*)
12951295
def units(with_prefix: true, format: nil)
12961296
return "" if @numerator == UNITY_ARRAY && @denominator == UNITY_ARRAY
12971297

1298-
output_numerator = ["1"]
1298+
output_numerator = ["1"]
12991299
output_denominator = []
1300-
num = @numerator.clone.compact
1301-
den = @denominator.clone.compact
1300+
num = @numerator.clone.compact
1301+
den = @denominator.clone.compact
13021302

13031303
process_unit_array = lambda do |unit_array|
13041304
definitions = unit_array.map { unit_class.definition(_1) }
@@ -1605,11 +1605,11 @@ def apply_signature_items(vector, items, sign)
16051605
def update_base_scalar
16061606
if base?
16071607
@base_scalar = @scalar
1608-
@signature = unit_signature
1608+
@signature = unit_signature
16091609
else
1610-
base = to_base
1610+
base = to_base
16111611
@base_scalar = base.scalar
1612-
@signature = base.signature
1612+
@signature = base.signature
16131613
end
16141614
end
16151615

@@ -2103,7 +2103,7 @@ def parse(passed_unit_string = "0")
21032103

21042104
if unit
21052105
copy(unit)
2106-
@scalar *= mult
2106+
@scalar *= mult
21072107
@base_scalar *= mult
21082108
return self
21092109
end
@@ -2199,7 +2199,7 @@ def parse(passed_unit_string = "0")
21992199

22002200
@scalar /= bottom_scalar
22012201

2202-
@numerator ||= UNITY_ARRAY
2202+
@numerator ||= UNITY_ARRAY
22032203
@denominator ||= UNITY_ARRAY
22042204
@numerator = top.scan(unit_match_regex).delete_if(&:empty?).compact if top
22052205
@denominator = bottom.scan(unit_match_regex).delete_if(&:empty?).compact if bottom

0 commit comments

Comments
 (0)