Assignment Branch Condition size for target_matches? is too high. [18.44/15] Open
def target_matches?(rule)
if rule.target_type == Togls::TargetTypes::NONE
return true
elsif rule.target_type == Togls::TargetTypes::NOT_SET
Togls.logger.warn "Rule (id: #{rule.id}) cannot have target type of :not_set"
- Read upRead up
- Exclude checks
This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric
Method has too many lines. [13/10] Open
def target_matches?(rule)
if rule.target_type == Togls::TargetTypes::NONE
return true
elsif rule.target_type == Togls::TargetTypes::NOT_SET
Togls.logger.warn "Rule (id: #{rule.id}) cannot have target type of :not_set"
- Read upRead up
- 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.
Perceived complexity for validate_target is too high. [8/7] Open
def validate_target(target)
is_explicit_target_type = @feature.target_type != Togls::TargetTypes::NONE &&
@feature.target_type != Togls::TargetTypes::NOT_SET &&
@feature.target_type != Togls::TargetTypes::EITHER
if @feature.target_type == Togls::TargetTypes::NONE && target
- Read upRead up
- Exclude checks
This cop tries to produce a complexity score that's a measure of the
complexity the reader experiences when looking at a method. For that
reason it considers when
nodes as something that doesn't add as much
complexity as an if
or a &&
. Except if it's one of those special
case
/when
constructs where there's no expression after case
. Then
the cop treats it as an if
/elsif
/elsif
... and lets all the when
nodes count. In contrast to the CyclomaticComplexity cop, this cop
considers else
nodes as adding complexity.
Example:
def my_method # 1
if cond # 1
case var # 2 (0.8 + 4 * 0.2, rounded)
when 1 then func_one
when 2 then func_two
when 3 then func_three
when 4..10 then func_other
end
else # 1
do_something until a && b # 2
end # ===
end # 7 complexity points
Cyclomatic complexity for validate_target is too high. [7/6] Open
def validate_target(target)
is_explicit_target_type = @feature.target_type != Togls::TargetTypes::NONE &&
@feature.target_type != Togls::TargetTypes::NOT_SET &&
@feature.target_type != Togls::TargetTypes::EITHER
if @feature.target_type == Togls::TargetTypes::NONE && target
- Read upRead up
- Exclude checks
This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.
An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.
Use a guard clause instead of wrapping the code inside a conditional expression. Open
if @feature.target_type == Togls::TargetTypes::NONE && target
- 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
Redundant return
detected. Open
return true
- Read upRead up
- Exclude checks
This cop checks for redundant return
expressions.
Example:
def test
return something
end
def test
one
two
three
return something
end
It should be extended to handle methods whose body is if/else or a case expression with a default branch.
Use a guard clause instead of wrapping the code inside a conditional expression. Open
if rule.target_type == Togls::TargetTypes::NONE
- 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
Line is too long. [81/80] Open
# NOT_SET | something (foo) | false | broken - shouldn't happen
- Exclude checks
Align the operands of an expression in an assignment spanning multiple lines. Open
@feature.target_type != Togls::TargetTypes::NOT_SET &&
- Read upRead up
- Exclude checks
This cop checks the indentation of the right hand side operand in binary operations that span more than one line.
Example:
# bad
if a +
b
something
end
# good
if a +
b
something
end
Line is too long. [178/80] Open
Togls.logger.warn "Feature (key: #{feature.key}) cannot have target type of :not_set when rule (id: #{rule.id}) specifies a target type (target_type: #{rule.target_type}"
- Exclude checks
Missing magic comment # frozen_string_literal: true
. Open
module Togls
- Read upRead up
- Exclude checks
This cop is designed to help upgrade to Ruby 3.0. It will add the
comment # frozen_string_literal: true
to the top of files to
enable frozen string literals. Frozen string literals may be default
in Ruby 3.0. The comment will be added below a shebang and encoding
comment. The frozen string literal comment is only valid in Ruby 2.3+.
Example: EnforcedStyle: when_needed (default)
# The `when_needed` style will add the frozen string literal comment
# to files only when the `TargetRubyVersion` is set to 2.3+.
# bad
module Foo
# ...
end
# good
# frozen_string_literal: true
module Foo
# ...
end
Example: EnforcedStyle: always
# The `always` style will always add the frozen string literal comment
# to a file, regardless of the Ruby version or if `freeze` or `<<` are
# called on a string literal.
# bad
module Bar
# ...
end
# good
# frozen_string_literal: true
module Bar
# ...
end
Example: EnforcedStyle: never
# The `never` will enforce that the frozen string literal comment does
# not exist in a file.
# bad
# frozen_string_literal: true
module Baz
# ...
end
# good
module Baz
# ...
end
Align the operands of an expression in an assignment spanning multiple lines. Open
@feature.target_type != Togls::TargetTypes::EITHER
- Read upRead up
- Exclude checks
This cop checks the indentation of the right hand side operand in binary operations that span more than one line.
Example:
# bad
if a +
b
something
end
# good
if a +
b
something
end
Line is too long. [83/80] Open
is_explicit_target_type = @feature.target_type != Togls::TargetTypes::NONE &&
- Exclude checks
Line is too long. [137/80] Open
Togls.logger.info("Togls evaluated feature(#{@feature.key}).off?(#{target.inspect}) to #{result.inspect} using rule, #{@rule.id}.")
- Exclude checks
Line is too long. [81/80] Open
# something (foo) | NOT_SET | false | broken - shouldn't happen
- Exclude checks
Redundant return
detected. Open
return false
- Read upRead up
- Exclude checks
This cop checks for redundant return
expressions.
Example:
def test
return something
end
def test
one
two
three
return something
end
It should be extended to handle methods whose body is if/else or a case expression with a default branch.
Line is too long. [81/80] Open
# NONE | NOT_SET | false | broken - shouldn't happen
- Exclude checks
Line is too long. [85/80] Open
Togls.logger.warn "Rule (id: #{rule.id}) cannot have target type of :not_set"
- Exclude checks
Line is too long. [136/80] Open
Togls.logger.info("Togls evaluated feature(#{@feature.key}).on?(#{target.inspect}) to #{result.inspect} using rule, #{@rule.id}.")
- Exclude checks
Redundant return
detected. Open
return false
- Read upRead up
- Exclude checks
This cop checks for redundant return
expressions.
Example:
def test
return something
end
def test
one
two
three
return something
end
It should be extended to handle methods whose body is if/else or a case expression with a default branch.
Redundant return
detected. Open
return true
- Read upRead up
- Exclude checks
This cop checks for redundant return
expressions.
Example:
def test
return something
end
def test
one
two
three
return something
end
It should be extended to handle methods whose body is if/else or a case expression with a default branch.
Line is too long. [81/80] Open
# NOT_SET | NOT_SET | false | broken - shouldn't happen
- Exclude checks