Skip to content

Commit

Permalink
Fixed Rubocop offences (#2127)
Browse files Browse the repository at this point in the history
  • Loading branch information
namangupta01 authored and jywarren committed Jan 27, 2018
1 parent 097605a commit 34935fb
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 70 deletions.
16 changes: 15 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,21 @@ AllCops:
- 'script/**/*'
- 'lib/**/*'
- 'test/**/*'
- 'public/**/*'
- 'Dangerfile'
TargetRubyVersion: '2.4'

Style/FrozenStringLiteralComment:
Enabled: false
Enabled: false

Metrics/ParameterLists:
Enabled: false

Metrics/ModuleLength:
Max: 303

Metrics/ClassLength:
Max: 660

Style/RegexpLiteral:
Enabled: false
4 changes: 2 additions & 2 deletions app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def spam
@nodes = if params[:type] == 'wiki'
@nodes.where(type: 'page', status: 1)
else
@nodes.where(status: 0)
end
@nodes.where(status: 0)
end
else
flash[:error] = 'Only moderators can moderate posts.'
redirect_to '/dashboard'
Expand Down
20 changes: 9 additions & 11 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ def set_sidebar(type = :generic, data = :all, args = {})
Node.questions
.joins(:revision)
else
Node.research_notes
.joins(:revision)
.order('node.nid DESC')
.paginate(page: params[:page])
end
Node.research_notes.joins(:revision).order('node.nid DESC').paginate(page: params[:page])
end

@notes = @notes.where('node.nid != (?)', @node.nid) if @node
@notes = @notes.where('node_revisions.status = 1 AND node.nid NOT IN (?)', hidden_nids) unless hidden_nids.empty?

Expand Down Expand Up @@ -163,17 +161,17 @@ def comments_node_and_path
# finding node for node comments
@comment.node
else
# finding node for answer comments
@comment.answer.node
end
# finding node for answer comments
@comment.answer.node
end

@path = if params[:type] && params[:type] == 'question'
# questions path
@node.path(:question)
else
# notes path
@node.path
end
# notes path
@node.path
end
end

# used for url redirects for friendly_id
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/like_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def liked?
result = if result.nil?
false
else
result.liking
end
result.liking
end
render json: result
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/stats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def index
@time = if params[:time]
Time.parse(params[:time])
else
Time.now
end
Time.now
end

@weekly_notes = Node.select(%i(created type status))
.where(type: 'note', status: 1, created: @time.to_i - 1.weeks.to_i..@time.to_i)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/subscription_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def add
end

# test for uniqueness, handle it as a validation error if you like
if TagSelection.where(following: true, user_id: current_user.uid, tid: tag.tid).length > 0
if TagSelection.where(following: true, user_id: current_user.uid, tid: tag.tid).positive?
flash[:error] = "You are already subscribed to '#{params[:name]}'"
redirect_to "/subscriptions" + "?_=" + Time.now.to_i.to_s
else
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/tag_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def show

@tagnames = [params[:id]]
@tag = Tag.find_by(name: params[:id])
@noteCount = Tag.taggedNodeCount(params[:id]) || 0
@note_count = Tag.tagged_node_count(params[:id]) || 0
@users = Tag.contributors(@tagnames[0])

respond_with(nodes) do |format|
Expand Down Expand Up @@ -194,7 +194,7 @@ def show_for_author
render json: json
end
end
end
end

def widget
num = params[:n] || 4
Expand Down Expand Up @@ -350,7 +350,7 @@ def contributors
set_sidebar :tags, [params[:id]], note_count: 20
@tagnames = [params[:id]]
@tag = Tag.find_by(name: params[:id])
@noteCount = Tag.taggedNodeCount(params[:id]) || 0
@note_count = Tag.tagged_node_count(params[:id]) || 0
@users = Tag.contributors(@tagnames[0])
end

Expand Down
13 changes: 7 additions & 6 deletions app/controllers/wiki_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def show
@node = if params[:lang]
Node.find_wiki(params[:lang] + '/' + params[:id])
else
Node.find_wiki(params[:id])
end
Node.find_wiki(params[:id])
end

if @node&.has_power_tag('redirect') && Node.where(nid: @node.power_tag('redirect')).exists?
if current_user.nil? || (current_user.role != 'admin' && current_user.role != 'moderator')
Expand Down Expand Up @@ -91,8 +91,9 @@ def edit
@node = if params[:lang]
Node.find_wiki(params[:lang] + '/' + params[:id])
else
Node.find_wiki(params[:id])
end
Node.find_wiki(params[:id])
end

if @node.has_tag('locked') && (current_user.role != 'admin' && current_user.role != 'moderator')
flash[:warning] = "This page is <a href='/wiki/power-tags#Locking'>locked</a>, and only <a href='/wiki/moderators'>moderators</a> can edit it."
redirect_to @node.path
Expand Down Expand Up @@ -293,8 +294,8 @@ def index
order_string = if params[:order] == 'alphabetic'
'node_revisions.title ASC'
else
'node_revisions.timestamp DESC'
end
'node_revisions.timestamp DESC'
end

@wikis = Node.includes(:revision)
.references(:node_revisions)
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def render_comment_body(comment)

# replaces inline title suggestion(e.g: {New Title}) with the required link to change the title
def title_suggestion(comment)
comment.body.gsub(/\[propose:title\](.*?)\[\/propose\]/) do |title_suggestion|
comment.body.gsub(/\[propose:title\](.*?)\[\/propose\]/) do ||
a = ActionController::Base.new
is_creator = current_user.drupal_user == Node.find(comment.nid).author
title = Regexp.last_match(1)
Expand Down
12 changes: 6 additions & 6 deletions app/models/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,11 @@ def files
end

def answered
self.answers && self.answers.length > 0
self.answers&.length.positive?
end

def has_accepted_answers
self.answers.where(accepted: true).count > 0
self.answers.where(accepted: true).count.positive?
end

# users who like this node
Expand Down Expand Up @@ -455,8 +455,8 @@ def edit_path
path = if type == 'page' || type == 'tool' || type == 'place'
'/wiki/edit/' + self.path.split('/').last
else
'/notes/edit/' + id.to_s
end
'/notes/edit/' + id.to_s
end
path
end

Expand Down Expand Up @@ -515,8 +515,8 @@ def add_comment(params = {})
thread = if !comments.empty? && !comments.last.nil?
comments.last.next_thread
else
'01/'
end
'01/'
end
c = Comment.new(pid: 0,
nid: nid,
uid: params[:uid],
Expand Down
4 changes: 2 additions & 2 deletions app/models/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,11 @@ def self.tagged_nodes_by_author(tagname, user_id)
end
end

def self.taggedNodeCount(tagName)
def self.tagged_node_count(tag_name)
Node.where(status: 1, type: 'note')
.includes(:revision, :tag)
.references(:term_data, :node_revisions)
.where('term_data.name = ?', tagName)
.where('term_data.name = ?', tag_name)
.count
end
end
2 changes: 1 addition & 1 deletion app/models/user_tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def preprocess
end

def self.exists?(uid, value)
UserTag.where(uid: uid, value: value).count > 0
UserTag.where(uid: uid, value: value).count.positive?
end

def name
Expand Down
60 changes: 30 additions & 30 deletions app/services/typeahead_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,40 +86,40 @@ def maps(input, limit = 5)
end

# Run a search in any of the associated systems for references that contain the search string
def search_all(srchString, limit = 5)
def search_all(search_string, limit = 5)
sresult = TagList.new
unless srchString.nil? || srchString == 0
unless search_string.nil? || search_string.blank?
# notes
notesrch = search_notes(srchString, limit)
notesrch = search_notes(search_string, limit)
sresult.addAll(notesrch.getTags)
# wikis
wikisrch = search_wikis(srchString, limit)
wikisrch = search_wikis(search_string, limit)
sresult.addAll(wikisrch.getTags)
# User profiles
usersrch = search_profiles(srchString, limit)
usersrch = search_profiles(search_string, limit)
sresult.addAll(usersrch.getTags)
# Tags -- handled differently because tag
tagsrch = search_tags(srchString, limit)
tagsrch = search_tags(search_string, limit)
sresult.addAll(tagsrch.getTags)
# maps
mapsrch = search_maps(srchString, limit)
mapsrch = search_maps(search_string, limit)
sresult.addAll(mapsrch.getTags)
# questions
qsrch = search_questions(srchString, limit)
qsrch = search_questions(search_string, limit)
sresult.addAll(qsrch.getTags)
#comments
commentsrch = search_comments(srchString, limit)
commentsrch = search_comments(search_string, limit)
sresult.addAll(commentsrch.getTags)
end
sresult
end

# Search profiles for matching text
def search_profiles(srchString, limit = 5)
def search_profiles(search_string, limit = 5)
sresult = TagList.new
unless srchString.nil? || srchString == 0
unless search_string.nil? || search_string.blank?
# User profiles
users(srchString, limit).each do |match|
users(search_string, limit).each do |match|
tval = TagResult.new
tval.tagId = 0
tval.tagType = 'user'
Expand All @@ -132,10 +132,10 @@ def search_profiles(srchString, limit = 5)
end

# Search notes for matching strings
def search_notes(srchString, limit = 5)
def search_notes(search_string, limit = 5)
sresult = TagList.new
unless srchString.nil? || srchString == 0
notes(srchString, limit).uniq.each do |match|
unless search_string.nil? || search_string.blank?
notes(search_string, limit).uniq.each do |match|
tval = TagResult.new
tval.tagId = match.nid
tval.tagVal = match.title
Expand All @@ -148,10 +148,10 @@ def search_notes(srchString, limit = 5)
end

# Search wikis for matching strings
def search_wikis(srchString, limit = 5)
def search_wikis(search_string, limit = 5)
sresult = TagList.new
unless srchString.nil? || srchString == 0
wikis(srchString, limit).select('node.title,node.type,node.nid,node.path').each do |match|
unless search_string.nil? || search_string.blank?
wikis(search_string, limit).select('node.title,node.type,node.nid,node.path').each do |match|
tval = TagResult.new
tval.tagId = match.nid
tval.tagVal = match.title
Expand All @@ -164,11 +164,11 @@ def search_wikis(srchString, limit = 5)
end

# Search maps for matching text
def search_maps(srchString, limit = 5)
def search_maps(search_string, limit = 5)
sresult = TagList.new
unless srchString.nil? || srchString == 0
unless search_string.nil? || search_string.blank?
# maps
maps(srchString, limit).select('title,type,nid,path').each do |match|
maps(search_string, limit).select('title,type,nid,path').each do |match|
tval = TagResult.new
tval.tagId = match.nid
tval.tagVal = match.title
Expand All @@ -181,11 +181,11 @@ def search_maps(srchString, limit = 5)
end

# Search tag values for matching text
def search_tags(srchString, limit = 5)
def search_tags(search_string, limit = 5)
sresult = TagList.new
unless srchString.nil? || srchString == 0
unless search_string.nil? || search_string.blank?
# Tags
tlist = tags(srchString, limit)
tlist = tags(search_string, limit)
tlist.each do |match|
ntag = TagResult.new
ntag.tagId = 0
Expand All @@ -200,8 +200,8 @@ def search_tags(srchString, limit = 5)
# Search question entries for matching text
def search_questions(input, limit = 5)
sresult = TagList.new
if ActiveRecord::Base.connection.adapter_name == 'Mysql2'
questions = Node.search(input)
questions = if ActiveRecord::Base.connection.adapter_name == 'Mysql2'
Node.search(input)
.group(:nid)
.includes(:node)
.references(:node)
Expand All @@ -211,7 +211,7 @@ def search_questions(input, limit = 5)
.joins(:tag)
.where('term_data.name LIKE ?', 'question:%')
else
questions = Node.where('title LIKE ?', '%' + input + '%')
Node.where('title LIKE ?', '%' + input + '%')
.joins(:tag)
.where('term_data.name LIKE ?', 'question:%')
.limit(limit)
Expand All @@ -232,10 +232,10 @@ def search_questions(input, limit = 5)
end

# Search comments for matching text
def search_comments(srchString, limit = 5)
def search_comments(search_string, limit = 5)
sresult = TagList.new
unless srchString.nil? || srchString == 0
comments(srchString, limit).each do |match|
unless search_string.nil? || search_string.blank?
comments(search_string, limit).each do |match|
tval = TagResult.new
tval.tagId = match.pid
tval.tagVal = match.comment.truncate(20)
Expand Down
4 changes: 2 additions & 2 deletions app/views/tag/_contributors.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<% end %>
<div class="row" id="highlight" style=" text-align: center;">
<h3 class="col-md-4 col-xs-12 col-sm-4"><%= @users.length || 0 %> contributors</h3>
<h3 class="col-md-4 col-xs-12 col-sm-4"><%= @noteCount %> research notes</h3>
<h3 class="col-md-4 col-xs-12 col-sm-4"><%= @note_count %> research notes</h3>
<h3 class="col-md-4 col-xs-12 col-sm-4"><%= @wikis.length %> wiki pages</h3>
</div>
<% if params["action"] == "contributors"%>
Expand All @@ -30,7 +30,7 @@
<% end %>
<% end %>
<% if @noteCount.nil? || @noteCount == 0 %>
<% if @note_count.nil? || @note_count == 0 %>
<p><%= raw t('tag.contributors.no_contributors', :tag => params[:id]) %>:</p>
<% else %>
<table class="table">
Expand Down

0 comments on commit 34935fb

Please sign in to comment.