Class has too many lines. [244/100] Open
class ProjectsController < ApplicationController
include ServiceRoles
before_action :authenticate_user,
only: [:index, :show]
- 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.
Class ProjectsController
has 29 methods (exceeds 20 allowed). Consider refactoring. Open
class ProjectsController < ApplicationController
include ServiceRoles
before_action :authenticate_user,
only: [:index, :show]
Method has too many lines. [15/10] Open
def merge_annotation_documents
record_count = error_count = 0
@project.merge_data.each do |merge_datum|
response = merge_request merge_datum
if response.kind_of? Net::HTTPSuccess
- 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. [13/10] Open
def process_iteration_data(raw_data)
@annotation_documents = false
iterate_service = @project.iterate_service
response = json_post_request iterate_service.url,
process_iteration_data_response_hash(raw_data)
- 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. [12/10] Open
def save_statistics
return unless @statistics
Statistic.transaction do
iteration_index = Statistic.where(project: @project).maximum(:iteration_index) || 0
iteration_index += 1
- 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 iterate
process_iteration_data(@project.iterate_data)
if @annotation_documents
save_statistics
record_count, error_count = save_annotation_documents
- 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 save_annotation_documents
record_count = error_count = 0
@annotation_documents.each do |annotation_document|
type_name = annotation_document['interface_type']
interface_type = InterfaceType.find_or_create_by(name: type_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.
Method merge_annotation_documents
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def merge_annotation_documents
record_count = error_count = 0
@project.merge_data.each do |merge_datum|
response = merge_request merge_datum
if response.kind_of? Net::HTTPSuccess
- 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 process_iteration_data
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def process_iteration_data(raw_data)
@annotation_documents = false
iterate_service = @project.iterate_service
response = json_post_request iterate_service.url,
process_iteration_data_response_hash(raw_data)
- 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 each_value
instead of values.each
. Open
params_interface.values.each do |interface_id|
- Read upRead up
- Exclude checks
This cop checks for uses of each_key
and each_value
Hash methods.
Note: If you have an array of two-element arrays, you can put parentheses around the block arguments to indicate that you're not working with a hash, and suppress RuboCop offenses.
Example:
# bad
hash.keys.each { |k| p k }
hash.values.each { |v| p v }
hash.each { |k, _v| p k }
hash.each { |_k, v| p v }
# good
hash.each_key { |k| p k }
hash.each_value { |v| p v }
Inconsistent indentation detected. Open
def process_iteration_data_response_hash(raw_data)
tokens = ApplicationController.generate_auth_token(2)
{
raw_data: raw_data,
callback_urls: [
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
Example:
class A
def test
puts 'hello'
puts 'world'
end
end
Inconsistent indentation detected. Open
def process_merged_data(response_body)
@project.update_merged_raw_datum(response_body)
end
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
Example:
class A
def test
puts 'hello'
puts 'world'
end
end
Inconsistent indentation detected. Open
def params_with_associated_models
new_params = project_params
@roles.each do |role|
service_symbol = "#{role}_service".to_sym
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
Example:
class A
def test
puts 'hello'
puts 'world'
end
end
Use %i
or %I
for an array of symbols. Open
only: [:create, :edit, :new, :show]
- Read upRead up
- Exclude checks
This cop can check for array literals made up of symbols that are not using the %i() syntax.
Alternatively, it checks for symbol arrays using the %i() syntax on projects which do not want to use that syntax.
Configuration option: MinSize
If set, arrays with fewer elements than this value will not trigger the
cop. For example, a MinSize of
3` will not enforce a style on an array
of 2 or fewer elements.
Example: EnforcedStyle: percent (default)
# good
%i[foo bar baz]
# bad
[:foo, :bar, :baz]
Example: EnforcedStyle: brackets
# good
[:foo, :bar, :baz]
# bad
%i[foo bar baz]
Use %i
or %I
for an array of symbols. Open
only: [:create, :edit, :new]
- Read upRead up
- Exclude checks
This cop can check for array literals made up of symbols that are not using the %i() syntax.
Alternatively, it checks for symbol arrays using the %i() syntax on projects which do not want to use that syntax.
Configuration option: MinSize
If set, arrays with fewer elements than this value will not trigger the
cop. For example, a MinSize of
3` will not enforce a style on an array
of 2 or fewer elements.
Example: EnforcedStyle: percent (default)
# good
%i[foo bar baz]
# bad
[:foo, :bar, :baz]
Example: EnforcedStyle: brackets
# good
[:foo, :bar, :baz]
# bad
%i[foo bar baz]
Line is too long. [83/80] Open
associated_problem_identifier = @project.associated_problem_identifiers.first
- Exclude checks
Line is too long. [90/80] Open
interface.associated_problem_identifiers.include?(associated_problem_identifier)
- Exclude checks
Favor a normal if-statement over a modifier clause in a multiline statement. Open
params_interface.values.each do |interface_id|
interfaces << Interface.find(interface_id) if interface_id != ''
end if params_interface
- Read upRead up
- Exclude checks
Checks for uses of if/unless modifiers with multiple-lines bodies.
Example:
# bad
{
result: 'this should not happen'
} unless cond
# good
{ result: 'ok' } if cond
Avoid rescuing without specifying an error class. Open
rescue
- Read upRead up
- Exclude checks
This cop checks for rescuing StandardError
. There are two supported
styles implicit
and explicit
. This cop will not register an offense
if any error other than StandardError
is specified.
Example: EnforcedStyle: implicit
# `implicit` will enforce using `rescue` instead of
# `rescue StandardError`.
# bad
begin
foo
rescue StandardError
bar
end
# good
begin
foo
rescue
bar
end
# good
begin
foo
rescue OtherError
bar
end
# good
begin
foo
rescue StandardError, SecurityError
bar
end
Example: EnforcedStyle: explicit (default)
# `explicit` will enforce using `rescue StandardError`
# instead of `rescue`.
# bad
begin
foo
rescue
bar
end
# good
begin
foo
rescue StandardError
bar
end
# good
begin
foo
rescue OtherError
bar
end
# good
begin
foo
rescue StandardError, SecurityError
bar
end
Inconsistent indentation detected. Open
def set_project
@project = current_role.projects.find(params[:id])
end
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
Example:
class A
def test
puts 'hello'
puts 'world'
end
end
Inconsistent indentation detected. Open
def process_iteration_data(raw_data)
@annotation_documents = false
iterate_service = @project.iterate_service
response = json_post_request iterate_service.url,
process_iteration_data_response_hash(raw_data)
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
Example:
class A
def test
puts 'hello'
puts 'world'
end
end
Prefer Object#is_a?
over Object#kind_of?
. Open
if response.kind_of? Net::HTTPSuccess
- Read upRead up
- Exclude checks
This cop enforces consistent use of Object#is_a?
or Object#kind_of?
.
Example: EnforcedStyle: is_a? (default)
# bad
var.kind_of?(Date)
var.kind_of?(Integer)
# good
var.is_a?(Date)
var.is_a?(Integer)
Example: EnforcedStyle: kind_of?
# bad
var.is_a?(Time)
var.is_a?(String)
# good
var.kind_of?(Time)
var.kind_of?(String)
Use %i
or %I
for an array of symbols. Open
except: [:index, :show]
- Read upRead up
- Exclude checks
This cop can check for array literals made up of symbols that are not using the %i() syntax.
Alternatively, it checks for symbol arrays using the %i() syntax on projects which do not want to use that syntax.
Configuration option: MinSize
If set, arrays with fewer elements than this value will not trigger the
cop. For example, a MinSize of
3` will not enforce a style on an array
of 2 or fewer elements.
Example: EnforcedStyle: percent (default)
# good
%i[foo bar baz]
# bad
[:foo, :bar, :baz]
Example: EnforcedStyle: brackets
# good
[:foo, :bar, :baz]
# bad
%i[foo bar baz]
Inconsistent indentation detected. Open
def set_additional_annotator
@additional_annotator = Annotator.find_by(id: params[:project][:annotator])
end
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
Example:
class A
def test
puts 'hello'
puts 'world'
end
end
Line is too long. [99/80] Open
redirect_to project_raw_data_path(@project), notice: I18n.t('projects.action.create.success')
- Exclude checks
Line is too long. [81/80] Open
process_iteration_data_response_hash(raw_data)
- Exclude checks
Put empty method definitions on a single line. Open
def edit
end
- Read upRead up
- Exclude checks
This cop checks for the formatting of empty method definitions.
By default it enforces empty method definitions to go on a single
line (compact style), but it can be configured to enforce the end
to go on its own line (expanded style).
Note: A method definition is not considered empty if it contains comments.
Example: EnforcedStyle: compact (default)
# bad
def foo(bar)
end
def self.foo(bar)
end
# good
def foo(bar); end
def foo(bar)
# baz
end
def self.foo(bar); end
Example: EnforcedStyle: expanded
# bad
def foo(bar); end
def self.foo(bar); end
# good
def foo(bar)
end
def self.foo(bar)
end
Inconsistent indentation detected. Open
def merge_annotation_documents
record_count = error_count = 0
@project.merge_data.each do |merge_datum|
response = merge_request merge_datum
if response.kind_of? Net::HTTPSuccess
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
Example:
class A
def test
puts 'hello'
puts 'world'
end
end
Inconsistent indentation detected. Open
def merge_request(merge_datum)
auth_token = ApplicationController.generate_auth_token
merge_datum[:callback_url] = api_v1_raw_datum_url merge_datum[:raw_datum][:id],
auth_token: auth_token
merge_service = @project.merge_service
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
Example:
class A
def test
puts 'hello'
puts 'world'
end
end
Inconsistent indentation detected. Open
def json_post_request(url, data)
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new uri.request_uri,
{ 'Content-Type' => 'application/json' }
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
Example:
class A
def test
puts 'hello'
puts 'world'
end
end
Inconsistent indentation detected. Open
def project_params
params.require(:project).permit(
:iterate_service,
:data,
:description,
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
Example:
class A
def test
puts 'hello'
puts 'world'
end
end
Line is too long. [81/80] Open
@additional_annotator = Annotator.find_by(id: params[:project][:annotator])
- Exclude checks
Line is too long. [87/80] Open
new_params[service_symbol] = Service.find_by_id(project_params[service_symbol])
- Exclude checks
Use 2 (not 0) spaces for indenting an expression spanning multiple lines. Open
interface.associated_problem_identifiers.include?(associated_problem_identifier)
- 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. [93/80] Open
objects_per_page = Rails.configuration.x.dalphi['paginated-objects-per-page']['projects']
- Exclude checks
Missing top-level class documentation comment. Open
class ProjectsController < ApplicationController
- 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
Inconsistent indentation detected. Open
def redirect_iterate_with_flash
flash[:error] = I18n.t('projects.iterate.error')
redirect_to project_annotation_documents_path(@project)
end
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
Example:
class A
def test
puts 'hello'
puts 'world'
end
end
Use %i
or %I
for an array of symbols. Open
only: [:index, :show]
- Read upRead up
- Exclude checks
This cop can check for array literals made up of symbols that are not using the %i() syntax.
Alternatively, it checks for symbol arrays using the %i() syntax on projects which do not want to use that syntax.
Configuration option: MinSize
If set, arrays with fewer elements than this value will not trigger the
cop. For example, a MinSize of
3` will not enforce a style on an array
of 2 or fewer elements.
Example: EnforcedStyle: percent (default)
# good
%i[foo bar baz]
# bad
[:foo, :bar, :baz]
Example: EnforcedStyle: brackets
# good
[:foo, :bar, :baz]
# bad
%i[foo bar baz]
Use %i
or %I
for an array of symbols. Open
except: [:create, :index, :new]
- Read upRead up
- Exclude checks
This cop can check for array literals made up of symbols that are not using the %i() syntax.
Alternatively, it checks for symbol arrays using the %i() syntax on projects which do not want to use that syntax.
Configuration option: MinSize
If set, arrays with fewer elements than this value will not trigger the
cop. For example, a MinSize of
3` will not enforce a style on an array
of 2 or fewer elements.
Example: EnforcedStyle: percent (default)
# good
%i[foo bar baz]
# bad
[:foo, :bar, :baz]
Example: EnforcedStyle: brackets
# good
[:foo, :bar, :baz]
# bad
%i[foo bar baz]
Line is too long. [91/80] Open
iteration_index = Statistic.where(project: @project).maximum(:iteration_index) || 0
- Exclude checks
Line is too long. [88/80] Open
# Never trust parameters from the scary internet, only allow the white list through.
- Exclude checks
Prefer Object#is_a?
over Object#kind_of?
. Open
response_body = JSON.parse(response.body) if response.kind_of? Net::HTTPSuccess
- Read upRead up
- Exclude checks
This cop enforces consistent use of Object#is_a?
or Object#kind_of?
.
Example: EnforcedStyle: is_a? (default)
# bad
var.kind_of?(Date)
var.kind_of?(Integer)
# good
var.is_a?(Date)
var.is_a?(Integer)
Example: EnforcedStyle: kind_of?
# bad
var.is_a?(Time)
var.is_a?(String)
# good
var.kind_of?(Time)
var.kind_of?(String)
Inconsistent indentation detected. Open
def redirect_merge_with_flash
flash[:error] = I18n.t('projects.merge.error')
redirect_to project_annotation_documents_path(@project)
end
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
Example:
class A
def test
puts 'hello'
puts 'world'
end
end
Line is too long. [82/80] Open
flash.now[:error] = I18n.t('simple_form.error_notification.default_message')
- Exclude checks
Inconsistent indentation detected. Open
def set_available_services
@available_services = {}
@roles.each do |role|
role_symbol = role.to_sym
@available_services[role_symbol] = Service.where(role: role_symbol)
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
Example:
class A
def test
puts 'hello'
puts 'world'
end
end
Line is too long. [90/80] Open
redirect_to project_path(@project), notice: I18n.t('projects.action.update.success')
- Exclude checks
Line is too long. [82/80] Open
flash.now[:error] = I18n.t('simple_form.error_notification.default_message')
- Exclude checks
Avoid rescuing without specifying an error class. Open
rescue
- Read upRead up
- Exclude checks
This cop checks for rescuing StandardError
. There are two supported
styles implicit
and explicit
. This cop will not register an offense
if any error other than StandardError
is specified.
Example: EnforcedStyle: implicit
# `implicit` will enforce using `rescue` instead of
# `rescue StandardError`.
# bad
begin
foo
rescue StandardError
bar
end
# good
begin
foo
rescue
bar
end
# good
begin
foo
rescue OtherError
bar
end
# good
begin
foo
rescue StandardError, SecurityError
bar
end
Example: EnforcedStyle: explicit (default)
# `explicit` will enforce using `rescue StandardError`
# instead of `rescue`.
# bad
begin
foo
rescue
bar
end
# good
begin
foo
rescue StandardError
bar
end
# good
begin
foo
rescue OtherError
bar
end
# good
begin
foo
rescue StandardError, SecurityError
bar
end
Inconsistent indentation detected. Open
def set_projects
@projects = current_role.projects
end
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
Example:
class A
def test
puts 'hello'
puts 'world'
end
end
Line is too long. [91/80] Open
render json: { associatedProblemIdentifiers: @project.associated_problem_identifiers },
- Exclude checks
Line is too long. [85/80] Open
response_body = JSON.parse(response.body) if response.kind_of? Net::HTTPSuccess
- Exclude checks
%w
-literals should be delimited by [
and ]
. Open
request.body = data.to_json(except: %w(created_at updated_at project_id requested_at))
- Read upRead up
- Exclude checks
This cop enforces the consistent usage of %
-literal delimiters.
Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.
Example:
# Style/PercentLiteralDelimiters:
# PreferredDelimiters:
# default: '[]'
# '%i': '()'
# good
%w[alpha beta] + %i(gamma delta)
# bad
%W(alpha #{beta})
# bad
%I(alpha beta)
Inconsistent indentation detected. Open
def save_annotation_documents
record_count = error_count = 0
@annotation_documents.each do |annotation_document|
type_name = annotation_document['interface_type']
interface_type = InterfaceType.find_or_create_by(name: type_name)
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
Example:
class A
def test
puts 'hello'
puts 'world'
end
end
Inconsistent indentation detected. Open
def add_interfaces_to_params(params)
interfaces = []
params_interface = params[:interfaces]
params_interface.values.each do |interface_id|
interfaces << Interface.find(interface_id) if interface_id != ''
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
Example:
class A
def test
puts 'hello'
puts 'world'
end
end
Line is too long. [85/80] Open
merge_datum[:callback_url] = api_v1_raw_datum_url merge_datum[:raw_datum][:id],
- Exclude checks
Redundant return
detected. To return multiple values, use an array. Open
return record_count, error_count
- 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. [92/80] Open
request.body = data.to_json(except: %w(created_at updated_at project_id requested_at))
- Exclude checks
Inconsistent indentation detected. Open
def set_interfaces
@interfaces = {}
return unless @project
associated_problem_identifier = @project.associated_problem_identifiers.first
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
Example:
class A
def test
puts 'hello'
puts 'world'
end
end
Inconsistent indentation detected. Open
def save_statistics
return unless @statistics
Statistic.transaction do
iteration_index = Statistic.where(project: @project).maximum(:iteration_index) || 0
iteration_index += 1
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
Example:
class A
def test
puts 'hello'
puts 'world'
end
end
Redundant curly braces around a hash parameter. Open
{ 'Content-Type' => 'application/json' }
- Read upRead up
- Exclude checks
This cop checks for braces around the last parameter in a method call
if the last parameter is a hash.
It supports braces
, no_braces
and context_dependent
styles.
Example: EnforcedStyle: braces
# The `braces` style enforces braces around all method
# parameters that are hashes.
# bad
some_method(x, y, a: 1, b: 2)
# good
some_method(x, y, {a: 1, b: 2})
Example: EnforcedStyle: no_braces (default)
# The `no_braces` style checks that the last parameter doesn't
# have braces around it.
# bad
some_method(x, y, {a: 1, b: 2})
# good
some_method(x, y, a: 1, b: 2)
Example: EnforcedStyle: context_dependent
# The `context_dependent` style checks that the last parameter
# doesn't have braces around it, but requires braces if the
# second to last parameter is also a hash literal.
# bad
some_method(x, y, {a: 1, b: 2})
some_method(x, y, {a: 1, b: 2}, a: 1, b: 2)
# good
some_method(x, y, a: 1, b: 2)
some_method(x, y, {a: 1, b: 2}, {a: 1, b: 2})