ece517-p3/expertiza

View on GitHub

Showing 2,813 of 2,813 total issues

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

  @@response = ''

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 comma after the last item of an array.
Open

  Coveralls::SimpleCov::Formatter,
Severity: Minor
Found in spec/spec_helper.rb by rubocop

This cop checks for trailing comma in array and hash literals.

Example: EnforcedStyleForMultiline: consistent_comma

# bad
a = [1, 2,]

# good
a = [
  1, 2,
  3,
]

# good
a = [
  1,
  2,
]

Example: EnforcedStyleForMultiline: comma

# bad
a = [1, 2,]

# good
a = [
  1,
  2,
]

Example: EnforcedStyleForMultiline: no_comma (default)

# bad
a = [1, 2,]

# good
a = [
  1,
  2
]

Useless assignment to variable - user_id.
Open

      user_id = double
Severity: Minor
Found in spec/models/user_spec.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

(...) interpreted as grouped expression.
Open

      expect(scores[:avg]).to eq (total_score1 + total_score2) / 2
Severity: Minor
Found in spec/models/answer_spec.rb by rubocop

Checks for space between the name of a called method and a left parenthesis.

Example:

# bad

puts (x + y)

Example:

# good

puts(x + y)

Use find_by instead of dynamic find_by_login.
Open

      user = User.find_by_login(params[:login][:name])
Severity: Minor
Found in app/controllers/auth_controller.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)

Useless assignment to variable - assignment.
Open

    assignment = Assignment.find(assignment_id)

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 find_by instead of dynamic find_by_name.
Open

          deadline_type_id = DeadlineType.find_by_name(deadline_type).id

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)

Avoid using update_all because it skips validations.
Open

          Bid.where(topic_id: topic_id, team_id: team_id).update_all(priority: index + 1)

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

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

      @@additional_info = 'add quiz scores'

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.

Prefer Date or Time over DateTime.
Open

        @assignment_review_due_date = DateTime.parse(@assignment_review_due_dates[i - 1].due_at.to_s).strftime("%Y-%m-%d %H:%M")

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)

Convert if nested inside else to elsif.
Open

      if AssignmentParticipant.exists? user_id: user.id, parent_id: params[:assignment_id]

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

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

  @@another_assignment_id = ''

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.

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

    @@assignment_id = params[:assignment_id]

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.

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

      @@additional_info = 'add expert grades'

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.

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

    @@response_body = response.body

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

      expect(html).to eq("<TR><TD align=\"left\"> test txt3 </TD><TD align=\"left\">Checkbox</TD><td align=\"center\">12</TD><TD align=\"center\">Checked/Unchecked</TD></TR>")
Severity: Minor
Found in spec/models/checkbox_spec.rb by rubocop

Use %r around regular expression.
Open

      expect { User.from_params(user: {}) }.to raise_error(RuntimeError, /a href='users\/new\/1'>create an account<\/a> for this user to continue/)
Severity: Minor
Found in spec/models/user_spec.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\//

Ambiguous negative number operator. Parenthesize the method arguments if it's surely a negative number operator, or add a whitespace to the right of the - if it should be a subtraction.
Open

      expect(Answer.get_total_score(response: [response_record], questions: [question1])).to eq -1.0
Severity: Minor
Found in spec/models/answer_spec.rb by rubocop

This cop checks for ambiguous operators in the first argument of a method invocation without parentheses.

Example:

# bad

# The `*` is interpreted as a splat operator but it could possibly be
# a `*` method invocation (i.e. `do_something.*(some_array)`).
do_something *some_array

Example:

# good

# With parentheses, there's no ambiguity.
do_something(*some_array)

Prefer Date or Time over DateTime.
Open

        @assignment_submission_due_date = DateTime.parse(@assignment_submission_due_dates[i - 1].due_at.to_s).strftime("%Y-%m-%d %H:%M")

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)

Do not use DateTime.parse.strftime without zone. Use one of Time.zone.parse.strftime, DateTime.current, DateTime.parse.strftime.in_time_zone, DateTime.parse.strftime.utc, DateTime.parse.strftime.getlocal, DateTime.parse.strftime.iso8601, DateTime.parse.strftime.jisx0301, DateTime.parse.strftime.rfc3339, DateTime.parse.strftime.to_i, DateTime.parse.strftime.to_f instead.
Open

        @assignment_submission_due_date = DateTime.parse(@assignment_submission_due_dates[i - 1].due_at.to_s).strftime("%Y-%m-%d %H:%M")

This cop checks for the use of Time methods without zone.

Built on top of Ruby on Rails style guide (https://github.com/bbatsov/rails-style-guide#time) and the article http://danilenko.org/2012/7/6/rails_timezones/ .

Two styles are supported for this cop. When EnforcedStyle is 'strict' then only use of Time.zone is allowed.

When EnforcedStyle is 'flexible' then it's also allowed to use Time.intimezone.

Example:

# always offense
Time.now
Time.parse('2015-03-02 19:05:37')

# no offense
Time.zone.now
Time.zone.parse('2015-03-02 19:05:37')

# no offense only if style is 'flexible'
Time.current
DateTime.strptime(str, "%Y-%m-%d %H:%M %Z").in_time_zone
Time.at(timestamp).in_time_zone
Severity
Category
Status
Source
Language