ece517-p3/expertiza

View on GitHub

Showing 2,813 of 2,813 total issues

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

    if proposer

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 normalcase for variable numbers.
Open

          if_condition_1 = (participants_hash[participants[rand_num].id] < review_strategy.reviews_per_student)

This cop makes sure that all numbered variables use the configured style, snakecase, normalcase or noninteger, for their numbering.

Example: EnforcedStyle: snake_case

# bad

variable1 = 1

# good

variable_1 = 1

Example: EnforcedStyle: normalcase (default)

# bad

variable_1 = 1

# good

variable1 = 1

Example: EnforcedStyle: non_integer

# bad

variable1 = 1

variable_1 = 1

# good

variableone = 1

variable_one = 1

Avoid using update_attribute because it skips validations.
Open

    if @response.update_attribute('is_submitted', false)

This cop checks for the use of methods which skip validations which are listed in http://guides.rubyonrails.org/active_record_validations.html#skipping-validations

Example:

# bad
Article.first.decrement!(:view_count)
DiscussionBoard.decrement_counter(:post_count, 5)
Article.first.increment!(:view_count)
DiscussionBoard.increment_counter(:post_count, 5)
person.toggle :active
product.touch
Billing.update_all("category = 'authorized', author = 'David'")
user.update_attribute(website: 'example.com')
user.update_columns(last_request_at: Time.current)
Post.update_counters 5, comment_count: -1, action_count: 1

# good
user.update_attributes(website: 'example.com')
FileUtils.touch('file')

Line is too long. [162/160]
Open

          self.avg_scores_by_round[reviewee.name][round] = calculate_avg_score_by_round(self.avg_scores_by_criterion[reviewee.name][round], rubric_questions_used)
Severity: Minor
Found in app/helpers/summary_helper.rb by rubocop

Avoid more than 3 levels of block nesting.
Open

              participants_with_min_assigned_reviews << participants.index(participant) if participants_hash[participant.id] == min_value

This cop checks for excessive nesting of conditional and looping constructs.

You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

The maximum level of nesting allowed is configurable.

Use normalcase for variable numbers.
Open

          if_condition_2 = (!selected_participants.include? participants[rand_num].id)

This cop makes sure that all numbered variables use the configured style, snakecase, normalcase or noninteger, for their numbering.

Example: EnforcedStyle: snake_case

# bad

variable1 = 1

# good

variable_1 = 1

Example: EnforcedStyle: normalcase (default)

# bad

variable_1 = 1

# good

variable1 = 1

Example: EnforcedStyle: non_integer

# bad

variable1 = 1

variable_1 = 1

# good

variableone = 1

variable_one = 1

Replace class var @@time_create_last_review_mapping_record with a class instance var.
Open

    @@time_create_last_review_mapping_record = ReviewResponseMap.

This cop checks for uses of class variables. Offenses are signaled only on assignment to class variables to reduce the number of offenses that would be reported.

end at 12, 4 is not aligned with case at 3, 13.
Open

    end

This cop checks whether the end keywords are aligned properly.

Three modes are supported through the EnforcedStyleAlignWith configuration parameter:

If it's set to keyword (which is the default), the end shall be aligned with the start of the keyword (if, class, etc.).

If it's set to variable the end shall be aligned with the left-hand-side of the variable assignment, if there is one.

If it's set to start_of_line, the end shall be aligned with the start of the line where the matching keyword appears.

Example: EnforcedStyleAlignWith: keyword (default)

# bad

variable = if true
    end

# good

variable = if true
           end

Example: EnforcedStyleAlignWith: variable

# bad

variable = if true
    end

# good

variable = if true
end

Example: EnforcedStyleAlignWith: startofline

# bad

variable = if true
    end

# good

puts(if true
end)

Useless assignment to variable - summary.
Open

        summary = [err.message]
Severity: Minor
Found in app/helpers/summary_helper.rb by rubocop

This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Use normalcase for variable numbers.
Open

    @all_reviewers_avg_vol_in_round_1 = @reviewers.inject(0) {|sum, r| sum += r.avg_vol_in_round_1 } / (@reviewers.blank? ? 1 : @reviewers.length)

This cop makes sure that all numbered variables use the configured style, snakecase, normalcase or noninteger, for their numbering.

Example: EnforcedStyle: snake_case

# bad

variable1 = 1

# good

variable_1 = 1

Example: EnforcedStyle: normalcase (default)

# bad

variable_1 = 1

# good

variable1 = 1

Example: EnforcedStyle: non_integer

# bad

variable1 = 1

variable_1 = 1

# good

variableone = 1

variable_one = 1

Avoid more than 3 levels of block nesting.
Open

            rand_num = if if_condition_1 or if_condition_2
                         # use original method to get random number
                         rand(0..num_participants - 1)
                       else
                         # rand_num should be the position of this participant in original array

This cop checks for excessive nesting of conditional and looping constructs.

You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

The maximum level of nesting allowed is configurable.

Line is too long. [162/160]
Open

      flash[:note] = "All metareview mappings for contributor \"" + mapping.reviewee.name + "\" and reviewer \"" + mapping.reviewer.name + "\" have been deleted."

Use submission_review_num.zero? instead of submission_review_num == 0.
Open

    if student_review_num != 0 and submission_review_num == 0

This cop checks for usage of comparison operators (==, >, <) to test numbers as zero, positive, or negative. These can be replaced by their respective predicate methods. The cop can also be configured to do the reverse.

The cop disregards #nonzero? as it its value is truthy or falsey, but not true and false, and thus not always interchangeable with != 0.

The cop ignores comparisons to global variables, since they are often populated with objects which can be compared with integers, but are not themselves Interger polymorphic.

Example: EnforcedStyle: predicate (default)

# bad

foo == 0
0 > foo
bar.baz > 0

# good

foo.zero?
foo.negative?
bar.baz.positive?

Example: EnforcedStyle: comparison

# bad

foo.zero?
foo.negative?
bar.baz.positive?

# good

foo == 0
0 > foo
bar.baz > 0

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

    info.html_safe
Severity: Minor
Found in app/helpers/student_task_helper.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>"

    Replace class var @@header with a class instance var.
    Open

        @@header = false
    Severity: Minor
    Found in app/helpers/chart_helper.rb by rubocop

    This cop checks for uses of class variables. Offenses are signaled only on assignment to class variables to reduce the number of offenses that would be reported.

    Line is too long. [162/160]
    Open

          flash[:success] = "The review mapping for \"" + review_response_map.reviewee.name + "\" and \"" + review_response_map.reviewer.name + "\" has been deleted."

    Replace class var @@chart_index with a class instance var.
    Open

        @@chart_index = 0
    Severity: Minor
    Found in app/helpers/chart_helper.rb by rubocop

    This cop checks for uses of class variables. Offenses are signaled only on assignment to class variables to reduce the number of offenses that would be reported.

    Avoid more than 3 levels of block nesting.
    Open

                if link.nil? or (link !~ %r{https*:\/\/wiki(.*)}) # can be extended for github links in future
                  color.push 'green'
                else
                  link_updated_at = get_link_updated_at(link)
                  color.push link_updated_since_last?(round, assignment_due_dates, link_updated_at) ? 'purple' : 'green'

    This cop checks for excessive nesting of conditional and looping constructs.

    You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

    The maximum level of nesting allowed is configurable.

    Use normalcase for variable numbers.
    Open

        @all_reviewers_avg_vol_in_round_3 = @reviewers.inject(0) {|sum, r| sum += r.avg_vol_in_round_3 } / (@reviewers.blank? ? 1 : @reviewers.length)

    This cop makes sure that all numbered variables use the configured style, snakecase, normalcase or noninteger, for their numbering.

    Example: EnforcedStyle: snake_case

    # bad
    
    variable1 = 1
    
    # good
    
    variable_1 = 1

    Example: EnforcedStyle: normalcase (default)

    # bad
    
    variable_1 = 1
    
    # good
    
    variable1 = 1

    Example: EnforcedStyle: non_integer

    # bad
    
    variable1 = 1
    
    variable_1 = 1
    
    # good
    
    variableone = 1
    
    variable_one = 1

    Use normalcase for variable numbers.
    Open

      def display_volume_metric(overall_avg_vol, avg_vol_in_round_1, avg_vol_in_round_2, avg_vol_in_round_3)

    This cop makes sure that all numbered variables use the configured style, snakecase, normalcase or noninteger, for their numbering.

    Example: EnforcedStyle: snake_case

    # bad
    
    variable1 = 1
    
    # good
    
    variable_1 = 1

    Example: EnforcedStyle: normalcase (default)

    # bad
    
    variable_1 = 1
    
    # good
    
    variable1 = 1

    Example: EnforcedStyle: non_integer

    # bad
    
    variable1 = 1
    
    variable_1 = 1
    
    # good
    
    variableone = 1
    
    variable_one = 1
    Severity
    Category
    Status
    Source
    Language