diff options
| author | Geremia Taglialatela <[email protected]> | 2023-07-01 09:33:16 +0200 |
|---|---|---|
| committer | Geremia Taglialatela <[email protected]> | 2023-07-01 09:33:16 +0200 |
| commit | b2636ddaebd9fd1ecd09466b4606792da53947a5 (patch) | |
| tree | 67c8278a06dd791a9210533428ab1dffa40fc7e2 | |
| parent | f2f6177efac76e6015b98c3290fd1839b8568fbe (diff) | |
| download | caxlsx-b2636ddaebd9fd1ecd09466b4606792da53947a5.tar.gz caxlsx-b2636ddaebd9fd1ecd09466b4606792da53947a5.zip | |
Fix Lint/NonLocalExitFromIterator offense
Uses `Array#any?` instead of `Array#each`.
According to benchmarks, `any?` is slightly faster when validation
fails (3%) and noticeably faster when validation passes (up to 60%)
| -rw-r--r-- | .rubocop_todo.yml | 4 | ||||
| -rw-r--r-- | lib/axlsx/util/validators.rb | 5 |
2 files changed, 2 insertions, 7 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index fcbc8c9f..bbe70cb3 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -56,10 +56,6 @@ Lint/DisjunctiveAssignmentInConstructor: Exclude: - 'lib/axlsx/drawing/num_data_source.rb' -Lint/NonLocalExitFromIterator: - Exclude: - - 'lib/axlsx/util/validators.rb' - # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments. Lint/UnusedBlockArgument: diff --git a/lib/axlsx/util/validators.rb b/lib/axlsx/util/validators.rb index fd17360e..5684c9cb 100644 --- a/lib/axlsx/util/validators.rb +++ b/lib/axlsx/util/validators.rb @@ -60,9 +60,8 @@ module Axlsx end v_class = v.is_a?(Class) ? v : v.class - Array(types).each do |t| - return if v_class <= t - end + return if Array(types).any? { |t| v_class <= t } + raise ArgumentError, format(ERR_TYPE, v.inspect, name, types.inspect) end end |
