Module has too many lines. [134/100] Open
module ArticlesHelper
# 'Read on' link to article for index-pages
# If external_url_redirect is set and a link_title is given,
# display this link title. Otherwise display a generic link title.
- Read upRead up
- Exclude checks
This cop checks if the length a module exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Assignment Branch Condition size for render_article_widgets is too high. [74.59/15] Open
def render_article_widgets(options={})
custom_css = options[:class] || ""
tags = options[:tagged_with] || ""
#include default widgets?
- 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
Complex method Goldencobra::ArticlesHelper#render_article_widgets (100.7) Open
def render_article_widgets(options={})
custom_css = options[:class] || ""
tags = options[:tagged_with] || ""
#include default widgets?
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Method has too many lines. [49/10] Open
def render_article_widgets(options={})
custom_css = options[:class] || ""
tags = options[:tagged_with] || ""
#include default widgets?
- 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 render_article_widgets is too high. [26/7] Open
def render_article_widgets(options={})
custom_css = options[:class] || ""
tags = options[:tagged_with] || ""
#include default widgets?
- 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 index_of_articles is too high. [33.12/15] Open
def index_of_articles(options={})
warn "Deprecated helper method 'index_of_articles'. Will be removed in GC 2.1"
if @article && @article.article_for_index_id.present? && master_index_article = Goldencobra::Article.find_by_id(@article.article_for_index_id)
result_list = ""
result_list += content_tag(:h2, raw(" "), class: "boxheader")
- Read upRead up
- Exclude checks
This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric
Cyclomatic complexity for render_article_widgets is too high. [20/6] Open
def render_article_widgets(options={})
custom_css = options[:class] || ""
tags = options[:tagged_with] || ""
#include default widgets?
- 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 render_article_widgets
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
def render_article_widgets(options={})
custom_css = options[:class] || ""
tags = options[:tagged_with] || ""
#include default widgets?
- 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 render_article_list_item is too high. [27.39/15] Open
def render_article_list_item(article_item)
result = ""
result += content_tag(:div, link_to(article_item.title, article_item.public_url), :class=> "title")
result += content_tag(:div, article_item.created_at.strftime("%d.%m.%Y %H:%M"), :class=>"created_at")
if @article.article_for_index_images == true && article_item.images.count > 0
- 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
Complex method Goldencobra::ArticlesHelper#index_of_articles (51.9) Open
def index_of_articles(options={})
warn "Deprecated helper method 'index_of_articles'. Will be removed in GC 2.1"
if @article && @article.article_for_index_id.present? && master_index_article = Goldencobra::Article.find_by_id(@article.article_for_index_id)
result_list = ""
result_list += content_tag(:h2, raw(" "), class: "boxheader")
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Assignment Branch Condition size for render_article_image_gallery is too high. [24.7/15] Open
def render_article_image_gallery(options = {})
if @article && @article.image_gallery_tags.present?
tags = @article.image_gallery_tags.split(",")
uploads = Goldencobra::Upload.tagged_with(tags)
list_items = ""
- 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 render_article_image_gallery(options = {})
if @article && @article.image_gallery_tags.present?
tags = @article.image_gallery_tags.split(",")
uploads = Goldencobra::Upload.tagged_with(tags)
list_items = ""
- 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 parse_glossar_entries(content,tag_name, parent_article_id=nil)
glossar_parent = nil
if parent_article_id
glossar_parent = Goldencobra::Article.find_by_id(parent_article_id)
glossar_article = glossar_parent.children.where(breadcrumb: tag_name).first
- 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 index_of_articles(options={})
warn "Deprecated helper method 'index_of_articles'. Will be removed in GC 2.1"
if @article && @article.article_for_index_id.present? && master_index_article = Goldencobra::Article.find_by_id(@article.article_for_index_id)
result_list = ""
result_list += content_tag(:h2, raw(" "), class: "boxheader")
- 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.
Complex method Goldencobra::ArticlesHelper#render_article_list_item (41.4) Open
def render_article_list_item(article_item)
result = ""
result += content_tag(:div, link_to(article_item.title, article_item.public_url), :class=> "title")
result += content_tag(:div, article_item.created_at.strftime("%d.%m.%Y %H:%M"), :class=>"created_at")
if @article.article_for_index_images == true && article_item.images.count > 0
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Complex method Goldencobra::ArticlesHelper#render_article_image_gallery (39.9) Open
def render_article_image_gallery(options = {})
if @article && @article.image_gallery_tags.present?
tags = @article.image_gallery_tags.split(",")
uploads = Goldencobra::Upload.tagged_with(tags)
list_items = ""
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Method render_article_widgets
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
def render_article_widgets(options={})
custom_css = options[:class] || ""
tags = options[:tagged_with] || ""
#include default widgets?
Cyclomatic complexity for index_of_articles is too high. [7/6] Open
def index_of_articles(options={})
warn "Deprecated helper method 'index_of_articles'. Will be removed in GC 2.1"
if @article && @article.article_for_index_id.present? && master_index_article = Goldencobra::Article.find_by_id(@article.article_for_index_id)
result_list = ""
result_list += content_tag(:h2, raw(" "), class: "boxheader")
- 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 index_of_articles
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def index_of_articles(options={})
warn "Deprecated helper method 'index_of_articles'. Will be removed in GC 2.1"
if @article && @article.article_for_index_id.present? && master_index_article = Goldencobra::Article.find_by_id(@article.article_for_index_id)
result_list = ""
result_list += content_tag(:h2, raw(" "), class: "boxheader")
- 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
Goldencobra::ArticlesHelper#render_article_image_gallery has approx 9 statements Open
def render_article_image_gallery(options = {})
- Read upRead up
- Exclude checks
A method with Too Many Statements
is any method that has a large number of lines.
Too Many Statements
warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements
counts +1 for every simple statement in a method and +1 for every statement within a control structure (if
, else
, case
, when
, for
, while
, until
, begin
, rescue
) but it doesn't count the control structure itself.
So the following method would score +6 in Reek's statement-counting algorithm:
def parse(arg, argv, &error)
if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
return nil, block, nil # +1
end
opt = (val = parse_arg(val, &error))[1] # +2
val = conv_arg(*val) # +3
if opt and !arg
argv.shift # +4
else
val[0] = nil # +5
end
val # +6
end
(You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)
Goldencobra::ArticlesHelper#parse_glossar_entries has approx 7 statements Open
def parse_glossar_entries(content,tag_name, parent_article_id=nil)
- Read upRead up
- Exclude checks
A method with Too Many Statements
is any method that has a large number of lines.
Too Many Statements
warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements
counts +1 for every simple statement in a method and +1 for every statement within a control structure (if
, else
, case
, when
, for
, while
, until
, begin
, rescue
) but it doesn't count the control structure itself.
So the following method would score +6 in Reek's statement-counting algorithm:
def parse(arg, argv, &error)
if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
return nil, block, nil # +1
end
opt = (val = parse_arg(val, &error))[1] # +2
val = conv_arg(*val) # +3
if opt and !arg
argv.shift # +4
else
val[0] = nil # +5
end
val # +6
end
(You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)
Goldencobra::ArticlesHelper#read_on refers to 'article' more than self (maybe move it to another class?) Open
target_window = article.redirection_target_in_new_window ? "_blank" : "_top"
html_class = "more #{options[:class]}".strip
if article.redirect_link_title.present?
link_to article.redirect_link_title, article.external_url_redirect, class: html_class, target: target_window
else
- Read upRead up
- Exclude checks
Feature Envy occurs when a code fragment references another object more often than it references itself, or when several clients do the same series of manipulations on a particular type of object.
Feature Envy reduces the code's ability to communicate intent: code that "belongs" on one class but which is located in another can be hard to find, and may upset the "System of Names" in the host class.
Feature Envy also affects the design's flexibility: A code fragment that is in the wrong class creates couplings that may not be natural within the application's domain, and creates a loss of cohesion in the unwilling host class.
Feature Envy often arises because it must manipulate other objects (usually its arguments) to get them into a useful form, and one force preventing them (the arguments) doing this themselves is that the common knowledge lives outside the arguments, or the arguments are of too basic a type to justify extending that type. Therefore there must be something which 'knows' about the contents or purposes of the arguments. That thing would have to be more than just a basic type, because the basic types are either containers which don't know about their contents, or they are single objects which can't capture their relationship with their fellows of the same type. So, this thing with the extra knowledge should be reified into a class, and the utility method will most likely belong there.
Example
Running Reek on:
class Warehouse
def sale_price(item)
(item.price - item.rebate) * @vat
end
end
would report:
Warehouse#total_price refers to item more than self (FeatureEnvy)
since this:
(item.price - item.rebate)
belongs to the Item class, not the Warehouse.
Goldencobra::ArticlesHelper#index_of_articles has approx 10 statements Open
def index_of_articles(options={})
- Read upRead up
- Exclude checks
A method with Too Many Statements
is any method that has a large number of lines.
Too Many Statements
warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements
counts +1 for every simple statement in a method and +1 for every statement within a control structure (if
, else
, case
, when
, for
, while
, until
, begin
, rescue
) but it doesn't count the control structure itself.
So the following method would score +6 in Reek's statement-counting algorithm:
def parse(arg, argv, &error)
if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
return nil, block, nil # +1
end
opt = (val = parse_arg(val, &error))[1] # +2
val = conv_arg(*val) # +3
if opt and !arg
argv.shift # +4
else
val[0] = nil # +5
end
val # +6
end
(You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)
Goldencobra::ArticlesHelper#render_article_widgets has approx 26 statements Open
def render_article_widgets(options={})
- Read upRead up
- Exclude checks
A method with Too Many Statements
is any method that has a large number of lines.
Too Many Statements
warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements
counts +1 for every simple statement in a method and +1 for every statement within a control structure (if
, else
, case
, when
, for
, while
, until
, begin
, rescue
) but it doesn't count the control structure itself.
So the following method would score +6 in Reek's statement-counting algorithm:
def parse(arg, argv, &error)
if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
return nil, block, nil # +1
end
opt = (val = parse_arg(val, &error))[1] # +2
val = conv_arg(*val) # +3
if opt and !arg
argv.shift # +4
else
val[0] = nil # +5
end
val # +6
end
(You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)
Goldencobra::ArticlesHelper#render_article_list_item has approx 7 statements Open
def render_article_list_item(article_item)
- Read upRead up
- Exclude checks
A method with Too Many Statements
is any method that has a large number of lines.
Too Many Statements
warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements
counts +1 for every simple statement in a method and +1 for every statement within a control structure (if
, else
, case
, when
, for
, while
, until
, begin
, rescue
) but it doesn't count the control structure itself.
So the following method would score +6 in Reek's statement-counting algorithm:
def parse(arg, argv, &error)
if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
return nil, block, nil # +1
end
opt = (val = parse_arg(val, &error))[1] # +2
val = conv_arg(*val) # +3
if opt and !arg
argv.shift # +4
else
val[0] = nil # +5
end
val # +6
end
(You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)
Goldencobra::ArticlesHelper#index_of_articles calls '@article.article_for_index_levels' 2 times Open
if @article.article_for_index_levels.to_i == 0 || (@article.depth + @article.article_for_index_levels.to_i > art.depth)
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Goldencobra::ArticlesHelper#render_article_list_item calls 'article_item.images' 2 times Open
if @article.article_for_index_images == true && article_item.images.count > 0
result += content_tag(:div, image_tag(article_item.images.first.image(:thumb)), class: "article_image")
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Goldencobra::ArticlesHelper#render_article_list_item calls 'article_item.public_url' 2 times Open
result += content_tag(:div, link_to(article_item.title, article_item.public_url), :class=> "title")
result += content_tag(:div, article_item.created_at.strftime("%d.%m.%Y %H:%M"), :class=>"created_at")
if @article.article_for_index_images == true && article_item.images.count > 0
result += content_tag(:div, image_tag(article_item.images.first.image(:thumb)), class: "article_image")
end
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Goldencobra::ArticlesHelper has no descriptive comment Open
module ArticlesHelper
- Read upRead up
- Exclude checks
Classes and modules are the units of reuse and release. It is therefore considered good practice to annotate every class and module with a brief comment outlining its responsibilities.
Example
Given
class Dummy
# Do things...
end
Reek would emit the following warning:
test.rb -- 1 warning:
[1]:Dummy has no descriptive comment (IrresponsibleModule)
Fixing this is simple - just an explaining comment:
# The Dummy class is responsible for ...
class Dummy
# Do things...
end
Goldencobra::ArticlesHelper#render_article_widgets calls 'params[:frontend_tags][:format]' 2 times Open
if params[:frontend_tags] && params[:frontend_tags].class != String && params[:frontend_tags][:format] && params[:frontend_tags][:format] == "email"
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Goldencobra::ArticlesHelper#render_article_widgets calls 'template.render(Goldencobra::Article::LiquidParser)' 2 times Open
result << raw(template.render(Goldencobra::Article::LiquidParser))
else
result << content_tag(widget_wrapper, raw(template.render(Goldencobra::Article::LiquidParser)), html_data_options)
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Goldencobra::ArticlesHelper#render_article_image_gallery calls '@article.image_gallery_tags' 2 times Open
if @article && @article.image_gallery_tags.present?
tags = @article.image_gallery_tags.split(",")
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Goldencobra::ArticlesHelper#render_article_widgets calls 'params[:frontend_tags]' 4 times Open
if params[:frontend_tags] && params[:frontend_tags].class != String && params[:frontend_tags][:format] && params[:frontend_tags][:format] == "email"
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Goldencobra::ArticlesHelper#render_article_type_content calls '@article.kind_of_article_type' 2 times Open
if @article.article_type.present? && @article.kind_of_article_type.present?
render partial: "articletypes/#{@article.article_type_form_file.underscore.parameterize.downcase}/#{@article.kind_of_article_type.downcase}"
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Goldencobra::ArticlesHelper#index_of_articles calls 'options[:wrapper]' 2 times Open
dom_element = (options[:wrapper]).present? ? options[:wrapper] : :div
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Goldencobra::ArticlesHelper#render_article_widgets calls 'tags.split(",")' 2 times Open
article_widgets = @article.widgets.active.tagged_with(tags.split(","))
else
article_widgets = []
end
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Goldencobra::ArticlesHelper#render_article_widgets calls 'options[:article]' 2 times Open
if options[:article].present?
include_articles = options[:article].to_s == "true"
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Goldencobra::ArticlesHelper#render_article_image_gallery calls 'upload.image' 2 times Open
link_to upload.image.url(options[:target_image_size] || :large), title: raw(upload.description) do
image_tag(upload.image.url(options[:link_image_size] || :thumb), alt: upload.alt_text)
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Goldencobra::ArticlesHelper#render_article_widgets calls 'widget.id' 2 times Open
"id" => widget.id_name.present? ? widget.id_name : "widget_id_#{widget.id}",
'data-id' => widget.id
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Goldencobra::ArticlesHelper#read_on calls 'article.redirect_link_title' 2 times Open
if article.redirect_link_title.present?
link_to article.redirect_link_title, article.external_url_redirect, class: html_class, target: target_window
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Goldencobra::ArticlesHelper#render_article_widgets calls 'raw(template.render(Goldencobra::Article::LiquidParser))' 2 times Open
result << raw(template.render(Goldencobra::Article::LiquidParser))
else
result << content_tag(widget_wrapper, raw(template.render(Goldencobra::Article::LiquidParser)), html_data_options)
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Goldencobra::ArticlesHelper#render_article_widgets calls 'widget.id_name' 2 times Open
"id" => widget.id_name.present? ? widget.id_name : "widget_id_#{widget.id}",
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Goldencobra::ArticlesHelper#index_of_articles calls '@article.article_for_index_levels.to_i' 2 times Open
if @article.article_for_index_levels.to_i == 0 || (@article.depth + @article.article_for_index_levels.to_i > art.depth)
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Goldencobra::ArticlesHelper#index_of_articles calls '@article.article_for_index_id' 2 times Open
if @article && @article.article_for_index_id.present? && master_index_article = Goldencobra::Article.find_by_id(@article.article_for_index_id)
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Goldencobra::ArticlesHelper#parse_glossar_entries doesn't depend on instance state (maybe move it to another class?) Open
def parse_glossar_entries(content,tag_name, parent_article_id=nil)
- Read upRead up
- Exclude checks
A Utility Function is any instance method that has no dependency on the state of the instance.
Goldencobra::ArticlesHelper#render_article_widgets performs a nil-check Open
if !defined?(current_user).nil? || !defined?(current_visitor).nil?
- Read upRead up
- Exclude checks
A NilCheck
is a type check. Failures of NilCheck
violate the "tell, don't ask" principle.
Additionally, type checks often mask bigger problems in your source code like not using OOP and / or polymorphism when you should.
Example
Given
class Klass
def nil_checker(argument)
if argument.nil?
puts "argument isn't nil!"
end
end
end
Reek would emit the following warning:
test.rb -- 1 warning:
[3]:Klass#nil_checker performs a nil-check. (NilCheck)
Goldencobra::ArticlesHelper#render_article_type_content has unused parameter 'options' Open
def render_article_type_content(options={})
- Read upRead up
- Exclude checks
Unused Parameter
refers to methods with parameters that are unused in scope of the method.
Having unused parameters in a method is code smell because leaving dead code in a method can never improve the method and it makes the code confusing to read.
Example
Given:
class Klass
def unused_parameters(x,y,z)
puts x,y # but not z
end
end
Reek would emit the following warning:
[2]:Klass#unused_parameters has unused parameter 'z' (UnusedParameters)
Align the elements of a hash literal if they span more than one line. Open
"id" => widget.id_name.present? ? widget.id_name : "widget_id_#{widget.id}",
- Read upRead up
- Exclude checks
Check that the keys, separators, and values of a multi-line hash literal are aligned according to configuration. The configuration options are:
- key (left align keys)
- separator (align hash rockets and colons, right align keys)
- table (left align keys, hash rockets, and values)
The treatment of hashes passed as the last argument to a method call can also be configured. The options are:
- always_inspect
- always_ignore
- ignore_implicit (without curly braces)
- ignore_explicit (with curly braces)
Example: EnforcedHashRocketStyle: key (default)
# bad
{
:foo => bar,
:ba => baz
}
# good
{
:foo => bar,
:ba => baz
}
Example: EnforcedHashRocketStyle: separator
# bad
{
:foo => bar,
:ba => baz
}
{
:foo => bar,
:ba => baz
}
# good
{
:foo => bar,
:ba => baz
}
Example: EnforcedHashRocketStyle: table
# bad
{
:foo => bar,
:ba => baz
}
# good
{
:foo => bar,
:ba => baz
}
Example: EnforcedColonStyle: key (default)
# bad
{
foo: bar,
ba: baz
}
# good
{
foo: bar,
ba: baz
}
Example: EnforcedColonStyle: separator
# bad
{
foo: bar,
ba: baz
}
# good
{
foo: bar,
ba: baz
}
Example: EnforcedColonStyle: table
# bad
{
foo: bar,
ba: baz
}
# good
{
foo: bar,
ba: baz
}
Example: EnforcedLastArgumentHashStyle: always_inspect (default)
# Inspect both implicit and explicit hashes.
# bad
do_something(foo: 1,
bar: 2)
# bad
do_something({foo: 1,
bar: 2})
# good
do_something(foo: 1,
bar: 2)
# good
do_something(
foo: 1,
bar: 2
)
# good
do_something({foo: 1,
bar: 2})
# good
do_something({
foo: 1,
bar: 2
})
Example: EnforcedLastArgumentHashStyle: always_ignore
# Ignore both implicit and explicit hashes.
# good
do_something(foo: 1,
bar: 2)
# good
do_something({foo: 1,
bar: 2})
Example: EnforcedLastArgumentHashStyle: ignore_implicit
# Ignore only implicit hashes.
# bad
do_something({foo: 1,
bar: 2})
# good
do_something(foo: 1,
bar: 2)
Example: EnforcedLastArgumentHashStyle: ignore_explicit
# Ignore only explicit hashes.
# bad
do_something(foo: 1,
bar: 2)
# good
do_something({foo: 1,
bar: 2})
Extra empty line detected at module body end. Open
end
- Read upRead up
- Exclude checks
This cops checks if empty lines around the bodies of modules match the configuration.
Example: EnforcedStyle: empty_lines
# good
module Foo
def bar
# ...
end
end
Example: EnforcedStyle: emptylinesexcept_namespace
# good
module Foo
module Bar
# ...
end
end
Example: EnforcedStyle: emptylinesspecial
# good
module Foo
def bar; end
end
Example: EnforcedStyle: noemptylines (default)
# good
module Foo
def bar
# ...
end
end
Use 2 (not 1) spaces for indentation. Open
render partial: "articletypes/#{@article.article_type_form_file.underscore.parameterize.downcase}/#{@article.kind_of_article_type.downcase}"
- 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
Missing space after #
. Open
#include default widgets?
- Read upRead up
- Exclude checks
This cop checks whether comments have a leading space after the
#
denoting the start of the comment. The leading space is not
required for some RDoc special syntax, like #++
, #--
,
#:nodoc
, =begin
- and =end
comments, "shebang" directives,
or rackup options.
Example:
# bad
#Some comment
# good
# Some comment
Extra empty line detected at module body beginning. Open
# 'Read on' link to article for index-pages
- Read upRead up
- Exclude checks
This cops checks if empty lines around the bodies of modules match the configuration.
Example: EnforcedStyle: empty_lines
# good
module Foo
def bar
# ...
end
end
Example: EnforcedStyle: emptylinesexcept_namespace
# good
module Foo
module Bar
# ...
end
end
Example: EnforcedStyle: emptylinesspecial
# good
module Foo
def bar; end
end
Example: EnforcedStyle: noemptylines (default)
# good
module Foo
def bar
# ...
end
end
Extra blank line detected. Open
# [render_article_image_gallery description]
- Read upRead up
- Exclude checks
This cops checks for two or more consecutive blank lines.
Example:
# bad - It has two empty lines.
some_method
# one empty line
# two empty lines
some_method
# good
some_method
# one empty line
some_method
Missing space after #
. Open
#Parse text for a single Word and make a link to an Article to this Word as a Subarticle of a given Article
- Read upRead up
- Exclude checks
This cop checks whether comments have a leading space after the
#
denoting the start of the comment. The leading space is not
required for some RDoc special syntax, like #++
, #--
,
#:nodoc
, =begin
- and =end
comments, "shebang" directives,
or rackup options.
Example:
# bad
#Some comment
# good
# Some comment
Align the elements of a hash literal if they span more than one line. Open
'data-id' => widget.id
- Read upRead up
- Exclude checks
Check that the keys, separators, and values of a multi-line hash literal are aligned according to configuration. The configuration options are:
- key (left align keys)
- separator (align hash rockets and colons, right align keys)
- table (left align keys, hash rockets, and values)
The treatment of hashes passed as the last argument to a method call can also be configured. The options are:
- always_inspect
- always_ignore
- ignore_implicit (without curly braces)
- ignore_explicit (with curly braces)
Example: EnforcedHashRocketStyle: key (default)
# bad
{
:foo => bar,
:ba => baz
}
# good
{
:foo => bar,
:ba => baz
}
Example: EnforcedHashRocketStyle: separator
# bad
{
:foo => bar,
:ba => baz
}
{
:foo => bar,
:ba => baz
}
# good
{
:foo => bar,
:ba => baz
}
Example: EnforcedHashRocketStyle: table
# bad
{
:foo => bar,
:ba => baz
}
# good
{
:foo => bar,
:ba => baz
}
Example: EnforcedColonStyle: key (default)
# bad
{
foo: bar,
ba: baz
}
# good
{
foo: bar,
ba: baz
}
Example: EnforcedColonStyle: separator
# bad
{
foo: bar,
ba: baz
}
# good
{
foo: bar,
ba: baz
}
Example: EnforcedColonStyle: table
# bad
{
foo: bar,
ba: baz
}
# good
{
foo: bar,
ba: baz
}
Example: EnforcedLastArgumentHashStyle: always_inspect (default)
# Inspect both implicit and explicit hashes.
# bad
do_something(foo: 1,
bar: 2)
# bad
do_something({foo: 1,
bar: 2})
# good
do_something(foo: 1,
bar: 2)
# good
do_something(
foo: 1,
bar: 2
)
# good
do_something({foo: 1,
bar: 2})
# good
do_something({
foo: 1,
bar: 2
})
Example: EnforcedLastArgumentHashStyle: always_ignore
# Ignore both implicit and explicit hashes.
# good
do_something(foo: 1,
bar: 2)
# good
do_something({foo: 1,
bar: 2})
Example: EnforcedLastArgumentHashStyle: ignore_implicit
# Ignore only implicit hashes.
# bad
do_something({foo: 1,
bar: 2})
# good
do_something(foo: 1,
bar: 2)
Example: EnforcedLastArgumentHashStyle: ignore_explicit
# Ignore only explicit hashes.
# bad
do_something(foo: 1,
bar: 2)
# good
do_something({foo: 1,
bar: 2})
Use 2 (not 0) spaces for rails indentation. Open
def render_article_list_item(article_item)
- 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
Use empty lines between method definitions. Open
def parse_glossar_entries(content,tag_name, parent_article_id=nil)
- Read upRead up
- Exclude checks
This cop checks whether method definitions are separated by one empty line.
NumberOfEmptyLines
can be an integer (default is 1) or
an array (e.g. [1, 2]) to specify a minimum and maximum
number of empty lines permitted.
AllowAdjacentOneLineDefs
configures whether adjacent
one-line method definitions are considered an offense.
Example:
# bad
def a
end
def b
end
Example:
# good
def a
end
def b
end
Missing space after #
. Open
#Ausgabe aller Hauptbestandteile eines Artikels über "content_for :xy"
- Read upRead up
- Exclude checks
This cop checks whether comments have a leading space after the
#
denoting the start of the comment. The leading space is not
required for some RDoc special syntax, like #++
, #--
,
#:nodoc
, =begin
- and =end
comments, "shebang" directives,
or rackup options.
Example:
# bad
#Some comment
# good
# Some comment
Use empty lines between method definitions. Open
def render_article_image_gallery(options = {})
- Read upRead up
- Exclude checks
This cop checks whether method definitions are separated by one empty line.
NumberOfEmptyLines
can be an integer (default is 1) or
an array (e.g. [1, 2]) to specify a minimum and maximum
number of empty lines permitted.
AllowAdjacentOneLineDefs
configures whether adjacent
one-line method definitions are considered an offense.
Example:
# bad
def a
end
def b
end
Example:
# good
def a
end
def b
end
Extra blank line detected. Open
#Parse text for a single Word and make a link to an Article to this Word as a Subarticle of a given Article
- Read upRead up
- Exclude checks
This cops checks for two or more consecutive blank lines.
Example:
# bad - It has two empty lines.
some_method
# one empty line
# two empty lines
some_method
# good
some_method
# one empty line
some_method
Surrounding space missing in default value assignment. Open
def render_article_widgets(options={})
- Read upRead up
- Exclude checks
Checks that the equals signs in parameter default assignments have or don't have surrounding space depending on configuration.
Example: EnforcedStyle: space (default)
# bad
def some_method(arg1=:default, arg2=nil, arg3=[])
# do something...
end
# good
def some_method(arg1 = :default, arg2 = nil, arg3 = [])
# do something...
end
Example: EnforcedStyle: no_space
# bad
def some_method(arg1 = :default, arg2 = nil, arg3 = [])
# do something...
end
# good
def some_method(arg1=:default, arg2=nil, arg3=[])
# do something...
end
Space inside { missing. Open
render partial: "/goldencobra/articles/show", locals: {article: article}
- Read upRead up
- Exclude checks
Checks that braces used for hash literals have or don't have surrounding space depending on configuration.
Example: EnforcedStyle: space (default)
# The `space` style enforces that hash literals have
# surrounding space.
# bad
h = {a: 1, b: 2}
# good
h = { a: 1, b: 2 }
Example: EnforcedStyle: no_space
# The `no_space` style enforces that hash literals have
# no surrounding space.
# bad
h = { a: 1, b: 2 }
# good
h = {a: 1, b: 2}
Example: EnforcedStyle: compact
# The `compact` style normally requires a space inside
# hash braces, with the exception that successive left
# braces or right braces are collapsed together in nested hashes.
# bad
h = { a: { b: 2 } }
# good
h = { a: { b: 2 }}
Example: EnforcedStyleForEmptyBraces: no_space (default)
# The `no_space` EnforcedStyleForEmptyBraces style enforces that
# empty hash braces do not contain spaces.
# bad
foo = { }
bar = { }
# good
foo = {}
bar = {}
Example: EnforcedStyleForEmptyBraces: space
# The `space` EnforcedStyleForEmptyBraces style enforces that
# empty hash braces contain space.
# bad
foo = {}
# good
foo = { }
foo = { }
foo = { }
Line is too long. [131/100] Open
link_to t(:read_on, scope: [:articles]), article.public_url, class: html_class, target: target_window, title: article.title
- Read upRead up
- Exclude checks
This cop checks the length of lines in the source code.
The maximum length is configurable.
The tab size is configured in the IndentationWidth
of the Layout/Tab
cop.
Line is too long. [113/100] Open
master_index_article.descendants.order(:created_at).limit(@article.article_for_index_limit).each do |art|
- Read upRead up
- Exclude checks
This cop checks the length of lines in the source code.
The maximum length is configurable.
The tab size is configured in the IndentationWidth
of the Layout/Tab
cop.
Surrounding space missing for operator =>
. Open
result += content_tag(:div, article_item.created_at.strftime("%d.%m.%Y %H:%M"), :class=>"created_at")
- Read upRead up
- Exclude checks
Checks that operators have space around them, except for ** which should not have surrounding space.
Example:
# bad
total = 3*4
"apple"+"juice"
my_number = 38/4
a ** b
# good
total = 3 * 4
"apple" + "juice"
my_number = 38 / 4
a**b
Use ==
if you meant to do a comparison or wrap the expression in parentheses to indicate you meant to assign in a condition. Open
if @article && @article.article_for_index_id.present? && master_index_article = Goldencobra::Article.find_by_id(@article.article_for_index_id)
- Read upRead up
- Exclude checks
This cop checks for assignments in the conditions of if/while/until.
Example:
# bad
if some_var = true
do_something
end
Example:
# good
if some_var == true
do_something
end
Convert if
nested inside else
to elsif
. Open
if !defined?(current_user).nil? || !defined?(current_visitor).nil?
- Read upRead up
- Exclude checks
If the else
branch of a conditional consists solely of an if
node,
it can be combined with the else
to become an elsif
.
This helps to keep the nesting level from getting too deep.
Example:
# bad
if condition_a
action_a
else
if condition_b
action_b
else
action_c
end
end
# good
if condition_a
action_a
elsif condition_b
action_b
else
action_c
end
Missing space after #
. Open
#Wenn format email, dann gibt es keinen realen webseit besucher
- Read upRead up
- Exclude checks
This cop checks whether comments have a leading space after the
#
denoting the start of the comment. The leading space is not
required for some RDoc special syntax, like #++
, #--
,
#:nodoc
, =begin
- and =end
comments, "shebang" directives,
or rackup options.
Example:
# bad
#Some comment
# good
# Some comment
Surrounding space missing in default value assignment. Open
def index_of_articles(options={})
- Read upRead up
- Exclude checks
Checks that the equals signs in parameter default assignments have or don't have surrounding space depending on configuration.
Example: EnforcedStyle: space (default)
# bad
def some_method(arg1=:default, arg2=nil, arg3=[])
# do something...
end
# good
def some_method(arg1 = :default, arg2 = nil, arg3 = [])
# do something...
end
Example: EnforcedStyle: no_space
# bad
def some_method(arg1 = :default, arg2 = nil, arg3 = [])
# do something...
end
# good
def some_method(arg1=:default, arg2=nil, arg3=[])
# do something...
end
Line is too long. [108/100] Open
"id" => widget.id_name.present? ? widget.id_name : "widget_id_#{widget.id}",
- Read upRead up
- Exclude checks
This cop checks the length of lines in the source code.
The maximum length is configurable.
The tab size is configured in the IndentationWidth
of the Layout/Tab
cop.
Do not use parentheses for method calls with no arguments. Open
ability = Ability.new()
- Read upRead up
- Exclude checks
This cop checks for unwanted parentheses in parameterless method calls.
Example:
# bad
object.some_method()
# good
object.some_method
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. Open
'data-id' => widget.id
- Read upRead up
- Exclude checks
Checks if uses of quotes match the configured preference.
Example: EnforcedStyle: single_quotes (default)
# bad
"No special symbols"
"No string interpolation"
"Just text"
# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"
Example: EnforcedStyle: double_quotes
# bad
'Just some text'
'No special chars or interpolation'
# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"
Closing hash brace must be on the same line as the last hash element when opening brace is on the same line as the first hash element. Open
}
- Read upRead up
- Exclude checks
This cop checks that the closing brace in a hash literal is either on the same line as the last hash element, or a new line.
When using the symmetrical
(default) style:
If a hash's opening brace is on the same line as the first element of the hash, then the closing brace should be on the same line as the last element of the hash.
If a hash's opening brace is on the line above the first element of the hash, then the closing brace should be on the line below the last element of the hash.
When using the new_line
style:
The closing brace of a multi-line hash literal must be on the line after the last element of the hash.
When using the same_line
style:
The closing brace of a multi-line hash literal must be on the same line as the last element of the hash.
Example: EnforcedStyle: symmetrical (default)
# bad
{ a: 1,
b: 2
}
# bad
{
a: 1,
b: 2 }
# good
{ a: 1,
b: 2 }
# good
{
a: 1,
b: 2
}
Example: EnforcedStyle: new_line
# bad
{
a: 1,
b: 2 }
# bad
{ a: 1,
b: 2 }
# good
{ a: 1,
b: 2
}
# good
{
a: 1,
b: 2
}
Example: EnforcedStyle: same_line
# bad
{ a: 1,
b: 2
}
# bad
{
a: 1,
b: 2
}
# good
{
a: 1,
b: 2 }
# good
{ a: 1,
b: 2 }
Missing space after #
. Open
#include article widgets?
- Read upRead up
- Exclude checks
This cop checks whether comments have a leading space after the
#
denoting the start of the comment. The leading space is not
required for some RDoc special syntax, like #++
, #--
,
#:nodoc
, =begin
- and =end
comments, "shebang" directives,
or rackup options.
Example:
# bad
#Some comment
# good
# Some comment
Surrounding space missing for operator =>
. Open
result += content_tag(:div, link_to(s("goldencobra.article.article_index.link_to_article"), article_item.public_url), :class=> "link_to_article")
- Read upRead up
- Exclude checks
Checks that operators have space around them, except for ** which should not have surrounding space.
Example:
# bad
total = 3*4
"apple"+"juice"
my_number = 38/4
a ** b
# good
total = 3 * 4
"apple" + "juice"
my_number = 38 / 4
a**b
Use the return of the conditional for variable assignment and comparison. Open
if options[:article].present?
include_articles = options[:article].to_s == "true"
else
include_articles = true
end
- Exclude checks
Line is too long. [149/100] Open
render partial: "articletypes/#{@article.article_type_form_file.underscore.parameterize.downcase}/#{@article.kind_of_article_type.downcase}"
- Read upRead up
- Exclude checks
This cop checks the length of lines in the source code.
The maximum length is configurable.
The tab size is configured in the IndentationWidth
of the Layout/Tab
cop.
Use the new Ruby 1.9 hash syntax. Open
result += content_tag(:div, link_to(article_item.title, article_item.public_url), :class=> "title")
- 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 the new Ruby 1.9 hash syntax. Open
result += content_tag(:div, link_to(s("goldencobra.article.article_index.link_to_article"), article_item.public_url), :class=> "link_to_article")
- 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}
Prefer to_s
over string interpolation. Open
result_list += content_tag(:h1, "#{master_index_article.title}", class: "headline")
- Read upRead up
- Exclude checks
This cop checks for strings that are just an interpolated expression.
Example:
# bad
"#{@var}"
# good
@var.to_s
# good if @var is already a String
@var
Use next
to skip iteration. Open
if ability.can?(:read, widget)
- Read upRead up
- Exclude checks
Use next
to skip iteration instead of a condition at the end.
Example: EnforcedStyle: skipmodifierifs (default)
# bad
[1, 2].each do |a|
if a == 1
puts a
end
end
# good
[1, 2].each do |a|
next unless a == 1
puts a
end
# good
[1, 2].each do |o|
puts o unless o == 1
end
Example: EnforcedStyle: always
# With `always` all conditions at the end of an iteration needs to be
# replaced by next - with `skip_modifier_ifs` the modifier if like
# this one are ignored: `[1, 2].each { |a| return 'yes' if a == 1 }`
# bad
[1, 2].each do |o|
puts o unless o == 1
end
# bad
[1, 2].each do |a|
if a == 1
puts a
end
end
# good
[1, 2].each do |a|
next unless a == 1
puts a
end
Line is too long. [154/100] Open
result_list += content_tag(dom_element, rendered_article_list_item, id: "article_index_list_item_#{art.id}", class: "article_index_list_item")
- Read upRead up
- Exclude checks
This cop checks the length of lines in the source code.
The maximum length is configurable.
The tab size is configured in the IndentationWidth
of the Layout/Tab
cop.
Line is too long. [105/100] Open
result += content_tag(:div, link_to(article_item.title, article_item.public_url), :class=> "title")
- Read upRead up
- Exclude checks
This cop checks the length of lines in the source code.
The maximum length is configurable.
The tab size is configured in the IndentationWidth
of the Layout/Tab
cop.
Use the return of the conditional for variable assignment and comparison. Open
if @article && include_articles
article_widgets = @article.widgets.active.tagged_with(tags.split(","))
else
article_widgets = []
end
- Exclude checks
Missing space after #
. Open
#render Widgets
- Read upRead up
- Exclude checks
This cop checks whether comments have a leading space after the
#
denoting the start of the comment. The leading space is not
required for some RDoc special syntax, like #++
, #--
,
#:nodoc
, =begin
- and =end
comments, "shebang" directives,
or rackup options.
Example:
# bad
#Some comment
# good
# Some comment
Missing space after #
. Open
#check if current user has permissions to see this widget
- Read upRead up
- Exclude checks
This cop checks whether comments have a leading space after the
#
denoting the start of the comment. The leading space is not
required for some RDoc special syntax, like #++
, #--
,
#:nodoc
, =begin
- and =end
comments, "shebang" directives,
or rackup options.
Example:
# bad
#Some comment
# good
# Some comment
Surrounding space missing in default value assignment. Open
def read_on(article, options={})
- Read upRead up
- Exclude checks
Checks that the equals signs in parameter default assignments have or don't have surrounding space depending on configuration.
Example: EnforcedStyle: space (default)
# bad
def some_method(arg1=:default, arg2=nil, arg3=[])
# do something...
end
# good
def some_method(arg1 = :default, arg2 = nil, arg3 = [])
# do something...
end
Example: EnforcedStyle: no_space
# bad
def some_method(arg1 = :default, arg2 = nil, arg3 = [])
# do something...
end
# good
def some_method(arg1=:default, arg2=nil, arg3=[])
# do something...
end
Space inside } missing. Open
render partial: "/goldencobra/articles/show", locals: {article: article}
- Read upRead up
- Exclude checks
Checks that braces used for hash literals have or don't have surrounding space depending on configuration.
Example: EnforcedStyle: space (default)
# The `space` style enforces that hash literals have
# surrounding space.
# bad
h = {a: 1, b: 2}
# good
h = { a: 1, b: 2 }
Example: EnforcedStyle: no_space
# The `no_space` style enforces that hash literals have
# no surrounding space.
# bad
h = { a: 1, b: 2 }
# good
h = {a: 1, b: 2}
Example: EnforcedStyle: compact
# The `compact` style normally requires a space inside
# hash braces, with the exception that successive left
# braces or right braces are collapsed together in nested hashes.
# bad
h = { a: { b: 2 } }
# good
h = { a: { b: 2 }}
Example: EnforcedStyleForEmptyBraces: no_space (default)
# The `no_space` EnforcedStyleForEmptyBraces style enforces that
# empty hash braces do not contain spaces.
# bad
foo = { }
bar = { }
# good
foo = {}
bar = {}
Example: EnforcedStyleForEmptyBraces: space
# The `space` EnforcedStyleForEmptyBraces style enforces that
# empty hash braces contain space.
# bad
foo = {}
# good
foo = { }
foo = { }
foo = { }
Line is too long. [116/100] Open
link_to article.redirect_link_title, article.external_url_redirect, class: html_class, target: target_window
- Read upRead up
- Exclude checks
This cop checks the length of lines in the source code.
The maximum length is configurable.
The tab size is configured in the IndentationWidth
of the Layout/Tab
cop.
Line is too long. [148/100] Open
if @article && @article.article_for_index_id.present? && master_index_article = Goldencobra::Article.find_by_id(@article.article_for_index_id)
- Read upRead up
- Exclude checks
This cop checks the length of lines in the source code.
The maximum length is configurable.
The tab size is configured in the IndentationWidth
of the Layout/Tab
cop.
Line is too long. [111/100] Open
result += content_tag(:div, image_tag(article_item.images.first.image(:thumb)), class: "article_image")
- Read upRead up
- Exclude checks
This cop checks the length of lines in the source code.
The maximum length is configurable.
The tab size is configured in the IndentationWidth
of the Layout/Tab
cop.
Missing top-level module documentation comment. Open
module ArticlesHelper
- 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
Use a guard clause instead of wrapping the code inside a conditional expression. Open
if glossar_article.present?
- Read upRead up
- Exclude checks
Use a guard clause instead of wrapping the code inside a conditional expression
Example:
# bad
def test
if something
work
end
end
# good
def test
return unless something
work
end
# also good
def test
work if something
end
# bad
if something
raise 'exception'
else
ok
end
# good
raise 'exception' if something
ok
Prefer to_s
over string interpolation. Open
content = content.gsub(/\b(?<!\/)#{tag_name}(?!<)\b/, "#{replace_with}")
- Read upRead up
- Exclude checks
This cop checks for strings that are just an interpolated expression.
Example:
# bad
"#{@var}"
# good
@var.to_s
# good if @var is already a String
@var
Surrounding space missing in default value assignment. Open
def parse_glossar_entries(content,tag_name, parent_article_id=nil)
- Read upRead up
- Exclude checks
Checks that the equals signs in parameter default assignments have or don't have surrounding space depending on configuration.
Example: EnforcedStyle: space (default)
# bad
def some_method(arg1=:default, arg2=nil, arg3=[])
# do something...
end
# good
def some_method(arg1 = :default, arg2 = nil, arg3 = [])
# do something...
end
Example: EnforcedStyle: no_space
# bad
def some_method(arg1 = :default, arg2 = nil, arg3 = [])
# do something...
end
# good
def some_method(arg1=:default, arg2=nil, arg3=[])
# do something...
end
Useless assignment to variable - content
. Open
content = content.gsub(/\b(?<!\/)#{tag_name}(?!<)\b/, "#{replace_with}")
- Read upRead up
- Exclude checks
This cop checks for every useless assignment to local variable in every
scope.
The basic idea for this cop was from the warning of ruby -cw
:
assigned but unused variable - foo
Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.
Example:
# bad
def some_method
some_var = 1
do_something
end
Example:
# good
def some_method
some_var = 1
do_something(some_var)
end
Line is too long. [126/100] Open
result << content_tag(widget_wrapper, raw(template.render(Goldencobra::Article::LiquidParser)), html_data_options)
- Read upRead up
- Exclude checks
This cop checks the length of lines in the source code.
The maximum length is configurable.
The tab size is configured in the IndentationWidth
of the Layout/Tab
cop.
Line is too long. [107/100] Open
result += content_tag(:div, article_item.created_at.strftime("%d.%m.%Y %H:%M"), :class=>"created_at")
- Read upRead up
- Exclude checks
This cop checks the length of lines in the source code.
The maximum length is configurable.
The tab size is configured in the IndentationWidth
of the Layout/Tab
cop.
Line is too long. [151/100] Open
result += content_tag(:div, link_to(s("goldencobra.article.article_index.link_to_article"), article_item.public_url), :class=> "link_to_article")
- Read upRead up
- Exclude checks
This cop checks the length of lines in the source code.
The maximum length is configurable.
The tab size is configured in the IndentationWidth
of the Layout/Tab
cop.
Use compact module/class definition instead of nested style. Open
module Goldencobra
- Read upRead up
- Exclude checks
This cop checks the style of children definitions at classes and modules. Basically there are two different styles:
Example: EnforcedStyle: nested (default)
# good
# have each child on its own line
class Foo
class Bar
end
end
Example: EnforcedStyle: compact
# good
# combine definitions as much as possible
class Foo::Bar
end
The compact style is only forced for classes/modules with one child.
Use a guard clause instead of wrapping the code inside a conditional expression. Open
if @article
- Read upRead up
- Exclude checks
Use a guard clause instead of wrapping the code inside a conditional expression
Example:
# bad
def test
if something
work
end
end
# good
def test
return unless something
work
end
# also good
def test
work if something
end
# bad
if something
raise 'exception'
else
ok
end
# good
raise 'exception' if something
ok
Use @article.article_for_index_levels.to_i.zero?
instead of @article.article_for_index_levels.to_i == 0
. Open
if @article.article_for_index_levels.to_i == 0 || (@article.depth + @article.article_for_index_levels.to_i > art.depth)
- 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 Integer
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 %r
around regular expression. Open
content = content.gsub(/\b(?<!\/)#{tag_name}(?!<)\b/, "#{replace_with}")
- Read upRead up
- Exclude checks
This cop enforces using // or %r around regular expressions.
Example: EnforcedStyle: slashes (default)
# bad
snake_case = %r{^[\dA-Z_]+$}
# bad
regex = %r{
foo
(bar)
(baz)
}x
# good
snake_case = /^[\dA-Z_]+$/
# good
regex = /
foo
(bar)
(baz)
/x
Example: EnforcedStyle: percent_r
# bad
snake_case = /^[\dA-Z_]+$/
# bad
regex = /
foo
(bar)
(baz)
/x
# good
snake_case = %r{^[\dA-Z_]+$}
# good
regex = %r{
foo
(bar)
(baz)
}x
Example: EnforcedStyle: mixed
# bad
snake_case = %r{^[\dA-Z_]+$}
# bad
regex = /
foo
(bar)
(baz)
/x
# good
snake_case = /^[\dA-Z_]+$/
# good
regex = %r{
foo
(bar)
(baz)
}x
Example: AllowInnerSlashes: false (default)
# If `false`, the cop will always recommend using `%r` if one or more
# slashes are found in the regexp string.
# bad
x =~ /home\//
# good
x =~ %r{home/}
Example: AllowInnerSlashes: true
# good
x =~ /home\//
Surrounding space missing for operator =>
. Open
result += content_tag(:div, link_to(article_item.title, article_item.public_url), :class=> "title")
- Read upRead up
- Exclude checks
Checks that operators have space around them, except for ** which should not have surrounding space.
Example:
# bad
total = 3*4
"apple"+"juice"
my_number = 38/4
a ** b
# good
total = 3 * 4
"apple" + "juice"
my_number = 38 / 4
a**b
Unused method argument - options
. If it's necessary, use _
or _options
as an argument name to indicate that it won't be used. You can also write as render_article_type_content(*)
if you want the method to accept any arguments but don't care about them. Open
def render_article_type_content(options={})
- Read upRead up
- Exclude checks
This cop checks for unused method arguments.
Example:
# bad
def some_method(used, unused, _unused_but_allowed)
puts used
end
Example:
# good
def some_method(used, _unused, _unused_but_allowed)
puts used
end
Line is too long. [146/100] Open
glossar_article = Goldencobra::Article.create(title: tag_name, breadcrumb: tag_name, article_type: "Default Show", parent: glossar_parent)
- Read upRead up
- Exclude checks
This cop checks the length of lines in the source code.
The maximum length is configurable.
The tab size is configured in the IndentationWidth
of the Layout/Tab
cop.
Do not use parentheses for method calls with no arguments. Open
ability = Ability.new()
- Read upRead up
- Exclude checks
This cop checks for unwanted parentheses in parameterless method calls.
Example:
# bad
object.some_method()
# good
object.some_method
Redundant return
detected. Open
return raw(result)
- Read upRead up
- Exclude checks
This cop checks for redundant return
expressions.
Example:
# These bad cases should be extended to handle methods whose body is
# if/else or a case expression with a default branch.
# bad
def test
return something
end
# bad
def test
one
two
three
return something
end
# good
def test
return something if something_else
end
# good
def test
if x
elsif y
else
end
end
Surrounding space missing in default value assignment. Open
def render_article_type_content(options={})
- Read upRead up
- Exclude checks
Checks that the equals signs in parameter default assignments have or don't have surrounding space depending on configuration.
Example: EnforcedStyle: space (default)
# bad
def some_method(arg1=:default, arg2=nil, arg3=[])
# do something...
end
# good
def some_method(arg1 = :default, arg2 = nil, arg3 = [])
# do something...
end
Example: EnforcedStyle: no_space
# bad
def some_method(arg1 = :default, arg2 = nil, arg3 = [])
# do something...
end
# good
def some_method(arg1=:default, arg2=nil, arg3=[])
# do something...
end
Line is too long. [154/100] Open
if params[:frontend_tags] && params[:frontend_tags].class != String && params[:frontend_tags][:format] && params[:frontend_tags][:format] == "email"
- Read upRead up
- Exclude checks
This cop checks the length of lines in the source code.
The maximum length is configurable.
The tab size is configured in the IndentationWidth
of the Layout/Tab
cop.
Use %i
or %I
for an array of symbols. Open
link_to t(:read_on, scope: [:articles]), article.public_url, class: html_class, target: target_window, title: article.title
- 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]
Missing space after #
. Open
#Get default widgets
- Read upRead up
- Exclude checks
This cop checks whether comments have a leading space after the
#
denoting the start of the comment. The leading space is not
required for some RDoc special syntax, like #++
, #--
,
#:nodoc
, =begin
- and =end
comments, "shebang" directives,
or rackup options.
Example:
# bad
#Some comment
# good
# Some comment
Missing space after #
. Open
#Sort widgets bei global sorter id
- Read upRead up
- Exclude checks
This cop checks whether comments have a leading space after the
#
denoting the start of the comment. The leading space is not
required for some RDoc special syntax, like #++
, #--
,
#:nodoc
, =begin
- and =end
comments, "shebang" directives,
or rackup options.
Example:
# bad
#Some comment
# good
# Some comment
Unnecessary utf-8 encoding comment. Open
# encoding: utf-8
- Read upRead up
- Exclude checks
This cop checks ensures source files have no utf-8 encoding comments.
Example:
# bad
# encoding: UTF-8
# coding: UTF-8
# -*- coding: UTF-8 -*-
Use a guard clause instead of wrapping the code inside a conditional expression. Open
if @article && @article.article_for_index_id.present? && master_index_article = Goldencobra::Article.find_by_id(@article.article_for_index_id)
- Read upRead up
- Exclude checks
Use a guard clause instead of wrapping the code inside a conditional expression
Example:
# bad
def test
if something
work
end
end
# good
def test
return unless something
work
end
# also good
def test
work if something
end
# bad
if something
raise 'exception'
else
ok
end
# good
raise 'exception' if something
ok
Redundant return
detected. Open
return raw(result)
- Read upRead up
- Exclude checks
This cop checks for redundant return
expressions.
Example:
# These bad cases should be extended to handle methods whose body is
# if/else or a case expression with a default branch.
# bad
def test
return something
end
# bad
def test
one
two
three
return something
end
# good
def test
return something if something_else
end
# good
def test
if x
elsif y
else
end
end
Use the new Ruby 1.9 hash syntax. Open
result += content_tag(:div, article_item.created_at.strftime("%d.%m.%Y %H:%M"), :class=>"created_at")
- 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 the double pipe equals operator ||=
instead. Open
unless glossar_article
glossar_article = Goldencobra::Article.create(title: tag_name, breadcrumb: tag_name, article_type: "Default Show", parent: glossar_parent)
end
- Read upRead up
- Exclude checks
This cop checks for potential usage of the ||=
operator.
Example:
# bad
name = name ? name : 'Bozhidar'
# bad
name = if name
name
else
'Bozhidar'
end
# bad
unless name
name = 'Bozhidar'
end
# bad
name = 'Bozhidar' unless name
# good - set name to 'Bozhidar', only if it's nil or false
name ||= 'Bozhidar'
Space missing after comma. Open
def parse_glossar_entries(content,tag_name, parent_article_id=nil)
- 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 { missing. Open
html_data_options = {"class" => "#{widget.css_name} #{custom_css} goldencobra_widget",
- Read upRead up
- Exclude checks
Checks that braces used for hash literals have or don't have surrounding space depending on configuration.
Example: EnforcedStyle: space (default)
# The `space` style enforces that hash literals have
# surrounding space.
# bad
h = {a: 1, b: 2}
# good
h = { a: 1, b: 2 }
Example: EnforcedStyle: no_space
# The `no_space` style enforces that hash literals have
# no surrounding space.
# bad
h = { a: 1, b: 2 }
# good
h = {a: 1, b: 2}
Example: EnforcedStyle: compact
# The `compact` style normally requires a space inside
# hash braces, with the exception that successive left
# braces or right braces are collapsed together in nested hashes.
# bad
h = { a: { b: 2 } }
# good
h = { a: { b: 2 }}
Example: EnforcedStyleForEmptyBraces: no_space (default)
# The `no_space` EnforcedStyleForEmptyBraces style enforces that
# empty hash braces do not contain spaces.
# bad
foo = { }
bar = { }
# good
foo = {}
bar = {}
Example: EnforcedStyleForEmptyBraces: space
# The `space` EnforcedStyleForEmptyBraces style enforces that
# empty hash braces contain space.
# bad
foo = {}
# good
foo = { }
foo = { }
foo = { }
Line is too long. [111/100] Open
#Parse text for a single Word and make a link to an Article to this Word as a Subarticle of a given Article
- Read upRead up
- Exclude checks
This cop checks the length of lines in the source code.
The maximum length is configurable.
The tab size is configured in the IndentationWidth
of the Layout/Tab
cop.
Line is too long. [110/100] Open
link_to upload.image.url(options[:target_image_size] || :large), title: raw(upload.description) do
- Read upRead up
- Exclude checks
This cop checks the length of lines in the source code.
The maximum length is configurable.
The tab size is configured in the IndentationWidth
of the Layout/Tab
cop.
Line is too long. [129/100] Open
if @article.article_for_index_levels.to_i == 0 || (@article.depth + @article.article_for_index_levels.to_i > art.depth)
- Read upRead up
- Exclude checks
This cop checks the length of lines in the source code.
The maximum length is configurable.
The tab size is configured in the IndentationWidth
of the Layout/Tab
cop.