ece517-p3/expertiza

View on GitHub

Showing 2,813 of 2,813 total issues

Unused method argument - team_name_prefix. If it's necessary, use _ or _team_name_prefix as an argument name to indicate that it won't be used. You can also write as generate_team_name(*) if you want the method to accept any arguments but don't care about them.
Open

  def self.generate_team_name(team_name_prefix = '')
Severity: Minor
Found in app/models/team.rb by rubocop

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. [321/160]
Open

    raise ArgumentError, "Not enough fields on this line." if row_hash.empty? || (row_hash[:teammembers].length < 2 && (options[:has_teamname] == "true_first" || options[:has_teamname] == "true_last")) || (row_hash[:teammembers].empty? && (options[:has_teamname] == "true_first" || options[:has_teamname] == "true_last"))
Severity: Minor
Found in app/models/team.rb by rubocop

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

      if teamtype.is_a?(CourseTeam)
Severity: Minor
Found in app/models/team.rb by rubocop

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

Convert if nested inside else to elsif.
Open

      if teamtype.is_a?(CourseTeam)
Severity: Minor
Found in app/models/team.rb by rubocop

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

Tagging a string as html safe may be a security risk.
Open

    html.html_safe
Severity: Minor
Found in app/models/upload_file.rb by rubocop

This cop checks for the use of output safety calls like htmlsafe, raw, and safeconcat. These methods do not escape content. They simply return a SafeBuffer containing the content as is. Instead, use safe_join to join content and escape it and concat to concatenate content and escape it, ensuring its safety.

Example:

user_content = "hi"

# bad
"

#{user_content}

".html_safe # => ActiveSupport::SafeBuffer "

hi

" # good content_tag(:p, user_content) # => ActiveSupport::SafeBuffer "

<b>hi</b>

" # bad out = "" out << "
  • #{user_content}
  • " out << "
  • #{user_content}
  • " out.html_safe # => ActiveSupport::SafeBuffer "
  • hi
  • hi
  • " # good out = [] out << content_tag(:li, user_content) out << content_tag(:li, user_content) safe_join(out) # => ActiveSupport::SafeBuffer # "
  • <b>hi</b>
  • <b>hi</b>
  • " # bad out = "

    trusted content

    ".html_safe out.safe_concat(user_content) # => ActiveSupport::SafeBuffer "

    trusted_content

    hi" # good out = "

    trusted content

    ".html_safe out.concat(user_content) # => ActiveSupport::SafeBuffer # "

    trusted_content

    <b>hi</b>" # safe, though maybe not good style out = "trusted content" result = out.concat(user_content) # => String "trusted contenthi" # because when rendered in ERB the String will be escaped: # <%= result %> # => trusted content<b>hi</b> # bad (user_content + " " + content_tag(:span, user_content)).html_safe # => ActiveSupport::SafeBuffer "hi <span><b>hi</b></span>" # good safe_join([user_content, " ", content_tag(:span, user_content)]) # => ActiveSupport::SafeBuffer # "<b>hi</b> <span>&lt;b&gt;hi&lt;/b&gt;</span>"

    Favor modifier unless usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
    Open

        unless CourseParticipant.exists?(user_id: user.id, parent_id: id)
    Severity: Minor
    Found in app/models/course_participant.rb by rubocop

    Checks for if and unless statements that would fit on one line if written as a modifier if/unless. The maximum line length is configured in the Metrics/LineLength cop.

    Example:

    # bad
    if condition
      do_stuff(bar)
    end
    
    unless qux.empty?
      Foo.do_something
    end
    
    # good
    do_stuff(bar) if condition
    Foo.do_something unless qux.empty?

    Move @response_maps = ResponseMap.where('reviewed_object_id = ? && type = ?', self.id, @response_type) out of the conditional.
    Open

          @response_maps = ResponseMap.where('reviewed_object_id = ? && type = ?', self.id, @response_type)
    Severity: Minor
    Found in app/models/on_the_fly_calc.rb by rubocop

    This cop checks for identical lines at the beginning or end of each branch of a conditional statement.

    Example:

    # bad
    if condition
      do_x
      do_z
    else
      do_y
      do_z
    end
    
    # good
    if condition
      do_x
    else
      do_y
    end
    do_z
    
    # bad
    if condition
      do_z
      do_x
    else
      do_z
      do_y
    end
    
    # good
    do_z
    if condition
      do_x
    else
      do_y
    end
    
    # bad
    case foo
    when 1
      do_x
    when 2
      do_x
    else
      do_x
    end
    
    # good
    case foo
    when 1
      do_x
      do_y
    when 2
      # nothing
    else
      do_x
      do_z
    end

    Use find_by instead of where.first.
    Open

          team = where(["name =? && parent_id =?", name, id]).first
    Severity: Minor
    Found in app/models/team.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')

    Specify an :inverse_of option.
    Open

      has_one :team_user_node, foreign_key: 'node_object_id', dependent: :destroy
    Severity: Minor
    Found in app/models/teams_user.rb by rubocop

    This cop looks for has(one|many) and belongsto associations where ActiveRecord can't automatically determine the inverse association because of a scope or the options used. This can result in unnecessary queries in some circumstances. :inverse_of must be manually specified for associations to work in both ways, or set to false to opt-out.

    Example:

    # good
    class Blog < ApplicationRecord
      has_many :posts
    end
    
    class Post < ApplicationRecord
      belongs_to :blog
    end

    Example:

    # bad
    class Blog < ApplicationRecord
      has_many :posts, -> { order(published_at: :desc) }
    end
    
    class Post < ApplicationRecord
      belongs_to :blog
    end
    
    # good
    class Blog < ApplicationRecord
      has_many(:posts,
        -> { order(published_at: :desc) },
        inverse_of: :blog
      )
    end
    
    class Post < ApplicationRecord
      belongs_to :blog
    end
    
    # good
    class Blog < ApplicationRecord
      with_options inverse_of: :blog do
        has_many :posts, -> { order(published_at: :desc) }
      end
    end
    
    class Post < ApplicationRecord
      belongs_to :blog
    end

    Example:

    # bad
    class Picture < ApplicationRecord
      belongs_to :imageable, polymorphic: true
    end
    
    class Employee < ApplicationRecord
      has_many :pictures, as: :imageable
    end
    
    class Product < ApplicationRecord
      has_many :pictures, as: :imageable
    end
    
    # good
    class Picture < ApplicationRecord
      belongs_to :imageable, polymorphic: true
    end
    
    class Employee < ApplicationRecord
      has_many :pictures, as: :imageable, inverse_of: :imageable
    end
    
    class Product < ApplicationRecord
      has_many :pictures, as: :imageable, inverse_of: :imageable
    end

    Example:

    # bad
    # However, RuboCop can not detect this pattern...
    class Physician < ApplicationRecord
      has_many :appointments
      has_many :patients, through: :appointments
    end
    
    class Appointment < ApplicationRecord
      belongs_to :physician
      belongs_to :patient
    end
    
    class Patient < ApplicationRecord
      has_many :appointments
      has_many :physicians, through: :appointments
    end
    
    # good
    class Physician < ApplicationRecord
      has_many :appointments
      has_many :patients, through: :appointments
    end
    
    class Appointment < ApplicationRecord
      belongs_to :physician, inverse_of: :appointments
      belongs_to :patient, inverse_of: :appointments
    end
    
    class Patient < ApplicationRecord
      has_many :appointments
      has_many :physicians, through: :appointments
    end

    @see http://guides.rubyonrails.org/association_basics.html#bi-directional-associations @see http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Setting+Inverses

    Prefer each over for.
    Open

        for j in questionnaire_min..questionnaire_max
    Severity: Minor
    Found in app/models/scale.rb by rubocop

    This cop looks for uses of the for keyword, or each method. The preferred alternative is set in the EnforcedStyle configuration parameter. An each call with a block on a single line is always allowed, however.

    Tagging a string as html safe may be a security risk.
    Open

        html.html_safe
    Severity: Minor
    Found in app/models/scale.rb by rubocop

    This cop checks for the use of output safety calls like htmlsafe, raw, and safeconcat. These methods do not escape content. They simply return a SafeBuffer containing the content as is. Instead, use safe_join to join content and escape it and concat to concatenate content and escape it, ensuring its safety.

    Example:

    user_content = "hi"
    
    # bad
    "

    #{user_content}

    ".html_safe # => ActiveSupport::SafeBuffer "

    hi

    " # good content_tag(:p, user_content) # => ActiveSupport::SafeBuffer "

    <b>hi</b>

    " # bad out = "" out << "
  • #{user_content}
  • " out << "
  • #{user_content}
  • " out.html_safe # => ActiveSupport::SafeBuffer "
  • hi
  • hi
  • " # good out = [] out << content_tag(:li, user_content) out << content_tag(:li, user_content) safe_join(out) # => ActiveSupport::SafeBuffer # "
  • <b>hi</b>
  • <b>hi</b>
  • " # bad out = "

    trusted content

    ".html_safe out.safe_concat(user_content) # => ActiveSupport::SafeBuffer "

    trusted_content

    hi" # good out = "

    trusted content

    ".html_safe out.concat(user_content) # => ActiveSupport::SafeBuffer # "

    trusted_content

    <b>hi</b>" # safe, though maybe not good style out = "trusted content" result = out.concat(user_content) # => String "trusted contenthi" # because when rendered in ERB the String will be escaped: # <%= result %> # => trusted content<b>hi</b> # bad (user_content + " " + content_tag(:span, user_content)).html_safe # => ActiveSupport::SafeBuffer "hi <span><b>hi</b></span>" # good safe_join([user_content, " ", content_tag(:span, user_content)]) # => ActiveSupport::SafeBuffer # "<b>hi</b> <span>&lt;b&gt;hi&lt;/b&gt;</span>"

    Use snake_case for variable names.
    Open

          confirmationStatus = SignUpSheet.confirmTopic(user_id, team.id, topic_id, assignment_id) if topic_id
    Severity: Minor
    Found in app/models/sign_up_sheet.rb by rubocop

    This cop makes sure that all variables use the configured style, snake_case or camelCase, for their names.

    Example: EnforcedStyle: snake_case (default)

    # bad
    fooBar = 1
    
    # good
    foo_bar = 1

    Example: EnforcedStyle: camelCase

    # bad
    foo_bar = 1
    
    # good
    fooBar = 1

    Use snake_case for variable names.
    Open

        signUp = SignedUpTeam.where(topic_id: topic_id).first
    Severity: Minor
    Found in app/models/sign_up_sheet.rb by rubocop

    This cop makes sure that all variables use the configured style, snake_case or camelCase, for their names.

    Example: EnforcedStyle: snake_case (default)

    # bad
    fooBar = 1
    
    # good
    foo_bar = 1

    Example: EnforcedStyle: camelCase

    # bad
    foo_bar = 1
    
    # good
    fooBar = 1

    Prefer Date or Time over DateTime.
    Open

          duedate['review_' + round.to_s] = DateTime.parse(duedate_rev['due_at'].to_s).strftime("%Y-%m-%d %H:%M:%S")
    Severity: Minor
    Found in app/models/sign_up_sheet.rb by rubocop

    This cop checks for uses of DateTime that should be replaced by Date or Time.

    Example:

    # bad - uses `DateTime` for current time
    DateTime.now
    
    # good - uses `Time` for current time
    Time.now
    
    # bad - uses `DateTime` for modern date
    DateTime.iso8601('2016-06-29')
    
    # good - uses `Date` for modern date
    Date.iso8601('2016-06-29')
    
    # good - uses `DateTime` with start argument for historical date
    DateTime.iso8601('1751-04-23', Date::ENGLAND)

    Use find_by instead of where.first.
    Open

          duedate_rev = TopicDueDate.where(parent_id: topic.id, deadline_type_id: deadline_type_rev, round: round).first
    Severity: Minor
    Found in app/models/sign_up_sheet.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')

    Method ControllerAction#controller is defined at both app/models/controller_action.rb:8 and app/models/controller_action.rb:15.
    Open

      def controller
    Severity: Minor
    Found in app/models/controller_action.rb by rubocop

    This cop checks for duplicated instance (or singleton) method definitions.

    Example:

    # bad
    
    def duplicated
      1
    end
    
    def duplicated
      2
    end

    Example:

    # bad
    
    def duplicated
      1
    end
    
    alias duplicated other_duplicated

    Example:

    # good
    
    def duplicated
      1
    end
    
    def other_duplicated
      2
    end

    Variable starting_index used in void context.
    Open

        starting_index
    Severity: Minor
    Found in app/models/team.rb by rubocop

    This cop checks for operators, variables and literals used in void context.

    Example:

    # bad
    
    def some_method
      some_num * 10
      do_something
    end

    Example:

    # bad
    
    def some_method(some_var)
      some_var
      do_something
    end

    Example:

    # good
    
    def some_method
      do_something
      some_num * 10
    end

    Example:

    # good
    
    def some_method(some_var)
      do_something
      some_var
    end

    Prefer each over for.
    Open

        for i in (1..num_of_teams).to_a
    Severity: Minor
    Found in app/models/team.rb by rubocop

    This cop looks for uses of the for keyword, or each method. The preferred alternative is set in the EnforcedStyle configuration parameter. An each call with a block on a single line is always allowed, however.

    Tagging a string as html safe may be a security risk.
    Open

        html.html_safe
    Severity: Minor
    Found in app/models/upload_file.rb by rubocop

    This cop checks for the use of output safety calls like htmlsafe, raw, and safeconcat. These methods do not escape content. They simply return a SafeBuffer containing the content as is. Instead, use safe_join to join content and escape it and concat to concatenate content and escape it, ensuring its safety.

    Example:

    user_content = "hi"
    
    # bad
    "

    #{user_content}

    ".html_safe # => ActiveSupport::SafeBuffer "

    hi

    " # good content_tag(:p, user_content) # => ActiveSupport::SafeBuffer "

    <b>hi</b>

    " # bad out = "" out << "
  • #{user_content}
  • " out << "
  • #{user_content}
  • " out.html_safe # => ActiveSupport::SafeBuffer "
  • hi
  • hi
  • " # good out = [] out << content_tag(:li, user_content) out << content_tag(:li, user_content) safe_join(out) # => ActiveSupport::SafeBuffer # "
  • <b>hi</b>
  • <b>hi</b>
  • " # bad out = "

    trusted content

    ".html_safe out.safe_concat(user_content) # => ActiveSupport::SafeBuffer "

    trusted_content

    hi" # good out = "

    trusted content

    ".html_safe out.concat(user_content) # => ActiveSupport::SafeBuffer # "

    trusted_content

    <b>hi</b>" # safe, though maybe not good style out = "trusted content" result = out.concat(user_content) # => String "trusted contenthi" # because when rendered in ERB the String will be escaped: # <%= result %> # => trusted content<b>hi</b> # bad (user_content + " " + content_tag(:span, user_content)).html_safe # => ActiveSupport::SafeBuffer "hi <span><b>hi</b></span>" # good safe_join([user_content, " ", content_tag(:span, user_content)]) # => ActiveSupport::SafeBuffer # "<b>hi</b> <span>&lt;b&gt;hi&lt;/b&gt;</span>"

    Do not prefix reader method names with get_.
    Open

      def get_creation_date; end
    Severity: Minor
    Found in app/models/node.rb by rubocop

    This cop makes sure that accessor methods are named properly.

    Example:

    # bad
    def set_attribute(value)
    end
    
    # good
    def attribute=(value)
    end
    
    # bad
    def get_attribute
    end
    
    # good
    def attribute
    end
    Severity
    Category
    Status
    Source
    Language