Assignment Branch Condition size for index is too high. [88.17/15] Open
def index
sticky_scope = current_user.all_stickies
sticky_scope = sticky_scope.with_owner(current_user.id) if params[:assigned_to_me] == '1'
sticky_scope = sticky_scope.where(project_id: params[:project_id]) unless params[:project_id].blank?
sticky_scope = sticky_scope.where.not(owner_id: nil) if params[:unassigned].to_s != '1'
- 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 set_filtered_sticky_scope is too high. [60.05/15] Open
def set_filtered_sticky_scope
@anchor_date = (Date.parse(params[:date]) rescue Date.today)
sticky_scope = current_user.all_viewable_stickies
sticky_scope = sticky_scope.with_tag(current_user.all_viewable_tags.where(name: params[:tags].to_s.split(',')).select(:id)) unless params[:tags].blank?
- 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 sticky_params is too high. [58.84/15] Open
def sticky_params
params[:sticky] ||= { blank: '1' }
params[:sticky][:due_date] = parse_date(params[:sticky][:due_date]) unless params[:sticky][:due_date].blank?
- 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 week is too high. [49.13/15] Open
def week
flash.delete(:notice)
week_padding = 12
@beginning_of_anchor_week = @anchor_date.wday == 0 ? @anchor_date : @anchor_date.beginning_of_week - 1.day
@beginning = @beginning_of_anchor_week - week_padding.weeks
- 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 index
has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring. Open
def index
sticky_scope = current_user.all_stickies
sticky_scope = sticky_scope.with_owner(current_user.id) if params[:assigned_to_me] == '1'
sticky_scope = sticky_scope.where(project_id: params[:project_id]) unless params[:project_id].blank?
sticky_scope = sticky_scope.where.not(owner_id: nil) if params[:unassigned].to_s != '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
Assignment Branch Condition size for generate_csv is too high. [35.24/15] Open
def generate_csv(task_scope)
@csv_string = CSV.generate do |csv|
csv << ['Name', 'Due Date', 'Description', 'Completed', 'Assigned To', 'Tags', 'Project', 'Creator', 'Board', 'Due Time', 'Duration', 'Duration Units']
task_scope.each do |sticky|
csv << [sticky.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
Method has too many lines. [29/10] Open
def index
sticky_scope = current_user.all_stickies
sticky_scope = sticky_scope.with_owner(current_user.id) if params[:assigned_to_me] == '1'
sticky_scope = sticky_scope.where(project_id: params[:project_id]) unless params[:project_id].blank?
sticky_scope = sticky_scope.where.not(owner_id: nil) if params[:unassigned].to_s != '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.
Assignment Branch Condition size for move is too high. [32.19/15] Open
def move
params[:due_date] = parse_date(params[:due_date])
@all_dates = []
if @sticky && params[:due_date].present?
- 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. [22/10] Open
def move
params[:due_date] = parse_date(params[:due_date])
@all_dates = []
if @sticky && params[:due_date].present?
- 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.
Cyclomatic complexity for index is too high. [16/6] Open
def index
sticky_scope = current_user.all_stickies
sticky_scope = sticky_scope.with_owner(current_user.id) if params[:assigned_to_me] == '1'
sticky_scope = sticky_scope.where(project_id: params[:project_id]) unless params[:project_id].blank?
sticky_scope = sticky_scope.where.not(owner_id: nil) if params[:unassigned].to_s != '1'
- 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 destroy is too high. [25.5/15] Open
def destroy
if @sticky.group && params[:discard] == 'following'
@sticky.group.stickies.where('due_date >= ?', @sticky.due_date).destroy_all
elsif @sticky.group && params[:discard] == 'all'
@sticky.group.destroy
- 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. [19/10] Open
def generate_csv(task_scope)
@csv_string = CSV.generate do |csv|
csv << ['Name', 'Due Date', 'Description', 'Completed', 'Assigned To', 'Tags', 'Project', 'Creator', 'Board', 'Due Time', 'Duration', 'Duration Units']
task_scope.each do |sticky|
csv << [sticky.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 has too many lines. [19/10] Open
def week
flash.delete(:notice)
week_padding = 12
@beginning_of_anchor_week = @anchor_date.wday == 0 ? @anchor_date : @anchor_date.beginning_of_week - 1.day
@beginning = @beginning_of_anchor_week - week_padding.weeks
- 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 index is too high. [15/7] Open
def index
sticky_scope = current_user.all_stickies
sticky_scope = sticky_scope.with_owner(current_user.id) if params[:assigned_to_me] == '1'
sticky_scope = sticky_scope.where(project_id: params[:project_id]) unless params[:project_id].blank?
sticky_scope = sticky_scope.where.not(owner_id: nil) if params[:unassigned].to_s != '1'
- 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
Assignment Branch Condition size for update is too high. [21.79/15] Open
def update
@from_date = @sticky.due_date
respond_to do |format|
if @sticky.update(sticky_params)
- 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. [16/10] Open
def edit
respond_to do |format|
if @sticky
@project = @sticky.project
format.html
- 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.
File stickies_controller.rb
has 265 lines of code (exceeds 250 allowed). Consider refactoring. Open
class StickiesController < ApplicationController
before_action :authenticate_user!
before_action :set_viewable_sticky, only: [:show]
before_action :find_editable_project_or_first_project, only: [:new, :create, :edit, :update]
before_action :set_editable_sticky, only: [:edit, :move, :move_to_board, :complete, :update, :destroy]
Assignment Branch Condition size for move_to_board is too high. [20.35/15] Open
def move_to_board
@board = current_user.all_boards.find_by_id(params[:board_id])
@original_board = @sticky.board if @sticky
if @sticky && @board && @sticky.board != @board
- 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 sticky_params
params[:sticky] ||= { blank: '1' }
params[:sticky][:due_date] = parse_date(params[:sticky][:due_date]) unless params[:sticky][:due_date].blank?
- 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 update
@from_date = @sticky.due_date
respond_to do |format|
if @sticky.update(sticky_params)
- 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 generate_csv
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def generate_csv(task_scope)
@csv_string = CSV.generate do |csv|
csv << ['Name', 'Due Date', 'Description', 'Completed', 'Assigned To', 'Tags', 'Project', 'Creator', 'Board', 'Due Time', 'Duration', 'Duration Units']
task_scope.each do |sticky|
csv << [sticky.name,
- 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
Assignment Branch Condition size for month is too high. [18.06/15] Open
def month
flash.delete(:notice)
if current_user.calendar_view == '4week'
@start_date = @anchor_date.beginning_of_week(:sunday)
@end_date = @start_date + 27.days
- 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
Perceived complexity for move is too high. [10/7] Open
def move
params[:due_date] = parse_date(params[:due_date])
@all_dates = []
if @sticky && params[:due_date].present?
- 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
Assignment Branch Condition size for edit is too high. [18.22/15] Open
def edit
respond_to do |format|
if @sticky
@project = @sticky.project
format.html
- 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 create is too high. [18.14/15] Open
def create
@sticky = @project.stickies.where(user_id: current_user.id).new(sticky_params)
respond_to do |format|
if @sticky.save
- 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. [12/10] Open
def create
@sticky = @project.stickies.where(user_id: current_user.id).new(sticky_params)
respond_to do |format|
if @sticky.save
- 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 move_to_board is too high. [9/7] Open
def move_to_board
@board = current_user.all_boards.find_by_id(params[:board_id])
@original_board = @sticky.board if @sticky
if @sticky && @board && @sticky.board != @board
- 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 move_to_board is too high. [8/6] Open
def move_to_board
@board = current_user.all_boards.find_by_id(params[:board_id])
@original_board = @sticky.board if @sticky
if @sticky && @board && @sticky.board != @board
- 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.
Method has too many lines. [12/10] Open
def set_filtered_sticky_scope
@anchor_date = (Date.parse(params[:date]) rescue Date.today)
sticky_scope = current_user.all_viewable_stickies
sticky_scope = sticky_scope.with_tag(current_user.all_viewable_tags.where(name: params[:tags].to_s.split(',')).select(:id)) unless params[:tags].blank?
- 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 sticky_params is too high. [9/7] Open
def sticky_params
params[:sticky] ||= { blank: '1' }
params[:sticky][:due_date] = parse_date(params[:sticky][:due_date]) unless params[:sticky][:due_date].blank?
- 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 sticky_params is too high. [8/6] Open
def sticky_params
params[:sticky] ||= { blank: '1' }
params[:sticky][:due_date] = parse_date(params[:sticky][:due_date]) unless params[:sticky][:due_date].blank?
- 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.
Method has too many lines. [11/10] Open
def destroy
if @sticky.group && params[:discard] == 'following'
@sticky.group.stickies.where('due_date >= ?', @sticky.due_date).destroy_all
elsif @sticky.group && params[:discard] == 'all'
@sticky.group.destroy
- 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.
Cyclomatic complexity for move is too high. [7/6] Open
def move
params[:due_date] = parse_date(params[:due_date])
@all_dates = []
if @sticky && params[:due_date].present?
- 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.
Method sticky_params
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def sticky_params
params[:sticky] ||= { blank: '1' }
params[:sticky][:due_date] = parse_date(params[:sticky][:due_date]) unless params[:sticky][:due_date].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 index
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
def index
sticky_scope = current_user.all_stickies
sticky_scope = sticky_scope.with_owner(current_user.id) if params[:assigned_to_me] == '1'
sticky_scope = sticky_scope.where(project_id: params[:project_id]) unless params[:project_id].blank?
sticky_scope = sticky_scope.where.not(owner_id: nil) if params[:unassigned].to_s != '1'
Method move
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def move
params[:due_date] = parse_date(params[:due_date])
@all_dates = []
if @sticky && params[:due_date].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 set_filtered_sticky_scope
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def set_filtered_sticky_scope
@anchor_date = (Date.parse(params[:date]) rescue Date.today)
sticky_scope = current_user.all_viewable_stickies
sticky_scope = sticky_scope.with_tag(current_user.all_viewable_tags.where(name: params[:tags].to_s.split(',')).select(:id)) unless params[:tags].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 destroy
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def destroy
if @sticky.group && params[:discard] == 'following'
@sticky.group.stickies.where('due_date >= ?', @sticky.due_date).destroy_all
elsif @sticky.group && params[:discard] == 'all'
@sticky.group.destroy
- 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 update
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def update
@from_date = @sticky.due_date
respond_to do |format|
if @sticky.update(sticky_params)
- 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 edit
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def edit
respond_to do |format|
if @sticky
@project = @sticky.project
format.html
- 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 if params[:tag_ids].present?
instead of unless params[:tag_ids].blank?
. Open
sticky_scope = sticky_scope.with_tag(params[:tag_ids].split(',')) unless params[:tag_ids].blank?
- Read upRead up
- Exclude checks
This cops checks for code that can be changed to blank?
.
Settings:
NotNilAndNotEmpty: Convert checks for not nil
and not empty?
to present?
NotBlank: Convert usages of not blank?
to present?
UnlessBlank: Convert usages of unless
blank?
to if
present?
Example:
# NotNilAndNotEmpty: true
# bad
!foo.nil? && !foo.empty?
foo != nil && !foo.empty?
!foo.blank?
# good
foo.present?
# NotBlank: true
# bad
!foo.blank?
not foo.blank?
# good
foo.present?
# UnlessBlank: true
# bad
something unless foo.blank?
# good
something if foo.present?
Do not use Date.today
without zone. Use Time.zone.today
instead. Open
@anchor_date = (Date.parse(params[:date]) rescue Date.today)
- Read upRead up
- Exclude checks
This cop checks for the correct use of Date methods, such as Date.today, Date.current etc.
Using Date.today is dangerous, because it doesn't know anything about Rails time zone. You must use Time.zone.today instead.
The cop also reports warnings when you are using 'to_time' method, because it doesn't know about Rails time zone either.
Two styles are supported for this cop. When EnforcedStyle is 'strict' then the Date methods (today, current, yesterday, tomorrow) are prohibited and the usage of both 'totime' and 'totimeincurrent_zone' is reported as warning.
When EnforcedStyle is 'flexible' then only 'Date.today' is prohibited and only 'to_time' is reported as warning.
Example: EnforcedStyle: strict
# bad
Date.current
Date.yesterday
Date.today
date.to_time
date.to_time_in_current_zone
# good
Time.zone.today
Time.zone.today - 1.day
Example: EnforcedStyle: flexible (default)
# bad
Date.today
date.to_time
# good
Time.zone.today
Time.zone.today - 1.day
Date.current
Date.yesterday
date.to_time_in_current_zone
Use find_by
instead of dynamic find_by_id
. Open
@board = current_user.all_boards.find_by_id(params[:board_id])
- Read upRead up
- Exclude checks
This cop checks dynamic find_by_*
methods.
Use find_by
instead of dynamic method.
See. https://github.com/bbatsov/rails-style-guide#find_by
Example:
# bad
User.find_by_name(name)
# bad
User.find_by_name_and_email(name)
# bad
User.find_by_email!(name)
# good
User.find_by(name: name)
# good
User.find_by(name: name, email: email)
# good
User.find_by!(email: email)
Use find_by
instead of dynamic find_by_id
. Open
@sticky = current_user.all_viewable_stickies.find_by_id(params[:id])
- Read upRead up
- Exclude checks
This cop checks dynamic find_by_*
methods.
Use find_by
instead of dynamic method.
See. https://github.com/bbatsov/rails-style-guide#find_by
Example:
# bad
User.find_by_name(name)
# bad
User.find_by_name_and_email(name)
# bad
User.find_by_email!(name)
# good
User.find_by(name: name)
# good
User.find_by(name: name, email: email)
# good
User.find_by!(email: email)
Use find_by
instead of dynamic find_by_id
. Open
@sticky = current_user.all_viewable_stickies.find_by_id(params[:id])
- Read upRead up
- Exclude checks
This cop checks dynamic find_by_*
methods.
Use find_by
instead of dynamic method.
See. https://github.com/bbatsov/rails-style-guide#find_by
Example:
# bad
User.find_by_name(name)
# bad
User.find_by_name_and_email(name)
# bad
User.find_by_email!(name)
# good
User.find_by(name: name)
# good
User.find_by(name: name, email: email)
# good
User.find_by!(email: email)
Use if params[:sticky][:due_date].present?
instead of unless params[:sticky][:due_date].blank?
. Open
params[:sticky][:due_date] = parse_date(params[:sticky][:due_date]) unless params[:sticky][:due_date].blank?
- Read upRead up
- Exclude checks
This cops checks for code that can be changed to blank?
.
Settings:
NotNilAndNotEmpty: Convert checks for not nil
and not empty?
to present?
NotBlank: Convert usages of not blank?
to present?
UnlessBlank: Convert usages of unless
blank?
to if
present?
Example:
# NotNilAndNotEmpty: true
# bad
!foo.nil? && !foo.empty?
foo != nil && !foo.empty?
!foo.blank?
# good
foo.present?
# NotBlank: true
# bad
!foo.blank?
not foo.blank?
# good
foo.present?
# UnlessBlank: true
# bad
something unless foo.blank?
# good
something if foo.present?
Use find_by
instead of dynamic find_by_id
. Open
@sticky = current_user.all_stickies.find_by_id(params[:id])
- Read upRead up
- Exclude checks
This cop checks dynamic find_by_*
methods.
Use find_by
instead of dynamic method.
See. https://github.com/bbatsov/rails-style-guide#find_by
Example:
# bad
User.find_by_name(name)
# bad
User.find_by_name_and_email(name)
# bad
User.find_by_email!(name)
# good
User.find_by(name: name)
# good
User.find_by(name: name, email: email)
# good
User.find_by!(email: email)
Use if params[:tags].present?
instead of unless params[:tags].blank?
. Open
sticky_scope = sticky_scope.with_tag(current_user.all_viewable_tags.where(name: params[:tags].to_s.split(',')).select(:id)) unless params[:tags].blank?
- Read upRead up
- Exclude checks
This cops checks for code that can be changed to blank?
.
Settings:
NotNilAndNotEmpty: Convert checks for not nil
and not empty?
to present?
NotBlank: Convert usages of not blank?
to present?
UnlessBlank: Convert usages of unless
blank?
to if
present?
Example:
# NotNilAndNotEmpty: true
# bad
!foo.nil? && !foo.empty?
foo != nil && !foo.empty?
!foo.blank?
# good
foo.present?
# NotBlank: true
# bad
!foo.blank?
not foo.blank?
# good
foo.present?
# UnlessBlank: true
# bad
something unless foo.blank?
# good
something if foo.present?
Use if params[:owners].present?
instead of unless params[:owners].blank?
. Open
unless params[:owners].blank?
- Read upRead up
- Exclude checks
This cops checks for code that can be changed to blank?
.
Settings:
NotNilAndNotEmpty: Convert checks for not nil
and not empty?
to present?
NotBlank: Convert usages of not blank?
to present?
UnlessBlank: Convert usages of unless
blank?
to if
present?
Example:
# NotNilAndNotEmpty: true
# bad
!foo.nil? && !foo.empty?
foo != nil && !foo.empty?
!foo.blank?
# good
foo.present?
# NotBlank: true
# bad
!foo.blank?
not foo.blank?
# good
foo.present?
# UnlessBlank: true
# bad
something unless foo.blank?
# good
something if foo.present?
Do not use Date.today
without zone. Use Time.zone.today
instead. Open
sticky_scope = sticky_scope.where(completed: false).due_date_before_or_blank(Date.today)
- Read upRead up
- Exclude checks
This cop checks for the correct use of Date methods, such as Date.today, Date.current etc.
Using Date.today is dangerous, because it doesn't know anything about Rails time zone. You must use Time.zone.today instead.
The cop also reports warnings when you are using 'to_time' method, because it doesn't know about Rails time zone either.
Two styles are supported for this cop. When EnforcedStyle is 'strict' then the Date methods (today, current, yesterday, tomorrow) are prohibited and the usage of both 'totime' and 'totimeincurrent_zone' is reported as warning.
When EnforcedStyle is 'flexible' then only 'Date.today' is prohibited and only 'to_time' is reported as warning.
Example: EnforcedStyle: strict
# bad
Date.current
Date.yesterday
Date.today
date.to_time
date.to_time_in_current_zone
# good
Time.zone.today
Time.zone.today - 1.day
Example: EnforcedStyle: flexible (default)
# bad
Date.today
date.to_time
# good
Time.zone.today
Time.zone.today - 1.day
Date.current
Date.yesterday
date.to_time_in_current_zone
Use find_by
instead of dynamic find_by_id
. Open
@sticky = current_user.all_viewable_stickies.find_by_id(params[:id])
- Read upRead up
- Exclude checks
This cop checks dynamic find_by_*
methods.
Use find_by
instead of dynamic method.
See. https://github.com/bbatsov/rails-style-guide#find_by
Example:
# bad
User.find_by_name(name)
# bad
User.find_by_name_and_email(name)
# bad
User.find_by_email!(name)
# good
User.find_by(name: name)
# good
User.find_by(name: name, email: email)
# good
User.find_by!(email: email)
Use if params[:project_ids].present?
instead of unless params[:project_ids].blank?
. Open
sticky_scope = sticky_scope.where(project_id: current_user.all_viewable_projects.where(id: params[:project_ids].to_s.split(',')).select(:id)) unless params[:project_ids].blank?
- Read upRead up
- Exclude checks
This cops checks for code that can be changed to blank?
.
Settings:
NotNilAndNotEmpty: Convert checks for not nil
and not empty?
to present?
NotBlank: Convert usages of not blank?
to present?
UnlessBlank: Convert usages of unless
blank?
to if
present?
Example:
# NotNilAndNotEmpty: true
# bad
!foo.nil? && !foo.empty?
foo != nil && !foo.empty?
!foo.blank?
# good
foo.present?
# NotBlank: true
# bad
!foo.blank?
not foo.blank?
# good
foo.present?
# UnlessBlank: true
# bad
something unless foo.blank?
# good
something if foo.present?
Use if params[:sticky][:repeat].present?
instead of unless params[:sticky][:repeat].blank?
. Open
params[:sticky][:repeat] = (Sticky::REPEAT.flatten.uniq.include?(params[:sticky][:repeat]) ? params[:sticky][:repeat] : 'none') unless params[:sticky][:repeat].blank?
- Read upRead up
- Exclude checks
This cops checks for code that can be changed to blank?
.
Settings:
NotNilAndNotEmpty: Convert checks for not nil
and not empty?
to present?
NotBlank: Convert usages of not blank?
to present?
UnlessBlank: Convert usages of unless
blank?
to if
present?
Example:
# NotNilAndNotEmpty: true
# bad
!foo.nil? && !foo.empty?
foo != nil && !foo.empty?
!foo.blank?
# good
foo.present?
# NotBlank: true
# bad
!foo.blank?
not foo.blank?
# good
foo.present?
# UnlessBlank: true
# bad
something unless foo.blank?
# good
something if foo.present?
Do not use Date.today
without zone. Use Time.zone.today
instead. Open
sticky_scope = sticky_scope.where(completed: false).due_date_after_or_blank(Date.today)
- Read upRead up
- Exclude checks
This cop checks for the correct use of Date methods, such as Date.today, Date.current etc.
Using Date.today is dangerous, because it doesn't know anything about Rails time zone. You must use Time.zone.today instead.
The cop also reports warnings when you are using 'to_time' method, because it doesn't know about Rails time zone either.
Two styles are supported for this cop. When EnforcedStyle is 'strict' then the Date methods (today, current, yesterday, tomorrow) are prohibited and the usage of both 'totime' and 'totimeincurrent_zone' is reported as warning.
When EnforcedStyle is 'flexible' then only 'Date.today' is prohibited and only 'to_time' is reported as warning.
Example: EnforcedStyle: strict
# bad
Date.current
Date.yesterday
Date.today
date.to_time
date.to_time_in_current_zone
# good
Time.zone.today
Time.zone.today - 1.day
Example: EnforcedStyle: flexible (default)
# bad
Date.today
date.to_time
# good
Time.zone.today
Time.zone.today - 1.day
Date.current
Date.yesterday
date.to_time_in_current_zone
Use if params[:project_id].present?
instead of unless params[:project_id].blank?
. Open
sticky_scope = sticky_scope.where(project_id: params[:project_id]) unless params[:project_id].blank?
- Read upRead up
- Exclude checks
This cops checks for code that can be changed to blank?
.
Settings:
NotNilAndNotEmpty: Convert checks for not nil
and not empty?
to present?
NotBlank: Convert usages of not blank?
to present?
UnlessBlank: Convert usages of unless
blank?
to if
present?
Example:
# NotNilAndNotEmpty: true
# bad
!foo.nil? && !foo.empty?
foo != nil && !foo.empty?
!foo.blank?
# good
foo.present?
# NotBlank: true
# bad
!foo.blank?
not foo.blank?
# good
foo.present?
# UnlessBlank: true
# bad
something unless foo.blank?
# good
something if foo.present?
Similar blocks of code found in 2 locations. Consider refactoring. Open
if params[:sticky_board_name].to_s.strip.blank?
params[:sticky][:board_id] = nil
else
@board = @project.boards.where(name: params[:sticky_board_name].to_s.strip).first_or_create(user_id: current_user.id)
params[:sticky][:board_id] = @board.id
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 37.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Unused block argument - k
. If it's necessary, use _
or _k
as an argument name to indicate that it won't be used. Open
@max_incomplete_count = @date_count_hash.collect { |k,v| v[:incomplete] }.max || 0
- Read upRead up
- Exclude checks
This cop checks for unused block arguments.
Example:
# bad
do_something do |used, unused|
puts used
end
do_something do |bar|
puts :foo
end
define_method(:foo) do |bar|
puts :baz
end
Example:
#good
do_something do |used, _unused|
puts used
end
do_something do
puts :foo
end
define_method(:foo) do |_bar|
puts :baz
end
Line is too long. [161/120] Open
disposition: "attachment; filename=\"#{current_user.last_name.gsub(/[^a-zA-Z0-9_]/, '_')}_#{Time.zone.today.strftime('%Y%m%d')}.csv\""
- Exclude checks
Space missing after comma. Open
['S','M','T','W','R','F','S'].each_with_index do |day, day_index|
- Read upRead up
- Exclude checks
Checks for comma (,) not followed by some kind of space.
Example:
# bad
[1,2]
{ foo:bar,}
# good
[1, 2]
{ foo:bar, }
Line is too long. [128/120] Open
@order = (params[:scope_direction] == 'reverse' ? "stickies.due_date NULLS FIRST" : "stickies.due_date DESC NULLS LAST")
- Exclude checks
Line is too long. [132/120] Open
@all_dates += @sticky.shift_group((@to_date - @from_date).round, params[:shift]) if @from_date.present? && @to_date.present?
- Exclude checks
Space missing inside }. Open
sticky.tags.collect{|t| t.name}.join('; '),
- Read upRead up
- Exclude checks
Checks that block braces have or don't have surrounding space inside them on configuration. For blocks taking parameters, it checks that the left brace has or doesn't have trailing space depending on configuration.
Example: EnforcedStyle: space (default)
# The `space` style enforces that block braces have
# surrounding space.
# bad
some_array.each {puts e}
# good
some_array.each { puts e }
Example: EnforcedStyle: no_space
# The `no_space` style enforces that block braces don't
# have surrounding space.
# bad
some_array.each { puts e }
# good
some_array.each {puts e}
Example: EnforcedStyleForEmptyBraces: no_space (default)
# The `no_space` EnforcedStyleForEmptyBraces style enforces that
# block braces don't have a space in between when empty.
# bad
some_array.each { }
some_array.each { }
some_array.each { }
# good
some_array.each {}
Example: EnforcedStyleForEmptyBraces: space
# The `space` EnforcedStyleForEmptyBraces style enforces that
# block braces have at least a spece in between when empty.
# bad
some_array.each {}
# good
some_array.each { }
some_array.each { }
some_array.each { }
Example: SpaceBeforeBlockParameters: true (default)
# The SpaceBeforeBlockParameters style set to `true` enforces that
# there is a space between `{` and `|`. Overrides `EnforcedStyle`
# if there is a conflict.
# bad
[1, 2, 3].each {|n| n * 2 }
# good
[1, 2, 3].each { |n| n * 2 }
Example: SpaceBeforeBlockParameters: true
# The SpaceBeforeBlockParameters style set to `false` enforces that
# there is no space between `{` and `|`. Overrides `EnforcedStyle`
# if there is a conflict.
# bad
[1, 2, 3].each { |n| n * 2 }
# good
[1, 2, 3].each {|n| n * 2 }
Line is too long. [128/120] Open
@order = (params[:scope_direction] == 'reverse' ? "stickies.due_date NULLS FIRST" : "stickies.due_date DESC NULLS LAST")
- Exclude checks
Line is too long. [125/120] Open
@board = @project.boards.where(name: params[:sticky_board_name].to_s.strip).first_or_create(user_id: current_user.id)
- Exclude checks
Space missing after comma. Open
['S','M','T','W','R','F','S'].each_with_index do |day, day_index|
- Read upRead up
- Exclude checks
Checks for comma (,) not followed by some kind of space.
Example:
# bad
[1,2]
{ foo:bar,}
# good
[1, 2]
{ foo:bar, }
Line is too long. [130/120] Open
@all_dates += @sticky.shift_group((@to_date - @from_date).round, params[:shift]) if @from_date.present? && @to_date.present?
- Exclude checks
Use ||
instead of or
. Open
sticky_scope = sticky_scope.with_board(params[:board_id]) unless params[:board_id].blank? or params[:board_id] == 'all'
- Read upRead up
- Exclude checks
This cop checks for uses of and
and or
, and suggests using &&
and
|| instead
. It can be configured to check only in conditions, or in
all contexts.
Example: EnforcedStyle: always (default)
# bad
foo.save and return
# bad
if foo and bar
end
# good
foo.save && return
# good
if foo && bar
end
Example: EnforcedStyle: conditionals
# bad
if foo and bar
end
# good
foo.save && return
# good
foo.save and return
# good
if foo && bar
end
Put empty method definitions on a single line. Open
def show
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
Pass &:name
as an argument to collect
instead of a block. Open
sticky.tags.collect{|t| t.name}.join('; '),
- Read upRead up
- Exclude checks
Use symbols as procs when possible.
Example:
# bad
something.map { |s| s.upcase }
# good
something.map(&:upcase)
Space missing after comma. Open
['S','M','T','W','R','F','S'].each_with_index do |day, day_index|
- Read upRead up
- Exclude checks
Checks for comma (,) not followed by some kind of space.
Example:
# bad
[1,2]
{ foo:bar,}
# good
[1, 2]
{ foo:bar, }
Space missing to the left of {. Open
sticky.tags.collect{|t| t.name}.join('; '),
- Read upRead up
- Exclude checks
Checks that block braces have or don't have a space before the opening brace depending on configuration.
Example:
# bad
foo.map{ |a|
a.bar.to_s
}
# good
foo.map { |a|
a.bar.to_s
}
Line is too long. [141/120] Open
completed_dates = @stickies.with_due_date_for_calendar(@beginning, @beginning + 6.months - 1.day).where(completed: true).pluck(:due_date)
- Exclude checks
Line is too long. [157/120] Open
:description, :owner_id, :board_id, :due_date, :due_time, :completed, :duration, :duration_units, :all_day, { :tag_ids => [] }, :repeat, :repeat_amount
- Exclude checks
Line is too long. [129/120] Open
sticky_scope = sticky_scope.where.not(project_id: current_user.project_preferences.where(archived: true).select(:project_id))
- Exclude checks
Use self-assignment shorthand +=
. Open
date = date + 1.week
- Read upRead up
- Exclude checks
This cop enforces the use the shorthand for self-assignment.
Example:
# bad
x = x + 1
# good
x += 1
Use %i
or %I
for an array of symbols. Open
before_action :set_filtered_sticky_scope, only: [:day, :week, :month, :tasks, :move]
- 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]
Indent when
as deep as case
. Open
case params[:scope] when 'completed'
- Read upRead up
- Exclude checks
This cop checks how the whens of a case expression are indented in relation to its case or end keyword.
It will register a separate offense for each misaligned when.
Example:
# If Layout/EndAlignment is set to keyword style (default)
# *case* and *end* should always be aligned to same depth,
# and therefore *when* should always be aligned to both -
# regardless of configuration.
# bad for all styles
case n
when 0
x * 2
else
y / 3
end
# good for all styles
case n
when 0
x * 2
else
y / 3
end
Example: EnforcedStyle: case (default)
# if EndAlignment is set to other style such as
# start_of_line (as shown below), then *when* alignment
# configuration does have an effect.
# bad
a = case n
when 0
x * 2
else
y / 3
end
# good
a = case n
when 0
x * 2
else
y / 3
end
Example: EnforcedStyle: end
# bad
a = case n
when 0
x * 2
else
y / 3
end
# good
a = case n
when 0
x * 2
else
y / 3
end
Space missing after comma. Open
['S','M','T','W','R','F','S'].each_with_index do |day, day_index|
- Read upRead up
- Exclude checks
Checks for comma (,) not followed by some kind of space.
Example:
# bad
[1,2]
{ foo:bar,}
# good
[1, 2]
{ foo:bar, }
Line is too long. [123/120] Open
sticky_scope = sticky_scope.with_board(params[:board_id]) unless params[:board_id].blank? or params[:board_id] == 'all'
- Exclude checks
Line is too long. [180/120] Open
sticky_scope = sticky_scope.where(project_id: current_user.all_viewable_projects.where(id: params[:project_ids].to_s.split(',')).select(:id)) unless params[:project_ids].blank?
- Exclude checks
Avoid using rescue
in its modifier form. Open
@anchor_date = (Date.parse(params[:date]) rescue Date.today)
- Read upRead up
- Exclude checks
This cop checks for uses of rescue in its modifier form.
Example:
# bad
some_method rescue handle_error
# good
begin
some_method
rescue
handle_error
end
Line is too long. [170/120] Open
params[:sticky][:repeat] = (Sticky::REPEAT.flatten.uniq.include?(params[:sticky][:repeat]) ? params[:sticky][:repeat] : 'none') unless params[:sticky][:repeat].blank?
- Exclude checks
Space missing after comma. Open
@max_incomplete_count = @date_count_hash.collect { |k,v| v[:incomplete] }.max || 0
- Read upRead up
- Exclude checks
Checks for comma (,) not followed by some kind of space.
Example:
# bad
[1,2]
{ foo:bar,}
# good
[1, 2]
{ foo:bar, }
Space inside parentheses detected. Open
format.html { redirect_to month_path( date: @sticky.due_date.blank? ? '' : @sticky.due_date.strftime('%Y%m%d') ), notice: 'Task was successfully deleted.' }
- Read upRead up
- Exclude checks
Checks for spaces inside ordinary round parentheses.
Example:
# bad
f( 3)
g = (a + 3 )
# good
f(3)
g = (a + 3)
Line is too long. [162/120] Open
format.html { redirect_to month_path( date: @sticky.due_date.blank? ? '' : @sticky.due_date.strftime('%Y%m%d') ), notice: 'Task was successfully deleted.' }
- Exclude checks
Space between { and | missing. Open
incomplete = incomplete_dates.select{|d| current_date == d.to_date }.count
- Read upRead up
- Exclude checks
Checks that block braces have or don't have surrounding space inside them on configuration. For blocks taking parameters, it checks that the left brace has or doesn't have trailing space depending on configuration.
Example: EnforcedStyle: space (default)
# The `space` style enforces that block braces have
# surrounding space.
# bad
some_array.each {puts e}
# good
some_array.each { puts e }
Example: EnforcedStyle: no_space
# The `no_space` style enforces that block braces don't
# have surrounding space.
# bad
some_array.each { puts e }
# good
some_array.each {puts e}
Example: EnforcedStyleForEmptyBraces: no_space (default)
# The `no_space` EnforcedStyleForEmptyBraces style enforces that
# block braces don't have a space in between when empty.
# bad
some_array.each { }
some_array.each { }
some_array.each { }
# good
some_array.each {}
Example: EnforcedStyleForEmptyBraces: space
# The `space` EnforcedStyleForEmptyBraces style enforces that
# block braces have at least a spece in between when empty.
# bad
some_array.each {}
# good
some_array.each { }
some_array.each { }
some_array.each { }
Example: SpaceBeforeBlockParameters: true (default)
# The SpaceBeforeBlockParameters style set to `true` enforces that
# there is a space between `{` and `|`. Overrides `EnforcedStyle`
# if there is a conflict.
# bad
[1, 2, 3].each {|n| n * 2 }
# good
[1, 2, 3].each { |n| n * 2 }
Example: SpaceBeforeBlockParameters: true
# The SpaceBeforeBlockParameters style set to `false` enforces that
# there is no space between `{` and `|`. Overrides `EnforcedStyle`
# if there is a conflict.
# bad
[1, 2, 3].each { |n| n * 2 }
# good
[1, 2, 3].each {|n| n * 2 }
Space missing inside }. Open
sticky_scope = sticky_scope.where(completed: (params[:status] || []).collect{|v| (v.to_s == 'completed')})
- Read upRead up
- Exclude checks
Checks that block braces have or don't have surrounding space inside them on configuration. For blocks taking parameters, it checks that the left brace has or doesn't have trailing space depending on configuration.
Example: EnforcedStyle: space (default)
# The `space` style enforces that block braces have
# surrounding space.
# bad
some_array.each {puts e}
# good
some_array.each { puts e }
Example: EnforcedStyle: no_space
# The `no_space` style enforces that block braces don't
# have surrounding space.
# bad
some_array.each { puts e }
# good
some_array.each {puts e}
Example: EnforcedStyleForEmptyBraces: no_space (default)
# The `no_space` EnforcedStyleForEmptyBraces style enforces that
# block braces don't have a space in between when empty.
# bad
some_array.each { }
some_array.each { }
some_array.each { }
# good
some_array.each {}
Example: EnforcedStyleForEmptyBraces: space
# The `space` EnforcedStyleForEmptyBraces style enforces that
# block braces have at least a spece in between when empty.
# bad
some_array.each {}
# good
some_array.each { }
some_array.each { }
some_array.each { }
Example: SpaceBeforeBlockParameters: true (default)
# The SpaceBeforeBlockParameters style set to `true` enforces that
# there is a space between `{` and `|`. Overrides `EnforcedStyle`
# if there is a conflict.
# bad
[1, 2, 3].each {|n| n * 2 }
# good
[1, 2, 3].each { |n| n * 2 }
Example: SpaceBeforeBlockParameters: true
# The SpaceBeforeBlockParameters style set to `false` enforces that
# there is no space between `{` and `|`. Overrides `EnforcedStyle`
# if there is a conflict.
# bad
[1, 2, 3].each { |n| n * 2 }
# good
[1, 2, 3].each {|n| n * 2 }
Space missing after comma. Open
['S','M','T','W','R','F','S'].each_with_index do |day, day_index|
- Read upRead up
- Exclude checks
Checks for comma (,) not followed by some kind of space.
Example:
# bad
[1,2]
{ foo:bar,}
# good
[1, 2]
{ foo:bar, }
Space missing to the left of {. Open
sticky_scope = sticky_scope.where(completed: (params[:status] || []).collect{|v| (v.to_s == 'completed')})
- Read upRead up
- Exclude checks
Checks that block braces have or don't have a space before the opening brace depending on configuration.
Example:
# bad
foo.map{ |a|
a.bar.to_s
}
# good
foo.map { |a|
a.bar.to_s
}
Space between { and | missing. Open
sticky.tags.collect{|t| t.name}.join('; '),
- Read upRead up
- Exclude checks
Checks that block braces have or don't have surrounding space inside them on configuration. For blocks taking parameters, it checks that the left brace has or doesn't have trailing space depending on configuration.
Example: EnforcedStyle: space (default)
# The `space` style enforces that block braces have
# surrounding space.
# bad
some_array.each {puts e}
# good
some_array.each { puts e }
Example: EnforcedStyle: no_space
# The `no_space` style enforces that block braces don't
# have surrounding space.
# bad
some_array.each { puts e }
# good
some_array.each {puts e}
Example: EnforcedStyleForEmptyBraces: no_space (default)
# The `no_space` EnforcedStyleForEmptyBraces style enforces that
# block braces don't have a space in between when empty.
# bad
some_array.each { }
some_array.each { }
some_array.each { }
# good
some_array.each {}
Example: EnforcedStyleForEmptyBraces: space
# The `space` EnforcedStyleForEmptyBraces style enforces that
# block braces have at least a spece in between when empty.
# bad
some_array.each {}
# good
some_array.each { }
some_array.each { }
some_array.each { }
Example: SpaceBeforeBlockParameters: true (default)
# The SpaceBeforeBlockParameters style set to `true` enforces that
# there is a space between `{` and `|`. Overrides `EnforcedStyle`
# if there is a conflict.
# bad
[1, 2, 3].each {|n| n * 2 }
# good
[1, 2, 3].each { |n| n * 2 }
Example: SpaceBeforeBlockParameters: true
# The SpaceBeforeBlockParameters style set to `false` enforces that
# there is no space between `{` and `|`. Overrides `EnforcedStyle`
# if there is a conflict.
# bad
[1, 2, 3].each { |n| n * 2 }
# good
[1, 2, 3].each {|n| n * 2 }
Line is too long. [155/120] Open
sticky_scope = sticky_scope.with_tag(current_user.all_viewable_tags.where(name: params[:tags].to_s.split(',')).select(:id)) unless params[:tags].blank?
- Exclude checks
Line is too long. [157/120] Open
csv << ['Name', 'Due Date', 'Description', 'Completed', 'Assigned To', 'Tags', 'Project', 'Creator', 'Board', 'Due Time', 'Duration', 'Duration Units']
- Exclude checks
Use @anchor_date.wday.zero?
instead of @anchor_date.wday == 0
. Open
@beginning = @anchor_date.wday == 0 ? @anchor_date : @anchor_date.beginning_of_week - 1.day
- Read upRead up
- Exclude checks
This cop checks for usage of comparison operators (==
,
>
, <
) to test numbers as zero, positive, or negative.
These can be replaced by their respective predicate methods.
The cop can also be configured to do the reverse.
The cop disregards #nonzero?
as it its value is truthy or falsey,
but not true
and false
, and thus not always interchangeable with
!= 0
.
The cop ignores comparisons to global variables, since they are often
populated with objects which can be compared with integers, but are
not themselves Interger
polymorphic.
Example: EnforcedStyle: predicate (default)
# bad
foo == 0
0 > foo
bar.baz > 0
# good
foo.zero?
foo.negative?
bar.baz.positive?
Example: EnforcedStyle: comparison
# bad
foo.zero?
foo.negative?
bar.baz.positive?
# good
foo == 0
0 > foo
bar.baz > 0
Use %i
or %I
for an array of symbols. Open
before_action :find_editable_project_or_first_project, only: [:new, :create, :edit, :update]
- 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]
Space missing to the left of {. Open
incomplete = incomplete_dates.select{|d| current_date == d.to_date }.count
- Read upRead up
- Exclude checks
Checks that block braces have or don't have a space before the opening brace depending on configuration.
Example:
# bad
foo.map{ |a|
a.bar.to_s
}
# good
foo.map { |a|
a.bar.to_s
}
Line is too long. [143/120] Open
incomplete_dates = @stickies.with_due_date_for_calendar(@beginning, @beginning + 6.months - 1.day).where(completed: false).pluck(:due_date)
- Exclude checks
Use the new Ruby 1.9 hash syntax. Open
:description, :owner_id, :board_id, :due_date, :due_time, :completed, :duration, :duration_units, :all_day, { :tag_ids => [] }, :repeat, :repeat_amount
- 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}
Use %w
or %W
for an array of words. Open
['S','M','T','W','R','F','S'].each_with_index do |day, day_index|
- Read upRead up
- Exclude checks
This cop can check for array literals made up of word-like strings, that are not using the %w() syntax.
Alternatively, it can check for uses of the %w() syntax, in projects which do not want to include 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
%w[foo bar baz]
# bad
['foo', 'bar', 'baz']
Example: EnforcedStyle: brackets
# good
['foo', 'bar', 'baz']
# bad
%w[foo bar baz]
Use 2 (not -18) spaces for indentation. Open
sticky_scope = sticky_scope.where(completed: true)
- Read upRead up
- Exclude checks
This cops checks for indentation that doesn't use the specified number of spaces.
See also the IndentationConsistency cop which is the companion to this one.
Example:
# bad
class A
def test
puts 'hello'
end
end
# good
class A
def test
puts 'hello'
end
end
Example: IgnoredPatterns: ['^\s*module']
# bad
module A
class B
def test
puts 'hello'
end
end
end
# good
module A
class B
def test
puts 'hello'
end
end
end
Space missing to the left of {. Open
completed = completed_dates.select{|d| current_date == d.to_date }.count
- Read upRead up
- Exclude checks
Checks that block braces have or don't have a space before the opening brace depending on configuration.
Example:
# bad
foo.map{ |a|
a.bar.to_s
}
# good
foo.map { |a|
a.bar.to_s
}
Space between { and | missing. Open
sticky_scope = sticky_scope.where(completed: (params[:status] || []).collect{|v| (v.to_s == 'completed')})
- Read upRead up
- Exclude checks
Checks that block braces have or don't have surrounding space inside them on configuration. For blocks taking parameters, it checks that the left brace has or doesn't have trailing space depending on configuration.
Example: EnforcedStyle: space (default)
# The `space` style enforces that block braces have
# surrounding space.
# bad
some_array.each {puts e}
# good
some_array.each { puts e }
Example: EnforcedStyle: no_space
# The `no_space` style enforces that block braces don't
# have surrounding space.
# bad
some_array.each { puts e }
# good
some_array.each {puts e}
Example: EnforcedStyleForEmptyBraces: no_space (default)
# The `no_space` EnforcedStyleForEmptyBraces style enforces that
# block braces don't have a space in between when empty.
# bad
some_array.each { }
some_array.each { }
some_array.each { }
# good
some_array.each {}
Example: EnforcedStyleForEmptyBraces: space
# The `space` EnforcedStyleForEmptyBraces style enforces that
# block braces have at least a spece in between when empty.
# bad
some_array.each {}
# good
some_array.each { }
some_array.each { }
some_array.each { }
Example: SpaceBeforeBlockParameters: true (default)
# The SpaceBeforeBlockParameters style set to `true` enforces that
# there is a space between `{` and `|`. Overrides `EnforcedStyle`
# if there is a conflict.
# bad
[1, 2, 3].each {|n| n * 2 }
# good
[1, 2, 3].each { |n| n * 2 }
Example: SpaceBeforeBlockParameters: true
# The SpaceBeforeBlockParameters style set to `false` enforces that
# there is no space between `{` and `|`. Overrides `EnforcedStyle`
# if there is a conflict.
# bad
[1, 2, 3].each { |n| n * 2 }
# good
[1, 2, 3].each {|n| n * 2 }
Space inside parentheses detected. Open
format.html { redirect_to month_path( date: @sticky.due_date.blank? ? '' : @sticky.due_date.strftime('%Y%m%d') ), notice: 'Task was successfully deleted.' }
- Read upRead up
- Exclude checks
Checks for spaces inside ordinary round parentheses.
Example:
# bad
f( 3)
g = (a + 3 )
# good
f(3)
g = (a + 3)
Use @anchor_date.wday.zero?
instead of @anchor_date.wday == 0
. Open
@beginning_of_anchor_week = @anchor_date.wday == 0 ? @anchor_date : @anchor_date.beginning_of_week - 1.day
- Read upRead up
- Exclude checks
This cop checks for usage of comparison operators (==
,
>
, <
) to test numbers as zero, positive, or negative.
These can be replaced by their respective predicate methods.
The cop can also be configured to do the reverse.
The cop disregards #nonzero?
as it its value is truthy or falsey,
but not true
and false
, and thus not always interchangeable with
!= 0
.
The cop ignores comparisons to global variables, since they are often
populated with objects which can be compared with integers, but are
not themselves Interger
polymorphic.
Example: EnforcedStyle: predicate (default)
# bad
foo == 0
0 > foo
bar.baz > 0
# good
foo.zero?
foo.negative?
bar.baz.positive?
Example: EnforcedStyle: comparison
# bad
foo.zero?
foo.negative?
bar.baz.positive?
# good
foo == 0
0 > foo
bar.baz > 0
Use %i
or %I
for an array of symbols. Open
before_action :redirect_without_sticky, only: [:show, :update, :destroy]
- 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. [176/120] Open
@order = (params[:scope_direction] == 'reverse' ? "(stickies.due_date IS NULL) DESC, stickies.due_date DESC" : "(stickies.due_date IS NULL) ASC, stickies.due_date ASC")
- Exclude checks
Use %i
or %I
for an array of symbols. Open
before_action :set_editable_sticky, only: [:edit, :move, :move_to_board, :complete, :update, :destroy]
- 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]
Space between { and | missing. Open
completed = completed_dates.select{|d| current_date == d.to_date }.count
- Read upRead up
- Exclude checks
Checks that block braces have or don't have surrounding space inside them on configuration. For blocks taking parameters, it checks that the left brace has or doesn't have trailing space depending on configuration.
Example: EnforcedStyle: space (default)
# The `space` style enforces that block braces have
# surrounding space.
# bad
some_array.each {puts e}
# good
some_array.each { puts e }
Example: EnforcedStyle: no_space
# The `no_space` style enforces that block braces don't
# have surrounding space.
# bad
some_array.each { puts e }
# good
some_array.each {puts e}
Example: EnforcedStyleForEmptyBraces: no_space (default)
# The `no_space` EnforcedStyleForEmptyBraces style enforces that
# block braces don't have a space in between when empty.
# bad
some_array.each { }
some_array.each { }
some_array.each { }
# good
some_array.each {}
Example: EnforcedStyleForEmptyBraces: space
# The `space` EnforcedStyleForEmptyBraces style enforces that
# block braces have at least a spece in between when empty.
# bad
some_array.each {}
# good
some_array.each { }
some_array.each { }
some_array.each { }
Example: SpaceBeforeBlockParameters: true (default)
# The SpaceBeforeBlockParameters style set to `true` enforces that
# there is a space between `{` and `|`. Overrides `EnforcedStyle`
# if there is a conflict.
# bad
[1, 2, 3].each {|n| n * 2 }
# good
[1, 2, 3].each { |n| n * 2 }
Example: SpaceBeforeBlockParameters: true
# The SpaceBeforeBlockParameters style set to `false` enforces that
# there is no space between `{` and `|`. Overrides `EnforcedStyle`
# if there is a conflict.
# bad
[1, 2, 3].each { |n| n * 2 }
# good
[1, 2, 3].each {|n| n * 2 }
Use %w
or %W
for an array of words. Open
params[:scope] = (['completed', 'past_due', 'upcoming'].include?(params[:scope]) ? params[:scope] : 'upcoming')
- Read upRead up
- Exclude checks
This cop can check for array literals made up of word-like strings, that are not using the %w() syntax.
Alternatively, it can check for uses of the %w() syntax, in projects which do not want to include 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
%w[foo bar baz]
# bad
['foo', 'bar', 'baz']
Example: EnforcedStyle: brackets
# good
['foo', 'bar', 'baz']
# bad
%w[foo bar baz]
Space missing after comma. Open
['S','M','T','W','R','F','S'].each_with_index do |day, day_index|
- Read upRead up
- Exclude checks
Checks for comma (,) not followed by some kind of space.
Example:
# bad
[1,2]
{ foo:bar,}
# good
[1, 2]
{ foo:bar, }
Unused block argument - day
. If it's necessary, use _
or _day
as an argument name to indicate that it won't be used. Open
['S','M','T','W','R','F','S'].each_with_index do |day, day_index|
- Read upRead up
- Exclude checks
This cop checks for unused block arguments.
Example:
# bad
do_something do |used, unused|
puts used
end
do_something do |bar|
puts :foo
end
define_method(:foo) do |bar|
puts :baz
end
Example:
#good
do_something do |used, _unused|
puts used
end
do_something do
puts :foo
end
define_method(:foo) do |_bar|
puts :baz
end
Line is too long. [129/120] Open
sticky_scope = sticky_scope.where(completed: current_user.calendar_task_status) unless current_user.calendar_task_status.nil?
- Exclude checks