murb/workbook

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

Summary

Maintainability
A
3 hrs
Test Coverage

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

      def to_xlsx options = {}
        formats_to_xlsx_format

        book = init_xlsx_spreadsheet_template.workbook
        book.worksheets.pop(book.worksheets.count - count) if book.worksheets && (book.worksheets.count > count)
Severity: Minor
Found in lib/workbook/writers/xlsx_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

Perceived complexity for to_xlsx is too high. [15/8]
Open

      def to_xlsx options = {}
        formats_to_xlsx_format

        book = init_xlsx_spreadsheet_template.workbook
        book.worksheets.pop(book.worksheets.count - count) if book.worksheets && (book.worksheets.count > count)
Severity: Minor
Found in lib/workbook/writers/xlsx_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

Cyclomatic complexity for to_xlsx is too high. [14/7]
Open

      def to_xlsx options = {}
        formats_to_xlsx_format

        book = init_xlsx_spreadsheet_template.workbook
        book.worksheets.pop(book.worksheets.count - count) if book.worksheets && (book.worksheets.count > count)
Severity: Minor
Found in lib/workbook/writers/xlsx_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_xlsx has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

      def to_xlsx options = {}
        formats_to_xlsx_format

        book = init_xlsx_spreadsheet_template.workbook
        book.worksheets.pop(book.worksheets.count - count) if book.worksheets && (book.worksheets.count > count)
Severity: Minor
Found in lib/workbook/writers/xlsx_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 format_to_xlsx_format is too high. [10/7]
Open

      def format_to_xlsx_format f
        f = make_sure_f_is_a_workbook_format f

        xlsfmt = {}
        xlsfmt[:fg_color] = "FF#{f[:color].to_s.upcase}".delete("#") if f[:color]
Severity: Minor
Found in lib/workbook/writers/xlsx_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 has too many lines. [13/10]
Open

      def format_to_xlsx_format f
        f = make_sure_f_is_a_workbook_format f

        xlsfmt = {}
        xlsfmt[:fg_color] = "FF#{f[:color].to_s.upcase}".delete("#") if f[:color]
Severity: Minor
Found in lib/workbook/writers/xlsx_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

Perceived complexity for format_to_xlsx_format is too high. [10/8]
Open

      def format_to_xlsx_format f
        f = make_sure_f_is_a_workbook_format f

        xlsfmt = {}
        xlsfmt[:fg_color] = "FF#{f[:color].to_s.upcase}".delete("#") if f[:color]
Severity: Minor
Found in lib/workbook/writers/xlsx_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_xlsx has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def to_xlsx options = {}
        formats_to_xlsx_format

        book = init_xlsx_spreadsheet_template.workbook
        book.worksheets.pop(book.worksheets.count - count) if book.worksheets && (book.worksheets.count > count)
Severity: Minor
Found in lib/workbook/writers/xlsx_writer.rb - About 1 hr to fix

    Method format_to_xlsx_format has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

          def format_to_xlsx_format f
            f = make_sure_f_is_a_workbook_format f
    
            xlsfmt = {}
            xlsfmt[:fg_color] = "FF#{f[:color].to_s.upcase}".delete("#") if f[:color]
    Severity: Minor
    Found in lib/workbook/writers/xlsx_writer.rb - About 45 mins 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

    Assignment Branch Condition size for to_xlsx is too high. [<17, 62, 14> 65.8/17]
    Open

          def to_xlsx options = {}
            formats_to_xlsx_format
    
            book = init_xlsx_spreadsheet_template.workbook
            book.worksheets.pop(book.worksheets.count - count) if book.worksheets && (book.worksheets.count > count)
    Severity: Minor
    Found in lib/workbook/writers/xlsx_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 format_to_xlsx_format is too high. [<10, 40, 12> 42.94/17]
    Open

          def format_to_xlsx_format f
            f = make_sure_f_is_a_workbook_format f
    
            xlsfmt = {}
            xlsfmt[:fg_color] = "FF#{f[:color].to_s.upcase}".delete("#") if f[:color]
    Severity: Minor
    Found in lib/workbook/writers/xlsx_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. [134/120]
    Open

            xlsfmt[:b] = true if (f[:font_weight].to_s == "bold") || (f[:font_weight].to_i >= 600) || f[:font_style].to_s.match("oblique")
    Severity: Minor
    Found in lib/workbook/writers/xlsx_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",
    }

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

    require "axlsx"
    Severity: Minor
    Found in lib/workbook/writers/xlsx_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 - t. If it's necessary, use _ or _t as an argument name to indicate that it won't be used.
    Open

              v.each do |t, s|
    Severity: Minor
    Found in lib/workbook/writers/xlsx_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

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

            xlsfmt[:fg_color] = "FF#{f[:color].to_s.upcase}".delete("#") if f[:color]
    Severity: Minor
    Found in lib/workbook/writers/xlsx_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 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_xlsx(*) if you want the method to accept any arguments but don't care about them.
    Open

          def to_xlsx options = {}
    Severity: Minor
    Found in lib/workbook/writers/xlsx_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

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

            xlsfmt[:b] = true if (f[:font_weight].to_s == "bold") || (f[:font_weight].to_i >= 600) || f[:font_style].to_s.match("oblique")
    Severity: Minor
    Found in lib/workbook/writers/xlsx_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 stream_xlsx options = {}
    Severity: Minor
    Found in lib/workbook/writers/xlsx_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

    Modifier form of if makes the line too long.
    Open

            xlsfmt[:b] = true if (f[:font_weight].to_s == "bold") || (f[:font_weight].to_i >= 600) || f[:font_style].to_s.match("oblique")
    Severity: Minor
    Found in lib/workbook/writers/xlsx_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 def with parentheses when there are parameters.
    Open

          def format_to_xlsx_format f
    Severity: Minor
    Found in lib/workbook/writers/xlsx_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 def with parentheses when there are parameters.
    Open

          def to_xlsx options = {}
    Severity: Minor
    Found in lib/workbook/writers/xlsx_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 def with parentheses when there are parameters.
    Open

          def xlsx_sheet a
    Severity: Minor
    Found in lib/workbook/writers/xlsx_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

    Unused block argument - time. You can omit the argument if you don't care about it.
    Open

              (xlsx_sheet.rows.count - s.table.count).times do |time|
    Severity: Minor
    Found in lib/workbook/writers/xlsx_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 a guard clause (return unless to_xlsx(options).serialize(filename)) instead of wrapping the code inside a conditional expression.
    Open

            if to_xlsx(options).serialize(filename)
    Severity: Minor
    Found in lib/workbook/writers/xlsx_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

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

            xlsfmt[:i] = true if f[:font_style].to_s == "italic"
    Severity: Minor
    Found in lib/workbook/writers/xlsx_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

    require "workbook/readers/xls_shared"
    Severity: Minor
    Found in lib/workbook/writers/xlsx_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"

    Method parameter must be at least 3 characters long.
    Open

          def xlsx_sheet a
    Severity: Minor
    Found in lib/workbook/writers/xlsx_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

            xlsfmt[:u] = true if f[:text_decoration].to_s.include?("underline")
    Severity: Minor
    Found in lib/workbook/writers/xlsx_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"

    Method parameter must be at least 3 characters long.
    Open

          def make_sure_f_is_a_workbook_format f
    Severity: Minor
    Found in lib/workbook/writers/xlsx_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

    Freeze mutable objects assigned to constants.
    Open

          CELL_TYPE_MAPPING = {
            decimal: :integer,
            integer: :integer,
            float: :float,
            string: :text,
    Severity: Minor
    Found in lib/workbook/writers/xlsx_writer.rb by rubocop

    This cop checks whether some constant value isn't a mutable literal (e.g. array or hash).

    Strict mode can be used to freeze all constants, rather than just literals. Strict mode is considered an experimental feature. It has not been updated with an exhaustive list of all methods that will produce frozen objects so there is a decent chance of getting some false positives. Luckily, there is no harm in freezing an already frozen object.

    From Ruby 3.0, this cop honours the magic comment 'shareableconstantvalue'. When this magic comment is set to any acceptable value other than none, it will suppress the offenses raised by this cop. It enforces frozen state.

    NOTE: Regexp and Range literals are frozen objects since Ruby 3.0.

    NOTE: From Ruby 3.0, interpolated strings are not frozen when # frozen-string-literal: true is used, so this cop enforces explicit freezing for such strings.

    NOTE: From Ruby 3.0, this cop allows explicit freezing of constants when the shareable_constant_value directive is used.

    Safety:

    This cop's autocorrection is unsafe since any mutations on objects that are made frozen will change from being accepted to raising FrozenError, and will need to be manually refactored.

    Example: EnforcedStyle: literals (default)

    # bad
    CONST = [1, 2, 3]
    
    # good
    CONST = [1, 2, 3].freeze
    
    # good
    CONST = <<~TESTING.freeze
      This is a heredoc
    TESTING
    
    # good
    CONST = Something.new

    Example: EnforcedStyle: strict

    # bad
    CONST = Something.new
    
    # bad
    CONST = Struct.new do
      def foo
        puts 1
      end
    end
    
    # good
    CONST = Something.new.freeze
    
    # good
    CONST = Struct.new do
      def foo
        puts 1
      end
    end.freeze

    Example:

    # Magic comment - shareable_constant_value: literal
    
    # bad
    CONST = [1, 2, 3]
    
    # good
    # shareable_constant_value: literal
    CONST = [1, 2, 3]

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

            template.formats.each do |n, v|
    Severity: Minor
    Found in lib/workbook/writers/xlsx_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

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

            if to_xlsx(options).serialize(filename)
    Severity: Minor
    Found in lib/workbook/writers/xlsx_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 def with parentheses when there are parameters.
    Open

          def make_sure_f_is_a_workbook_format f
    Severity: Minor
    Found in lib/workbook/writers/xlsx_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

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

            xlsfmt[:b] = true if (f[:font_weight].to_s == "bold") || (f[:font_weight].to_i >= 600) || f[:font_style].to_s.match("oblique")
    Severity: Minor
    Found in lib/workbook/writers/xlsx_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"

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

        module XlsxWriter
    Severity: Minor
    Found in lib/workbook/writers/xlsx_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

    Method parameter must be at least 3 characters long.
    Open

          def format_to_xlsx_format f
    Severity: Minor
    Found in lib/workbook/writers/xlsx_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

    Use def with parentheses when there are parameters.
    Open

          def write_to_xlsx filename = "#{title}.xlsx", options = {}
    Severity: Minor
    Found in lib/workbook/writers/xlsx_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

    There are no issues that match your filters.

    Category
    Status