ManageIQ/linux_admin

View on GitHub
lib/linux_admin/disk.rb

Summary

Maintainability
A
45 mins
Test Coverage
A
100%

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

    def create_partition(partition_type, *args)
      create_partition_table unless has_partition_table?

      start = finish = size = nil
      case args.length
Severity: Minor
Found in lib/linux_admin/disk.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

Use filter_map instead.
Open

      result.output.split("\n").collect do |string|
        path, size, type, *model = string.split
        if type.casecmp?('disk') && size.to_i > 0
          self.new(:path => path, :size => size.to_i, :model => model.join(' '))
        end
Severity: Minor
Found in lib/linux_admin/disk.rb by rubocop

Use match? instead of =~ when MatchData is not used.
Open

        elsif l =~ /^Model:.*/
Severity: Minor
Found in lib/linux_admin/disk.rb by rubocop

In Ruby 2.4, String#match?, Regexp#match? and Symbol#match? have been added. The methods are faster than match. Because the methods avoid creating a MatchData object or saving backref. So, when MatchData is not used, use match? instead of match.

Example:

# bad
def foo
  if x =~ /re/
    do_something
  end
end

# bad
def foo
  if x.match(/re/)
    do_something
  end
end

# bad
def foo
  if /re/ === x
    do_something
  end
end

# good
def foo
  if x.match?(/re/)
    do_something
  end
end

# good
def foo
  if x =~ /re/
    do_something(Regexp.last_match)
  end
end

# good
def foo
  if x.match(/re/)
    do_something($~)
  end
end

# good
def foo
  if /re/ === x
    do_something($~)
  end
end

Use match? instead of =~ when MatchData is not used.
Open

        if l =~ /^ [0-9].*/
Severity: Minor
Found in lib/linux_admin/disk.rb by rubocop

In Ruby 2.4, String#match?, Regexp#match? and Symbol#match? have been added. The methods are faster than match. Because the methods avoid creating a MatchData object or saving backref. So, when MatchData is not used, use match? instead of match.

Example:

# bad
def foo
  if x =~ /re/
    do_something
  end
end

# bad
def foo
  if x.match(/re/)
    do_something
  end
end

# bad
def foo
  if /re/ === x
    do_something
  end
end

# good
def foo
  if x.match?(/re/)
    do_something
  end
end

# good
def foo
  if x =~ /re/
    do_something(Regexp.last_match)
  end
end

# good
def foo
  if x.match(/re/)
    do_something($~)
  end
end

# good
def foo
  if /re/ === x
    do_something($~)
  end
end

There are no issues that match your filters.

Category
Status