cloudamatic/mu

View on GitHub

Showing 2,704 of 2,705 total issues

Use each_key instead of keys.each.
Open

              bindings['by_scope']['projects'][args[:project]].keys.each { |r|
Severity: Minor
Found in modules/mu/providers/google/role.rb 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 }

Unused method argument - deploy_id.
Open

        def self.cleanup(noop: false, deploy_id: MU.deploy_id, ignoremaster: false, region: MU.curRegion, credentials: nil, flags: {})

This cop checks for unused method arguments.

Example:

# bad

def some_method(used, unused, _unused_but_allowed)
  puts used
end

Example:

# good

def some_method(used, _unused, _unused_but_allowed)
  puts used
end

Use tr instead of gsub.
Open

            filter += %Q{ AND (labels.mu-master-ip = "#{MU.mu_public_ip.gsub(/\./, "_")}")}

This cop identifies places where gsub can be replaced by tr or delete.

Example:

# bad
'abc'.gsub('b', 'd')
'abc'.gsub('a', '')
'abc'.gsub(/a/, 'd')
'abc'.gsub!('a', 'd')

# good
'abc'.gsub(/.*/, 'a')
'abc'.gsub(/a+/, 'd')
'abc'.tr('b', 'd')
'a b c'.delete(' ')

Do not suppress exceptions.
Open

          rescue Aws::CloudWatchLogs::Errors::ResourceAlreadyExistsException

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

Use caller(1..1).first instead of caller[0].
Open

              MU.log "Duplicate request to create alarm #{name}. This one came from #{caller[0]}", MU::WARN
Severity: Minor
Found in modules/mu/providers/aws/alarm.rb by rubocop

This cop identifies places where caller[n] can be replaced by caller(n..n).first.

Example:

# bad
caller[1]
caller.first
caller_locations[1]
caller_locations.first

# good
caller(2..2).first
caller(1..1).first
caller_locations(2..2).first
caller_locations(1..1).first

Do not suppress exceptions.
Open

                rescue StandardError
Severity: Minor
Found in modules/mu/providers/aws/server.rb 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

Variable bok used in void context.
Open

              bok

This cop checks for operators, variables and literals used in void context.

Example:

# bad

def some_method
  some_num * 10
  do_something
end

Example:

# bad

def some_method(some_var)
  some_var
  do_something
end

Example:

# good

def some_method
  do_something
  some_num * 10
end

Example:

# good

def some_method(some_var)
  do_something
  some_var
end

Unused method argument - flags.
Open

        def self.cleanup(noop: false, deploy_id: MU.deploy_id, ignoremaster: false, credentials: nil, flags: {})
Severity: Minor
Found in modules/mu/providers/aws/cdn.rb by rubocop

This cop checks for unused method arguments.

Example:

# bad

def some_method(used, unused, _unused_but_allowed)
  puts used
end

Example:

# good

def some_method(used, _unused, _unused_but_allowed)
  puts used
end

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

                f.lambda_function_arn.match(/^arn:.*?:lambda:([^:]+?):(\d*):function:([^:]+)/)
Severity: Minor
Found in modules/mu/providers/aws/cdn.rb 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'

Redundant use of Object#to_s in interpolation.
Open

                  MU.log "Purging #{del.size.to_s} objects and versions from #{bucket.name}"
Severity: Minor
Found in modules/mu/providers/aws/bucket.rb 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}"

Use == if you meant to do a comparison or wrap the expression in parentheses to indicate you meant to assign in a condition.
Open

                      if tg_name = @deploy.getResourceName(tg_cfg["name"], max_length: 32, disallowed_chars: /[^A-Za-z0-9-]/)

This cop checks for assignments in the conditions of if/while/until.

Example:

# bad

if some_var = true
  do_something
end

Example:

# good

if some_var == true
  do_something
end

Avoid more than 4 levels of block nesting.
Open

                      if !ext_check or
                         !ext_check.load_balancer_descriptions or
                         !ext_check.load_balancer_descriptions[0]
                        sleep 3
                      else stillhere = false

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 casecmp instead of upcase ==.
Open

                if listener[:protocol].upcase == 'HTTP' or listener[:protocol].upcase == 'HTTPS'

This cop identifies places where a case-insensitive string comparison can better be implemented using casecmp.

Example:

# bad
str.downcase == 'abc'
str.upcase.eql? 'ABC'
'abc' == str.downcase
'ABC'.eql? str.upcase
str.downcase == str.downcase

# good
str.casecmp('ABC').zero?
'abc'.casecmp(str).zero?

end at 1335, 10 is not aligned with if at 1329, 24.
Open

          end
Severity: Minor
Found in modules/mu/providers/aws/vpc.rb by rubocop

This cop checks whether the end keywords are aligned properly.

Three modes are supported through the EnforcedStyleAlignWith configuration parameter:

If it's set to keyword (which is the default), the end shall be aligned with the start of the keyword (if, class, etc.).

If it's set to variable the end shall be aligned with the left-hand-side of the variable assignment, if there is one.

If it's set to start_of_line, the end shall be aligned with the start of the line where the matching keyword appears.

Example: EnforcedStyleAlignWith: keyword (default)

# bad

variable = if true
    end

# good

variable = if true
           end

Example: EnforcedStyleAlignWith: variable

# bad

variable = if true
    end

# good

variable = if true
end

Example: EnforcedStyleAlignWith: startofline

# bad

variable = if true
    end

# good

puts(if true
end)

Useless assignment to variable - cert_domains. Use _ or _cert_domains as a variable name to indicate that it won't be used.
Open

                cert_arn, cert_domains = MU::Cloud::AWS.resolveSSLCertificate(dom['certificate'], region: dom['region'], credentials: dom['credentials'])

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 =~ in places where the MatchData returned by #match will not be used.
Open

                  elsif m_desc.method_integration.uri.match(/#{@region}:([^:]+):action\/(.*)/)

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'

Useless assignment to variable - start.
Open

start = Time.now

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 =~ in places where the MatchData returned by #match will not be used.
Open

            if cluster.match(/^#{deploy_id}-/)

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'

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

          cluster["flavor"] = "EKS" if cluster["flavor"].match(/^Kubernetes$/i)

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'

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

              if pol.policy_arn.match(/arn:aws(?:-us-gov)?:iam::aws:policy\//)
Severity: Minor
Found in modules/mu/providers/aws/user.rb 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'
Severity
Category
Status
Source
Language