Similar blocks of code found in 2 locations. Consider refactoring. Open
if not File.exists?(shared_edits_directory)
Chef::Log.info("HI - Creating HA mount directory [#{shared_edits_directory}]") if debug
directory shared_edits_directory do
owner "hdfs"
group "hadoop"
- Read upRead up
- Create a ticketCreate a ticket
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 36.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Use !
instead of not
. (https://github.com/bbatsov/ruby-style-guide#bang-not-not) Open
if not File.exists?(shared_edits_directory)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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 2 spaces for indentation in an array, relative to the start of the line where the left square bracket is. Open
nfs-utils
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks the indentation of the first element in an array literal where the opening bracket and the first element are on separate lines. The other elements' indentations are handled by the AlignArray cop.
By default, array literals that are arguments in a method call with parentheses, and where the opening square bracket of the array is on the same line as the opening parenthesis of the method call, shall have their first element indented one step (two spaces) more than the position inside the opening parenthesis.
Other array literals shall have their first element indented one step more than the start of the line where the opening square bracket is.
This default style is called 'specialinsideparentheses'. Alternative styles are 'consistent' and 'align_brackets'. Here are examples:
Example: EnforcedStyle: specialinsideparentheses (default)
# The `special_inside_parentheses` style enforces that the first
# element in an array literal where the opening bracket and first
# element are on seprate lines is indented one step (two spaces) more
# than the position inside the opening parenthesis.
#bad
array = [
:value
]
and_in_a_method_call([
:no_difference
])
#good
array = [
:value
]
but_in_a_method_call([
:its_like_this
])
Example: EnforcedStyle: consistent
# The `consistent` style enforces that the first element in an array
# literal where the opening bracket and the first element are on
# seprate lines is indented the same as an array literal which is not
# defined inside a method call.
#bad
# consistent
array = [
:value
]
but_in_a_method_call([
:its_like_this
])
#good
array = [
:value
]
and_in_a_method_call([
:no_difference
])
Example: EnforcedStyle: align_brackets
# The `align_brackets` style enforces that the opening and closing
# brackets are indented to the same position.
#bad
# align_brackets
and_now_for_something = [
:completely_different
]
#good
# align_brackets
and_now_for_something = [
:completely_different
]
Space missing after comma. (https://github.com/bbatsov/ruby-style-guide#spaces-operators) Open
ha_filer_ip = BarclampLibrary::Barclamp::Inventory.get_network_by_type(n,"admin").address
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for comma (,) not followed by some kind of space.
Example:
# bad
[1,2]
{ foo:bar,}
# good
[1, 2]
{ foo:bar, }
Surrounding space missing for operator =
. (https://github.com/bbatsov/ruby-style-guide#spaces-operators) Open
nfs_packages=%w{
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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
Convert if
nested inside else
to elsif
. Open
Chef::Log.info("HI - HA mount directory already exists [#{shared_edits_directory}]") if debug
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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
File.exists?
is deprecated in favor of File.exist?
. Open
if not File.exists?(shared_edits_directory)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for uses of the deprecated class method usages.
Example:
# bad
File.exists?(some_path)
Example:
# good
File.exist?(some_path)
Do not use semicolons to terminate expressions. (https://github.com/bbatsov/ruby-style-guide#no-semicolon) Open
break;
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for multiple expressions placed on the same line. It also checks for lines terminated with a semicolon.
Example:
# bad
foo = 1; bar = 2;
baz = 3;
# good
foo = 1
bar = 2
baz = 3
Use []
for an array of words. (https://github.com/SUSE/style-guides/blob/master/Ruby.md#stylewordarray) Open
nfs_packages=%w{
nfs-utils
}
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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]
Indent the right bracket the same as the start of the line where the left bracket is. Open
}
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks the indentation of the first element in an array literal where the opening bracket and the first element are on separate lines. The other elements' indentations are handled by the AlignArray cop.
By default, array literals that are arguments in a method call with parentheses, and where the opening square bracket of the array is on the same line as the opening parenthesis of the method call, shall have their first element indented one step (two spaces) more than the position inside the opening parenthesis.
Other array literals shall have their first element indented one step more than the start of the line where the opening square bracket is.
This default style is called 'specialinsideparentheses'. Alternative styles are 'consistent' and 'align_brackets'. Here are examples:
Example: EnforcedStyle: specialinsideparentheses (default)
# The `special_inside_parentheses` style enforces that the first
# element in an array literal where the opening bracket and first
# element are on seprate lines is indented one step (two spaces) more
# than the position inside the opening parenthesis.
#bad
array = [
:value
]
and_in_a_method_call([
:no_difference
])
#good
array = [
:value
]
but_in_a_method_call([
:its_like_this
])
Example: EnforcedStyle: consistent
# The `consistent` style enforces that the first element in an array
# literal where the opening bracket and the first element are on
# seprate lines is indented the same as an array literal which is not
# defined inside a method call.
#bad
# consistent
array = [
:value
]
but_in_a_method_call([
:its_like_this
])
#good
array = [
:value
]
and_in_a_method_call([
:no_difference
])
Example: EnforcedStyle: align_brackets
# The `align_brackets` style enforces that the opening and closing
# brackets are indented to the same position.
#bad
# align_brackets
and_now_for_something = [
:completely_different
]
#good
# align_brackets
and_now_for_something = [
:completely_different
]
%w
-literals should be delimited by [
and ]
. (https://github.com/bbatsov/ruby-style-guide#percent-literal-braces) Open
nfs_packages=%w{
nfs-utils
}
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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)
The name of this source file (cm-ha-filer-mount.rb
) should use snake_case. (https://github.com/bbatsov/ruby-style-guide#snake-case-files) Open
#
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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