From 4e555613a021639c12be713c438bb124622c72d3 Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Wed, 31 May 2023 17:31:59 +0200 Subject: Remove redundant parentheses - Style/ParenthesesAroundCondition - Style/RedundantParentheses - Style/TernaryParentheses `Style/ParenthesesAroundCondition` may be questionable, but a majority of comparison where not using parentheses, so offenses have been fixed for uniformity across the codebase --- .rubocop_todo.yml | 31 --------------------------- lib/axlsx/drawing/area_series.rb | 2 +- lib/axlsx/drawing/bar_3D_chart.rb | 4 ++-- lib/axlsx/drawing/bar_chart.rb | 4 ++-- lib/axlsx/drawing/line_3D_chart.rb | 2 +- lib/axlsx/drawing/line_series.rb | 2 +- lib/axlsx/drawing/scatter_series.rb | 2 +- lib/axlsx/package.rb | 2 +- lib/axlsx/stylesheet/font.rb | 4 ++-- lib/axlsx/util/validators.rb | 6 +++--- lib/axlsx/workbook/worksheet/pivot_table.rb | 2 +- lib/axlsx/workbook/worksheet/rich_text_run.rb | 4 ++-- lib/axlsx/workbook/worksheet/worksheet.rb | 2 +- 13 files changed, 18 insertions(+), 49 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index fc0449d9..f76f66af 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -307,14 +307,6 @@ Style/ParallelAssignment: - 'lib/axlsx/package.rb' - 'lib/axlsx/workbook/worksheet/row.rb' -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowSafeAssignment, AllowInMultilineConditions. -Style/ParenthesesAroundCondition: - Exclude: - - 'lib/axlsx/stylesheet/font.rb' - - 'lib/axlsx/util/validators.rb' - - 'lib/axlsx/workbook/worksheet/rich_text_run.rb' - # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: PreferredDelimiters. Style/PercentLiteralDelimiters: @@ -370,19 +362,6 @@ Style/RedundantInterpolation: - 'lib/axlsx/workbook/worksheet/table.rb' - 'lib/axlsx/workbook/worksheet/worksheet.rb' -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantParentheses: - Exclude: - - 'lib/axlsx/drawing/area_series.rb' - - 'lib/axlsx/drawing/bar_3D_chart.rb' - - 'lib/axlsx/drawing/bar_chart.rb' - - 'lib/axlsx/drawing/line_3D_chart.rb' - - 'lib/axlsx/drawing/line_series.rb' - - 'lib/axlsx/drawing/scatter_series.rb' - - 'lib/axlsx/package.rb' - - 'lib/axlsx/workbook/worksheet/pivot_table.rb' - - 'lib/axlsx/workbook/worksheet/worksheet.rb' - # This cop supports safe autocorrection (--autocorrect). Style/RedundantRegexpEscape: Exclude: @@ -429,16 +408,6 @@ Style/StringLiterals: Style/SymbolArray: EnforcedStyle: brackets -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, AllowSafeAssignment. -# SupportedStyles: require_parentheses, require_no_parentheses, require_parentheses_when_complex -Style/TernaryParentheses: - Exclude: - - 'lib/axlsx/drawing/area_series.rb' - - 'lib/axlsx/drawing/line_series.rb' - - 'lib/axlsx/drawing/scatter_series.rb' - - 'lib/axlsx/workbook/worksheet/rich_text_run.rb' - # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, IgnoreClassMethods, AllowedMethods. # AllowedMethods: to_ary, to_a, to_c, to_enum, to_h, to_hash, to_i, to_int, to_io, to_open, to_path, to_proc, to_r, to_regexp, to_str, to_s, to_sym diff --git a/lib/axlsx/drawing/area_series.rb b/lib/axlsx/drawing/area_series.rb index c43fe929..30bd9402 100644 --- a/lib/axlsx/drawing/area_series.rb +++ b/lib/axlsx/drawing/area_series.rb @@ -94,7 +94,7 @@ module Axlsx @labels.to_xml_string(str) unless @labels.nil? @data.to_xml_string(str) unless @data.nil? - str << '' + str << '' end end diff --git a/lib/axlsx/drawing/bar_3D_chart.rb b/lib/axlsx/drawing/bar_3D_chart.rb index 604a9d17..4b688668 100644 --- a/lib/axlsx/drawing/bar_3D_chart.rb +++ b/lib/axlsx/drawing/bar_3D_chart.rb @@ -99,14 +99,14 @@ module Axlsx # space between bar or column clusters, as a percentage of the bar or column width. def gap_width=(v) RangeValidator.validate "Bar3DChart.gap_width", 0, 500, v - @gap_width = (v) + @gap_width = v end alias :gapWidth= :gap_width= # space between bar or column clusters, as a percentage of the bar or column width. def gap_depth=(v) RangeValidator.validate "Bar3DChart.gap_depth", 0, 500, v - @gap_depth = (v) + @gap_depth = v end alias :gapDepth= :gap_depth= diff --git a/lib/axlsx/drawing/bar_chart.rb b/lib/axlsx/drawing/bar_chart.rb index 87fd66c0..0dcf2c11 100644 --- a/lib/axlsx/drawing/bar_chart.rb +++ b/lib/axlsx/drawing/bar_chart.rb @@ -91,13 +91,13 @@ module Axlsx # space between bar or column clusters, as a percentage of the bar or column width. def gap_width=(v) RangeValidator.validate "BarChart.gap_width", 0, 500, v - @gap_width = (v) + @gap_width = v end alias :gapWidth= :gap_width= def overlap=(v) RangeValidator.validate "BarChart.overlap", -100, 100, v - @overlap = (v) + @overlap = v end # The shape of the bars or columns diff --git a/lib/axlsx/drawing/line_3D_chart.rb b/lib/axlsx/drawing/line_3D_chart.rb index 024ece0a..54f0170f 100644 --- a/lib/axlsx/drawing/line_3D_chart.rb +++ b/lib/axlsx/drawing/line_3D_chart.rb @@ -50,7 +50,7 @@ module Axlsx # @see gapDepth def gap_depth=(v) RegexValidator.validate "Line3DChart.gapWidth", GAP_AMOUNT_PERCENT, v - @gap_depth = (v) + @gap_depth = v end alias :gapDepth= :gap_depth= diff --git a/lib/axlsx/drawing/line_series.rb b/lib/axlsx/drawing/line_series.rb index d6a412e4..9f8e09e3 100644 --- a/lib/axlsx/drawing/line_series.rb +++ b/lib/axlsx/drawing/line_series.rb @@ -94,7 +94,7 @@ module Axlsx @labels.to_xml_string(str) unless @labels.nil? @data.to_xml_string(str) unless @data.nil? - str << '' + str << '' end end diff --git a/lib/axlsx/drawing/scatter_series.rb b/lib/axlsx/drawing/scatter_series.rb index 2838c3de..a287a112 100644 --- a/lib/axlsx/drawing/scatter_series.rb +++ b/lib/axlsx/drawing/scatter_series.rb @@ -110,7 +110,7 @@ module Axlsx end @xData.to_xml_string(str) unless @xData.nil? @yData.to_xml_string(str) unless @yData.nil? - str << '' + str << '' end str end diff --git a/lib/axlsx/package.rb b/lib/axlsx/package.rb index 26f838f8..295ff2eb 100644 --- a/lib/axlsx/package.rb +++ b/lib/axlsx/package.rb @@ -266,7 +266,7 @@ module Axlsx [ { entry: CONTENT_TYPES_PN, doc: content_types, schema: CONTENT_TYPES_XSD }, { entry: RELS_PN, doc: relationships, schema: RELS_XSD }, - *(parts.sort_by { |part| part[:entry] }.reverse) + *parts.sort_by { |part| part[:entry] }.reverse ] end diff --git a/lib/axlsx/stylesheet/font.rb b/lib/axlsx/stylesheet/font.rb index 8b183b6e..2d9647af 100644 --- a/lib/axlsx/stylesheet/font.rb +++ b/lib/axlsx/stylesheet/font.rb @@ -124,8 +124,8 @@ module Axlsx # @see u def u=(v) - v = :single if (v == true || v == 1 || v == :true || v == 'true') - v = :none if (v == false || v == 0 || v == :false || v == 'false') + v = :single if v == true || v == 1 || v == :true || v == 'true' + v = :none if v == false || v == 0 || v == :false || v == 'false' Axlsx::validate_cell_u v @u = v end diff --git a/lib/axlsx/util/validators.rb b/lib/axlsx/util/validators.rb index 695d28ad..48c12c13 100644 --- a/lib/axlsx/util/validators.rb +++ b/lib/axlsx/util/validators.rb @@ -41,7 +41,7 @@ module Axlsx # @param [Regexp] regex The regular expression to evaluate # @param [Any] v The value to validate. def self.validate(name, regex, v) - raise ArgumentError, (ERR_REGEX % [v.inspect, regex.to_s]) unless (v.respond_to?(:to_s) && regex.match?(v.to_s)) + raise ArgumentError, (ERR_REGEX % [v.inspect, regex.to_s]) unless v.respond_to?(:to_s) && regex.match?(v.to_s) end end @@ -71,7 +71,7 @@ module Axlsx # @para, [Any] v the value to validate # @raise [ArgumentError] raised if the value cannot be converted to an integer def self.validate_integerish(v) - raise ArgumentError, (ERR_INTEGERISH % v.inspect) unless (v.respond_to?(:to_i) && v.to_i.is_a?(Integer)) + raise ArgumentError, (ERR_INTEGERISH % v.inspect) unless v.respond_to?(:to_i) && v.to_i.is_a?(Integer) end # Requires that the value is between -54000000 and 54000000 @@ -79,7 +79,7 @@ module Axlsx # @raise [ArgumentError] raised if the value cannot be converted to an integer between the allowed angle values for chart label rotation. # @return [Boolean] true if the data is valid def self.validate_angle(v) - raise ArgumentError, (ERR_ANGLE % v.inspect) unless (v.to_i >= -5400000 && v.to_i <= 5400000) + raise ArgumentError, (ERR_ANGLE % v.inspect) unless v.to_i >= -5400000 && v.to_i <= 5400000 end # Validates an unsigned intger diff --git a/lib/axlsx/workbook/worksheet/pivot_table.rb b/lib/axlsx/workbook/worksheet/pivot_table.rb index a75842cd..aca3ccb5 100644 --- a/lib/axlsx/workbook/worksheet/pivot_table.rb +++ b/lib/axlsx/workbook/worksheet/pivot_table.rb @@ -245,7 +245,7 @@ module Axlsx str << "" data.each do |datum_value| # The correct name prefix in ["Sum","Average", etc...] - str << "" diff --git a/lib/axlsx/workbook/worksheet/rich_text_run.rb b/lib/axlsx/workbook/worksheet/rich_text_run.rb index 9f66959a..dac27752 100644 --- a/lib/axlsx/workbook/worksheet/rich_text_run.rb +++ b/lib/axlsx/workbook/worksheet/rich_text_run.rb @@ -130,7 +130,7 @@ module Axlsx # @see u def u=(v) - v = :single if (v == true || v == 1 || v == :true || v == 'true') + v = :single if v == true || v == 1 || v == :true || v == 'true' set_run_style :validate_cell_u, :u, v end @@ -242,7 +242,7 @@ module Axlsx return sz if sz font = styles.fonts[styles.cellXfs[style].fontId] || styles.fonts[0] - (font.b || (defined?(@b) && @b)) ? (font.sz * 1.5) : font.sz + font.b || (defined?(@b) && @b) ? (font.sz * 1.5) : font.sz end def style diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index 90461c66..f2587edb 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -753,7 +753,7 @@ module Axlsx def validate_sheet_name(name) DataTypeValidator.validate :worksheet_name, String, name # ignore first character (BOM) after encoding to utf16 because Excel does so, too. - raise ArgumentError, (ERR_SHEET_NAME_EMPTY) if name.empty? + raise ArgumentError, ERR_SHEET_NAME_EMPTY if name.empty? character_length = name.encode("utf-16")[1..-1].encode("utf-16").bytesize / 2 raise ArgumentError, (ERR_SHEET_NAME_TOO_LONG % name) if character_length > WORKSHEET_MAX_NAME_LENGTH -- cgit v1.2.3