Showing 49 of 49 total issues
Avoid bare attribute keys Open
default['consul_template']['service']['data_dir'] = default_data_dir
- Read upRead up
- Exclude checks
This warning is shown when, within a cookbook attributes file, you refer
to an attribute as you would a local variable rather than as an attribute
of the node
object. It is valid to do the former, but you should prefer
the later more explicit approach to accessing attributes because it is
easier for users of your cookbooks to understand.
Avoid bare attribute keys Open
default['consul_template']['config']['conf_dir'] = default_conf_dir
- Read upRead up
- Exclude checks
This warning is shown when, within a cookbook attributes file, you refer
to an attribute as you would a local variable rather than as an attribute
of the node
object. It is valid to do the former, but you should prefer
the later more explicit approach to accessing attributes because it is
easier for users of your cookbooks to understand.
Avoid bare attribute keys Open
default['consul_template']['config']['template_dir'] = default_template_dir
- Read upRead up
- Exclude checks
This warning is shown when, within a cookbook attributes file, you refer
to an attribute as you would a local variable rather than as an attribute
of the node
object. It is valid to do the former, but you should prefer
the later more explicit approach to accessing attributes because it is
easier for users of your cookbooks to understand.
Similar blocks of code found in 2 locations. Consider refactoring. Open
describe ConsulTemplateCookbook::Resource::ConsulTemplateService do
step_into(:consul_template_service)
let(:chefspec_options) { { os: 'linux', platform: 'centos', version: '6.7' } }
recipe 'consul_template::default'
- Read upRead up
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 27.
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
Similar blocks of code found in 2 locations. Consider refactoring. Open
describe ConsulTemplateCookbook::Resource::ConsulTemplateInstallation do
step_into(:consul_template_installation)
let(:chefspec_options) { { os: 'linux', platform: 'centos', version: '6.7' } }
recipe 'consul_template::default'
- Read upRead up
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 27.
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
Trailing whitespace detected. Open
- Exclude checks
Use 2 (not 4) spaces for indentation. Open
extend ::ConsulTemplateCookbook::NSSMHelpers
- Read upRead up
- Exclude checks
This cops checks for indentation that doesn't use the specified number of spaces.
See also the IndentationConsistency cop which is the companion to this one.
Example:
# bad
class A
def test
puts 'hello'
end
end
# good
class A
def test
puts 'hello'
end
end
Example: IgnoredPatterns: ['^\s*module']
# bad
module A
class B
def test
puts 'hello'
end
end
end
# good
module A
class B
def test
puts 'hello'
end
end
end
Trailing whitespace detected. Open
- Exclude checks
Trailing whitespace detected. Open
end
- Exclude checks
%w
-literals should be delimited by [
and ]
. Open
%w(Application
AppParameters
AppDirectory
AppExit
AppAffinity
- Read upRead up
- 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)
Re-enable Style/Documentation cop with # rubocop:enable
after disabling it. Open
# rubocop:disable Style/Documentation
- Exclude checks
Prefer annotated tokens (like %<foo>s</foo>
) over template tokens (like %{foo}
). Open
archive_url: 'https://releases.hashicorp.com/consul-template/%{version}/%{basename}',
- Read upRead up
- Exclude checks
Use a consistent style for named format string tokens.
Note:
unannotated
style cop only works for strings
which are passed as arguments to those methods:
sprintf
, format
, %
.
The reason is that unannotated format is very similar
to encoded URLs or Date/Time formatting strings.
Example: EnforcedStyle: annotated (default)
# bad
format('%{greeting}', greeting: 'Hello')
format('%s', 'Hello')
# good
format('%<greeting>s', greeting: 'Hello')</greeting>
Example: EnforcedStyle: template
# bad
format('%<greeting>s', greeting: 'Hello')
format('%s', 'Hello')
# good
format('%{greeting}', greeting: 'Hello')</greeting>
Example: EnforcedStyle: unannotated
# bad
format('%<greeting>s', greeting: 'Hello')
format('%{greeting}', 'Hello')
# good
format('%s', 'Hello')</greeting>
Don't use parentheses around the condition of an if
. Open
ps_stop_consul_template if (windows? && !other_versions.empty?)
- Read upRead up
- Exclude checks
This cop checks for the presence of superfluous parentheses around the condition of if/unless/while/until.
Example:
# bad
x += 1 while (x < 10)
foo unless (bar || baz)
if (x > 10)
elsif (x < 3)
end
# good
x += 1 while x < 10
foo unless bar || baz
if x > 10
elsif x < 3
end
Use exit_code.zero?
instead of exit_code == 0
. Open
exit_code == 0 ? true : false
- Read upRead up
- Exclude checks
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
%w
-literals should be delimited by [
and ]
. Open
provides(:consul_template_service, os: %w(windows))
- Read upRead up
- 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)
This conditional expression can just be replaced by exit_code == 0
. Open
exit_code == 0 ? true : false
- Read upRead up
- Exclude checks
This cop checks for redundant returning of true/false in conditionals.
Example:
# bad
x == y ? true : false
# bad
if x == y
true
else
false
end
# good
x == y
# bad
x == y ? false : true
# good
x != y
Use a guard clause instead of wrapping the code inside a conditional expression. Open
if (node['platform_family'] == 'rhel') && (node['platform_version'].to_i == 6)
- Read upRead up
- Exclude checks
Use a guard clause instead of wrapping the code inside a conditional expression
Example:
# bad
def test
if something
work
end
end
# good
def test
return unless something
work
end
# also good
def test
work if something
end
# bad
if something
raise 'exception'
else
ok
end
# good
raise 'exception' if something
ok
%i
-literals should be delimited by [
and ]
. Open
%i(destination command command_timeout perms backup)
- Read upRead up
- 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)
Re-enable Style/Documentation cop with # rubocop:enable
after disabling it. Open
# rubocop:disable Style/Documentation
- Exclude checks
Parenthesize the param new_resource.nssm_params.select { |_k, v| v != '' }
to make sure that the block will be associated with the new_resource.nssm_params.select
method call. Open
parameters new_resource.nssm_params.select { |_k, v| v != '' }
- Read upRead up
- Exclude checks
This cop checks for ambiguous block association with method when param passed without parentheses.
Example:
# bad
some_method a { |val| puts val }
Example:
# good
# With parentheses, there's no ambiguity.
some_method(a) { |val| puts val }
# good
# Operator methods require no disambiguation
foo == bar { |b| b.baz }
# good
# Lambda arguments require no disambiguation
foo = ->(bar) { bar.baz }