diff options
| author | Zsolt Kozaroczy <[email protected]> | 2023-05-04 09:08:36 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-05-04 09:08:36 +0200 |
| commit | 679c2d435037291e331e1f4c7d06342d76856fde (patch) | |
| tree | 076ea47e1644fe37909d2438d9dc3c97ca50ef5c | |
| parent | aaf88bd98054b1823ba0ade4b883b84e41b5e947 (diff) | |
| parent | 6a61caa26ef8e8fbe3a88ecd9341976e5a177db5 (diff) | |
| download | caxlsx-679c2d435037291e331e1f4c7d06342d76856fde.tar.gz caxlsx-679c2d435037291e331e1f4c7d06342d76856fde.zip | |
Merge pull request #215 from tagliala/chore/fix-minor-safe-offenses-to-production-code
Fix safe, minor offenses to production code
| -rw-r--r-- | .rubocop.yml | 3 | ||||
| -rw-r--r-- | .rubocop_todo.yml | 57 | ||||
| -rw-r--r-- | lib/axlsx/drawing/axis.rb | 6 | ||||
| -rw-r--r-- | lib/axlsx/drawing/chart.rb | 4 | ||||
| -rw-r--r-- | lib/axlsx/drawing/view_3D.rb | 4 | ||||
| -rw-r--r-- | lib/axlsx/package.rb | 6 | ||||
| -rw-r--r-- | lib/axlsx/stylesheet/styles.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/util/simple_typed_list.rb | 6 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/auto_filter/filters.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/cell.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/rich_text_run.rb | 4 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/sheet_protection.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/worksheet.rb | 6 |
13 files changed, 25 insertions, 79 deletions
diff --git a/.rubocop.yml b/.rubocop.yml index d64b3394..c5452382 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -33,6 +33,9 @@ Minitest: Style: Enabled: true +Style/Semicolon: + AllowAsExpressionSeparator: true + Style/NumericLiterals: Exclude: - 'lib/**/*' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 0f609d00..1f4fc376 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -72,13 +72,6 @@ Lint/NonLocalExitFromIterator: - 'lib/axlsx/util/validators.rb' # This cop supports safe autocorrection (--autocorrect). -Lint/RedundantStringCoercion: - Exclude: - - 'lib/axlsx/workbook/worksheet/auto_filter/filters.rb' - - 'lib/axlsx/workbook/worksheet/cell.rb' - - 'lib/axlsx/workbook/worksheet/rich_text_run.rb' - -# This cop supports safe autocorrection (--autocorrect). # Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments. Lint/UnusedBlockArgument: Exclude: @@ -161,15 +154,6 @@ Style/ClassVars: Style/ColonMethodCall: Enabled: false -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: Keywords, RequireColon. -# Keywords: TODO, FIXME, OPTIMIZE, HACK, REVIEW, NOTE -Style/CommentAnnotation: - Exclude: - - 'lib/axlsx/drawing/axis.rb' - - 'lib/axlsx/drawing/chart.rb' - - 'lib/axlsx/drawing/view_3D.rb' - # This cop supports unsafe autocorrection (--autocorrect-all). Style/ConcatArrayLiterals: Exclude: @@ -186,11 +170,6 @@ Style/ConditionalAssignment: - 'lib/axlsx/workbook/worksheet/data_bar.rb' - 'lib/axlsx/workbook/worksheet/rich_text_run.rb' -# This cop supports safe autocorrection (--autocorrect). -Style/DefWithParentheses: - Exclude: - - 'lib/axlsx/stylesheet/styles.rb' - Style/DocumentDynamicEvalDefinition: Exclude: - 'lib/axlsx/util/simple_typed_list.rb' @@ -212,11 +191,6 @@ Style/Documentation: - 'lib/axlsx/workbook/worksheet/sheet_format_pr.rb' # This cop supports safe autocorrection (--autocorrect). -Style/EvalWithLocation: - Exclude: - - 'lib/axlsx/util/simple_typed_list.rb' - -# This cop supports safe autocorrection (--autocorrect). Style/ExpandPathArguments: Exclude: - 'axlsx.gemspec' @@ -322,21 +296,6 @@ Style/LineEndConcatenation: - 'lib/axlsx/package.rb' # This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowedMethods, AllowedPatterns. -Style/MethodCallWithoutArgsParentheses: - Exclude: - - 'lib/axlsx/package.rb' - -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: require_parentheses, require_no_parentheses, require_no_parentheses_except_multiline -Style/MethodDefParentheses: - Exclude: - - 'lib/axlsx/util/simple_typed_list.rb' - - 'lib/axlsx/workbook/worksheet/rich_text_run.rb' - - 'lib/axlsx/workbook/worksheet/worksheet.rb' - -# This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowMethodComparison. Style/MultipleComparison: Exclude: @@ -389,17 +348,6 @@ Style/Next: - 'lib/axlsx/stylesheet/styles.rb' # This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: predicate, comparison -Style/NilComparison: - Exclude: - - 'lib/axlsx/drawing/axis.rb' - - 'lib/axlsx/drawing/chart.rb' - - 'lib/axlsx/drawing/view_3D.rb' - - 'lib/axlsx/workbook/worksheet/sheet_protection.rb' - - 'lib/axlsx/workbook/worksheet/worksheet.rb' - -# This cop supports safe autocorrection (--autocorrect). # Configuration parameters: IncludeSemanticChanges. Style/NonNilCheck: Exclude: @@ -608,11 +556,6 @@ Style/SelfAssignment: - 'lib/axlsx/stylesheet/color.rb' # This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowAsExpressionSeparator. -Style/Semicolon: - Enabled: false - -# This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowIfMethodIsEmpty. Style/SingleLineMethods: Enabled: false diff --git a/lib/axlsx/drawing/axis.rb b/lib/axlsx/drawing/axis.rb index 9ca03fb1..601a7c85 100644 --- a/lib/axlsx/drawing/axis.rb +++ b/lib/axlsx/drawing/axis.rb @@ -152,7 +152,7 @@ module Axlsx str << ('<c:delete val="' << @delete.to_s << '"/>') str << ('<c:axPos val="' << @ax_pos.to_s << '"/>') str << '<c:majorGridlines>' - # TODO shape properties need to be extracted into a class + # TODO: shape properties need to be extracted into a class if gridlines == false str << '<c:spPr>' str << '<a:ln>' @@ -161,7 +161,7 @@ module Axlsx str << '</c:spPr>' end str << '</c:majorGridlines>' - @title.to_xml_string(str) unless @title == nil + @title.to_xml_string(str) unless @title.nil? # Need to set sourceLinked to 0 if we're setting a format code on this row # otherwise it will never take, as it will always prefer the 'General' formatting # of the cells themselves @@ -169,7 +169,7 @@ module Axlsx str << '<c:majorTickMark val="none"/>' str << '<c:minorTickMark val="none"/>' str << ('<c:tickLblPos val="' << @tick_lbl_pos.to_s << '"/>') - # TODO - this is also being used for series colors + # TODO: this is also being used for series colors # time to extract this into a class spPr - Shape Properties if @color str << '<c:spPr><a:ln><a:solidFill>' diff --git a/lib/axlsx/drawing/chart.rb b/lib/axlsx/drawing/chart.rb index e9f4441f..0c68ff4b 100644 --- a/lib/axlsx/drawing/chart.rb +++ b/lib/axlsx/drawing/chart.rb @@ -49,7 +49,7 @@ module Axlsx # @return [Series] attr_reader :series_type - # TODO data labels! + # TODO: data labels! def d_lbls @d_lbls ||= DLbls.new(self.class) end @@ -210,7 +210,7 @@ module Axlsx str << ('<c:style val="' << style.to_s << '"/>') str << '<c:chart>' @title.to_xml_string(str) unless @title.empty? - str << ('<c:autoTitleDeleted val="' << (@title == nil).to_s << '"/>') + str << ('<c:autoTitleDeleted val="' << @title.nil?.to_s << '"/>') @view_3D.to_xml_string(str) if @view_3D str << '<c:floor><c:thickness val="0"/></c:floor>' str << '<c:sideWall><c:thickness val="0"/></c:sideWall>' diff --git a/lib/axlsx/drawing/view_3D.rb b/lib/axlsx/drawing/view_3D.rb index 1f701f32..ff26deb9 100644 --- a/lib/axlsx/drawing/view_3D.rb +++ b/lib/axlsx/drawing/view_3D.rb @@ -104,10 +104,10 @@ module Axlsx private - # Note: move this to Axlsx module if we find the smae pattern elsewhere. + # NOTE: move this to Axlsx module if we find the same pattern elsewhere. def element_for_attribute(name, namespace = '') val = Axlsx.instance_values_for(self)[name] - return "" if val == nil + return "" if val.nil? "<%s:%s val='%s'/>" % [namespace, Axlsx::camel(name, false), val] end diff --git a/lib/axlsx/package.rb b/lib/axlsx/package.rb index b61c3de1..f22ad2ac 100644 --- a/lib/axlsx/package.rb +++ b/lib/axlsx/package.rb @@ -31,7 +31,7 @@ module Axlsx # Shortcut to specify that the workbook should use autowidth # @see Workbook#use_autowidth def use_autowidth=(v) - Axlsx::validate_boolean(v); + Axlsx::validate_boolean(v) workbook.use_autowidth = v end @@ -44,7 +44,7 @@ module Axlsx # Shortcut to specify that the workbook should use shared strings # @see Workbook#use_shared_strings def use_shared_strings=(v) - Axlsx::validate_boolean(v); + Axlsx::validate_boolean(v) workbook.use_shared_strings = v end @@ -347,7 +347,7 @@ module Axlsx # @return [ContentType] # @private def base_content_types - c_types = ContentType.new() + c_types = ContentType.new c_types << Default.new(:ContentType => RELS_CT, :Extension => RELS_EX) c_types << Default.new(:Extension => XML_EX, :ContentType => XML_CT) c_types << Override.new(:PartName => "/#{APP_PN}", :ContentType => APP_CT) diff --git a/lib/axlsx/stylesheet/styles.rb b/lib/axlsx/stylesheet/styles.rb index ca2c7a8c..3b462d37 100644 --- a/lib/axlsx/stylesheet/styles.rb +++ b/lib/axlsx/stylesheet/styles.rb @@ -115,7 +115,7 @@ module Axlsx attr_reader :tableStyles # Creates a new Styles object and prepopulates it with the requires objects to generate a valid package style part. - def initialize() + def initialize load_default_styles end diff --git a/lib/axlsx/util/simple_typed_list.rb b/lib/axlsx/util/simple_typed_list.rb index 51b8a8d5..59b25564 100644 --- a/lib/axlsx/util/simple_typed_list.rb +++ b/lib/axlsx/util/simple_typed_list.rb @@ -6,7 +6,7 @@ module Axlsx # @param [Array, Class] type An array of Class objects or a single Class object # @param [String] serialize_as The tag name to use in serialization # @raise [ArgumentError] if all members of type are not Class objects - def initialize type, serialize_as = nil, start_size = 0 + def initialize(type, serialize_as = nil, start_size = 0) if type.is_a? Array type.each { |item| raise ArgumentError, "All members of type must be Class objects" unless item.is_a? Class } @allowed_types = type @@ -149,7 +149,7 @@ module Axlsx # determines if the index is protected # @param [Integer] index - def protected? index + def protected?(index) return false unless locked_at.is_a? Integer index < locked_at @@ -166,7 +166,7 @@ module Axlsx def #{method}(*args, &block) @list.send(:#{method}, *args, &block) end - } + }, __FILE__, __LINE__ - 4 end def to_xml_string(str = '') diff --git a/lib/axlsx/workbook/worksheet/auto_filter/filters.rb b/lib/axlsx/workbook/worksheet/auto_filter/filters.rb index 83da2da2..90a5ff48 100644 --- a/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +++ b/lib/axlsx/workbook/worksheet/auto_filter/filters.rb @@ -119,7 +119,7 @@ module Axlsx # Serializes the filter value object # @param [String] str The string to concact the serialization information to. def to_xml_string(str = '') - str << "<filter val='#{@val.to_s}' />" + str << "<filter val='#{@val}' />" end end diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb index 508e9dd8..13c762ef 100644 --- a/lib/axlsx/workbook/worksheet/cell.rb +++ b/lib/axlsx/workbook/worksheet/cell.rb @@ -481,7 +481,7 @@ module Axlsx return unless INLINE_STYLES.include?(attr.to_sym) Axlsx.send(validator, value) unless validator.nil? - self.instance_variable_set :"@#{attr.to_s}", value + self.instance_variable_set :"@#{attr}", value @is_text_run = true end diff --git a/lib/axlsx/workbook/worksheet/rich_text_run.rb b/lib/axlsx/workbook/worksheet/rich_text_run.rb index 78639575..f9d2932f 100644 --- a/lib/axlsx/workbook/worksheet/rich_text_run.rb +++ b/lib/axlsx/workbook/worksheet/rich_text_run.rb @@ -197,7 +197,7 @@ module Axlsx return unless INLINE_STYLES.include?(attr.to_sym) Axlsx.send(validator, value) unless validator.nil? - self.instance_variable_set :"@#{attr.to_s}", value + self.instance_variable_set :"@#{attr}", value end # Serializes the RichTextRun @@ -253,7 +253,7 @@ module Axlsx # Converts the value to the correct XML representation (fixes issues with # Numbers) - def xml_value value + def xml_value(value) if value == true 1 elsif value == false diff --git a/lib/axlsx/workbook/worksheet/sheet_protection.rb b/lib/axlsx/workbook/worksheet/sheet_protection.rb index 7433d5bb..42d74695 100644 --- a/lib/axlsx/workbook/worksheet/sheet_protection.rb +++ b/lib/axlsx/workbook/worksheet/sheet_protection.rb @@ -65,7 +65,7 @@ module Axlsx # encodes password for protection locking def password=(v) - return if v == nil + return if v.nil? @password = create_password_hash(v) end diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index b4cad5be..1fb55ff2 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -544,9 +544,9 @@ module Axlsx # @param [Integer|Float|nil] widths def column_widths(*widths) widths.each_with_index do |value, index| - next if value == nil + next if value.nil? - Axlsx::validate_unsigned_numeric(value) unless value == nil + Axlsx::validate_unsigned_numeric(value) unless value.nil? find_or_create_column_info(index).width = value end end @@ -637,7 +637,7 @@ module Axlsx # Serializes the worksheet object to an xml string # This intentionally does not use nokogiri for performance reasons # @return [String] - def to_xml_string str = '' + def to_xml_string(str = '') add_autofilter_defined_name_to_workbook auto_filter.apply if auto_filter.range str << '<?xml version="1.0" encoding="UTF-8"?>' |
