diaspora/diaspora

View on GitHub

Showing 4,306 of 4,306 total issues

Redundant self detected.
Open

      remote_path = self.unprocessed_image.url
Severity: Minor
Found in app/models/photo.rb by rubocop

This cop checks for redundant uses of self.

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.

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

    Example:

    def bar :baz end

    def foo(bar) self.bar # resolves name clash with argument end

    def foo2 bar = 1 self.bar # resolves name clash with local variable end

  • Calling an attribute writer to prevent an local variable assignment

    attr_writer :bar

    def foo self.bar= 1 # Make sure above attr writer is called end

Special cases:

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

Space between { and | detected.
Open

    t.add lambda { |photo|
Severity: Minor
Found in app/models/photo.rb by rubocop

Checks that block braces have or don't have surrounding space inside them on configuration. For blocks taking parameters, it checks that the left brace has or doesn't have trailing space depending on configuration.

Prefer single-quoted strings inside interpolations.
Open

      remote_path = "#{AppConfig.pod_uri.to_s.chomp("/")}#{self.unprocessed_image.url}"
Severity: Minor
Found in app/models/photo.rb by rubocop

Extra empty line detected at class body beginning.
Open


  include Diaspora::Federated::Base
Severity: Minor
Found in app/models/comment.rb by rubocop

This cops checks if empty lines around the bodies of classes match the configuration.

Example:

EnforcedStyle: empty_lines

# good

class Foo

   def bar
     ...
   end

end

Do not use unless with else. Rewrite these with the positive case first.
Open

    unless self.unprocessed_image.url.match(/^https?:\/\//)
      remote_path = "#{AppConfig.pod_uri.to_s.chomp("/")}#{self.unprocessed_image.url}"
    else
      remote_path = self.unprocessed_image.url
    end
Severity: Minor
Found in app/models/photo.rb by rubocop

Use find_by instead of dynamic find_by_guid.
Open

    message = StatusMessage.find_by_guid(self.status_message_guid)
Severity: Minor
Found in app/models/photo.rb by rubocop

This cop checks dynamic find_by_* methods. Use find_by instead of dynamic method. See. https://github.com/bbatsov/rails-style-guide#find_by

Example:

# bad
User.find_by_name(name)

# bad
User.find_by_name_and_email(name)

# bad
User.find_by_email!(name)

# good
User.find_by(name: name)

# good
User.find_by(name: name, email: email)

# good
User.find_by!(email: email)

Extra empty line detected at class body beginning.
Open


    self.include_root_in_json = false

This cops checks if empty lines around the bodies of classes match the configuration.

Example:

EnforcedStyle: empty_lines

# good

class Foo

   def bar
     ...
   end

end

Use next to skip iteration.
Open

      if recipient.local?
Severity: Minor
Found in app/models/conversation.rb by rubocop

Use next to skip iteration instead of a condition at the end.

Example:

# bad
[1, 2].each do |a|
  if a == 1 do
    puts a
  end
end

# good
[1, 2].each do |a|
  next unless a == 1
  puts a
end

Redundant self detected.
Open

      self.messages.to_a[-visibility.unread]
Severity: Minor
Found in app/models/conversation.rb by rubocop

This cop checks for redundant uses of self.

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.

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

    Example:

    def bar :baz end

    def foo(bar) self.bar # resolves name clash with argument end

    def foo2 bar = 1 self.bar # resolves name clash with local variable end

  • Calling an attribute writer to prevent an local variable assignment

    attr_writer :bar

    def foo self.bar= 1 # Make sure above attr writer is called end

Special cases:

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

Use !empty? instead of size > 0.
Open

    return unless @last_author.present? || messages.size > 0
Severity: Minor
Found in app/models/conversation.rb by rubocop

This cop checks for receiver.length == 0 predicates and the negated versions receiver.length > 0 and receiver.length != 0. These can be replaced with receiver.empty? and !receiver.empty? respectively.

Example:

# bad
[1, 2, 3].length == 0
0 == "foobar".length
hash.size > 0

# good
[1, 2, 3].empty?
"foobar".empty?
!hash.empty?

Freeze mutable objects assigned to constants.
Open

  ERROR_MAP = {
    ConnectionTester::AddressFailure  => :dns_failed,
    ConnectionTester::DNSFailure      => :dns_failed,
    ConnectionTester::NetFailure      => :net_failed,
    ConnectionTester::SSLFailure      => :ssl_failed,
Severity: Minor
Found in app/models/pod.rb by rubocop

This cop checks whether some constant value isn't a mutable literal (e.g. array or hash).

Example:

# bad
CONST = [1, 2, 3]

# good
CONST = [1, 2, 3].freeze

Use %r around regular expression.
Open

    unless self.unprocessed_image.url.match(/^https?:\/\//)
Severity: Minor
Found in app/models/photo.rb by rubocop

This cop enforces using // or %r around regular expressions.

Example:

# Good if EnforcedStyle is slashes or mixed, bad if percent_r.
snake_case = /^[\dA-Z_]+$/

# Good if EnforcedStyle is percent_r, bad if slashes or mixed.
snake_case = %r{^[\dA-Z_]+$}

# Good if EnforcedStyle is slashes, bad if percent_r or mixed.
regex = /
  foo
  (bar)
  (baz)
/x

# Good if EnforcedStyle is percent_r or mixed, bad if slashes.
regex = %r{
  foo
  (bar)
  (baz)
}x

# Bad unless AllowInnerSlashes is true.
x =~ /home\//

Use the new Ruby 1.9 hash syntax.
Open

      {:target => @target}
Severity: Minor
Found in app/models/participation.rb by rubocop

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'"

# good
{a: 2, b: 1}
{:c => 2, 'd' => 2} # acceptable since 'd' isn't a symbol
{d: 1, 'e' => 2} # technically not forbidden

# bad
{:a => 2}
{b: 1, :c => 2}

Example:

"EnforcedStyle => 'hash_rockets'"

# good
{:a => 1, :b => 2}

# bad
{a: 1, b: 2}
{c: 1, 'd' => 5}

Example:

"EnforcedStyle => 'no_mixed_keys'"

# good
{:a => 1, :b => 2}
{c: 1, d: 2}

# bad
{:a => 1, b: 2}
{c: 1, 'd' => 2}

Example:

"EnforcedStyle => 'ruby19_no_mixed_keys'"

# good
{a: 1, b: 2}
{:c => 3, 'd' => 4}

# bad
{:a => 1, :b => 2}
{c: 2, 'd' => 3} # should just use hash rockets

Redundant self detected.
Open

    self.text.strip! unless self.text.nil?
Severity: Minor
Found in app/models/comment.rb by rubocop

This cop checks for redundant uses of self.

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.

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

    Example:

    def bar :baz end

    def foo(bar) self.bar # resolves name clash with argument end

    def foo2 bar = 1 self.bar # resolves name clash with local variable end

  • Calling an attribute writer to prevent an local variable assignment

    attr_writer :bar

    def foo self.bar= 1 # Make sure above attr writer is called end

Special cases:

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

Redundant self detected.
Open

    if visibility = self.conversation_visibilities.where(:person_id => user.person.id).where('unread > 0').first
Severity: Minor
Found in app/models/conversation.rb by rubocop

This cop checks for redundant uses of self.

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.

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

    Example:

    def bar :baz end

    def foo(bar) self.bar # resolves name clash with argument end

    def foo2 bar = 1 self.bar # resolves name clash with local variable end

  • Calling an attribute writer to prevent an local variable assignment

    attr_writer :bar

    def foo self.bar= 1 # Make sure above attr writer is called end

Special cases:

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Open

    name_start = remote_path.rindex '/'
Severity: Minor
Found in app/models/photo.rb by rubocop

Use the new Ruby 1.9 hash syntax.
Open

  validates :text, :presence => true, :length => {:maximum => 65535}
Severity: Minor
Found in app/models/comment.rb by rubocop

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'"

# good
{a: 2, b: 1}
{:c => 2, 'd' => 2} # acceptable since 'd' isn't a symbol
{d: 1, 'e' => 2} # technically not forbidden

# bad
{:a => 2}
{b: 1, :c => 2}

Example:

"EnforcedStyle => 'hash_rockets'"

# good
{:a => 1, :b => 2}

# bad
{a: 1, b: 2}
{c: 1, 'd' => 5}

Example:

"EnforcedStyle => 'no_mixed_keys'"

# good
{:a => 1, :b => 2}
{c: 1, d: 2}

# bad
{:a => 1, b: 2}
{c: 1, 'd' => 2}

Example:

"EnforcedStyle => 'ruby19_no_mixed_keys'"

# good
{a: 1, b: 2}
{:c => 3, 'd' => 4}

# bad
{:a => 1, :b => 2}
{c: 2, 'd' => 3} # should just use hash rockets

Separate every 3 digits in the integer portion of a number with underscores(_).
Open

  validates :text, :presence => true, :length => {:maximum => 65535}
Severity: Minor
Found in app/models/comment.rb by rubocop

Freeze mutable objects assigned to constants.
Open

  DEFAULT_PORTS = [URI::HTTP::DEFAULT_PORT, URI::HTTPS::DEFAULT_PORT]
Severity: Minor
Found in app/models/pod.rb by rubocop

This cop checks whether some constant value isn't a mutable literal (e.g. array or hash).

Example:

# bad
CONST = [1, 2, 3]

# good
CONST = [1, 2, 3].freeze

Use find_by instead of where.first.
Open

    if visibility = self.conversation_visibilities.where(:person_id => user.person.id).where('unread > 0').first
Severity: Minor
Found in app/models/conversation.rb by rubocop

This cop is used to identify usages of where.first and change them to use find_by instead.

Example:

# bad
User.where(name: 'Bruce').first
User.where(name: 'Bruce').take

# good
User.find_by(name: 'Bruce')
Severity
Category
Status
Source