File base.rb
has 335 lines of code (exceeds 250 allowed). Consider refactoring. Open
require "bolognese"
class Base
include Importable
include Cacheable
Class Base
has 30 methods (exceeds 20 allowed). Consider refactoring. Open
class Base
include Importable
include Cacheable
include ::Bolognese::MetadataUtils
Perceived complexity for queue_jobs is too high. [13/8] Open
def queue_jobs(options = {})
options[:number] = options[:number].to_i || 1
options[:size] = options[:size].presence || job_batch_size
options[:from_date] =
options[:from_date].presence || (Time.now.to_date - 1.day).iso8601
- Read upRead up
- Exclude checks
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
Perceived complexity for get_orcid_metadata is too high. [9/8] Open
def self.get_orcid_metadata(id)
# use metadata stored with DataCite if they exist
response = get_researcher_metadata(id)
return response if response.present?
- Read upRead up
- Exclude checks
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
Method queue_jobs
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
def queue_jobs(options = {})
options[:number] = options[:number].to_i || 1
options[:size] = options[:size].presence || job_batch_size
options[:from_date] =
options[:from_date].presence || (Time.now.to_date - 1.day).iso8601
Method get_orcid_metadata
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.get_orcid_metadata(id)
# use metadata stored with DataCite if they exist
response = get_researcher_metadata(id)
return response if response.present?
Method queue_jobs
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def queue_jobs(options = {})
options[:number] = options[:number].to_i || 1
options[:size] = options[:size].presence || job_batch_size
options[:from_date] =
options[:from_date].presence || (Time.now.to_date - 1.day).iso8601
- 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 get_crossref_metadata
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.get_crossref_metadata(id)
doi = doi_from_url(id)
return {} if doi.blank?
url = "https://api.crossref.org/works/#{Addressable::URI.encode(doi)}?mailto=info@datacite.org"
Method parse_attributes
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def self.parse_attributes(element, options = {})
content = options[:content] || "__content__"
case element
when String
- 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 get_orcid_metadata
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def self.get_orcid_metadata(id)
# use metadata stored with DataCite if they exist
response = get_researcher_metadata(id)
return response if response.present?
- 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 get_crossref_metadata
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def self.get_crossref_metadata(id)
doi = doi_from_url(id)
return {} if doi.blank?
url = "https://api.crossref.org/works/#{Addressable::URI.encode(doi)}?mailto=info@datacite.org"
- 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 immutable Array literals in loops. It is better to extract it into a local variable or a constant. Open
["IsVersionOf", "IsIdenticalTo", "IsPartOf",
"IsSupplementTo"].include?(ri["relationType"])
- Exclude checks
Do not read from ENV
directly post initialization. Open
Rails.logger.error "AWS_REGION has not been specified" if ENV["AWS_REGION"].blank?
- Exclude checks
Do not read from ENV
directly post initialization. Open
url = ENV["API_URL"] + "/dois/#{doi}"
- Exclude checks
Do not read from ENV
directly post initialization. Open
region = ENV["AWS_REGION"] ||= "eu-west-1"
- Exclude checks
Do not read from ENV
directly post initialization. Open
Rails.logger.error "Queue name has not been specified" if ENV["ENVIRONMENT"].blank?
- Exclude checks
Do not read from ENV
directly post initialization. Open
"#{ENV['API_URL']}/dois?"
- Exclude checks
Do not read from ENV
directly post initialization. Open
url = ENV["API_URL"] + "/dois/#{doi}?affiliation=true"
- Exclude checks
Do not read from ENV
directly post initialization. Open
url = ENV["VOLPINO_URL"] + "/users/#{orcid}"
- Exclude checks
Do not read from ENV
directly post initialization. Open
options[:queue_name] ||= "#{ENV['ENVIRONMENT']}_usage"
- Exclude checks
Do not read from ENV
directly post initialization. Open
url = ENV["API_URL"] + "/users/#{orcid}"
- Exclude checks
Do not read from ENV
directly post initialization. Open
url = ENV["ORCID_API_URL"] + "/#{orcid}/person"
- Exclude checks
Do not read from ENV
directly post initialization. Open
bearer: ENV["STAFF_PROFILES_ADMIN_TOKEN"])
- Exclude checks
Do not read from ENV
directly post initialization. Open
url = ENV["API_URL"] + "/dois/#{doi}"
- Exclude checks
Line is too long. [140/120] Open
if /\A(?:(http|https):\/\/(dx\.)?(doi.org|handle.test.datacite.org|handle.stage.datacite.org)\/)?(doi:)?(10\.\d{4,5}\/.+)\z/.match?(url)
- Read upRead up
- Exclude checks
Checks the length of lines in the source code.
The maximum length is configurable.
The tab size is configured in the IndentationWidth
of the Layout/IndentationStyle
cop.
It also ignores a shebang line by default.
This cop has some autocorrection capabilities. It can programmatically shorten certain long lines by inserting line breaks into expressions that can be safely split across lines. These include arrays, hashes, and method calls with argument lists.
If autocorrection is enabled, the following Layout cops are recommended to further format the broken lines. (Many of these are enabled by default.)
- ArgumentAlignment
- ArrayAlignment
- BlockAlignment
- BlockDelimiters
- BlockEndNewline
- ClosingParenthesisIndentation
- FirstArgumentIndentation
- FirstArrayElementIndentation
- FirstHashElementIndentation
- FirstParameterIndentation
- HashAlignment
- IndentationWidth
- MultilineArrayLineBreaks
- MultilineBlockLayout
- MultilineHashBraceLayout
- MultilineHashKeyLineBreaks
- MultilineMethodArgumentLineBreaks
- MultilineMethodParameterLineBreaks
- ParameterAlignment
Together, these cops will pretty print hashes, arrays, method calls, etc. For example, let's say the max columns is 25:
Example:
# bad
{foo: "0000000000", bar: "0000000000", baz: "0000000000"}
# good
{foo: "0000000000",
bar: "0000000000", baz: "0000000000"}
# good (with recommended cops enabled)
{
foo: "0000000000",
bar: "0000000000",
baz: "0000000000",
}
Line is too long. [130/120] Open
type = Bolognese::Utils::DC_TO_SO_TRANSLATIONS[resource_type_general.to_s.dasherize] # || attributes.dig("types", "schemaOrg")
- Read upRead up
- Exclude checks
Checks the length of lines in the source code.
The maximum length is configurable.
The tab size is configured in the IndentationWidth
of the Layout/IndentationStyle
cop.
It also ignores a shebang line by default.
This cop has some autocorrection capabilities. It can programmatically shorten certain long lines by inserting line breaks into expressions that can be safely split across lines. These include arrays, hashes, and method calls with argument lists.
If autocorrection is enabled, the following Layout cops are recommended to further format the broken lines. (Many of these are enabled by default.)
- ArgumentAlignment
- ArrayAlignment
- BlockAlignment
- BlockDelimiters
- BlockEndNewline
- ClosingParenthesisIndentation
- FirstArgumentIndentation
- FirstArrayElementIndentation
- FirstHashElementIndentation
- FirstParameterIndentation
- HashAlignment
- IndentationWidth
- MultilineArrayLineBreaks
- MultilineBlockLayout
- MultilineHashBraceLayout
- MultilineHashKeyLineBreaks
- MultilineMethodArgumentLineBreaks
- MultilineMethodParameterLineBreaks
- ParameterAlignment
Together, these cops will pretty print hashes, arrays, method calls, etc. For example, let's say the max columns is 25:
Example:
# bad
{foo: "0000000000", bar: "0000000000", baz: "0000000000"}
# good
{foo: "0000000000",
bar: "0000000000", baz: "0000000000"}
# good (with recommended cops enabled)
{
foo: "0000000000",
bar: "0000000000",
baz: "0000000000",
}
Line is too long. [130/120] Open
text = "[Event Data] Queued #{source_id} import for #{total} DOIs updated #{options[:from_date]} - #{options[:until_date]}."
- Read upRead up
- Exclude checks
Checks the length of lines in the source code.
The maximum length is configurable.
The tab size is configured in the IndentationWidth
of the Layout/IndentationStyle
cop.
It also ignores a shebang line by default.
This cop has some autocorrection capabilities. It can programmatically shorten certain long lines by inserting line breaks into expressions that can be safely split across lines. These include arrays, hashes, and method calls with argument lists.
If autocorrection is enabled, the following Layout cops are recommended to further format the broken lines. (Many of these are enabled by default.)
- ArgumentAlignment
- ArrayAlignment
- BlockAlignment
- BlockDelimiters
- BlockEndNewline
- ClosingParenthesisIndentation
- FirstArgumentIndentation
- FirstArrayElementIndentation
- FirstHashElementIndentation
- FirstParameterIndentation
- HashAlignment
- IndentationWidth
- MultilineArrayLineBreaks
- MultilineBlockLayout
- MultilineHashBraceLayout
- MultilineHashKeyLineBreaks
- MultilineMethodArgumentLineBreaks
- MultilineMethodParameterLineBreaks
- ParameterAlignment
Together, these cops will pretty print hashes, arrays, method calls, etc. For example, let's say the max columns is 25:
Example:
# bad
{foo: "0000000000", bar: "0000000000", baz: "0000000000"}
# good
{foo: "0000000000",
bar: "0000000000", baz: "0000000000"}
# good (with recommended cops enabled)
{
foo: "0000000000",
bar: "0000000000",
baz: "0000000000",
}
Avoid when
branches without a body. Open
when "journal"
- Read upRead up
- Exclude checks
Checks for the presence of when
branches without a body.
Example:
# bad
case foo
when bar
do_something
when baz
end
Example:
# good
case condition
when foo
do_something
when bar
nil
end
Example: AllowComments: true (default)
# good
case condition
when foo
do_something
when bar
# noop
end
Example: AllowComments: false
# bad
case condition
when foo
do_something
when bar
# do nothing
end
Avoid when
branches without a body. Open
when "peer-review"
- Read upRead up
- Exclude checks
Checks for the presence of when
branches without a body.
Example:
# bad
case foo
when bar
do_something
when baz
end
Example:
# good
case condition
when foo
do_something
when bar
nil
end
Example: AllowComments: true (default)
# good
case condition
when foo
do_something
when bar
# noop
end
Example: AllowComments: false
# bad
case condition
when foo
do_something
when bar
# do nothing
end
Useless assignment to variable - publisher
. Open
publisher = if attributes["publisher"].present?
- Read upRead up
- Exclude checks
Checks for every useless assignment to local variable in every
scope.
The basic idea for this cop was from the warning of ruby -cw
:
assigned but unused variable - foo
Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.
Example:
# bad
def some_method
some_var = 1
do_something
end
Example:
# good
def some_method
some_var = 1
do_something(some_var)
end
Useless assignment to variable - a
. Open
a = options[:first] ? a.first : a.unwrap
- Read upRead up
- Exclude checks
Checks for every useless assignment to local variable in every
scope.
The basic idea for this cop was from the warning of ruby -cw
:
assigned but unused variable - foo
Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.
Example:
# bad
def some_method
some_var = 1
do_something
end
Example:
# good
def some_method
some_var = 1
do_something(some_var)
end
Avoid when
branches without a body. Open
when "other"
- Read upRead up
- Exclude checks
Checks for the presence of when
branches without a body.
Example:
# bad
case foo
when bar
do_something
when baz
end
Example:
# good
case condition
when foo
do_something
when bar
nil
end
Example: AllowComments: true (default)
# good
case condition
when foo
do_something
when bar
# noop
end
Example: AllowComments: false
# bad
case condition
when foo
do_something
when bar
# do nothing
end