murb/workbook

View on GitHub
lib/workbook/writers/xls_writer.rb

Summary

Maintainability
B
6 hrs
Test Coverage

Module has too many lines. [110/100]
Open

    module XlsWriter
      # Generates an Spreadsheet (from the spreadsheet gem) in order to build an xls
      #
      # @param [Hash] options A hash with options (unused so far)
      # @return [Spreadsheet] A Spreadsheet object, ready for writing or more lower level operations
Severity: Minor
Found in lib/workbook/writers/xls_writer.rb by rubocop

This cop checks if the length a module exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

You can set literals you want to fold with CountAsOne. Available are: 'array', 'hash', and 'heredoc'. Each literal will be counted as one line regardless of its actual size.

Example: CountAsOne: ['array', 'heredoc']

module M
  ARRAY = [         # +1
    1,
    2
  ]

  HASH = {          # +3
    key: 'value'
  }

  MSG = <<~HEREDOC  # +1
    Heredoc
    content.
  HEREDOC
end                 # 5 points

Method has too many lines. [36/10]
Open

      def to_xls options = {}
        book = init_spreadsheet_template
        each_with_index do |s, si|
          xls_sheet = xls_sheet(si)
          xls_sheet.name = s.name
Severity: Minor
Found in lib/workbook/writers/xls_writer.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

You can set literals you want to fold with CountAsOne. Available are: 'array', 'hash', and 'heredoc'. Each literal will be counted as one line regardless of its actual size.

NOTE: The ExcludedMethods configuration is deprecated and only kept for backwards compatibility. Please use IgnoredMethods instead.

Example: CountAsOne: ['array', 'heredoc']

def m
  array = [       # +1
    1,
    2
  ]

  hash = {        # +3
    key: 'value'
  }

  <<~HEREDOC      # +1
    Heredoc
    content.
  HEREDOC
end               # 5 points

Method format_to_xls_format has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

      def format_to_xls_format f
        unless f.is_a? Workbook::Format
          f = Workbook::Format.new f
        end
        xlsfmt = f.return_raw_for Spreadsheet::Format
Severity: Minor
Found in lib/workbook/writers/xls_writer.rb - About 2 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method has too many lines. [18/10]
Open

      def format_to_xls_format f
        unless f.is_a? Workbook::Format
          f = Workbook::Format.new f
        end
        xlsfmt = f.return_raw_for Spreadsheet::Format
Severity: Minor
Found in lib/workbook/writers/xls_writer.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

You can set literals you want to fold with CountAsOne. Available are: 'array', 'hash', and 'heredoc'. Each literal will be counted as one line regardless of its actual size.

NOTE: The ExcludedMethods configuration is deprecated and only kept for backwards compatibility. Please use IgnoredMethods instead.

Example: CountAsOne: ['array', 'heredoc']

def m
  array = [       # +1
    1,
    2
  ]

  hash = {        # +3
    key: 'value'
  }

  <<~HEREDOC      # +1
    Heredoc
    content.
  HEREDOC
end               # 5 points

Method has too many lines. [16/10]
Open

      def parse_font_family(format)
        font = format[:font_family].to_s.split.last
        valid_values = [:none, :roman, :swiss, :modern, :script, :decorative]
        if valid_values.include?(font)
          font
Severity: Minor
Found in lib/workbook/writers/xls_writer.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

You can set literals you want to fold with CountAsOne. Available are: 'array', 'hash', and 'heredoc'. Each literal will be counted as one line regardless of its actual size.

NOTE: The ExcludedMethods configuration is deprecated and only kept for backwards compatibility. Please use IgnoredMethods instead.

Example: CountAsOne: ['array', 'heredoc']

def m
  array = [       # +1
    1,
    2
  ]

  hash = {        # +3
    key: 'value'
  }

  <<~HEREDOC      # +1
    Heredoc
    content.
  HEREDOC
end               # 5 points

Cyclomatic complexity for format_to_xls_format is too high. [11/7]
Open

      def format_to_xls_format f
        unless f.is_a? Workbook::Format
          f = Workbook::Format.new f
        end
        xlsfmt = f.return_raw_for Spreadsheet::Format
Severity: Minor
Found in lib/workbook/writers/xls_writer.rb by rubocop

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one. Blocks that are calls to builtin iteration methods (e.g. `ary.map{...}) also add one, others are ignored.

def each_child_node(*types)               # count begins: 1
  unless block_given?                     # unless: +1
    return to_enum(__method__, *types)

  children.each do |child|                # each{}: +1
    next unless child.is_a?(Node)         # unless: +1

    yield child if types.empty? ||        # if: +1, ||: +1
                   types.include?(child.type)
  end

  self
end                                       # total: 6

Method to_xls has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

      def to_xls options = {}
        book = init_spreadsheet_template
        each_with_index do |s, si|
          xls_sheet = xls_sheet(si)
          xls_sheet.name = s.name
Severity: Minor
Found in lib/workbook/writers/xls_writer.rb - About 2 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Cyclomatic complexity for to_xls is too high. [10/7]
Open

      def to_xls options = {}
        book = init_spreadsheet_template
        each_with_index do |s, si|
          xls_sheet = xls_sheet(si)
          xls_sheet.name = s.name
Severity: Minor
Found in lib/workbook/writers/xls_writer.rb by rubocop

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one. Blocks that are calls to builtin iteration methods (e.g. `ary.map{...}) also add one, others are ignored.

def each_child_node(*types)               # count begins: 1
  unless block_given?                     # unless: +1
    return to_enum(__method__, *types)

  children.each do |child|                # each{}: +1
    next unless child.is_a?(Node)         # unless: +1

    yield child if types.empty? ||        # if: +1, ||: +1
                   types.include?(child.type)
  end

  self
end                                       # total: 6

Perceived complexity for format_to_xls_format is too high. [11/8]
Open

      def format_to_xls_format f
        unless f.is_a? Workbook::Format
          f = Workbook::Format.new f
        end
        xlsfmt = f.return_raw_for Spreadsheet::Format
Severity: Minor
Found in lib/workbook/writers/xls_writer.rb by rubocop

This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points

Perceived complexity for to_xls is too high. [11/8]
Open

      def to_xls options = {}
        book = init_spreadsheet_template
        each_with_index do |s, si|
          xls_sheet = xls_sheet(si)
          xls_sheet.name = s.name
Severity: Minor
Found in lib/workbook/writers/xls_writer.rb by rubocop

This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points

Method to_xls has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def to_xls options = {}
        book = init_spreadsheet_template
        each_with_index do |s, si|
          xls_sheet = xls_sheet(si)
          xls_sheet.name = s.name
Severity: Minor
Found in lib/workbook/writers/xls_writer.rb - About 1 hr to fix

    Assignment Branch Condition size for format_to_xls_format is too high. [<12, 38, 10> 41.09/17]
    Open

          def format_to_xls_format f
            unless f.is_a? Workbook::Format
              f = Workbook::Format.new f
            end
            xlsfmt = f.return_raw_for Spreadsheet::Format
    Severity: Minor
    Found in lib/workbook/writers/xls_writer.rb by rubocop

    This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric and https://en.wikipedia.org/wiki/ABC_Software_Metric.

    Interpreting ABC size:

    • <= 17 satisfactory
    • 18..30 unsatisfactory
    • > 30 dangerous

    You can have repeated "attributes" calls count as a single "branch". For this purpose, attributes are any method with no argument; no attempt is meant to distinguish actual attr_reader from other methods.

    Example: CountRepeatedAttributes: false (default is true)

    # `model` and `current_user`, refenced 3 times each,
     # are each counted as only 1 branch each if
     # `CountRepeatedAttributes` is set to 'false'
    
     def search
       @posts = model.active.visible_by(current_user)
                 .search(params[:q])
       @posts = model.some_process(@posts, current_user)
       @posts = model.another_process(@posts, current_user)
    
       render 'pages/search/page'
     end

    This cop also takes into account IgnoredMethods (defaults to [])

    Assignment Branch Condition size for parse_font_family is too high. [<5, 16, 4> 17.23/17]
    Open

          def parse_font_family(format)
            font = format[:font_family].to_s.split.last
            valid_values = [:none, :roman, :swiss, :modern, :script, :decorative]
            if valid_values.include?(font)
              font
    Severity: Minor
    Found in lib/workbook/writers/xls_writer.rb by rubocop

    This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric and https://en.wikipedia.org/wiki/ABC_Software_Metric.

    Interpreting ABC size:

    • <= 17 satisfactory
    • 18..30 unsatisfactory
    • > 30 dangerous

    You can have repeated "attributes" calls count as a single "branch". For this purpose, attributes are any method with no argument; no attempt is meant to distinguish actual attr_reader from other methods.

    Example: CountRepeatedAttributes: false (default is true)

    # `model` and `current_user`, refenced 3 times each,
     # are each counted as only 1 branch each if
     # `CountRepeatedAttributes` is set to 'false'
    
     def search
       @posts = model.active.visible_by(current_user)
                 .search(params[:q])
       @posts = model.some_process(@posts, current_user)
       @posts = model.another_process(@posts, current_user)
    
       render 'pages/search/page'
     end

    This cop also takes into account IgnoredMethods (defaults to [])

    Assignment Branch Condition size for to_xls is too high. [<22, 53, 10> 58.25/17]
    Open

          def to_xls options = {}
            book = init_spreadsheet_template
            each_with_index do |s, si|
              xls_sheet = xls_sheet(si)
              xls_sheet.name = s.name
    Severity: Minor
    Found in lib/workbook/writers/xls_writer.rb by rubocop

    This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric and https://en.wikipedia.org/wiki/ABC_Software_Metric.

    Interpreting ABC size:

    • <= 17 satisfactory
    • 18..30 unsatisfactory
    • > 30 dangerous

    You can have repeated "attributes" calls count as a single "branch". For this purpose, attributes are any method with no argument; no attempt is meant to distinguish actual attr_reader from other methods.

    Example: CountRepeatedAttributes: false (default is true)

    # `model` and `current_user`, refenced 3 times each,
     # are each counted as only 1 branch each if
     # `CountRepeatedAttributes` is set to 'false'
    
     def search
       @posts = model.active.visible_by(current_user)
                 .search(params[:q])
       @posts = model.some_process(@posts, current_user)
       @posts = model.another_process(@posts, current_user)
    
       render 'pages/search/page'
     end

    This cop also takes into account IgnoredMethods (defaults to [])

    Line is too long. [188/120]
    Open

          # @param [Workbook::Format, Hash] f A Workbook::Format or hash with format-options (:font_weight, :rotation, :background_color, :number_format, :text_direction, :color, :font_family)
    Severity: Minor
    Found in lib/workbook/writers/xls_writer.rb by rubocop

    This cop checks the length of lines in the source code. The maximum length is configurable. The tab size is configured in the IndentationWidth of the Layout/IndentationStyle cop. It also ignores a shebang line by default.

    This cop has some autocorrection capabilities. It can programmatically shorten certain long lines by inserting line breaks into expressions that can be safely split across lines. These include arrays, hashes, and method calls with argument lists.

    If autocorrection is enabled, the following Layout cops are recommended to further format the broken lines. (Many of these are enabled by default.)

    • ArgumentAlignment
    • BlockAlignment
    • BlockDelimiters
    • BlockEndNewline
    • ClosingParenthesisIndentation
    • FirstArgumentIndentation
    • FirstArrayElementIndentation
    • FirstHashElementIndentation
    • FirstParameterIndentation
    • HashAlignment
    • IndentationWidth
    • MultilineArrayLineBreaks
    • MultilineBlockLayout
    • MultilineHashBraceLayout
    • MultilineHashKeyLineBreaks
    • MultilineMethodArgumentLineBreaks
    • ParameterAlignment

    Together, these cops will pretty print hashes, arrays, method calls, etc. For example, let's say the max columns is 25:

    Example:

    # bad
    {foo: "0000000000", bar: "0000000000", baz: "0000000000"}
    
    # good
    {foo: "0000000000",
    bar: "0000000000", baz: "0000000000"}
    
    # good (with recommended cops enabled)
    {
      foo: "0000000000",
      bar: "0000000000",
      baz: "0000000000",
    }

    Line is too long. [130/120]
    Open

              xlsfmt.pattern_fg_color = html_color_to_xls_color(f[:background_color]) if html_color_to_xls_color(f[:background_color])
    Severity: Minor
    Found in lib/workbook/writers/xls_writer.rb by rubocop

    This cop checks the length of lines in the source code. The maximum length is configurable. The tab size is configured in the IndentationWidth of the Layout/IndentationStyle cop. It also ignores a shebang line by default.

    This cop has some autocorrection capabilities. It can programmatically shorten certain long lines by inserting line breaks into expressions that can be safely split across lines. These include arrays, hashes, and method calls with argument lists.

    If autocorrection is enabled, the following Layout cops are recommended to further format the broken lines. (Many of these are enabled by default.)

    • ArgumentAlignment
    • BlockAlignment
    • BlockDelimiters
    • BlockEndNewline
    • ClosingParenthesisIndentation
    • FirstArgumentIndentation
    • FirstArrayElementIndentation
    • FirstHashElementIndentation
    • FirstParameterIndentation
    • HashAlignment
    • IndentationWidth
    • MultilineArrayLineBreaks
    • MultilineBlockLayout
    • MultilineHashBraceLayout
    • MultilineHashKeyLineBreaks
    • MultilineMethodArgumentLineBreaks
    • ParameterAlignment

    Together, these cops will pretty print hashes, arrays, method calls, etc. For example, let's say the max columns is 25:

    Example:

    # bad
    {foo: "0000000000", bar: "0000000000", baz: "0000000000"}
    
    # good
    {foo: "0000000000",
    bar: "0000000000", baz: "0000000000"}
    
    # good (with recommended cops enabled)
    {
      foo: "0000000000",
      bar: "0000000000",
      baz: "0000000000",
    }

    Line is too long. [124/120]
    Open

            # even after removing the worksheet's content... which solved some incompatibilities, but not for popping worksheets
    Severity: Minor
    Found in lib/workbook/writers/xls_writer.rb by rubocop

    This cop checks the length of lines in the source code. The maximum length is configurable. The tab size is configured in the IndentationWidth of the Layout/IndentationStyle cop. It also ignores a shebang line by default.

    This cop has some autocorrection capabilities. It can programmatically shorten certain long lines by inserting line breaks into expressions that can be safely split across lines. These include arrays, hashes, and method calls with argument lists.

    If autocorrection is enabled, the following Layout cops are recommended to further format the broken lines. (Many of these are enabled by default.)

    • ArgumentAlignment
    • BlockAlignment
    • BlockDelimiters
    • BlockEndNewline
    • ClosingParenthesisIndentation
    • FirstArgumentIndentation
    • FirstArrayElementIndentation
    • FirstHashElementIndentation
    • FirstParameterIndentation
    • HashAlignment
    • IndentationWidth
    • MultilineArrayLineBreaks
    • MultilineBlockLayout
    • MultilineHashBraceLayout
    • MultilineHashKeyLineBreaks
    • MultilineMethodArgumentLineBreaks
    • ParameterAlignment

    Together, these cops will pretty print hashes, arrays, method calls, etc. For example, let's say the max columns is 25:

    Example:

    # bad
    {foo: "0000000000", bar: "0000000000", baz: "0000000000"}
    
    # good
    {foo: "0000000000",
    bar: "0000000000", baz: "0000000000"}
    
    # good (with recommended cops enabled)
    {
      foo: "0000000000",
      bar: "0000000000",
      baz: "0000000000",
    }

    Line is too long. [123/120]
    Open

            # book.worksheets.pop(book.worksheets.count - self.count) if book.worksheets and book.worksheets.count > self.count
    Severity: Minor
    Found in lib/workbook/writers/xls_writer.rb by rubocop

    This cop checks the length of lines in the source code. The maximum length is configurable. The tab size is configured in the IndentationWidth of the Layout/IndentationStyle cop. It also ignores a shebang line by default.

    This cop has some autocorrection capabilities. It can programmatically shorten certain long lines by inserting line breaks into expressions that can be safely split across lines. These include arrays, hashes, and method calls with argument lists.

    If autocorrection is enabled, the following Layout cops are recommended to further format the broken lines. (Many of these are enabled by default.)

    • ArgumentAlignment
    • BlockAlignment
    • BlockDelimiters
    • BlockEndNewline
    • ClosingParenthesisIndentation
    • FirstArgumentIndentation
    • FirstArrayElementIndentation
    • FirstHashElementIndentation
    • FirstParameterIndentation
    • HashAlignment
    • IndentationWidth
    • MultilineArrayLineBreaks
    • MultilineBlockLayout
    • MultilineHashBraceLayout
    • MultilineHashKeyLineBreaks
    • MultilineMethodArgumentLineBreaks
    • ParameterAlignment

    Together, these cops will pretty print hashes, arrays, method calls, etc. For example, let's say the max columns is 25:

    Example:

    # bad
    {foo: "0000000000", bar: "0000000000", baz: "0000000000"}
    
    # good
    {foo: "0000000000",
    bar: "0000000000", baz: "0000000000"}
    
    # good (with recommended cops enabled)
    {
      foo: "0000000000",
      bar: "0000000000",
      baz: "0000000000",
    }

    Line is too long. [123/120]
    Open

            # book.worksheets.pop(book.worksheets.count - self.count) if book.worksheets and book.worksheets.count > self.count
    Severity: Minor
    Found in lib/workbook/writers/xls_writer.rb by rubocop

    This cop checks the length of lines in the source code. The maximum length is configurable. The tab size is configured in the IndentationWidth of the Layout/IndentationStyle cop. It also ignores a shebang line by default.

    This cop has some autocorrection capabilities. It can programmatically shorten certain long lines by inserting line breaks into expressions that can be safely split across lines. These include arrays, hashes, and method calls with argument lists.

    If autocorrection is enabled, the following Layout cops are recommended to further format the broken lines. (Many of these are enabled by default.)

    • ArgumentAlignment
    • BlockAlignment
    • BlockDelimiters
    • BlockEndNewline
    • ClosingParenthesisIndentation
    • FirstArgumentIndentation
    • FirstArrayElementIndentation
    • FirstHashElementIndentation
    • FirstParameterIndentation
    • HashAlignment
    • IndentationWidth
    • MultilineArrayLineBreaks
    • MultilineBlockLayout
    • MultilineHashBraceLayout
    • MultilineHashKeyLineBreaks
    • MultilineMethodArgumentLineBreaks
    • ParameterAlignment

    Together, these cops will pretty print hashes, arrays, method calls, etc. For example, let's say the max columns is 25:

    Example:

    # bad
    {foo: "0000000000", bar: "0000000000", baz: "0000000000"}
    
    # good
    {foo: "0000000000",
    bar: "0000000000", baz: "0000000000"}
    
    # good (with recommended cops enabled)
    {
      foo: "0000000000",
      bar: "0000000000",
      baz: "0000000000",
    }

    Use def with parentheses when there are parameters.
    Open

          def to_xls options = {}
    Severity: Minor
    Found in lib/workbook/writers/xls_writer.rb by rubocop

    This cop checks for parentheses around the arguments in method definitions. Both instance and class/singleton methods are checked.

    This cop does not consider endless methods, since parentheses are always required for them.

    Example: EnforcedStyle: require_parentheses (default)

    # The `require_parentheses` style requires method definitions
    # to always use parentheses
    
    # bad
    def bar num1, num2
      num1 + num2
    end
    
    def foo descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name
      do_something
    end
    
    # good
    def bar(num1, num2)
      num1 + num2
    end
    
    def foo(descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name)
      do_something
    end

    Example: EnforcedStyle: requirenoparentheses

    # The `require_no_parentheses` style requires method definitions
    # to never use parentheses
    
    # bad
    def bar(num1, num2)
      num1 + num2
    end
    
    def foo(descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name)
      do_something
    end
    
    # good
    def bar num1, num2
      num1 + num2
    end
    
    def foo descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name
      do_something
    end

    Example: EnforcedStyle: requirenoparenthesesexceptmultiline

    # The `require_no_parentheses_except_multiline` style prefers no
    # parentheses when method definition arguments fit on single line,
    # but prefers parentheses when arguments span multiple lines.
    
    # bad
    def bar(num1, num2)
      num1 + num2
    end
    
    def foo descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name
      do_something
    end
    
    # good
    def bar num1, num2
      num1 + num2
    end
    
    def foo(descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name)
      do_something
    end

    Method parameter must be at least 3 characters long.
    Open

          def xls_sheet a
    Severity: Minor
    Found in lib/workbook/writers/xls_writer.rb by rubocop

    This cop checks method parameter names for how descriptive they are. It is highly configurable.

    The MinNameLength config option takes an integer. It represents the minimum amount of characters the name must be. Its default is 3. The AllowNamesEndingInNumbers config option takes a boolean. When set to false, this cop will register offenses for names ending with numbers. Its default is false. The AllowedNames config option takes an array of permitted names that will never register an offense. The ForbiddenNames config option takes an array of restricted names that will always register an offense.

    Example:

    # bad
    def bar(varOne, varTwo)
      varOne + varTwo
    end
    
    # With `AllowNamesEndingInNumbers` set to false
    def foo(num1, num2)
      num1 * num2
    end
    
    # With `MinArgNameLength` set to number greater than 1
    def baz(a, b, c)
      do_stuff(a, b, c)
    end
    
    # good
    def bar(thud, fred)
      thud + fred
    end
    
    def foo(speed, distance)
      speed * distance
    end
    
    def baz(age_a, height_b, gender_c)
      do_stuff(age_a, height_b, gender_c)
    end

    Prefer single-quoted strings when you don't need string interpolation or special symbols.
    Open

                "times" => :roman,
    Severity: Minor
    Found in lib/workbook/writers/xls_writer.rb by rubocop

    Checks if uses of quotes match the configured preference.

    Example: EnforcedStyle: single_quotes (default)

    # bad
    "No special symbols"
    "No string interpolation"
    "Just text"
    
    # good
    'No special symbols'
    'No string interpolation'
    'Just text'
    "Wait! What's #{this}!"

    Example: EnforcedStyle: double_quotes

    # bad
    'Just some text'
    'No special chars or interpolation'
    
    # good
    "Just some text"
    "No special chars or interpolation"
    "Every string in #{project} uses double_quotes"

    Favor modifier unless usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
    Open

            unless f.is_a? Workbook::Format
    Severity: Minor
    Found in lib/workbook/writers/xls_writer.rb by rubocop

    Checks for if and unless statements that would fit on one line if written as modifier if/unless. The cop also checks for modifier if/unless lines that exceed the maximum line length.

    The maximum line length is configured in the Layout/LineLength cop. The tab size is configured in the IndentationWidth of the Layout/IndentationStyle cop.

    Example:

    # bad
    if condition
      do_stuff(bar)
    end
    
    unless qux.empty?
      Foo.do_something
    end
    
    do_something_with_a_long_name(arg) if long_condition_that_prevents_code_fit_on_single_line
    
    # good
    do_stuff(bar) if condition
    Foo.do_something unless qux.empty?
    
    if long_condition_that_prevents_code_fit_on_single_line
      do_something_with_a_long_name(arg)
    end
    
    if short_condition # a long comment that makes it too long if it were just a single line
      do_something
    end

    Unused method argument - options. If it's necessary, use _ or _options as an argument name to indicate that it won't be used. You can also write as to_xls(*) if you want the method to accept any arguments but don't care about them.
    Open

          def to_xls options = {}
    Severity: Minor
    Found in lib/workbook/writers/xls_writer.rb by rubocop

    This cop checks for unused method arguments.

    Example:

    # bad
    def some_method(used, unused, _unused_but_allowed)
      puts used
    end
    
    # good
    def some_method(used, _unused, _unused_but_allowed)
      puts used
    end

    Example: AllowUnusedKeywordArguments: false (default)

    # bad
    def do_something(used, unused: 42)
      used
    end

    Example: AllowUnusedKeywordArguments: true

    # good
    def do_something(used, unused: 42)
      used
    end

    Example: IgnoreEmptyMethods: true (default)

    # good
    def do_something(unused)
    end

    Example: IgnoreEmptyMethods: false

    # bad
    def do_something(unused)
    end

    Example: IgnoreNotImplementedMethods: true (default)

    # good
    def do_something(unused)
      raise NotImplementedError
    end
    
    def do_something_else(unused)
      fail "TODO"
    end

    Example: IgnoreNotImplementedMethods: false

    # bad
    def do_something(unused)
      raise NotImplementedError
    end
    
    def do_something_else(unused)
      fail "TODO"
    end

    Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
    Open

            if to_xls(options).write(filename)
    Severity: Minor
    Found in lib/workbook/writers/xls_writer.rb by rubocop

    Checks for if and unless statements that would fit on one line if written as modifier if/unless. The cop also checks for modifier if/unless lines that exceed the maximum line length.

    The maximum line length is configured in the Layout/LineLength cop. The tab size is configured in the IndentationWidth of the Layout/IndentationStyle cop.

    Example:

    # bad
    if condition
      do_stuff(bar)
    end
    
    unless qux.empty?
      Foo.do_something
    end
    
    do_something_with_a_long_name(arg) if long_condition_that_prevents_code_fit_on_single_line
    
    # good
    do_stuff(bar) if condition
    Foo.do_something unless qux.empty?
    
    if long_condition_that_prevents_code_fit_on_single_line
      do_something_with_a_long_name(arg)
    end
    
    if short_condition # a long comment that makes it too long if it were just a single line
      do_something
    end

    Prefer single-quoted strings when you don't need string interpolation or special symbols.
    Open

                "times new roman" => :roman
    Severity: Minor
    Found in lib/workbook/writers/xls_writer.rb by rubocop

    Checks if uses of quotes match the configured preference.

    Example: EnforcedStyle: single_quotes (default)

    # bad
    "No special symbols"
    "No string interpolation"
    "Just text"
    
    # good
    'No special symbols'
    'No string interpolation'
    'Just text'
    "Wait! What's #{this}!"

    Example: EnforcedStyle: double_quotes

    # bad
    'Just some text'
    'No special chars or interpolation'
    
    # good
    "Just some text"
    "No special chars or interpolation"
    "Every string in #{project} uses double_quotes"

    Prefer single-quoted strings when you don't need string interpolation or special symbols.
    Open

                "arial" => :swiss,
    Severity: Minor
    Found in lib/workbook/writers/xls_writer.rb by rubocop

    Checks if uses of quotes match the configured preference.

    Example: EnforcedStyle: single_quotes (default)

    # bad
    "No special symbols"
    "No string interpolation"
    "Just text"
    
    # good
    'No special symbols'
    'No string interpolation'
    'Just text'
    "Wait! What's #{this}!"

    Example: EnforcedStyle: double_quotes

    # bad
    'Just some text'
    'No special chars or interpolation'
    
    # good
    "Just some text"
    "No special chars or interpolation"
    "Every string in #{project} uses double_quotes"

    Use def with parentheses when there are parameters.
    Open

          def xls_sheet a
    Severity: Minor
    Found in lib/workbook/writers/xls_writer.rb by rubocop

    This cop checks for parentheses around the arguments in method definitions. Both instance and class/singleton methods are checked.

    This cop does not consider endless methods, since parentheses are always required for them.

    Example: EnforcedStyle: require_parentheses (default)

    # The `require_parentheses` style requires method definitions
    # to always use parentheses
    
    # bad
    def bar num1, num2
      num1 + num2
    end
    
    def foo descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name
      do_something
    end
    
    # good
    def bar(num1, num2)
      num1 + num2
    end
    
    def foo(descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name)
      do_something
    end

    Example: EnforcedStyle: requirenoparentheses

    # The `require_no_parentheses` style requires method definitions
    # to never use parentheses
    
    # bad
    def bar(num1, num2)
      num1 + num2
    end
    
    def foo(descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name)
      do_something
    end
    
    # good
    def bar num1, num2
      num1 + num2
    end
    
    def foo descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name
      do_something
    end

    Example: EnforcedStyle: requirenoparenthesesexceptmultiline

    # The `require_no_parentheses_except_multiline` style prefers no
    # parentheses when method definition arguments fit on single line,
    # but prefers parentheses when arguments span multiple lines.
    
    # bad
    def bar(num1, num2)
      num1 + num2
    end
    
    def foo descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name
      do_something
    end
    
    # good
    def bar num1, num2
      num1 + num2
    end
    
    def foo(descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name)
      do_something
    end

    Method parameter must be at least 3 characters long.
    Open

          def format_to_xls_format f
    Severity: Minor
    Found in lib/workbook/writers/xls_writer.rb by rubocop

    This cop checks method parameter names for how descriptive they are. It is highly configurable.

    The MinNameLength config option takes an integer. It represents the minimum amount of characters the name must be. Its default is 3. The AllowNamesEndingInNumbers config option takes a boolean. When set to false, this cop will register offenses for names ending with numbers. Its default is false. The AllowedNames config option takes an array of permitted names that will never register an offense. The ForbiddenNames config option takes an array of restricted names that will always register an offense.

    Example:

    # bad
    def bar(varOne, varTwo)
      varOne + varTwo
    end
    
    # With `AllowNamesEndingInNumbers` set to false
    def foo(num1, num2)
      num1 * num2
    end
    
    # With `MinArgNameLength` set to number greater than 1
    def baz(a, b, c)
      do_stuff(a, b, c)
    end
    
    # good
    def bar(thud, fred)
      thud + fred
    end
    
    def foo(speed, distance)
      speed * distance
    end
    
    def baz(age_a, height_b, gender_c)
      do_stuff(age_a, height_b, gender_c)
    end

    Prefer single-quoted strings when you don't need string interpolation or special symbols.
    Open

    require "spreadsheet"
    Severity: Minor
    Found in lib/workbook/writers/xls_writer.rb by rubocop

    Checks if uses of quotes match the configured preference.

    Example: EnforcedStyle: single_quotes (default)

    # bad
    "No special symbols"
    "No string interpolation"
    "Just text"
    
    # good
    'No special symbols'
    'No string interpolation'
    'Just text'
    "Wait! What's #{this}!"

    Example: EnforcedStyle: double_quotes

    # bad
    'Just some text'
    'No special chars or interpolation'
    
    # good
    "Just some text"
    "No special chars or interpolation"
    "Every string in #{project} uses double_quotes"

    Unused block argument - c. If it's necessary, use _ or _c as an argument name to indicate that it won't be used.
    Open

            xls_sheet.row(row_index).each_with_index do |c, ci|
    Severity: Minor
    Found in lib/workbook/writers/xls_writer.rb by rubocop

    This cop checks for unused block arguments.

    Example:

    # bad
    do_something do |used, unused|
      puts used
    end
    
    do_something do |bar|
      puts :foo
    end
    
    define_method(:foo) do |bar|
      puts :baz
    end
    
    # good
    do_something do |used, _unused|
      puts used
    end
    
    do_something do
      puts :foo
    end
    
    define_method(:foo) do |_bar|
      puts :baz
    end

    Example: IgnoreEmptyBlocks: true (default)

    # good
    do_something { |unused| }

    Example: IgnoreEmptyBlocks: false

    # bad
    do_something { |unused| }

    Example: AllowUnusedKeywordArguments: false (default)

    # bad
    do_something do |unused: 42|
      foo
    end

    Example: AllowUnusedKeywordArguments: true

    # good
    do_something do |unused: 42|
      foo
    end

    Use next to skip iteration.
    Open

                  if c
    Severity: Minor
    Found in lib/workbook/writers/xls_writer.rb by rubocop

    Use next to skip iteration instead of a condition at the end.

    Example: EnforcedStyle: skipmodifierifs (default)

    # bad
    [1, 2].each do |a|
      if a == 1
        puts a
      end
    end
    
    # good
    [1, 2].each do |a|
      next unless a == 1
      puts a
    end
    
    # good
    [1, 2].each do |a|
      puts a if a == 1
    end

    Example: EnforcedStyle: always

    # With `always` all conditions at the end of an iteration needs to be
    # replaced by next - with `skip_modifier_ifs` the modifier if like
    # this one are ignored: `[1, 2].each { |a| puts a if a == 1 }`
    
    # bad
    [1, 2].each do |a|
      puts a if a == 1
    end
    
    # bad
    [1, 2].each do |a|
      if a == 1
        puts a
      end
    end
    
    # good
    [1, 2].each do |a|
      next unless a == 1
      puts a
    end

    Use def with parentheses when there are parameters.
    Open

          def write_to_xls filename = "#{title}.xls", options = {}
    Severity: Minor
    Found in lib/workbook/writers/xls_writer.rb by rubocop

    This cop checks for parentheses around the arguments in method definitions. Both instance and class/singleton methods are checked.

    This cop does not consider endless methods, since parentheses are always required for them.

    Example: EnforcedStyle: require_parentheses (default)

    # The `require_parentheses` style requires method definitions
    # to always use parentheses
    
    # bad
    def bar num1, num2
      num1 + num2
    end
    
    def foo descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name
      do_something
    end
    
    # good
    def bar(num1, num2)
      num1 + num2
    end
    
    def foo(descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name)
      do_something
    end

    Example: EnforcedStyle: requirenoparentheses

    # The `require_no_parentheses` style requires method definitions
    # to never use parentheses
    
    # bad
    def bar(num1, num2)
      num1 + num2
    end
    
    def foo(descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name)
      do_something
    end
    
    # good
    def bar num1, num2
      num1 + num2
    end
    
    def foo descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name
      do_something
    end

    Example: EnforcedStyle: requirenoparenthesesexceptmultiline

    # The `require_no_parentheses_except_multiline` style prefers no
    # parentheses when method definition arguments fit on single line,
    # but prefers parentheses when arguments span multiple lines.
    
    # bad
    def bar(num1, num2)
      num1 + num2
    end
    
    def foo descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name
      do_something
    end
    
    # good
    def bar num1, num2
      num1 + num2
    end
    
    def foo(descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name)
      do_something
    end

    Missing top-level documentation comment for module Workbook::Writers::XlsWriter.
    Open

        module XlsWriter
    Severity: Minor
    Found in lib/workbook/writers/xls_writer.rb by rubocop

    This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, constant definitions or constant visibility declarations.

    The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.

    Example:

    # bad
    class Person
      # ...
    end
    
    module Math
    end
    
    # good
    # Description/Explanation of Person class
    class Person
      # ...
    end
    
    # allowed
      # Class without body
      class Person
      end
    
      # Namespace - A namespace can be a class or a module
      # Containing a class
      module Namespace
        # Description/Explanation of Person class
        class Person
          # ...
        end
      end
    
      # Containing constant visibility declaration
      module Namespace
        class Private
        end
    
        private_constant :Private
      end
    
      # Containing constant definition
      module Namespace
        Public = Class.new
      end
    
      # Macro calls
      module Namespace
        extend Foo
      end

    Example: AllowedConstants: ['ClassMethods']

    # good
     module A
       module ClassMethods
         # ...
       end
      end

    Modifier form of if makes the line too long.
    Open

              xlsfmt.pattern_fg_color = html_color_to_xls_color(f[:background_color]) if html_color_to_xls_color(f[:background_color])
    Severity: Minor
    Found in lib/workbook/writers/xls_writer.rb by rubocop

    Checks for if and unless statements that would fit on one line if written as modifier if/unless. The cop also checks for modifier if/unless lines that exceed the maximum line length.

    The maximum line length is configured in the Layout/LineLength cop. The tab size is configured in the IndentationWidth of the Layout/IndentationStyle cop.

    Example:

    # bad
    if condition
      do_stuff(bar)
    end
    
    unless qux.empty?
      Foo.do_something
    end
    
    do_something_with_a_long_name(arg) if long_condition_that_prevents_code_fit_on_single_line
    
    # good
    do_stuff(bar) if condition
    Foo.do_something unless qux.empty?
    
    if long_condition_that_prevents_code_fit_on_single_line
      do_something_with_a_long_name(arg)
    end
    
    if short_condition # a long comment that makes it too long if it were just a single line
      do_something
    end

    Use %i or %I for an array of symbols.
    Open

            valid_values = [:none, :roman, :swiss, :modern, :script, :decorative]
    Severity: Minor
    Found in lib/workbook/writers/xls_writer.rb by rubocop

    This cop can check for array literals made up of symbols that are not using the %i() syntax.

    Alternatively, it checks for symbol arrays using the %i() syntax on projects which do not want to use that syntax.

    Configuration option: MinSize If set, arrays with fewer elements than this value will not trigger the cop. For example, a MinSize of 3 will not enforce a style on an array of 2 or fewer elements.

    Example: EnforcedStyle: percent (default)

    # good
    %i[foo bar baz]
    
    # bad
    [:foo, :bar, :baz]

    Example: EnforcedStyle: brackets

    # good
    [:foo, :bar, :baz]
    
    # bad
    %i[foo bar baz]

    Use def with parentheses when there are parameters.
    Open

          def format_to_xls_format f
    Severity: Minor
    Found in lib/workbook/writers/xls_writer.rb by rubocop

    This cop checks for parentheses around the arguments in method definitions. Both instance and class/singleton methods are checked.

    This cop does not consider endless methods, since parentheses are always required for them.

    Example: EnforcedStyle: require_parentheses (default)

    # The `require_parentheses` style requires method definitions
    # to always use parentheses
    
    # bad
    def bar num1, num2
      num1 + num2
    end
    
    def foo descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name
      do_something
    end
    
    # good
    def bar(num1, num2)
      num1 + num2
    end
    
    def foo(descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name)
      do_something
    end

    Example: EnforcedStyle: requirenoparentheses

    # The `require_no_parentheses` style requires method definitions
    # to never use parentheses
    
    # bad
    def bar(num1, num2)
      num1 + num2
    end
    
    def foo(descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name)
      do_something
    end
    
    # good
    def bar num1, num2
      num1 + num2
    end
    
    def foo descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name
      do_something
    end

    Example: EnforcedStyle: requirenoparenthesesexceptmultiline

    # The `require_no_parentheses_except_multiline` style prefers no
    # parentheses when method definition arguments fit on single line,
    # but prefers parentheses when arguments span multiple lines.
    
    # bad
    def bar(num1, num2)
      num1 + num2
    end
    
    def foo descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name
      do_something
    end
    
    # good
    def bar num1, num2
      num1 + num2
    end
    
    def foo(descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name)
      do_something
    end

    Use a guard clause (return unless to_xls(options).write(filename)) instead of wrapping the code inside a conditional expression.
    Open

            if to_xls(options).write(filename)
    Severity: Minor
    Found in lib/workbook/writers/xls_writer.rb by rubocop

    Use a guard clause instead of wrapping the code inside a conditional expression

    Example:

    # bad
    def test
      if something
        work
      end
    end
    
    # good
    def test
      return unless something
    
      work
    end
    
    # also good
    def test
      work if something
    end
    
    # bad
    if something
      raise 'exception'
    else
      ok
    end
    
    # good
    raise 'exception' if something
    ok
    
    # bad
    if something
      foo || raise('exception')
    else
      ok
    end
    
    # good
    foo || raise('exception') if something
    ok

    There are no issues that match your filters.

    Category
    Status