cloudamatic/mu

View on GitHub

Showing 2,704 of 2,705 total issues

Use =~ in places where the MatchData returned by #match will not be used.
Open

        ipcfg.subnet.id.match(/resourceGroups\/([^\/]+)\/providers\/Microsoft.Network\/virtualNetworks\/([^\/]+)\/subnets\/(.*)/)
Severity: Minor
Found in bin/mu-azure-setup by rubocop

This cop identifies the use of Regexp#match or String#match, which returns #<MatchData>/nil. The return value of =~ is an integral index/nil and is more performant.

Example:

# bad
do_something if str.match(/regex/)
while regex.match('str')
  do_something
end

# good
method(str =~ /regex/)
return value unless regex =~ 'str'

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

          data["subtree"].each_pair { |subkey, subdata|
Severity: Minor
Found in bin/mu-configure 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

Example:

#good

do_something do |used, _unused|
  puts used
end

do_something do
  puts :foo
end

define_method(:foo) do |_bar|
  puts :baz
end

Use =~ in places where the MatchData returned by #match will not be used.
Open

          if cloud.match(/^#{Regexp.quote(c)}$/i)
Severity: Minor
Found in bin/mu-run-tests by rubocop

This cop identifies the use of Regexp#match or String#match, which returns #<MatchData>/nil. The return value of =~ is an integral index/nil and is more performant.

Example:

# bad
do_something if str.match(/regex/)
while regex.match('str')
  do_something
end

# good
method(str =~ /regex/)
return value unless regex =~ 'str'

Prefer using YAML.safe_load over YAML.load.
Open

    localfile = YAML.load(File.read("#{home}/.mu.yaml"))
Severity: Minor
Found in bin/mu-load-config.rb by rubocop

This cop checks for the use of YAML class methods which have potential security issues leading to remote code execution when loading from an untrusted source.

Example:

# bad
YAML.load("--- foo")

# good
YAML.safe_load("--- foo")
YAML.dump("foo")

Useless assignment to variable - print_output.
Open

  print_output = $opts[:verbose] || do_nodes.size == 1
Severity: Minor
Found in bin/mu-node-manage by rubocop

This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

File.exists? is deprecated in favor of File.exist?.
Open

  if File.exists?("/opt/opscode/bin/chef-server-ctl")
Severity: Minor
Found in bin/mu-gcp-setup by rubocop

This cop checks for uses of the deprecated class method usages.

Example:

# bad

File.exists?(some_path)

Example:

# good

File.exist?(some_path)

Useless assignment to variable - bucket. Did you mean bucketobj?
Open

        bucket = MU::Cloud::Google.storage(credentials: credset).insert_bucket(
Severity: Minor
Found in bin/mu-gcp-setup by rubocop

This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Use meaningful heredoc delimiters.
Open

  EOS
Severity: Minor
Found in bin/mu-tunnel-nagios by rubocop

This cop checks that your heredocs are using meaningful delimiters. By default it disallows END and EO*, and can be configured through blacklisting additional delimiters.

Example:

# good
<<-SQL
  SELECT * FROM foo
SQL

# bad
<<-END
  SELECT * FROM foo
END

# bad
<<-EOS
  SELECT * FROM foo
EOS

Useless assignment to variable - bucket. Did you mean bucketobj?
Open

      bucket = MU::Cloud::Azure.storage(credentials: credset).get_bucket(bucketname)
Severity: Minor
Found in bin/mu-azure-setup by rubocop

This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

(...) interpreted as grouped expression.
Open

    puts (desc['required'] ? "REQUIRED".red.on_black : "OPTIONAL".yellow.on_black)+" - "+desc["desc"]
Severity: Minor
Found in bin/mu-configure by rubocop

Checks for space between the name of a called method and a left parenthesis.

Example:

# bad

puts (x + y)

Example:

# good

puts(x + y)

Redundant use of Object#to_s in interpolation.
Open

      FileUtils.cp("#{HOMEDIR}/.ssh/config", "#{HOMEDIR}/.ssh/config.bak.#{Process.pid.to_s}")
Severity: Minor
Found in bin/mu-configure by rubocop

This cop checks for string conversion in string interpolation, which is redundant.

Example:

# bad

"result is #{something.to_s}"

Example:

# good

"result is #{something}"

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

          map[count.to_s].each_pair { |k, v| v.delete("value") } # use defaults
Severity: Minor
Found in bin/mu-configure 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

Example:

#good

do_something do |used, _unused|
  puts used
end

do_something do
  puts :foo
end

define_method(:foo) do |_bar|
  puts :baz
end

Use meaningful heredoc delimiters.
Open

    EOS
Severity: Minor
Found in bin/mu-configure by rubocop

This cop checks that your heredocs are using meaningful delimiters. By default it disallows END and EO*, and can be configured through blacklisting additional delimiters.

Example:

# good
<<-SQL
  SELECT * FROM foo
SQL

# bad
<<-END
  SELECT * FROM foo
END

# bad
<<-EOS
  SELECT * FROM foo
EOS

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

    mommacat.kittens['servers'].each_pair { |habitat, nodeclasses|
Severity: Minor
Found in bin/mu-node-manage 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

Example:

#good

do_something do |used, _unused|
  puts used
end

do_something do
  puts :foo
end

define_method(:foo) do |_bar|
  puts :baz
end

Useless assignment to variable - e.
Open

            rescue MU::MuError => e
Severity: Minor
Found in bin/mu-node-manage by rubocop

This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Do not suppress exceptions.
Open

        rescue MU::Cloud::MuCloudResourceNotImplemented
Severity: Minor
Found in bin/mu-gen-docs by rubocop

This cop checks for rescue blocks with no body.

Example:

# bad

def some_method
  do_something
rescue
  # do nothing
end

Example:

# bad

begin
  do_something
rescue
  # do nothing
end

Example:

# good

def some_method
  do_something
rescue
  handle_exception
end

Example:

# good

begin
  do_something
rescue
  handle_exception
end

Do not shadow rescued Exceptions.
Open

  rescue LoadError, Gem::MissingSpecError
    _system("cd #{MU_BASE}/lib/modules && umask 0022 && /usr/local/ruby-current/bin/bundle install")
    require 'bundler'
    pwd = Dir.pwd
    Dir.chdir(MU_BASE+"/lib/modules")
Severity: Minor
Found in bin/mu-configure by rubocop

This cop checks for a rescued exception that get shadowed by a less specific exception being rescued before a more specific exception is rescued.

Example:

# bad

begin
  something
rescue Exception
  handle_exception
rescue StandardError
  handle_standard_error
end

# good

begin
  something
rescue StandardError
  handle_standard_error
rescue Exception
  handle_exception
end

# good, however depending on runtime environment.
#
# This is a special case for system call errors.
# System dependent error code depends on runtime environment.
# For example, whether `Errno::EAGAIN` and `Errno::EWOULDBLOCK` are
# the same error code or different error code depends on environment.
# This good case is for `Errno::EAGAIN` and `Errno::EWOULDBLOCK` with
# the same error code.
begin
  something
rescue Errno::EAGAIN, Errno::EWOULDBLOCK
  handle_standard_error
end

Useless assignment to variable - data.
Open

        data = nil
Severity: Minor
Found in bin/mu-configure by rubocop

This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Avoid more than 4 levels of block nesting.
Open

            puts "\n\n" if addnewline
Severity: Minor
Found in bin/mu-configure by rubocop

This cop checks for excessive nesting of conditional and looping constructs.

You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

The maximum level of nesting allowed is configurable.

Use each_key instead of keys.each.
Open

        $CONFIGURABLES[key]["subtree"].keys.each { |subkey|
Severity: Minor
Found in bin/mu-configure by rubocop

This cop checks for uses of each_key and each_value Hash methods.

Note: If you have an array of two-element arrays, you can put parentheses around the block arguments to indicate that you're not working with a hash, and suppress RuboCop offenses.

Example:

# bad
hash.keys.each { |k| p k }
hash.values.each { |v| p v }
hash.each { |k, _v| p k }
hash.each { |_k, v| p v }

# good
hash.each_key { |k| p k }
hash.each_value { |v| p v }
Severity
Category
Status
Source
Language