Showing 44 of 44 total issues
Class has too many lines. [143/100] Open
class Claim
include Comparable
CLAIM_REGEX = /^([\w_\-]+):([\w_.\-]+\w)(\.\*)?$/.freeze # allows for the optional `.*` at the end, that will be ignored on the Claim creation
GLOBAL_WILDCARD_CLAIM_REGEX = /^([\w_\-]+):\*$/.freeze # cater for `read:*` global claims
- Read upRead up
- Exclude checks
This cop checks if the length a class exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Assignment Branch Condition size for parse_query_hash is too high. [24.1/15] Open
def self.parse_query_hash(query_hash)
unless query_hash.is_a?(Hash) && query_hash.keys.size == 1 && query_hash.keys.first.present?
raise ArgumentError, 'we expect only 1 param, a hash, with a single key being the verb and its value being the resource to check'
end
- 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
Class Claim
has 24 methods (exceeds 20 allowed). Consider refactoring. Open
class Claim
include Comparable
CLAIM_REGEX = /^([\w_\-]+):([\w_.\-]+\w)(\.\*)?$/.freeze # allows for the optional `.*` at the end, that will be ignored on the Claim creation
GLOBAL_WILDCARD_CLAIM_REGEX = /^([\w_\-]+):\*$/.freeze # cater for `read:*` global claims
Assignment Branch Condition size for sub_claims_direct_children is too high. [20.54/15] Open
def sub_claims_direct_children(query:, claims:, only_direct: false)
subs = sub_claims(query: query, claims: claims)
return subs if subs.blank? || subs.include?(:all)
length_to_remove = query.size + 1 # for the : or the .
- 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
Assignment Branch Condition size for query_claims is too high. [20.62/15] Open
def query_claims(query:, claims:)
query_parts = query.split SEPARATOR_REGEX
claims.any? do |claim_string|
rule_parts = claim_string.split SEPARATOR_REGEX
- 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
Cyclomatic complexity for parse_query_hash is too high. [7/6] Open
def self.parse_query_hash(query_hash)
unless query_hash.is_a?(Hash) && query_hash.keys.size == 1 && query_hash.keys.first.present?
raise ArgumentError, 'we expect only 1 param, a hash, with a single key being the verb and its value being the resource to check'
end
- 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.
Assignment Branch Condition size for for is too high. [16.4/15] Open
def self.for(string)
s = string.to_s
# is this a global wildcard Claim?
global_match = GLOBAL_WILDCARD_CLAIM_REGEX.match(s)
- 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 lookup_direct_descendant
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def lookup_direct_descendant(verb:, resource:, resource_parts:)
return nil if global?
return nil unless same_verb? verb
return self.resource_parts.first if resource.blank?
- Read upRead up
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
Method lookup_direct_child
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def lookup_direct_child(verb:, resource:, resource_parts:)
return nil if global?
return nil unless same_verb? verb
return nil unless self.resource_parts.size == resource_parts.size + 1
- Read upRead up
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
Method check_query
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def check_query(verb:, resource:, resource_parts:)
return false unless same_verb? verb
return true if global?
- Read upRead up
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
Method parse_query_hash
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def self.parse_query_hash(query_hash)
unless query_hash.is_a?(Hash) && query_hash.keys.size == 1 && query_hash.keys.first.present?
raise ArgumentError, 'we expect only 1 param, a hash, with a single key being the verb and its value being the resource to check'
end
- Read upRead up
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
Method exact_or_ancestor?
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def exact_or_ancestor?(query:, claims:)
parts_and_separators = query.split SEPARATOR_CAPTURE_REGEX
found_ancestor = catch(:found_ancestor) do
parts_and_separators.each_with_index do |part, index|
next if DOT_COLON.include?(part)
- Read upRead up
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
Avoid too many return
statements within this method. Open
return nil unless self.resource.start_with? prefix
Avoid too many return
statements within this method. Open
return nil unless self.resource.start_with? prefix
Method query_claims
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def query_claims(query:, claims:)
query_parts = query.split SEPARATOR_REGEX
claims.any? do |claim_string|
rule_parts = claim_string.split SEPARATOR_REGEX
- Read upRead up
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
Use the new Ruby 1.9 hash syntax. Open
task :default => :spec
- Read upRead up
- Exclude checks
This cop checks hash literal syntax.
It can enforce either the use of the class hash rocket syntax or the use of the newer Ruby 1.9 syntax (when applicable).
A separate offense is registered for each problematic pair.
The supported styles are:
- ruby19 - forces use of the 1.9 syntax (e.g.
{a: 1}
) when hashes have all symbols for keys - hash_rockets - forces use of hash rockets for all hashes
- nomixedkeys - simply checks for hashes with mixed syntaxes
- ruby19nomixed_keys - forces use of ruby 1.9 syntax and forbids mixed syntax hashes
Example: EnforcedStyle: ruby19 (default)
# bad
{:a => 2}
{b: 1, :c => 2}
# good
{a: 2, b: 1}
{:c => 2, 'd' => 2} # acceptable since 'd' isn't a symbol
{d: 1, 'e' => 2} # technically not forbidden
Example: EnforcedStyle: hash_rockets
# bad
{a: 1, b: 2}
{c: 1, 'd' => 5}
# good
{:a => 1, :b => 2}
Example: EnforcedStyle: nomixedkeys
# bad
{:a => 1, b: 2}
{c: 1, 'd' => 2}
# good
{:a => 1, :b => 2}
{c: 1, d: 2}
Example: EnforcedStyle: ruby19nomixed_keys
# bad
{:a => 1, :b => 2}
{c: 2, 'd' => 3} # should just use hash rockets
# good
{a: 1, b: 2}
{:c => 3, 'd' => 4}
Avoid the use of double negation (!!
). Open
!!direct_child(query_hash)
- Read upRead up
- Exclude checks
This cop checks for uses of double negation (!!) to convert something to a boolean value. As this is both cryptic and usually redundant, it should be avoided.
Example:
# bad
!!something
# good
!something.nil?
Please, note that when something is a boolean value !!something and !something.nil? are not the same thing. As you're unlikely to write code that can accept values of any type this is rarely a problem in practice.
Line is too long. [146/140] Open
CLAIM_REGEX = /^([\w_\-]+):([\w_.\-]+\w)(\.\*)?$/.freeze # allows for the optional `.*` at the end, that will be ignored on the Claim creation
- Exclude checks
When defining the ===
operator, name its argument other
. Open
def ===(another_ability)
- Read upRead up
- Exclude checks
This cop makes sure that certain binary operator methods have their
sole parameter named other
.
Example:
# bad
def +(amount); end
# good
def +(other); end
Line is too long. [184/140] Open
raise ArgumentError, 'we expect only 1 param, a hash, with a single key being the verb and its value being the resource to check, and it being either blank or a valid resource'
- Exclude checks