rambler-digital-solutions/Generamba

View on GitHub
lib/generamba/cli/thor_extension.rb

Summary

Maintainability
A
35 mins
Test Coverage

Block has too many lines. [35/25]
Open

    no_commands do
      def ask_index(message, array)
        value_index = ask_with_validation(message,->(value){ (value.to_i >= 0 and value.to_i < array.count) },"Invalid selection. Please enter number from 0 to #{array.count-1}")
        return array[value_index.to_i]
      end
Severity: Minor
Found in lib/generamba/cli/thor_extension.rb by rubocop

This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

Method ask_file_with_path has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

      def ask_file_with_path(pattern, message_file_name)
        project_files = Dir[pattern]
        count = project_files.count
        default_message = "The path to a #{message_file_name}:"
        if count == 1
Severity: Minor
Found in lib/generamba/cli/thor_extension.rb - About 35 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

Space missing after comma.
Open

        value_index = ask_with_validation(message,->(value){ (value.to_i >= 0 and value.to_i < array.count) },"Invalid selection. Please enter number from 0 to #{array.count-1}")
Severity: Minor
Found in lib/generamba/cli/thor_extension.rb by rubocop

Checks for comma (,) not followed by some kind of space.

Example:

# bad
[1,2]
{ foo:bar,}

# good
[1, 2]
{ foo:bar, }

Space missing after comma.
Open

        return ask_with_validation(message,->(value){value.length > 0 },description)
Severity: Minor
Found in lib/generamba/cli/thor_extension.rb by rubocop

Checks for comma (,) not followed by some kind of space.

Example:

# bad
[1,2]
{ foo:bar,}

# good
[1, 2]
{ foo:bar, }

Space missing inside {.
Open

        return ask_with_validation(message,->(value){value.length > 0 },description)
Severity: Minor
Found in lib/generamba/cli/thor_extension.rb by rubocop

Checks that block braces have or don't have surrounding space inside them on configuration. For blocks taking parameters, it checks that the left brace has or doesn't have trailing space depending on configuration.

Example: EnforcedStyle: space (default)

# The `space` style enforces that block braces have
# surrounding space.

# bad
some_array.each {puts e}

# good
some_array.each { puts e }

Example: EnforcedStyle: no_space

# The `no_space` style enforces that block braces don't
# have surrounding space.

# bad
some_array.each { puts e }

# good
some_array.each {puts e}

Example: EnforcedStyleForEmptyBraces: no_space (default)

# The `no_space` EnforcedStyleForEmptyBraces style enforces that
# block braces don't have a space in between when empty.

# bad
some_array.each {   }
some_array.each {  }
some_array.each { }

# good
some_array.each {}

Example: EnforcedStyleForEmptyBraces: space

# The `space` EnforcedStyleForEmptyBraces style enforces that
# block braces have at least a spece in between when empty.

# bad
some_array.each {}

# good
some_array.each { }
some_array.each {  }
some_array.each {   }

Example: SpaceBeforeBlockParameters: true (default)

# The SpaceBeforeBlockParameters style set to `true` enforces that
# there is a space between `{` and `|`. Overrides `EnforcedStyle`
# if there is a conflict.

# bad
[1, 2, 3].each {|n| n * 2 }

# good
[1, 2, 3].each { |n| n * 2 }

Example: SpaceBeforeBlockParameters: true

# The SpaceBeforeBlockParameters style set to `false` enforces that
# there is no space between `{` and `|`. Overrides `EnforcedStyle`
# if there is a conflict.

# bad
[1, 2, 3].each { |n| n * 2 }

# good
[1, 2, 3].each {|n| n * 2 }

Space missing after comma.
Open

        value_index = ask_with_validation(message,->(value){ (value.to_i >= 0 and value.to_i < array.count) },"Invalid selection. Please enter number from 0 to #{array.count-1}")
Severity: Minor
Found in lib/generamba/cli/thor_extension.rb by rubocop

Checks for comma (,) not followed by some kind of space.

Example:

# bad
[1,2]
{ foo:bar,}

# good
[1, 2]
{ foo:bar, }

Surrounding space missing for operator -.
Open

        value_index = ask_with_validation(message,->(value){ (value.to_i >= 0 and value.to_i < array.count) },"Invalid selection. Please enter number from 0 to #{array.count-1}")
Severity: Minor
Found in lib/generamba/cli/thor_extension.rb by rubocop

Checks that operators have space around them, except for ** which should not have surrounding space.

Example:

# bad
total = 3*4
"apple"+"juice"
my_number = 38/4
a ** b

# good
total = 3 * 4
"apple" + "juice"
my_number = 38 / 4
a**b

Line is too long. [88/80]
Open

      def ask_non_empty_string(message, description = 'Value should be nonempty string')
Severity: Minor
Found in lib/generamba/cli/thor_extension.rb by rubocop

Line is too long. [178/80]
Open

        value_index = ask_with_validation(message,->(value){ (value.to_i >= 0 and value.to_i < array.count) },"Invalid selection. Please enter number from 0 to #{array.count-1}")
Severity: Minor
Found in lib/generamba/cli/thor_extension.rb by rubocop

Line is too long. [124/80]
Open

          is_right_path = yes?"The path to a #{message_file_name} is '#{project_files[0]}'. Do you want to use it? (yes/no)"
Severity: Minor
Found in lib/generamba/cli/thor_extension.rb by rubocop

Space missing after comma.
Open

        return ask_with_validation(message,->(value){value.length > 0 },description)
Severity: Minor
Found in lib/generamba/cli/thor_extension.rb by rubocop

Checks for comma (,) not followed by some kind of space.

Example:

# bad
[1,2]
{ foo:bar,}

# good
[1, 2]
{ foo:bar, }

Use nested module/class definitions instead of compact style.
Open

  class ::Thor
Severity: Minor
Found in lib/generamba/cli/thor_extension.rb by rubocop

This cop checks the style of children definitions at classes and modules. Basically there are two different styles:

Example: EnforcedStyle: nested (default)

# good
# have each child on its own line
class Foo
  class Bar
  end
end

Example: EnforcedStyle: compact

# good
# combine definitions as much as possible
class Foo::Bar
end

The compact style is only forced for classes/modules with one child.

Redundant return detected.
Open

        return array[value_index.to_i]
Severity: Minor
Found in lib/generamba/cli/thor_extension.rb by rubocop

This cop checks for redundant return expressions.

Example:

def test
  return something
end

def test
  one
  two
  three
  return something
end

It should be extended to handle methods whose body is if/else or a case expression with a default branch.

Redundant return detected.
Open

        return array
Severity: Minor
Found in lib/generamba/cli/thor_extension.rb by rubocop

This cop checks for redundant return expressions.

Example:

def test
  return something
end

def test
  one
  two
  three
  return something
end

It should be extended to handle methods whose body is if/else or a case expression with a default branch.

Final newline missing.
Open

end
Severity: Minor
Found in lib/generamba/cli/thor_extension.rb by rubocop

Line is too long. [84/80]
Open

        return ask_with_validation(message,->(value){value.length > 0 },description)
Severity: Minor
Found in lib/generamba/cli/thor_extension.rb by rubocop

Use array literal [] instead of Array.new.
Open

        array = Array.new
Severity: Minor
Found in lib/generamba/cli/thor_extension.rb by rubocop

This cop checks for the use of a method, the result of which would be a literal, like an empty array, hash or string.

Example:

# bad
a = Array.new
h = Hash.new
s = String.new

# good
a = []
h = {}
s = ''

Redundant return detected.
Open

        return ask_with_validation(message,->(value){value.length > 0 },description)
Severity: Minor
Found in lib/generamba/cli/thor_extension.rb by rubocop

This cop checks for redundant return expressions.

Example:

def test
  return something
end

def test
  one
  two
  three
  return something
end

It should be extended to handle methods whose body is if/else or a case expression with a default branch.

Space missing to the left of {.
Open

        value_index = ask_with_validation(message,->(value){ (value.to_i >= 0 and value.to_i < array.count) },"Invalid selection. Please enter number from 0 to #{array.count-1}")
Severity: Minor
Found in lib/generamba/cli/thor_extension.rb by rubocop

Checks that block braces have or don't have a space before the opening brace depending on configuration.

Example:

# bad
foo.map{ |a|
  a.bar.to_s
}

# good
foo.map { |a|
  a.bar.to_s
}

Use nested module/class definitions instead of compact style.
Open

module Generamba::CLI
Severity: Minor
Found in lib/generamba/cli/thor_extension.rb by rubocop

This cop checks the style of children definitions at classes and modules. Basically there are two different styles:

Example: EnforcedStyle: nested (default)

# good
# have each child on its own line
class Foo
  class Bar
  end
end

Example: EnforcedStyle: compact

# good
# combine definitions as much as possible
class Foo::Bar
end

The compact style is only forced for classes/modules with one child.

Space missing to the left of {.
Open

        return ask_with_validation(message,->(value){value.length > 0 },description)
Severity: Minor
Found in lib/generamba/cli/thor_extension.rb by rubocop

Checks that block braces have or don't have a space before the opening brace depending on configuration.

Example:

# bad
foo.map{ |a|
  a.bar.to_s
}

# good
foo.map { |a|
  a.bar.to_s
}

Use !empty? instead of length > 0.
Open

        return ask_with_validation(message,->(value){value.length > 0 },description)
Severity: Minor
Found in lib/generamba/cli/thor_extension.rb by rubocop

This cop checks for numeric comparisons that can be replaced by a predicate method, such as receiver.length == 0, receiver.length > 0, receiver.length != 0, receiver.length < 1 and receiver.size == 0 that can be replaced by receiver.empty? and !receiver.empty.

Example:

# bad
[1, 2, 3].length == 0
0 == "foobar".length
array.length < 1
{a: 1, b: 2}.length != 0
string.length > 0
hash.size > 0

# good
[1, 2, 3].empty?
"foobar".empty?
array.empty?
!{a: 1, b: 2}.empty?
!string.empty?
!hash.empty?

Put one space between the method name and the first argument.
Open

          is_right_path = yes?"The path to a #{message_file_name} is '#{project_files[0]}'. Do you want to use it? (yes/no)"
Severity: Minor
Found in lib/generamba/cli/thor_extension.rb by rubocop

Checks that exactly one space is used between a method name and the first argument for method calls without parentheses.

Alternatively, extra spaces can be added to align the argument with something on a preceding or following line, if the AllowForAlignment config parameter is true.

Example:

# bad
something  x
something   y, z
something'hello'

# good
something x
something y, z
something 'hello'

Missing top-level class documentation comment.
Open

  class ::Thor
Severity: Minor
Found in lib/generamba/cli/thor_extension.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, or constant definitions.

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

# good
# Description/Explanation of Person class
class Person
  # ...
end

Redundant return detected.
Open

        return xcode_path
Severity: Minor
Found in lib/generamba/cli/thor_extension.rb by rubocop

This cop checks for redundant return expressions.

Example:

def test
  return something
end

def test
  one
  two
  three
  return something
end

It should be extended to handle methods whose body is if/else or a case expression with a default branch.

Line is too long. [85/80]
Open

      def ask_with_validation(message, is_valid_value, description = 'Invalid value')
Severity: Minor
Found in lib/generamba/cli/thor_extension.rb by rubocop

Use && instead of and.
Open

        value_index = ask_with_validation(message,->(value){ (value.to_i >= 0 and value.to_i < array.count) },"Invalid selection. Please enter number from 0 to #{array.count-1}")
Severity: Minor
Found in lib/generamba/cli/thor_extension.rb by rubocop

This cop checks for uses of and and or, and suggests using && and || instead. It can be configured to check only in conditions, or in all contexts.

Example: EnforcedStyle: always (default)

# bad
foo.save and return

# bad
if foo and bar
end

# good
foo.save && return

# good
if foo && bar
end

Example: EnforcedStyle: conditionals

# bad
if foo and bar
end

# good
foo.save && return

# good
foo.save and return

# good
if foo && bar
end

There are no issues that match your filters.

Category
Status