kirushik/critical_chain

View on GitHub
app/decorators/estimation_decorator.rb

Summary

Maintainability
A
0 mins
Test Coverage

EstimationDecorator has no descriptive comment
Open

class EstimationDecorator < Draper::Decorator
Severity: Minor
Found in app/decorators/estimation_decorator.rb by reek

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

Missing frozen string literal comment.
Open

class EstimationDecorator < Draper::Decorator

Helps you transition from mutable string literals to frozen string literals. It will add the # frozen_string_literal: true magic comment to the top of files to enable frozen string literals. Frozen string literals may be default in future Ruby. The comment will be added below a shebang and encoding comment. The frozen string literal comment is only valid in Ruby 2.3+.

Note that the cop will accept files where the comment exists but is set to false instead of true.

To require a blank line after this comment, please see Layout/EmptyLineAfterMagicComment cop.

Safety:

This cop's autocorrection is unsafe since any strings mutations will change from being accepted to raising FrozenError, as all strings will become frozen by default, and will need to be manually refactored.

Example: EnforcedStyle: always (default)

# The `always` style will always add the frozen string literal comment
# to a file, regardless of the Ruby version or if `freeze` or `<<` are
# called on a string literal.
# bad
module Bar
  # ...
end

# good
# frozen_string_literal: true

module Bar
  # ...
end

# good
# frozen_string_literal: false

module Bar
  # ...
end

Example: EnforcedStyle: never

# The `never` will enforce that the frozen string literal comment does
# not exist in a file.
# bad
# frozen_string_literal: true

module Baz
  # ...
end

# good
module Baz
  # ...
end

Example: EnforcedStyle: always_true

# The `always_true` style enforces that the frozen string literal
# comment is set to `true`. This is a stricter option than `always`
# and forces projects to use frozen string literals.
# bad
# frozen_string_literal: false

module Baz
  # ...
end

# bad
module Baz
  # ...
end

# good
# frozen_string_literal: true

module Bar
  # ...
end

Avoid using rescue in its modifier form.
Wontfix

    object.total.to_fs(:rounded, significant: true).gsub(/\.0+$/, '') rescue "0"

Checks for uses of rescue in its modifier form is added for following reasons:

  • The syntax of modifier form rescue can be misleading because it might lead us to believe that rescue handles the given exception but it actually rescue all exceptions to return the given rescue block. In this case, value returned by handle_error or SomeException.

  • Modifier form rescue would rescue all the exceptions. It would silently skip all exception or errors and handle the error. Example: If NoMethodError is raised, modifier form rescue would handle the exception.

Example:

# bad
some_method rescue handle_error

# bad
some_method rescue SomeException

# good
begin
  some_method
rescue
  handle_error
end

# good
begin
  some_method
rescue SomeException
  handle_error
end

Surrounding space missing for operator *.
Open

    number_to_percentage(object.buffer_health*100, precision: 0)

Checks that operators have space around them, except for ** which should or shouldn't have surrounding space depending on configuration. It allows vertical alignment consisting of one or more whitespace around operators.

This cop has AllowForAlignment option. When true, allows most uses of extra spacing if the intent is to align with an operator on the previous or next line, not counting empty lines or comment lines.

Example:

# bad
total = 3*4
"apple"+"juice"
my_number = 38/4

# good
total = 3 * 4
"apple" + "juice"
my_number = 38 / 4

Example: AllowForAlignment: true (default)

# good
{
  1 =>  2,
  11 => 3
}

Example: AllowForAlignment: false

# bad
{
  1 =>  2,
  11 => 3
}

Example: EnforcedStyleForExponentOperator: no_space (default)

# bad
a ** b

# good
a**b

Example: EnforcedStyleForExponentOperator: space

# bad
a**b

# good
a ** b

Example: EnforcedStyleForRationalLiterals: no_space (default)

# bad
1 / 48r

# good
1/48r

Example: EnforcedStyleForRationalLiterals: space

# bad
1/48r

# good
1 / 48r

Missing top-level documentation comment for class EstimationDecorator.
Open

class EstimationDecorator < Draper::Decorator

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, constant definitions or constant visibility declarations.

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

module Math
end

# good
# Description/Explanation of Person class
class Person
  # ...
end

# allowed
  # Class without body
  class Person
  end

  # Namespace - A namespace can be a class or a module
  # Containing a class
  module Namespace
    # Description/Explanation of Person class
    class Person
      # ...
    end
  end

  # Containing constant visibility declaration
  module Namespace
    class Private
    end

    private_constant :Private
  end

  # Containing constant definition
  module Namespace
    Public = Class.new
  end

  # Macro calls
  module Namespace
    extend Foo
  end

Example: AllowedConstants: ['ClassMethods']

# good
 module A
   module ClassMethods
     # ...
   end
  end

Avoid using rescue in its modifier form.
Wontfix

    object.sum.to_fs(:rounded, significant: true).gsub(/\.0+$/, '') rescue "0"

Checks for uses of rescue in its modifier form is added for following reasons:

  • The syntax of modifier form rescue can be misleading because it might lead us to believe that rescue handles the given exception but it actually rescue all exceptions to return the given rescue block. In this case, value returned by handle_error or SomeException.

  • Modifier form rescue would rescue all the exceptions. It would silently skip all exception or errors and handle the error. Example: If NoMethodError is raised, modifier form rescue would handle the exception.

Example:

# bad
some_method rescue handle_error

# bad
some_method rescue SomeException

# good
begin
  some_method
rescue
  handle_error
end

# good
begin
  some_method
rescue SomeException
  handle_error
end

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Open

    object.sum.to_fs(:rounded, significant: true).gsub(/\.0+$/, '') rescue "0"

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"

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Open

    object.buffer.to_fs(:rounded, significant: true).gsub(/\.0+$/, '') rescue "0"

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"

Annotation keywords like TODO should be all upper case, followed by a colon, and a space, then a note describing the problem.
Open

    # TODO Replace whose with a proper number helper

Checks that comment annotation keywords are written according to guidelines.

Annotation keywords can be specified by overriding the cop's Keywords configuration. Keywords are allowed to be single words or phrases.

NOTE: With a multiline comment block (where each line is only a comment), only the first line will be able to register an offense, even if an annotation keyword starts another line. This is done to prevent incorrect registering of keywords (eg. review) inside a paragraph as an annotation.

Example: RequireColon: true (default)

# bad
# TODO make better

# good
# TODO: make better

# bad
# TODO:make better

# good
# TODO: make better

# bad
# fixme: does not work

# good
# FIXME: does not work

# bad
# Optimize does not work

# good
# OPTIMIZE: does not work

Example: RequireColon: false

# bad
# TODO: make better

# good
# TODO make better

# bad
# fixme does not work

# good
# FIXME does not work

# bad
# Optimize does not work

# good
# OPTIMIZE does not work

Avoid using rescue in its modifier form.
Wontfix

    object.buffer.to_fs(:rounded, significant: true).gsub(/\.0+$/, '') rescue "0"

Checks for uses of rescue in its modifier form is added for following reasons:

  • The syntax of modifier form rescue can be misleading because it might lead us to believe that rescue handles the given exception but it actually rescue all exceptions to return the given rescue block. In this case, value returned by handle_error or SomeException.

  • Modifier form rescue would rescue all the exceptions. It would silently skip all exception or errors and handle the error. Example: If NoMethodError is raised, modifier form rescue would handle the exception.

Example:

# bad
some_method rescue handle_error

# bad
some_method rescue SomeException

# good
begin
  some_method
rescue
  handle_error
end

# good
begin
  some_method
rescue SomeException
  handle_error
end

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Open

    object.total.to_fs(:rounded, significant: true).gsub(/\.0+$/, '') rescue "0"

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"

There are no issues that match your filters.

Category
Status