znamenica/dneslov

View on GitHub
app/models/concerns/tokens.rb

Summary

Maintainability
A
1 hr
Test Coverage

Identical blocks of code found in 7 locations. Consider refactoring.
Open

         scope :by_tokens, -> string_in do
            return self if string_in.blank?
            # TODO fix the correctness of the query
            klass = self.model_name.name.constantize
            or_rel_tokens = string_in.split(/\//).map do |or_token|
Severity: Major
Found in app/models/concerns/tokens.rb and 6 other locations - About 1 hr to fix
app/models/calendary.rb on lines 56..68
app/models/memo.rb on lines 148..163
app/models/memory.rb on lines 60..75
app/models/name.rb on lines 23..37
app/models/order.rb on lines 25..37
app/models/subject.rb on lines 30..42

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 55.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Space missing after semicolon.
Open

                  rel && rel.merge(and_rel) || and_rel ;end;end
Severity: Minor
Found in app/models/concerns/tokens.rb by rubocop

Checks for semicolon (;) not followed by some kind of space.

Example:

# bad
x = 1;y = 2

# good
x = 1; y = 2

Do not use spaces between -> and opening brace in lambda literals
Open

         scope :by_tokens, -> string_in do
            return self if string_in.blank?
            # TODO fix the correctness of the query
            klass = self.model_name.name.constantize
            or_rel_tokens = string_in.split(/\//).map do |or_token|
Severity: Minor
Found in app/models/concerns/tokens.rb by rubocop

This cop checks for spaces between -> and opening parameter brace in lambda literals.

Example: EnforcedStyle: requirenospace (default)

# bad
  a = -> (x, y) { x + y }

  # good
  a = ->(x, y) { x + y }

Example: EnforcedStyle: require_space

# bad
  a = ->(x, y) { x + y }

  # good
  a = -> (x, y) { x + y }

Wrap stabby lambda arguments with parentheses.
Open

         scope :by_tokens, -> string_in do
Severity: Minor
Found in app/models/concerns/tokens.rb by rubocop

Check for parentheses around stabby lambda arguments. There are two different styles. Defaults to require_parentheses.

Example: EnforcedStyle: require_parentheses (default)

# bad
->a,b,c { a + b + c }

# good
->(a,b,c) { a + b + c}

Example: EnforcedStyle: requirenoparentheses

# bad
->(a,b,c) { a + b + c }

# good
->a,b,c { a + b + c}

Expression at 15, 57 should be on its own line.
Open

                  rel && rel.merge(and_rel) || and_rel ;end;end
Severity: Minor
Found in app/models/concerns/tokens.rb by rubocop

This cop checks whether the end statement of a do..end block is on its own line.

Example:

# bad
blah do |i|
  foo(i) end

# good
blah do |i|
  foo(i)
end

# bad
blah { |i|
  foo(i) }

# good
blah { |i|
  foo(i)
}

Use %r around regular expression.
Open

            or_rel_tokens = string_in.split(/\//).map do |or_token|
Severity: Minor
Found in app/models/concerns/tokens.rb by rubocop

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 space after #.
Open

            # TODO fix the correctness of the query
Severity: Minor
Found in app/models/concerns/tokens.rb by rubocop

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 only ascii symbols in comments.
Open

            # TODO fix the correctness of the query
Severity: Minor
Found in app/models/concerns/tokens.rb by rubocop

This cop checks for non-ascii (non-English) characters in comments. You could set an array of allowed non-ascii chars in AllowedChars attribute (empty by default).

Example:

# bad
# Translates from English to 日本語。

# good
# Translates from English to Japanese

Missing top-level module documentation comment.
Open

module Tokens
Severity: Minor
Found in app/models/concerns/tokens.rb by rubocop

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

Space found before semicolon.
Open

                  rel && rel.merge(and_rel) || and_rel ;end;end
Severity: Minor
Found in app/models/concerns/tokens.rb by rubocop

Checks for semicolon (;) preceded by space.

Example:

# bad
x = 1 ; y = 2

# good
x = 1; y = 2

Expression at 15, 61 should be on its own line.
Open

                  rel && rel.merge(and_rel) || and_rel ;end;end
Severity: Minor
Found in app/models/concerns/tokens.rb by rubocop

This cop checks whether the end statement of a do..end block is on its own line.

Example:

# bad
blah do |i|
  foo(i) end

# good
blah do |i|
  foo(i)
end

# bad
blah { |i|
  foo(i) }

# good
blah { |i|
  foo(i)
}

Use the lambda method for multiline lambdas.
Open

         scope :by_tokens, -> string_in do
Severity: Minor
Found in app/models/concerns/tokens.rb by rubocop

This cop (by default) checks for uses of the lambda literal syntax for single line lambdas, and the method call syntax for multiline lambdas. It is configurable to enforce one of the styles for both single line and multiline lambdas as well.

Example: EnforcedStyle: linecountdependent (default)

# bad
f = lambda { |x| x }
f = ->(x) do
      x
    end

# good
f = ->(x) { x }
f = lambda do |x|
      x
    end

Example: EnforcedStyle: lambda

# bad
f = ->(x) { x }
f = ->(x) do
      x
    end

# good
f = lambda { |x| x }
f = lambda do |x|
      x
    end

Example: EnforcedStyle: literal

# bad
f = lambda { |x| x }
f = lambda do |x|
      x
    end

# good
f = ->(x) { x }
f = ->(x) do
      x
    end

Space missing after semicolon.
Open

                  rel && rel.merge(and_rel) || and_rel ;end;end
Severity: Minor
Found in app/models/concerns/tokens.rb by rubocop

Checks for semicolon (;) not followed by some kind of space.

Example:

# bad
x = 1;y = 2

# good
x = 1; y = 2

Redundant self detected.
Open

            self.merge(or_rel).distinct
Severity: Minor
Found in app/models/concerns/tokens.rb by rubocop

This cop checks for redundant uses of self.

The usage of self is only needed when:

  • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

  • Calling an attribute writer to prevent an local variable assignment.

Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

Note we allow uses of self with operators because it would be awkward otherwise.

Example:

# bad
def foo(bar)
  self.baz
end

# good
def foo(bar)
  self.bar  # Resolves name clash with the argument.
end

def foo
  bar = 1
  self.bar  # Resolves name clash with the local variable.
end

def foo
  %w[x y z].select do |bar|
    self.bar == bar  # Resolves name clash with argument of the block.
  end
end

Redundant self detected.
Open

            klass = self.model_name.name.constantize
Severity: Minor
Found in app/models/concerns/tokens.rb by rubocop

This cop checks for redundant uses of self.

The usage of self is only needed when:

  • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

  • Calling an attribute writer to prevent an local variable assignment.

Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

Note we allow uses of self with operators because it would be awkward otherwise.

Example:

# bad
def foo(bar)
  self.baz
end

# good
def foo(bar)
  self.bar  # Resolves name clash with the argument.
end

def foo
  bar = 1
  self.bar  # Resolves name clash with the local variable.
end

def foo
  %w[x y z].select do |bar|
    self.bar == bar  # Resolves name clash with argument of the block.
  end
end

There are no issues that match your filters.

Category
Status