summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGeremia Taglialatela <[email protected]>2023-05-20 17:52:35 +0200
committerGeremia Taglialatela <[email protected]>2023-05-20 17:52:35 +0200
commit611b57cdd44f3f5e91394c699ad98b7c05330a2e (patch)
tree3ac799c34fdc418ae31145feb1edf9d363b1d69a
parent6a4b82def2e94b4811c38c37e606d426710d1e6c (diff)
downloadcaxlsx-611b57cdd44f3f5e91394c699ad98b7c05330a2e.tar.gz
caxlsx-611b57cdd44f3f5e91394c699ad98b7c05330a2e.zip
Remove minor safe offenses
- Style/RaiseArgs - Style/RedundantCondition - Style/RedundantReturn - Style/SelfAssignment - Style/SoleNestedConditional
-rw-r--r--.rubocop_todo.yml34
-rw-r--r--lib/axlsx/drawing/area_series.rb2
-rw-r--r--lib/axlsx/drawing/line_series.rb2
-rw-r--r--lib/axlsx/package.rb4
-rw-r--r--lib/axlsx/stylesheet/color.rb2
-rw-r--r--lib/axlsx/stylesheet/styles.rb10
-rw-r--r--lib/axlsx/util/validators.rb5
-rw-r--r--lib/axlsx/util/zip_command.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/border_creator.rb4
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet.rb2
10 files changed, 16 insertions, 51 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index 19c4b3f5..bee3cf78 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -422,26 +422,11 @@ Style/QuotedSymbols:
- 'lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb'
# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: EnforcedStyle, AllowedCompactTypes.
-# SupportedStyles: compact, exploded
-Style/RaiseArgs:
- Exclude:
- - 'lib/axlsx/package.rb'
- - 'lib/axlsx/util/zip_command.rb'
- - 'lib/axlsx/workbook/worksheet/border_creator.rb'
-
-# This cop supports safe autocorrection (--autocorrect).
Style/RandomWithOffset:
Exclude:
- 'lib/axlsx/drawing/vml_shape.rb'
# This cop supports safe autocorrection (--autocorrect).
-Style/RedundantCondition:
- Exclude:
- - 'lib/axlsx/drawing/area_series.rb'
- - 'lib/axlsx/drawing/line_series.rb'
-
-# This cop supports safe autocorrection (--autocorrect).
Style/RedundantFileExtensionInRequire:
Exclude:
- 'lib/axlsx/content_type/content_type.rb'
@@ -485,14 +470,6 @@ Style/RedundantRegexpEscape:
- 'lib/axlsx/workbook/worksheet/table.rb'
# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: AllowMultipleReturnValues.
-Style/RedundantReturn:
- Exclude:
- - 'lib/axlsx/package.rb'
- - 'lib/axlsx/stylesheet/styles.rb'
- - 'lib/axlsx/workbook/worksheet/worksheet.rb'
-
-# This cop supports safe autocorrection (--autocorrect).
Style/RedundantSelf:
Enabled: false
@@ -503,11 +480,6 @@ Style/SafeNavigation:
Enabled: false
# This cop supports safe autocorrection (--autocorrect).
-Style/SelfAssignment:
- Exclude:
- - 'lib/axlsx/stylesheet/color.rb'
-
-# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowIfMethodIsEmpty.
Style/SingleLineMethods:
Enabled: false
@@ -520,12 +492,6 @@ Style/SlicingWithRange:
- 'lib/axlsx/workbook/worksheet/pivot_table.rb'
- 'lib/axlsx/workbook/worksheet/worksheet.rb'
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: AllowModifier.
-Style/SoleNestedConditional:
- Exclude:
- - 'lib/axlsx/util/validators.rb'
-
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/StringChars:
Exclude:
diff --git a/lib/axlsx/drawing/area_series.rb b/lib/axlsx/drawing/area_series.rb
index 5cebd7da..cf4aaf13 100644
--- a/lib/axlsx/drawing/area_series.rb
+++ b/lib/axlsx/drawing/area_series.rb
@@ -37,7 +37,7 @@ module Axlsx
# @param [Chart] chart
def initialize(chart, options = {})
@show_marker = false
- @marker_symbol = options[:marker_symbol] ? options[:marker_symbol] : :default
+ @marker_symbol = options[:marker_symbol] || :default
@smooth = false
@labels, @data = nil, nil
super(chart, options)
diff --git a/lib/axlsx/drawing/line_series.rb b/lib/axlsx/drawing/line_series.rb
index bbd3957e..fbed4000 100644
--- a/lib/axlsx/drawing/line_series.rb
+++ b/lib/axlsx/drawing/line_series.rb
@@ -37,7 +37,7 @@ module Axlsx
# @param [Chart] chart
def initialize(chart, options = {})
@show_marker = false
- @marker_symbol = options[:marker_symbol] ? options[:marker_symbol] : :default
+ @marker_symbol = options[:marker_symbol] || :default
@smooth = false
@labels, @data = nil, nil
super(chart, options)
diff --git a/lib/axlsx/package.rb b/lib/axlsx/package.rb
index b4116f76..7aa80b73 100644
--- a/lib/axlsx/package.rb
+++ b/lib/axlsx/package.rb
@@ -145,7 +145,7 @@ module Axlsx
# Encrypt the package into a CFB using the password provided
# This is not ready yet
def encrypt(file_name, password)
- return false
+ false
# moc = MsOffCrypto.new(file_name, password)
# moc.save
end
@@ -386,7 +386,7 @@ module Axlsx
options.merge!(secondary_options || {})
invalid_keys = options.keys - [:confirm_valid, :zip_command]
if invalid_keys.any?
- raise ArgumentError.new("Invalid keyword arguments: #{invalid_keys}")
+ raise ArgumentError, "Invalid keyword arguments: #{invalid_keys}"
end
[options.fetch(:confirm_valid, false), options.fetch(:zip_command, nil)]
diff --git a/lib/axlsx/stylesheet/color.rb b/lib/axlsx/stylesheet/color.rb
index 87308bb1..24fe3bc3 100644
--- a/lib/axlsx/stylesheet/color.rb
+++ b/lib/axlsx/stylesheet/color.rb
@@ -53,7 +53,7 @@ module Axlsx
def rgb=(v)
Axlsx::validate_string(v)
v = v.upcase
- v = v * 3 if v.size == 2
+ v *= 3 if v.size == 2
v = v.rjust(8, 'FF')
raise ArgumentError, "Invalid color rgb value: #{v}." unless /[0-9A-F]{8}/.match?(v)
diff --git a/lib/axlsx/stylesheet/styles.rb b/lib/axlsx/stylesheet/styles.rb
index e8263b45..dc44c2eb 100644
--- a/lib/axlsx/stylesheet/styles.rb
+++ b/lib/axlsx/stylesheet/styles.rb
@@ -278,11 +278,9 @@ module Axlsx
# Add styles to style_index cache for re-use
style_index[xf_index] = raw_style
- return xf_index
+ xf_index
else
- dxf_index = (dxfs << style)
-
- return dxf_index
+ dxfs << style
end
end
@@ -457,9 +455,9 @@ module Axlsx
end
if options[:type] == :dxf
- return border
+ border
else
- return borders << border
+ borders << border
end
end
diff --git a/lib/axlsx/util/validators.rb b/lib/axlsx/util/validators.rb
index e9cf13b6..72e3f2d8 100644
--- a/lib/axlsx/util/validators.rb
+++ b/lib/axlsx/util/validators.rb
@@ -55,9 +55,10 @@ module Axlsx
# @return [Boolean] true if validation succeeds.
# @see validate_boolean
def self.validate(name, types, v, other = false)
- if other.is_a?(Proc)
- raise ArgumentError, (ERR_TYPE % [v.inspect, name, types.inspect]) unless other.call(v)
+ if other.is_a?(Proc) && !other.call(v)
+ raise ArgumentError, (ERR_TYPE % [v.inspect, name, types.inspect])
end
+
v_class = v.is_a?(Class) ? v : v.class
Array(types).each do |t|
return if v_class <= t
diff --git a/lib/axlsx/util/zip_command.rb b/lib/axlsx/util/zip_command.rb
index e43ba03d..bc098a92 100644
--- a/lib/axlsx/util/zip_command.rb
+++ b/lib/axlsx/util/zip_command.rb
@@ -64,7 +64,7 @@ module Axlsx
command = "cd #{escaped_dir} && #{@zip_command} #{output} #{inputs}"
stdout_and_stderr, status = Open3.capture2e(command)
if !status.success?
- raise(ZipError.new(stdout_and_stderr))
+ raise ZipError, stdout_and_stderr
end
end
end
diff --git a/lib/axlsx/workbook/worksheet/border_creator.rb b/lib/axlsx/workbook/worksheet/border_creator.rb
index 6321916f..9abaded5 100644
--- a/lib/axlsx/workbook/worksheet/border_creator.rb
+++ b/lib/axlsx/workbook/worksheet/border_creator.rb
@@ -13,12 +13,12 @@ module Axlsx
if @edges == :all
@edges = Axlsx::Border::EDGES
elsif [email protected]_a?(Array)
- raise ArgumentError.new("Invalid edges provided, #{@edges}")
+ raise ArgumentError, "Invalid edges provided, #{@edges}"
else
@edges = @edges.map { |x| x&.to_sym }.uniq
if !(@edges - Axlsx::Border::EDGES).empty?
- raise ArgumentError.new("Invalid edges provided, #{edges}")
+ raise ArgumentError, "Invalid edges provided, #{edges}"
end
end
end
diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb
index 21c53409..aace58be 100644
--- a/lib/axlsx/workbook/worksheet/worksheet.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet.rb
@@ -693,7 +693,7 @@ module Axlsx
r = rows[row_index]
if r
- return r[col_index]
+ r[col_index]
end
end