crowbar/crowbar-hadoop

View on GitHub

Showing 509 of 509 total issues

Use && instead of and. (https://github.com/bbatsov/ruby-style-guide#no-and-or-or)
Open

        if n[:fqdn] and !n[:fqdn].empty?

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

Use ! instead of not. (https://github.com/bbatsov/ruby-style-guide#bang-not-not)
Open

    if not edgenodes.empty?

This cop checks for uses of the keyword not instead of !.

Example:

# bad - parentheses are required because of op precedence
x = (not something)

# good
x = !something

Use || instead of or. (https://github.com/bbatsov/ruby-style-guide#no-and-or-or)
Open

    edge_nodes = nodes.find_all { |n| n.role? "hadoop-edgenode" or n.role? "clouderamanager-edgenode" }

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

Avoid using {...} for multi-line blocks. (https://github.com/bbatsov/ruby-style-guide#single-line-blocks)
Open

to_use_disks.sort.each { |k|

Check for uses of braces or do/end around single line or multi-line blocks.

Example: EnforcedStyle: linecountbased (default)

# bad - single line block
items.each do |item| item / 5 end

# good - single line block
items.each { |item| item / 5 }

# bad - multi-line block
things.map { |thing|
  something = thing.some_method
  process(something)
}

# good - multi-line block
things.map do |thing|
  something = thing.some_method
  process(something)
end

Example: EnforcedStyle: semantic

# Prefer `do...end` over `{...}` for procedural blocks.

# return value is used/assigned
# bad
foo = map do |x|
  x
end
puts (map do |x|
  x
end)

# return value is not used out of scope
# good
map do |x|
  x
end

# Prefer `{...}` over `do...end` for functional blocks.

# return value is not used out of scope
# bad
each { |x|
  x
}

# return value is used/assigned
# good
foo = map { |x|
  x
}
map { |x|
  x
}.inspect

Example: EnforcedStyle: bracesforchaining

# bad
words.each do |word|
  word.flip.flop
end.join("-")

# good
words.each { |word|
  word.flip.flop
}.join("-")

Use array literal [] instead of Array.new. (https://github.com/bbatsov/ruby-style-guide#literal-array-hash)
Open

master_name_nodes = Array.new

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 = ''

Line is too long. [107/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength)
Open

    datanodes         = nodeswithroles.find_all { |n| n.roles.include?("hadoop_infrastructure-datanode" ) }

Favor unless over if for negative conditions. (https://github.com/bbatsov/ruby-style-guide#unless-for-negatives)
Open

    if not namenodes.empty?
      base["deployment"]["hadoop_infrastructure"]["elements"]["hadoop_infrastructure-namenode"] = namenodes
    end

Checks for uses of if with a negated condition. Only ifs without else are considered. There are three different styles:

- both
- prefix
- postfix

Example: EnforcedStyle: both (default)

# enforces `unless` for `prefix` and `postfix` conditionals

# bad

if !foo
  bar
end

# good

unless foo
  bar
end

# bad

bar if !foo

# good

bar unless foo

Example: EnforcedStyle: prefix

# enforces `unless` for just `prefix` conditionals

# bad

if !foo
  bar
end

# good

unless foo
  bar
end

# good

bar if !foo

Example: EnforcedStyle: postfix

# enforces `unless` for just `postfix` conditionals

# bad

bar if !foo

# good

bar unless foo

# good

if !foo
  bar
end

Line is too long. [101/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength)
Open

    base["deployment"]["hadoop"]["elements"]["hadoop-slavenode"] = slaves if slaves && !slaves.empty?

Use || instead of or. (https://github.com/bbatsov/ruby-style-guide#no-and-or-or)
Open

      next if tnodes.nil? or tnodes.empty?

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

Use !empty? instead of length > 0.
Open

    if !edge_fqdns.nil? && edge_fqdns.length > 0

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?

Surrounding space missing for operator =. (https://github.com/bbatsov/ruby-style-guide#spaces-operators)
Open

    disk[:uuid]=get_uuid disk[:name]

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

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

  if ! File.exists?(target_dev)

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

Example:

# bad

File.exists?(some_path)

Example:

# good

File.exist?(some_path)

Favor unless over if for negative conditions. (https://github.com/bbatsov/ruby-style-guide#unless-for-negatives)
Open

  if ! File.exists?(target_dev)
    Chef::Log.warn("HADOOP : device: #{target_dev} doesn't seem to exist. ignoring")
    next
  end

Checks for uses of if with a negated condition. Only ifs without else are considered. There are three different styles:

- both
- prefix
- postfix

Example: EnforcedStyle: both (default)

# enforces `unless` for `prefix` and `postfix` conditionals

# bad

if !foo
  bar
end

# good

unless foo
  bar
end

# bad

bar if !foo

# good

bar unless foo

Example: EnforcedStyle: prefix

# enforces `unless` for just `prefix` conditionals

# bad

if !foo
  bar
end

# good

unless foo
  bar
end

# good

bar if !foo

Example: EnforcedStyle: postfix

# enforces `unless` for just `postfix` conditionals

# bad

bar if !foo

# good

bar unless foo

# good

if !foo
  bar
end

Prefer double-quoted strings inside interpolations. (https://github.com/SUSE/style-guides/blob/master/Ruby.md#stylestringliteralsininterpolation)
Open

Chef::Log.info("HADOOP: found disk: #{to_use_disks.join(':')}") if debug

This cop checks that quotes inside the string interpolation match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
result = "Tests #{success ? "PASS" : "FAIL"}"

# good
result = "Tests #{success ? 'PASS' : 'FAIL'}"

Example: EnforcedStyle: double_quotes

# bad
result = "Tests #{success ? 'PASS' : 'FAIL'}"

# good
result = "Tests #{success ? "PASS" : "FAIL"}"

Space missing after comma. (https://github.com/bbatsov/ruby-style-guide#spaces-operators)
Open

  master_node_ip = BarclampLibrary::Barclamp::Inventory.get_network_by_type(master_name_node_objects[0],"admin").address

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

Example:

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

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

Convert if nested inside else to elsif.
Open

  Chef::Log.info("HADOOP : SECONDARY NAME NODE IP #{secondary_node_ip}") if debug

If the else branch of a conditional consists solely of an if node, it can be combined with the else to become an elsif. This helps to keep the nesting level from getting too deep.

Example:

# bad
if condition_a
  action_a
else
  if condition_b
    action_b
  else
    action_c
  end
end

# good
if condition_a
  action_a
elsif condition_b
  action_b
else
  action_c
end

Line is too long. [107/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength)
Open

      base["deployment"]["hadoop_infrastructure"]["elements"]["hadoop_infrastructure-server"] = servernodes

Use next to skip iteration. (https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals)
Open

      if n.admin?

Use next to skip iteration instead of a condition at the end.

Example: EnforcedStyle: skipmodifierifs (default)

# bad
[1, 2].each do |a|
  if a == 1
    puts a
  end
end

# good
[1, 2].each do |a|
  next unless a == 1
  puts a
end

# good
[1, 2].each do |o|
  puts o unless o == 1
end

Example: EnforcedStyle: always

# With `always` all conditions at the end of an iteration needs to be
# replaced by next - with `skip_modifier_ifs` the modifier if like
# this one are ignored: `[1, 2].each { |a| return 'yes' if a == 1 }`

# bad
[1, 2].each do |o|
  puts o unless o == 1
end

# bad
[1, 2].each do |a|
  if a == 1
    puts a
  end
end

# good
[1, 2].each do |a|
  next unless a == 1
  puts a
end

Space inside range literal. (https://github.com/bbatsov/ruby-style-guide#no-space-inside-range-literals)
Open

      nodes[3 .. nodes.size].each { |n|

Checks for spaces inside range literals.

Example:

# bad
1 .. 3

# good
1..3

# bad
'a' .. 'z'

# good
'a'..'z'

Space inside empty hash literal braces detected. (https://github.com/bbatsov/ruby-style-guide#spaces-operators)
Open

    base["deployment"]["zookeeper"]["elements"] = { }

Checks that braces used for hash literals have or don't have surrounding space depending on configuration.

Example: EnforcedStyle: space

# The `space` style enforces that hash literals have
# surrounding space.

# bad
h = {a: 1, b: 2}

# good
h = { a: 1, b: 2 }

Example: EnforcedStyle: no_space

# The `no_space` style enforces that hash literals have
# no surrounding space.

# bad
h = { a: 1, b: 2 }

# good
h = {a: 1, b: 2}

Example: EnforcedStyle: compact

# The `compact` style normally requires a space inside
# hash braces, with the exception that successive left
# braces or right braces are collapsed together in nested hashes.

# bad
h = { a: { b: 2 } }

# good
h = { a: { b: 2 }}
Severity
Category
Status
Source
Language