Method has too many lines. [15/10] Open
def default_config
{
'offline-mode' => {
'boshreleases' => false,
'stemcells' => true,
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Config has 25 constants Open
class Config
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Too Many Constants
is a special case of LargeClass
.
Example
Given this configuration
TooManyConstants:
max_constants: 3
and this code:
class TooManyConstants
CONST_1 = :dummy
CONST_2 = :dummy
CONST_3 = :dummy
CONST_4 = :dummy
end
Reek would emit the following warning:
test.rb -- 1 warnings:
[1]:TooManyConstants has 4 constants (TooManyConstants)
Method load_config
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def load_config
public_config = private_config = nil
public_config = YAML.load_file(@public_yaml, aliases: true) if File.exist?(@public_yaml)
private_config = YAML.load_file(@private_yaml, aliases: true) if File.exist?(@private_yaml)
@loaded_config = @loaded_config.deep_merge(public_config) unless public_config.nil?
- Read upRead up
- Create a ticketCreate a ticket
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Config#load_config performs a nil-check Open
@loaded_config = @loaded_config.deep_merge(public_config) unless public_config.nil?
@loaded_config = @loaded_config.deep_merge(private_config) unless private_config.nil?
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
A NilCheck
is a type check. Failures of NilCheck
violate the "tell, don't ask" principle.
Additionally, type checks often mask bigger problems in your source code like not using OOP and / or polymorphism when you should.
Example
Given
class Klass
def nil_checker(argument)
if argument.nil?
puts "argument isn't nil!"
end
end
end
Reek would emit the following warning:
test.rb -- 1 warning:
[3]:Klass#nil_checker performs a nil-check. (NilCheck)
Freeze mutable objects assigned to constants. Open
DEFAULT_RETRY = { CONFIG_TASK_KEY => DEFAULT_CONFIG_RETRY_TASK_LIMIT, CONFIG_PULL_KEY => DEFAULT_CONFIG_RETRY_PULL_LIMIT, CONFIG_PUSH_KEY => DEFAULT_CONFIG_RETRY_PUSH_LIMIT, CONFIG_BOSH_PUSH_KEY => DEFAULT_CONFIG_RETRY_BOSH_PUSH_LIMIT }
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks whether some constant value isn't a mutable literal (e.g. array or hash).
Example:
# bad
CONST = [1, 2, 3]
# good
CONST = [1, 2, 3].freeze