wearefine/fae

View on GitHub
app/helpers/fae/application_helper.rb

Summary

Maintainability
B
4 hrs
Test Coverage

Module has too many lines. [119/100]
Open

  module ApplicationHelper

    def form_header(name)
      name = name.class.name.split('::').last unless name.is_a? String
      form_title = "#{params[:action]} #{name}".titleize

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 change_item_link is too high. [35.83/15]
Open

    def change_item_link(change)
      text = "#{change.changeable_type.gsub('Fae::','')}: "
      test_source_method = :data_source_exists?

      if change.changeable_type.exclude?('Fae') && change.changeable_type.exclude?('Page') && !ActiveRecord::Base.connection.send(test_source_method, change.changeable_type.tableize)

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 change_item_link(change)
      text = "#{change.changeable_type.gsub('Fae::','')}: "
      test_source_method = :data_source_exists?

      if change.changeable_type.exclude?('Fae') && change.changeable_type.exclude?('Page') && !ActiveRecord::Base.connection.send(test_source_method, change.changeable_type.tableize)

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 page_title_piece is too high. [20.83/15]
Open

    def page_title_piece
      return @page_title_piece if @page_title_piece.present?

      action = params[:action].humanize.titleize unless params[:action] == 'index'
      controller = controller_title unless params[:controller] == 'fae/pages'

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 col_name_or_image is too high. [19.34/15]
Open

    def col_name_or_image(item, attribute)
      value = item.send(attribute)
      return if value.blank?
      # if item is an image
      if value.class.name == 'Fae::Image'

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Method has too many lines. [13/10]
Open

    def col_name_or_image(item, attribute)
      value = item.send(attribute)
      return if value.blank?
      # if item is an image
      if value.class.name == 'Fae::Image'

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 change_item_link is too high. [10/7]
Open

    def change_item_link(change)
      text = "#{change.changeable_type.gsub('Fae::','')}: "
      test_source_method = :data_source_exists?

      if change.changeable_type.exclude?('Fae') && change.changeable_type.exclude?('Page') && !ActiveRecord::Base.connection.send(test_source_method, change.changeable_type.tableize)

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 change_item_link is too high. [9/6]
Open

    def change_item_link(change)
      text = "#{change.changeable_type.gsub('Fae::','')}: "
      test_source_method = :data_source_exists?

      if change.changeable_type.exclude?('Fae') && change.changeable_type.exclude?('Page') && !ActiveRecord::Base.connection.send(test_source_method, change.changeable_type.tableize)

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 netlify_enabled? is too high. [17.72/15]
Open

    def netlify_enabled?
      Fae.netlify.present? &&
      Fae.netlify[:api_user].present? &&
      Fae.netlify[:api_token].present? &&
      Fae.netlify[:site].present? &&

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 col_name_or_image is too high. [9/7]
Open

    def col_name_or_image(item, attribute)
      value = item.send(attribute)
      return if value.blank?
      # if item is an image
      if value.class.name == 'Fae::Image'

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 col_name_or_image is too high. [8/6]
Open

    def col_name_or_image(item, attribute)
      value = item.send(attribute)
      return if value.blank?
      # if item is an image
      if value.class.name == 'Fae::Image'

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 change_item_link has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

    def change_item_link(change)
      text = "#{change.changeable_type.gsub('Fae::','')}: "
      test_source_method = :data_source_exists?

      if change.changeable_type.exclude?('Fae') && change.changeable_type.exclude?('Page') && !ActiveRecord::Base.connection.send(test_source_method, change.changeable_type.tableize)
Severity: Minor
Found in app/helpers/fae/application_helper.rb - About 1 hr to fix

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 col_name_or_image has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    def col_name_or_image(item, attribute)
      value = item.send(attribute)
      return if value.blank?
      # if item is an image
      if value.class.name == 'Fae::Image'
Severity: Minor
Found in app/helpers/fae/application_helper.rb - About 55 mins to fix

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 nav_active_class has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def nav_active_class(klass, level, idx, parent_idx = nil)
      return klass unless @fae_navigation.coordinates[level] == idx
      return klass unless parent_idx.blank? || @fae_navigation.coordinates[level-1] == parent_idx
      new_klass = parent_idx.blank? ? '-parent-current -open' : '-current'
      new_klass += " #{klass}" if klass.present?
Severity: Minor
Found in app/helpers/fae/application_helper.rb - About 45 mins to fix

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 page_title_piece has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def page_title_piece
      return @page_title_piece if @page_title_piece.present?

      action = params[:action].humanize.titleize unless params[:action] == 'index'
      controller = controller_title unless params[:controller] == 'fae/pages'
Severity: Minor
Found in app/helpers/fae/application_helper.rb - About 35 mins to fix

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 tr instead of gsub.
Open

      "#{item.class.name.underscore.gsub('/', '_').pluralize}_#{item.id}"

This cop identifies places where gsub can be replaced by tr or delete.

Example:

# bad
'abc'.gsub('b', 'd')
'abc'.gsub('a', '')
'abc'.gsub(/a/, 'd')
'abc'.gsub!('a', 'd')

# good
'abc'.gsub(/.*/, 'a')
'abc'.gsub(/a+/, 'd')
'abc'.tr('b', 'd')
'a b c'.delete(' ')

Use casecmp instead of downcase ==.
Open

      if image.asset.file.extension.downcase == 'svg'

This cop identifies places where a case-insensitive string comparison can better be implemented using casecmp.

Example:

# bad
str.downcase == 'abc'
str.upcase.eql? 'ABC'
'abc' == str.downcase
'ABC'.eql? str.upcase
str.downcase == str.downcase

# good
str.casecmp('ABC').zero?
'abc'.casecmp(str).zero?

Use delete instead of gsub.
Open

      fae.root_path.gsub('/', '')

This cop identifies places where gsub can be replaced by tr or delete.

Example:

# bad
'abc'.gsub('b', 'd')
'abc'.gsub('a', '')
'abc'.gsub(/a/, 'd')
'abc'.gsub!('a', 'd')

# good
'abc'.gsub(/.*/, 'a')
'abc'.gsub(/a+/, 'd')
'abc'.tr('b', 'd')
'a b c'.delete(' ')

Line is too long. [129/80]
Open

          return link_to text, fae.edit_content_block_path(change.changeable.slug) if change.changeable_type == 'Fae::StaticPage'

Surrounding space missing for operator -.
Open

      return klass unless parent_idx.blank? || @fae_navigation.coordinates[level-1] == parent_idx

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 %r around regular expression.
Open

      params[:controller].gsub(/fae\/|#{fae_scope}\//, '').humanize.titleize

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\//

Missing top-level module documentation comment.
Open

  module ApplicationHelper

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

Line is too long. [98/80]
Open

          parent = change.changeable.respond_to?(:fae_parent) ? change.changeable.fae_parent : nil

Use 2 (not 0) spaces for indenting an expression spanning multiple lines.
Open

      Fae.netlify[:api_token].present? &&

This cop checks the indentation of the right hand side operand in binary operations that span more than one line.

Example:

# bad
if a +
b
  something
end

# good
if a +
   b
  something
end

Avoid rescuing without specifying an error class.
Open

        rescue

This cop checks for rescuing StandardError. There are two supported styles implicit and explicit. This cop will not register an offense if any error other than StandardError is specified.

Example: EnforcedStyle: implicit

# `implicit` will enforce using `rescue` instead of
# `rescue StandardError`.

# bad
begin
  foo
rescue StandardError
  bar
end

# good
begin
  foo
rescue
  bar
end

# good
begin
  foo
rescue OtherError
  bar
end

# good
begin
  foo
rescue StandardError, SecurityError
  bar
end

Example: EnforcedStyle: explicit (default)

# `explicit` will enforce using `rescue StandardError`
# instead of `rescue`.

# bad
begin
  foo
rescue
  bar
end

# good
begin
  foo
rescue StandardError
  bar
end

# good
begin
  foo
rescue OtherError
  bar
end

# good
begin
  foo
rescue StandardError, SecurityError
  bar
end

Line is too long. [82/80]
Open

      action = params[:action].humanize.titleize unless params[:action] == 'index'

Line is too long. [86/80]
Open

        display_text = (display_text.is_a? Integer) ? display_text.to_s : display_text

Extra empty line detected at module body beginning.
Open


    def form_header(name)

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

Line is too long. [119/80]
Open

        image_tag(nested_table_thumb_url(value), class: 'addedit-form-thumb') if nested_table_thumb_url(value).present?

Use 2 (not 0) spaces for indenting an expression spanning multiple lines.
Open

      Fae.netlify[:api_base].present?

This cop checks the indentation of the right hand side operand in binary operations that span more than one line.

Example:

# bad
if a +
b
  something
end

# good
if a +
   b
  something
end

Line is too long. [97/80]
Open

      return klass unless parent_idx.blank? || @fae_navigation.coordinates[level-1] == parent_idx

Line is too long. [81/80]
Open

      current_page?(path) || path[1..-1].classify == params[:controller].classify

Space missing after comma.
Open

      text = "#{change.changeable_type.gsub('Fae::','')}: "

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. [98/80]
Open

      controller = controller.singularize if params[:action] == 'new' || params[:action] == 'edit'

Use a guard clause instead of wrapping the code inside a conditional expression.
Open

      if change.changeable_type.exclude?('Fae') && change.changeable_type.exclude?('Page') && !ActiveRecord::Base.connection.send(test_source_method, change.changeable_type.tableize)

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 2 (not 0) spaces for indenting an expression spanning multiple lines.
Open

      Fae.netlify[:site].present? &&

This cop checks the indentation of the right hand side operand in binary operations that span more than one line.

Example:

# bad
if a +
b
  something
end

# good
if a +
   b
  something
end

Use 2 (not 0) spaces for indenting an expression spanning multiple lines.
Open

      Fae.netlify[:api_user].present? &&

This cop checks the indentation of the right hand side operand in binary operations that span more than one line.

Example:

# bad
if a +
b
  something
end

# good
if a +
   b
  something
end

Omit parentheses for ternary conditions.
Open

        display_text = (display_text.is_a? Integer) ? display_text.to_s : display_text

This cop checks for the presence of parentheses around ternary conditions. It is configurable to enforce inclusion or omission of parentheses using EnforcedStyle. Omission is only enforced when removing the parentheses won't cause a different behavior.

Example: EnforcedStyle: requirenoparentheses (default)

# bad
foo = (bar?) ? a : b
foo = (bar.baz?) ? a : b
foo = (bar && baz) ? a : b

# good
foo = bar? ? a : b
foo = bar.baz? ? a : b
foo = bar && baz ? a : b

Example: EnforcedStyle: require_parentheses

# bad
foo = bar? ? a : b
foo = bar.baz? ? a : b
foo = bar && baz ? a : b

# good
foo = (bar?) ? a : b
foo = (bar.baz?) ? a : b
foo = (bar && baz) ? a : b

Example: EnforcedStyle: requireparentheseswhen_complex

# bad
foo = (bar?) ? a : b
foo = (bar.baz?) ? a : b
foo = bar && baz ? a : b

# good
foo = bar? ? a : b
foo = bar.baz? ? a : b
foo = (bar && baz) ? a : b

Line is too long. [131/80]
Open

        raise "#{loc} is a required local, please define it when you render this partial" unless local_assigns[loc.to_sym].present?

Line is too long. [182/80]
Open

      if change.changeable_type.exclude?('Fae') && change.changeable_type.exclude?('Page') && !ActiveRecord::Base.connection.send(test_source_method, change.changeable_type.tableize)

Use 2 (not 0) spaces for indenting an expression spanning multiple lines.
Open

      Fae.netlify[:site_id].present? &&

This cop checks the indentation of the right hand side operand in binary operations that span more than one line.

Example:

# bad
if a +
b
  something
end

# good
if a +
   b
  something
end

There are no issues that match your filters.

Category
Status