9troisquarts/ntq-excelsior

View on GitHub

Showing 211 of 211 total issues

Redundant escape inside regexp literal
Open

      if gsub_enclosure && header.scan(/^\/[\^]?([^(\$\/)]+)[\$]?\/[i]?$/i) && $1
Severity: Minor
Found in lib/ntq_excelsior/importer.rb by rubocop

Checks for redundant escapes inside Regexp literals.

Example:

# bad
%r{foo\/bar}

# good
%r{foo/bar}

# good
/foo\/bar/

# good
%r/foo\/bar/

# good
%r!foo\!bar!

# bad
/a\-b/

# good
/a-b/

# bad
/[\+\-]\d/

# good
/[+\-]\d/

Final newline missing.
Open

gem 'caxlsx', "~> 3.2"
Severity: Minor
Found in Gemfile by rubocop

Looks for trailing blank lines and a final newline in the source code.

Example: EnforcedStyle: final_newline (default)

# `final_newline` looks for one newline at the end of files.

# bad
class Foo; end

# EOF

# bad
class Foo; end # EOF

# good
class Foo; end
# EOF

Example: EnforcedStyle: finalblankline

# `final_blank_line` looks for one blank line followed by a new line
# at the end of files.

# bad
class Foo; end
# EOF

# bad
class Foo; end # EOF

# good
class Foo; end

# EOF

Method parameter must be at least 3 characters long.
Open

    def generate_workbook(wb, wb_styles)
Severity: Minor
Found in lib/ntq_excelsior/exporter.rb by rubocop

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 `MinNameLength` 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 double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Open

require 'caxlsx'
Severity: Minor
Found in lib/ntq_excelsior/exporter.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 double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Open

        config[:prompt] = list_config[:prompt] || ''
Severity: Minor
Found in lib/ntq_excelsior/exporter.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"

Assignment Branch Condition size for find_or_initialize_record is too high. [<3, 34, 7> 34.84/17]
Open

    def find_or_initialize_record(line)
      return nil unless self.class.primary_key && self.class.model_klass

      if line[self.class.primary_key.to_sym].present?
        if self.class.primary_key.to_sym == :id
Severity: Minor
Found in lib/ntq_excelsior/importer.rb by rubocop

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`, referenced 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 AllowedMethods (defaults to []) And AllowedPatterns (defaults to [])

Assignment Branch Condition size for import_line is too high. [<9, 20, 10> 24.1/17]
Open

    def import_line(line, save: true)
      record = find_or_initialize_record(line)
      return { status: :not_found } unless record

      @success = false
Severity: Minor
Found in lib/ntq_excelsior/importer.rb by rubocop

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`, referenced 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 AllowedMethods (defaults to []) And AllowedPatterns (defaults to [])

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Open

require 'ostruct'
Severity: Minor
Found in lib/ntq_excelsior/context.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 2 spaces for indentation in a hash, relative to the first position after the preceding left parenthesis.
Open

            range: cells_range([col_index, index + 1], [col_index, 1_000_000]),
Severity: Minor
Found in lib/ntq_excelsior/exporter.rb by rubocop

Checks the indentation of the first key in a hash literal where the opening brace and the first key are on separate lines. The other keys' indentations are handled by the HashAlignment cop.

By default, Hash literals that are arguments in a method call with parentheses, and where the opening curly brace of the hash is on the same line as the opening parenthesis of the method call, shall have their first key indented one step (two spaces) more than the position inside the opening parenthesis.

Other hash literals shall have their first key indented one step more than the start of the line where the opening curly brace is.

This default style is called 'specialinsideparentheses'. Alternative styles are 'consistent' and 'align_braces'. Here are examples:

Example: EnforcedStyle: specialinsideparentheses (default)

# The `special_inside_parentheses` style enforces that the first key
# in a hash literal where the opening brace and the first key are on
# separate lines is indented one step (two spaces) more than the
# position inside the opening parentheses.

# bad
hash = {
  key: :value
}
and_in_a_method_call({
  no: :difference
                     })
takes_multi_pairs_hash(x: {
  a: 1,
  b: 2
},
                       y: {
                         c: 1,
                         d: 2
                       })

# good
special_inside_parentheses
hash = {
  key: :value
}
but_in_a_method_call({
                       its_like: :this
                     })
takes_multi_pairs_hash(x: {
                         a: 1,
                         b: 2
                       },
                       y: {
                         c: 1,
                         d: 2
                       })

Example: EnforcedStyle: consistent

# The `consistent` style enforces that the first key in a hash
# literal where the opening brace and the first key are on
# separate lines is indented the same as a hash literal which is not
# defined inside a method call.

# bad
hash = {
  key: :value
}
but_in_a_method_call({
                       its_like: :this
                      })

# good
hash = {
  key: :value
}
and_in_a_method_call({
  no: :difference
})

Example: EnforcedStyle: align_braces

# The `align_brackets` style enforces that the opening and closing
# braces are indented to the same position.

# bad
and_now_for_something = {
                          completely: :different
}
takes_multi_pairs_hash(x: {
  a: 1,
  b: 2
},
                        y: {
                             c: 1,
                             d: 2
                           })

# good
and_now_for_something = {
                          completely: :different
                        }
takes_multi_pairs_hash(x: {
                            a: 1,
                            b: 2
                          },
                       y: {
                            c: 1,
                            d: 2
                          })

Don't use parentheses around a method call.
Open

      if (self.class.autoset)
Severity: Minor
Found in lib/ntq_excelsior/importer.rb by rubocop

Checks for redundant parentheses.

Example:

# bad
(x) if ((y.z).nil?)

# good
x if y.z.nil?

Use 2 (not 0) spaces for indentation.
Open

        def initialize(data)
Severity: Minor
Found in lib/ntq_excelsior/exporter.rb by rubocop

Checks for indentation that doesn't use the specified number of spaces.

See also the IndentationConsistency cop which is the companion to this one.

Example:

# bad
class A
 def test
  puts 'hello'
 end
end

# good
class A
  def test
    puts 'hello'
  end
end

Example: AllowedPatterns: ['^\s*module']

# bad
module A
class B
  def test
  puts 'hello'
  end
end
end

# good
module A
class B
  def test
    puts 'hello'
  end
end
end

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Open

        @action = record.persisted? ? 'update' : 'create'
Severity: Minor
Found in lib/ntq_excelsior/importer.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"

Assignment Branch Condition size for resolve_record_row is too high. [<8, 25, 5> 26.72/17]
Open

    def resolve_record_row(schema, record, index)
      row = { values: [], styles: [], merge_cells: [], height: nil, types: [] }
      col_index = 1
      schema.each do |column|
        next unless column_is_visible?(column, record)
Severity: Minor
Found in lib/ntq_excelsior/exporter.rb by rubocop

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`, referenced 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 AllowedMethods (defaults to []) And AllowedPatterns (defaults to [])

Use safe navigation (&.) instead of checking if an object exists before calling the method.
Open

      columns_with_children = columns.select{ |c| c[:children] && c[:children].any? }
Severity: Minor
Found in lib/ntq_excelsior/exporter.rb by rubocop

Transforms usages of a method call safeguarded by a non nil check for the variable whose method is being called to safe navigation (&.). If there is a method chain, all of the methods in the chain need to be checked for safety, and all of the methods will need to be changed to use safe navigation.

The default for ConvertCodeThatCanStartToReturnNil is false. When configured to true, this will check for code in the format !foo.nil? && foo.bar. As it is written, the return of this code is limited to false and whatever the return of the method is. If this is converted to safe navigation, foo&.bar can start returning nil as well as what the method returns.

The default for MaxChainLength is 2 We have limited the cop to not register an offense for method chains that exceed this option is set.

Safety:

Autocorrection is unsafe because if a value is false, the resulting code will have different behavior or raise an error.

x = false
x && x.foo  # return false
x&.foo      # raises NoMethodError

Example:

# bad
foo.bar if foo
foo.bar.baz if foo
foo.bar(param1, param2) if foo
foo.bar { |e| e.something } if foo
foo.bar(param) { |e| e.something } if foo

foo.bar if !foo.nil?
foo.bar unless !foo
foo.bar unless foo.nil?

foo && foo.bar
foo && foo.bar.baz
foo && foo.bar(param1, param2)
foo && foo.bar { |e| e.something }
foo && foo.bar(param) { |e| e.something }

foo ? foo.bar : nil
foo.nil? ? nil : foo.bar
!foo.nil? ? foo.bar : nil
!foo ? nil : foo.bar

# good
foo&.bar
foo&.bar&.baz
foo&.bar(param1, param2)
foo&.bar { |e| e.something }
foo&.bar(param) { |e| e.something }
foo && foo.bar.baz.qux # method chain with more than 2 methods
foo && foo.nil? # method that `nil` responds to

# Method calls that do not use `.`
foo && foo < bar
foo < bar if foo

# When checking `foo&.empty?` in a conditional, `foo` being `nil` will actually
# do the opposite of what the author intends.
foo && foo.empty?

# This could start returning `nil` as well as the return of the method
foo.nil? || foo.bar
!foo || foo.bar

# Methods that are used on assignment, arithmetic operation or
# comparison should not be converted to use safe navigation
foo.baz = bar if foo
foo.baz + bar if foo
foo.bar > 2 if foo

Use safe navigation (&.) instead of checking if an object exists before calling the method.
Open

        if row[:data_validations]
          row[:data_validations].each do |validation|
            sheet.add_data_validation(validation[:range], validation[:config])
          end
        end
Severity: Minor
Found in lib/ntq_excelsior/exporter.rb by rubocop

Transforms usages of a method call safeguarded by a non nil check for the variable whose method is being called to safe navigation (&.). If there is a method chain, all of the methods in the chain need to be checked for safety, and all of the methods will need to be changed to use safe navigation.

The default for ConvertCodeThatCanStartToReturnNil is false. When configured to true, this will check for code in the format !foo.nil? && foo.bar. As it is written, the return of this code is limited to false and whatever the return of the method is. If this is converted to safe navigation, foo&.bar can start returning nil as well as what the method returns.

The default for MaxChainLength is 2 We have limited the cop to not register an offense for method chains that exceed this option is set.

Safety:

Autocorrection is unsafe because if a value is false, the resulting code will have different behavior or raise an error.

x = false
x && x.foo  # return false
x&.foo      # raises NoMethodError

Example:

# bad
foo.bar if foo
foo.bar.baz if foo
foo.bar(param1, param2) if foo
foo.bar { |e| e.something } if foo
foo.bar(param) { |e| e.something } if foo

foo.bar if !foo.nil?
foo.bar unless !foo
foo.bar unless foo.nil?

foo && foo.bar
foo && foo.bar.baz
foo && foo.bar(param1, param2)
foo && foo.bar { |e| e.something }
foo && foo.bar(param) { |e| e.something }

foo ? foo.bar : nil
foo.nil? ? nil : foo.bar
!foo.nil? ? foo.bar : nil
!foo ? nil : foo.bar

# good
foo&.bar
foo&.bar&.baz
foo&.bar(param1, param2)
foo&.bar { |e| e.something }
foo&.bar(param) { |e| e.something }
foo && foo.bar.baz.qux # method chain with more than 2 methods
foo && foo.nil? # method that `nil` responds to

# Method calls that do not use `.`
foo && foo < bar
foo < bar if foo

# When checking `foo&.empty?` in a conditional, `foo` being `nil` will actually
# do the opposite of what the author intends.
foo && foo.empty?

# This could start returning `nil` as well as the return of the method
foo.nil? || foo.bar
!foo || foo.bar

# Methods that are used on assignment, arithmetic operation or
# comparison should not be converted to use safe navigation
foo.baz = bar if foo
foo.baz + bar if foo
foo.bar > 2 if foo

Trailing whitespace detected.
Open

  
Severity: Minor
Found in lib/ntq_excelsior/importer.rb by rubocop

Looks for trailing whitespace in the source code.

Example:

# The line in this example contains spaces after the 0.
# bad
x = 0

# The line in this example ends directly after the 0.
# good
x = 0

Example: AllowInHeredoc: false (default)

# The line in this example contains spaces after the 0.
# bad
code = <<~RUBY
  x = 0
RUBY

# ok
code = <<~RUBY
  x = 0 #{}
RUBY

# good
trailing_whitespace = ' '
code = <<~RUBY
  x = 0#{trailing_whitespace}
RUBY

Example: AllowInHeredoc: true

# The line in this example contains spaces after the 0.
# good
code = <<~RUBY
  x = 0
RUBY

Assignment Branch Condition size for required_headers is too high. [<5, 25, 8> 26.72/17]
Open

    def required_headers
      return @required_headers if @required_headers

      @required_columns = self.class.schema.select { |_field, column_config| !column_config.is_a?(Hash) || !column_config.key?(:required) || column_config[:required] }
      @required_headers = @required_columns.values.map { |column| get_column_header(column) }.map { |header| transform_header_to_regexp(header) }
Severity: Minor
Found in lib/ntq_excelsior/importer.rb by rubocop

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`, referenced 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 AllowedMethods (defaults to []) And AllowedPatterns (defaults to [])

Assignment Branch Condition size for spreadsheet_data is too high. [<7, 32, 15> 36.03/17]
Open

    def spreadsheet_data
      begin
        spreadsheet_data = spreadsheet.sheet(spreadsheet.sheets[0]).parse(header_search: required_headers)
        raise 'File is inconsistent, please check you have data in it or check for invalid characters in headers like , / ; etc...' unless spreadsheet_data.size > 0

Severity: Minor
Found in lib/ntq_excelsior/importer.rb by rubocop

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`, referenced 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 AllowedMethods (defaults to []) And AllowedPatterns (defaults to [])

Don't use parentheses around the condition of an if.
Open

      if (self.class.autoset)
Severity: Minor
Found in lib/ntq_excelsior/importer.rb by rubocop

Checks for the presence of superfluous parentheses around the condition of if/unless/while/until.

AllowSafeAssignment option for safe assignment. By safe assignment we mean putting parentheses around an assignment to indicate "I know I'm using an assignment as a condition. It's not a mistake."

Example:

# bad
x += 1 while (x < 10)
foo unless (bar || baz)

if (x > 10)
elsif (x < 3)
end

# good
x += 1 while x < 10
foo unless bar || baz

if x > 10
elsif x < 3
end

Example: AllowSafeAssignment: true (default)

# good
foo unless (bar = baz)

Example: AllowSafeAssignment: false

# bad
foo unless (bar = baz)

Example: AllowInMultilineConditions: false (default)

# bad
if (x > 10 &&
   y > 10)
end

# good
 if x > 10 &&
    y > 10
 end

Example: AllowInMultilineConditions: true

# good
if (x > 10 &&
   y > 10)
end

Redundant escape inside regexp literal
Open

      if gsub_enclosure && header.scan(/^\/[\^]?([^(\$\/)]+)[\$]?\/[i]?$/i) && $1
Severity: Minor
Found in lib/ntq_excelsior/importer.rb by rubocop

Checks for redundant escapes inside Regexp literals.

Example:

# bad
%r{foo\/bar}

# good
%r{foo/bar}

# good
/foo\/bar/

# good
%r/foo\/bar/

# good
%r!foo\!bar!

# bad
/a\-b/

# good
/a-b/

# bad
/[\+\-]\d/

# good
/[+\-]\d/
Severity
Category
Status
Source
Language