Showing 72 of 72 total issues
Method has too many lines. [20/10] Open
def self.fetch(options = {})
bucket = options[:bucket]
filename = options[:filename]
path = options[:path] || ''
storage_class = options[:storage_class] || 'STANDARD'
- 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.
Method has too many lines. [19/10] Open
def save_to(path, name = nil)
headers = {
'host' => @bucket.bucket_host
}
- 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.
Method has too many lines. [19/10] Open
def self.upload(options = {})
bucket = options[:bucket]
file = options[:file]
origin_file_name = File.basename(file)
filename = options[:filename] || origin_file_name
- 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.
Assignment Branch Condition size for resolve_response is too high. [20.49/15] Open
def resolve_response(response)
if response.success?
ret = resolve_bos_resault response
snake_hash_keys(ret)
elsif response.timed_out?
- 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. [15/10] Open
def resolve_response(response)
if response.success?
ret = resolve_bos_resault response
snake_hash_keys(ret)
elsif response.timed_out?
- 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.
Method has too many lines. [14/10] Open
def resolve_bos_resault(r)
ret = if !r.body.empty?
JSON.parse r.body, symbolize_names: true
else
{}
- 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.
Assignment Branch Condition size for upload is too high. [18.87/15] Open
def self.upload(options = {})
bucket = options[:bucket]
file = options[:file]
origin_file_name = File.basename(file)
filename = options[:filename] || origin_file_name
- 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 fetch is too high. [18.87/15] Open
def self.fetch(options = {})
bucket = options[:bucket]
filename = options[:filename]
path = options[:path] || ''
storage_class = options[:storage_class] || 'STANDARD'
- 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 sign(request)
digest = OpenSSL::Digest.new('sha256')
sign_key_prefix = "bce-auth-v1/#{BosClient.access_key_id}/#{get_canonical_time}/#{BosClient.expiration_in_seconds}"
sign_key = OpenSSL::HMAC.hexdigest digest, BosClient.secret_access_key, sign_key_prefix
- 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.
Method has too many lines. [11/10] Open
def get_canonical_headers(request)
headers_to_sign_keys = ['host',
'content-md5',
'content-length',
'content-type']
- 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.
Method resolve_response
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def resolve_response(response)
if response.success?
ret = resolve_bos_resault response
snake_hash_keys(ret)
elsif response.timed_out?
- 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 list_objects
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def list_objects(options = {})
prefix = options.fetch(:prefix, nil)
max_keys = options.fetch(:max_keys, 1000)
marker = options.fetch(:marker, nil)
delimiter = options.fetch(:delimiter, nil)
- 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
required_ruby_version
(2.0, declared in bos_client.gemspec) and TargetRubyVersion
(2.1, declared in .rubocop.yml) should be equal. Open
spec.required_ruby_version = '>= 2.0'
- Read upRead up
- Exclude checks
Checks that required_ruby_version
of gemspec and TargetRubyVersion
of .rubocop.yml are equal.
Thereby, RuboCop to perform static analysis working on the version
required by gemspec.
Example:
# When `TargetRubyVersion` of .rubocop.yml is `2.3`.
# bad
Gem::Specification.new do |spec|
spec.required_ruby_version = '>= 2.2.0'
end
# bad
Gem::Specification.new do |spec|
spec.required_ruby_version = '>= 2.4.0'
end
# good
Gem::Specification.new do |spec|
spec.required_ruby_version = '>= 2.3.0'
end
# good
Gem::Specification.new do |spec|
spec.required_ruby_version = '>= 2.3'
end
# good
Gem::Specification.new do |spec|
spec.required_ruby_version = ['>= 2.3.0', '< 2.5.0']
end
Unnecessary utf-8 encoding comment. Open
# coding: utf-8
- Exclude checks
Missing top-level module documentation comment. Open
module Helper
- Read upRead up
- Exclude checks
This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.
The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.
Example:
# bad
class Person
# ...
end
# good
# Description/Explanation of Person class
class Person
# ...
end
URI.encode
method is obsolete and should not be used. Instead, use CGI.escape
, URI.encode_www_form
or URI.encode_www_form_component
depending on your specific use case. Open
@uri = URI(URI.encode(url))
- Read upRead up
- Exclude checks
This cop identifies places where URI.escape
can be replaced by
CGI.escape
, URI.encode_www_form
or URI.encode_www_form_component
depending on your specific use case.
Also this cop identifies places where URI.unescape
can be replaced by
CGI.unescape
, URI.decode_www_form
or URI.decode_www_form_component
depending on your specific use case.
Example:
# bad
URI.escape('http://example.com')
URI.encode('http://example.com')
# good
CGI.escape('http://example.com')
URI.encode_www_form([['example', 'param'], ['lang', 'en']])
URI.encode_www_form(page: 10, locale: 'en')
URI.encode_www_form_component('http://example.com')
# bad
URI.unescape(enc_uri)
URI.decode(enc_uri)
# good
CGI.unescape(enc_uri)
URI.decode_www_form(enc_uri)
URI.decode_www_form_component(enc_uri)
Dependencies should be sorted in an alphabetical order within their section of the gemspec. Dependency pry
should appear before rspec
. Open
spec.add_development_dependency 'pry', '~> 0.1'
- Read upRead up
- Exclude checks
Dependencies in the gemspec should be alphabetically sorted.
Example:
# bad
spec.add_dependency 'rubocop'
spec.add_dependency 'rspec'
# good
spec.add_dependency 'rspec'
spec.add_dependency 'rubocop'
# good
spec.add_dependency 'rubocop'
spec.add_dependency 'rspec'
# bad
spec.add_development_dependency 'rubocop'
spec.add_development_dependency 'rspec'
# good
spec.add_development_dependency 'rspec'
spec.add_development_dependency 'rubocop'
# good
spec.add_development_dependency 'rubocop'
spec.add_development_dependency 'rspec'
# bad
spec.add_runtime_dependency 'rubocop'
spec.add_runtime_dependency 'rspec'
# good
spec.add_runtime_dependency 'rspec'
spec.add_runtime_dependency 'rubocop'
# good
spec.add_runtime_dependency 'rubocop'
spec.add_runtime_dependency 'rspec'
# good only if TreatCommentsAsGroupSeparators is true
# For code quality
spec.add_dependency 'rubocop'
# For tests
spec.add_dependency 'rspec'
Add an empty line after magic comments. Open
module BosClient
- Read upRead up
- Exclude checks
Checks for a newline after the final magic comment.
Example:
# good
# frozen_string_literal: true
# Some documentation for Person
class Person
# Some code
end
# bad
# frozen_string_literal: true
# Some documentation for Person
class Person
# Some code
end
Unnecessary utf-8 encoding comment. Open
# encoding: UTF-8
- Exclude checks
The use of eval
is a serious security risk. Open
eval "BosClient::Error::#{name}.new \"#{message}\""
- Read upRead up
- Exclude checks
This cop checks for the use of Kernel#eval
and Binding#eval
.
Example:
# bad
eval(something)
binding.eval(something)