crowbar/crowbar-hadoop

View on GitHub
chef/cookbooks/hadoop_infrastructure/recipes/node-setup.rb

Summary

Maintainability
C
1 day
Test Coverage

Similar blocks of code found in 5 locations. Consider refactoring.
Open

search(:node, "roles:hadoop_infrastructure-ha-journalingnode#{env_filter}") do |n|
  if n[:fqdn] and not n[:fqdn].empty?
    ipaddr = BarclampLibrary::Barclamp::Inventory.get_network_by_type(n,"admin").address
    ssh_key = n[:crowbar][:ssh][:root_pub_key] rescue nil
    node_rec = { fqdn: n[:fqdn], ipaddr: ipaddr, name: n.name, ssh_key: ssh_key }
Severity: Major
Found in chef/cookbooks/hadoop_infrastructure/recipes/node-setup.rb and 4 other locations - About 1 hr to fix
chef/cookbooks/hadoop_infrastructure/recipes/node-setup.rb on lines 136..143
chef/cookbooks/hadoop_infrastructure/recipes/node-setup.rb on lines 167..174
chef/cookbooks/hadoop_infrastructure/recipes/node-setup.rb on lines 182..189
chef/cookbooks/hadoop_infrastructure/recipes/node-setup.rb on lines 197..204

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 70.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 5 locations. Consider refactoring.
Open

search(:node, "roles:hadoop_infrastructure-namenode#{env_filter}") do |n|
  if n[:fqdn] and not n[:fqdn].empty?
    ipaddr = BarclampLibrary::Barclamp::Inventory.get_network_by_type(n,"admin").address
    ssh_key = n[:crowbar][:ssh][:root_pub_key] rescue nil
    node_rec = { fqdn: n[:fqdn], ipaddr: ipaddr, name: n.name, ssh_key: ssh_key }
Severity: Major
Found in chef/cookbooks/hadoop_infrastructure/recipes/node-setup.rb and 4 other locations - About 1 hr to fix
chef/cookbooks/hadoop_infrastructure/recipes/node-setup.rb on lines 167..174
chef/cookbooks/hadoop_infrastructure/recipes/node-setup.rb on lines 182..189
chef/cookbooks/hadoop_infrastructure/recipes/node-setup.rb on lines 197..204
chef/cookbooks/hadoop_infrastructure/recipes/node-setup.rb on lines 212..219

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 70.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 5 locations. Consider refactoring.
Open

search(:node, "roles:hadoop_infrastructure-server#{env_filter}") do |n|
  if n[:fqdn] and not n[:fqdn].empty?
    ipaddr = BarclampLibrary::Barclamp::Inventory.get_network_by_type(n,"admin").address
    ssh_key = n[:crowbar][:ssh][:root_pub_key] rescue nil
    node_rec = { fqdn: n[:fqdn], ipaddr: ipaddr, name: n.name, ssh_key: ssh_key }
Severity: Major
Found in chef/cookbooks/hadoop_infrastructure/recipes/node-setup.rb and 4 other locations - About 1 hr to fix
chef/cookbooks/hadoop_infrastructure/recipes/node-setup.rb on lines 136..143
chef/cookbooks/hadoop_infrastructure/recipes/node-setup.rb on lines 167..174
chef/cookbooks/hadoop_infrastructure/recipes/node-setup.rb on lines 197..204
chef/cookbooks/hadoop_infrastructure/recipes/node-setup.rb on lines 212..219

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 70.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 5 locations. Consider refactoring.
Open

search(:node, "roles:hadoop_infrastructure-edgenode#{env_filter}") do |n|
  if n[:fqdn] and not n[:fqdn].empty?
    ipaddr = BarclampLibrary::Barclamp::Inventory.get_network_by_type(n,"admin").address
    ssh_key = n[:crowbar][:ssh][:root_pub_key] rescue nil
    node_rec = { fqdn: n[:fqdn], ipaddr: ipaddr, name: n.name, ssh_key: ssh_key }
Severity: Major
Found in chef/cookbooks/hadoop_infrastructure/recipes/node-setup.rb and 4 other locations - About 1 hr to fix
chef/cookbooks/hadoop_infrastructure/recipes/node-setup.rb on lines 136..143
chef/cookbooks/hadoop_infrastructure/recipes/node-setup.rb on lines 182..189
chef/cookbooks/hadoop_infrastructure/recipes/node-setup.rb on lines 197..204
chef/cookbooks/hadoop_infrastructure/recipes/node-setup.rb on lines 212..219

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 70.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 5 locations. Consider refactoring.
Open

search(:node, "roles:hadoop_infrastructure-ha-filernode#{env_filter}") do |n|
  if n[:fqdn] and not n[:fqdn].empty?
    ipaddr = BarclampLibrary::Barclamp::Inventory.get_network_by_type(n,"admin").address
    ssh_key = n[:crowbar][:ssh][:root_pub_key] rescue nil
    node_rec = { fqdn: n[:fqdn], ipaddr: ipaddr, name: n.name, ssh_key: ssh_key }
Severity: Major
Found in chef/cookbooks/hadoop_infrastructure/recipes/node-setup.rb and 4 other locations - About 1 hr to fix
chef/cookbooks/hadoop_infrastructure/recipes/node-setup.rb on lines 136..143
chef/cookbooks/hadoop_infrastructure/recipes/node-setup.rb on lines 167..174
chef/cookbooks/hadoop_infrastructure/recipes/node-setup.rb on lines 182..189
chef/cookbooks/hadoop_infrastructure/recipes/node-setup.rb on lines 212..219

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 70.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||. (https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier)
Open

if File.exists?(rc_local_path)

Checks for if and unless statements that would fit on one line if written as a modifier if/unless. The maximum line length is configured in the Metrics/LineLength cop.

Example:

# bad
if condition
  do_stuff(bar)
end

unless qux.empty?
  Foo.do_something
end

# good
do_stuff(bar) if condition
Foo.do_something unless qux.empty?

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

  if n[:fqdn] and not n[:fqdn].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 and. (https://github.com/bbatsov/ruby-style-guide#no-and-or-or)
Open

if (cur_thpval == "never" and cur_buff != "always [never]") or (cur_thpval == "always" and cur_buff != "[always] never")

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 and. (https://github.com/bbatsov/ruby-style-guide#no-and-or-or)
Open

if (cur_thpval == "never" and cur_buff != "always [never]") or (cur_thpval == "always" and cur_buff != "[always] never")

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 rescue in its modifier form. (https://github.com/bbatsov/ruby-style-guide#no-rescue-modifiers)
Open

    ssh_key = n[:crowbar][:ssh][:root_pub_key] rescue nil

This cop checks for uses of rescue in its modifier form.

Example:

# bad
some_method rescue handle_error

# good
begin
  some_method
rescue
  handle_error
end

Use [] for an array of words. (https://github.com/SUSE/style-guides/blob/master/Ruby.md#stylewordarray)
Open

  xfs_packages=%w{
    xfsprogs
  }

This cop can check for array literals made up of word-like strings, that are not using the %w() syntax.

Alternatively, it can check for uses of the %w() syntax, in projects which do not want to include that syntax.

Configuration option: MinSize If set, arrays with fewer elements than this value will not trigger the cop. For example, a MinSize of 3 will not enforce a style on an array of 2 or fewer elements.

Example: EnforcedStyle: percent (default)

# good
%w[foo bar baz]

# bad
['foo', 'bar', 'baz']

Example: EnforcedStyle: brackets

# good
['foo', 'bar', 'baz']

# bad
%w[foo bar baz]

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

if File.exists?(defrag_file_pathname)

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

Example:

# bad

File.exists?(some_path)

Example:

# good

File.exist?(some_path)

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

  if n[:fqdn] and not n[:fqdn].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

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

    node_rec = { fqdn: n[:fqdn], ipaddr: ipaddr, name: n.name, ssh_key: ssh_key, hdfs_mounts: hdfs_mounts}

The name of this source file (node-setup.rb) should use snake_case. (https://github.com/bbatsov/ruby-style-guide#snake-case-files)
Open

#

This cop makes sure that Ruby source files have snake_case names. Ruby scripts (i.e. source files with a shebang in the first line) are ignored.

Example:

# bad
lib/layoutManager.rb

anything/usingCamelCase

# good
lib/layout_manager.rb

anything/using_snake_case.rake

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

  if n[:fqdn] and not 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 and. (https://github.com/bbatsov/ruby-style-guide#no-and-or-or)
Open

  if n[:fqdn] and not 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 n[:fqdn] and not n[:fqdn].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 %r around regular expression. (https://github.com/SUSE/style-guides/blob/master/Ruby.md#styleregexpliteral)
Open

thp_array = cur_buff.scan /^[\t ]*echo\s*(.+?)\s*>\s*\/sys\/kernel\/mm\/redhat_transparent_hugepage\/defrag[\t ]*$/m

This cop enforces using // or %r around regular expressions.

Example: EnforcedStyle: slashes (default)

# bad
snake_case = %r{^[\dA-Z_]+$}

# bad
regex = %r{
  foo
  (bar)
  (baz)
}x

# good
snake_case = /^[\dA-Z_]+$/

# good
regex = /
  foo
  (bar)
  (baz)
/x

Example: EnforcedStyle: percent_r

# bad
snake_case = /^[\dA-Z_]+$/

# bad
regex = /
  foo
  (bar)
  (baz)
/x

# good
snake_case = %r{^[\dA-Z_]+$}

# good
regex = %r{
  foo
  (bar)
  (baz)
}x

Example: EnforcedStyle: mixed

# bad
snake_case = %r{^[\dA-Z_]+$}

# bad
regex = /
  foo
  (bar)
  (baz)
/x

# good
snake_case = /^[\dA-Z_]+$/

# good
regex = %r{
  foo
  (bar)
  (baz)
}x

Example: AllowInnerSlashes: false (default)

# If `false`, the cop will always recommend using `%r` if one or more
# slashes are found in the regexp string.

# bad
x =~ /home\//

# good
x =~ %r{home/}

Example: AllowInnerSlashes: true

# good
x =~ /home\//

Avoid using rescue in its modifier form. (https://github.com/bbatsov/ruby-style-guide#no-rescue-modifiers)
Open

    ssh_key = n[:crowbar][:ssh][:root_pub_key] rescue nil

This cop checks for uses of rescue in its modifier form.

Example:

# bad
some_method rescue handle_error

# good
begin
  some_method
rescue
  handle_error
end

Use empty? instead of length == 0.
Open

  if cur_buff.length == 0 or cur_buff[cur_buff.length - 1] == 10

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?

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

  if n[:fqdn] and not 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 and. (https://github.com/bbatsov/ruby-style-guide#no-and-or-or)
Open

  if n[:fqdn] and not 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 and. (https://github.com/bbatsov/ruby-style-guide#no-and-or-or)
Open

  if n[:fqdn] and not 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 the return of the conditional for variable assignment and comparison.
Open

  if cur_buff.length == 0 or cur_buff[cur_buff.length - 1] == 10
    # Last line already has a line ender.
    new_buff = cur_buff + rep_str
  else
    # Last line does not already have a line ender.

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

    ipaddr = BarclampLibrary::Barclamp::Inventory.get_network_by_type(n,"admin").address

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. (https://github.com/bbatsov/ruby-style-guide#spaces-operators)
Open

    ipaddr = BarclampLibrary::Barclamp::Inventory.get_network_by_type(n,"admin").address

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. (https://github.com/bbatsov/ruby-style-guide#spaces-operators)
Open

    ipaddr = BarclampLibrary::Barclamp::Inventory.get_network_by_type(n,"admin").address

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

Example:

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

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

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

if (cur_thpval == "never" and cur_buff != "always [never]") or (cur_thpval == "always" and cur_buff != "[always] never")

Convert if nested inside else to elsif.
Open

  Chef::Log.info("HI - No updates to #{defrag_file_pathname} required") 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

Avoid using rescue in its modifier form. (https://github.com/bbatsov/ruby-style-guide#no-rescue-modifiers)
Open

    ssh_key = n[:crowbar][:ssh][:root_pub_key] rescue nil

This cop checks for uses of rescue in its modifier form.

Example:

# bad
some_method rescue handle_error

# good
begin
  some_method
rescue
  handle_error
end

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

thp_array = cur_buff.scan /^[\t ]*echo\s*(.+?)\s*>\s*\/sys\/kernel\/mm\/redhat_transparent_hugepage\/defrag[\t ]*$/m

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

    new_buff = cur_buff.gsub(/^[\t ]*echo\s*(.+?)\s*>\s*\/sys\/kernel\/mm\/redhat_transparent_hugepage\/defrag[\t ]*$/, rep_str)

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

if not new_buff.nil?

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

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

    ipaddr = BarclampLibrary::Barclamp::Inventory.get_network_by_type(n,"admin").address

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

Example:

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

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

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

  if n[:fqdn] and not n[:fqdn].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

Avoid using rescue in its modifier form. (https://github.com/bbatsov/ruby-style-guide#no-rescue-modifiers)
Open

    ssh_key = n[:crowbar][:ssh][:root_pub_key] rescue nil

This cop checks for uses of rescue in its modifier form.

Example:

# bad
some_method rescue handle_error

# good
begin
  some_method
rescue
  handle_error
end

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

  if cur_buff.length == 0 or cur_buff[cur_buff.length - 1] == 10

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

Convert if nested inside else to elsif.
Open

  Chef::Log.info("HI - No THP updates to #{rc_local_path} required") 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

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

  if n[:fqdn] and not n[:fqdn].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

Avoid using rescue in its modifier form. (https://github.com/bbatsov/ruby-style-guide#no-rescue-modifiers)
Open

    ssh_key = n[:crowbar][:ssh][:root_pub_key] rescue nil

This cop checks for uses of rescue in its modifier form.

Example:

# bad
some_method rescue handle_error

# good
begin
  some_method
rescue
  handle_error
end

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

    ipaddr = BarclampLibrary::Barclamp::Inventory.get_network_by_type(n,"admin").address

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

Example:

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

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

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

    node_rec = { fqdn: n[:fqdn], ipaddr: ipaddr, name: n.name, ssh_key: ssh_key, hdfs_mounts: hdfs_mounts}

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 }}

Convert if nested inside else to elsif.
Open

    Chef::Log.info("HI - Current THP setting is correct [#{reg_thpval},#{cur_thpval}]") 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

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

  if n[:fqdn] and not n[:fqdn].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

%w-literals should be delimited by [ and ]. (https://github.com/bbatsov/ruby-style-guide#percent-literal-braces)
Open

  xfs_packages=%w{
    xfsprogs
  }

This cop enforces the consistent usage of %-literal delimiters.

Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.

Example:

# Style/PercentLiteralDelimiters:
#   PreferredDelimiters:
#     default: '[]'
#     '%i':    '()'

# good
%w[alpha beta] + %i(gamma delta)

# bad
%W(alpha #{beta})

# bad
%I(alpha beta)

Use %r around regular expression. (https://github.com/SUSE/style-guides/blob/master/Ruby.md#styleregexpliteral)
Open

    new_buff = cur_buff.gsub(/^[\t ]*echo\s*(.+?)\s*>\s*\/sys\/kernel\/mm\/redhat_transparent_hugepage\/defrag[\t ]*$/, rep_str)

This cop enforces using // or %r around regular expressions.

Example: EnforcedStyle: slashes (default)

# bad
snake_case = %r{^[\dA-Z_]+$}

# bad
regex = %r{
  foo
  (bar)
  (baz)
}x

# good
snake_case = /^[\dA-Z_]+$/

# good
regex = /
  foo
  (bar)
  (baz)
/x

Example: EnforcedStyle: percent_r

# bad
snake_case = /^[\dA-Z_]+$/

# bad
regex = /
  foo
  (bar)
  (baz)
/x

# good
snake_case = %r{^[\dA-Z_]+$}

# good
regex = %r{
  foo
  (bar)
  (baz)
}x

Example: EnforcedStyle: mixed

# bad
snake_case = %r{^[\dA-Z_]+$}

# bad
regex = /
  foo
  (bar)
  (baz)
/x

# good
snake_case = /^[\dA-Z_]+$/

# good
regex = %r{
  foo
  (bar)
  (baz)
}x

Example: AllowInnerSlashes: false (default)

# If `false`, the cop will always recommend using `%r` if one or more
# slashes are found in the regexp string.

# bad
x =~ /home\//

# good
x =~ %r{home/}

Example: AllowInnerSlashes: true

# good
x =~ /home\//

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

if File.exists?(rc_local_path)

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

Example:

# bad

File.exists?(some_path)

Example:

# good

File.exist?(some_path)

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

  Chef::Log.info("HI - Updating #{defrag_file_pathname} with the new THP setting [#{cur_thpval}]") if debug

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

if (cur_thpval == "never" and cur_buff != "always [never]") or (cur_thpval == "always" and cur_buff != "[always] never")

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

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

    ipaddr = BarclampLibrary::Barclamp::Inventory.get_network_by_type(n,"admin").address

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

Example:

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

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

Use cur_buff.length.zero? instead of cur_buff.length == 0. (https://github.com/bbatsov/ruby-style-guide#predicate-methods)
Open

  if cur_buff.length == 0 or cur_buff[cur_buff.length - 1] == 10

This cop checks for usage of comparison operators (==, >, <) to test numbers as zero, positive, or negative. These can be replaced by their respective predicate methods. The cop can also be configured to do the reverse.

The cop disregards #nonzero? as it its value is truthy or falsey, but not true and false, and thus not always interchangeable with != 0.

The cop ignores comparisons to global variables, since they are often populated with objects which can be compared with integers, but are not themselves Interger polymorphic.

Example: EnforcedStyle: predicate (default)

# bad

foo == 0
0 > foo
bar.baz > 0

# good

foo.zero?
foo.negative?
bar.baz.positive?

Example: EnforcedStyle: comparison

# bad

foo.zero?
foo.negative?
bar.baz.positive?

# good

foo == 0
0 > foo
bar.baz > 0

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

  xfs_packages=%w{

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

Ambiguous regexp literal. Parenthesize the method arguments if it's surely a regexp literal, or add a whitespace to the right of the / if it should be a division.
Open

thp_array = cur_buff.scan /^[\t ]*echo\s*(.+?)\s*>\s*\/sys\/kernel\/mm\/redhat_transparent_hugepage\/defrag[\t ]*$/m

This cop checks for ambiguous regexp literals in the first argument of a method invocation without parentheses.

Example:

# bad

# This is interpreted as a method invocation with a regexp literal,
# but it could possibly be `/` method invocations.
# (i.e. `do_something./(pattern)./(i)`)
do_something /pattern/i

Example:

# good

# With parentheses, there's no ambiguity.
do_something(/pattern/i)

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

  if n[:fqdn] and not 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

Avoid using rescue in its modifier form. (https://github.com/bbatsov/ruby-style-guide#no-rescue-modifiers)
Open

    ssh_key = n[:crowbar][:ssh][:root_pub_key] rescue nil

This cop checks for uses of rescue in its modifier form.

Example:

# bad
some_method rescue handle_error

# good
begin
  some_method
rescue
  handle_error
end

There are no issues that match your filters.

Category
Status