enforce coding convention

replaced every `and` by `&&` and every `or` by `||`
This commit is contained in:
Régis Hanol 2013-03-05 01:42:44 +01:00
parent f544e1d4f7
commit 239cbd2d58
39 changed files with 75 additions and 76 deletions

View file

@ -1,6 +1,6 @@
class Admin::ExportController < Admin::AdminController
def create
unless Export.is_export_running? or Import.is_import_running?
unless Export.is_export_running? || Import.is_import_running?
job_id = Jobs.enqueue( :exporter, user_id: current_user.id )
render json: success_json.merge( job_id: job_id )
else

View file

@ -223,7 +223,7 @@ class ApplicationController < ActionController::Base
end
def mini_profiler_enabled?
defined?(Rack::MiniProfiler) and current_user.try(:admin?)
defined?(Rack::MiniProfiler) && current_user.try(:admin?)
end
def authorize_mini_profiler
@ -250,8 +250,7 @@ class ApplicationController < ActionController::Base
def check_xhr
unless (controller_name == 'forums' || controller_name == 'user_open_ids')
# render 'default/empty' unless ((request.format && request.format.json?) or request.xhr?)
raise RenderEmpty.new unless ((request.format && request.format.json?) or request.xhr?)
raise RenderEmpty.new unless ((request.format && request.format.json?) || request.xhr?)
end
end

View file

@ -4,7 +4,7 @@ class ClicksController < ApplicationController
def track
requires_parameter(:url)
if params[:topic_id].present? or params[:post_id].present?
if params[:topic_id].present? || params[:post_id].present?
args = {url: params[:url], ip: request.remote_ip}
args[:user_id] = current_user.id if current_user.present?
args[:post_id] = params[:post_id].to_i if params[:post_id].present?

View file

@ -12,7 +12,7 @@ class EmailController < ApplicationController
@user = User.find_by_temporary_key(params[:key])
# Don't allow the use of a key while logged in as a different user
@user = nil if current_user.present? and (@user != current_user)
@user = nil if current_user.present? && (@user != current_user)
if @user.present?
@user.update_column(:email_digests, false)

View file

@ -10,7 +10,7 @@ class ListController < ApplicationController
list_opts = {page: params[:page]}
# html format means we need to farm exclude from the site options
if params[:format].blank? or params[:format] == "html"
if params[:format].blank? || params[:format] == "html"
#TODO objectify this stuff
SiteSetting.top_menu.split('|').each do |f|
s = f.split(",")
@ -35,7 +35,7 @@ class ListController < ApplicationController
list = nil
# If they choose uncategorized, return topics NOT in a category
if params[:category] == Slug.for(SiteSetting.uncategorized_name) or params[:category] == SiteSetting.uncategorized_name
if params[:category] == Slug.for(SiteSetting.uncategorized_name) || params[:category] == SiteSetting.uncategorized_name
list = query.list_uncategorized
else
@category = Category.where("slug = ? or id = ?", params[:category], params[:category].to_i).includes(:featured_users).first

View file

@ -12,7 +12,7 @@ class PostActionsController < ApplicationController
post_action = PostAction.act(current_user, @post, action.id, params[:message])
if post_action.blank? or post_action.errors.present?
if post_action.blank? || post_action.errors.present?
render_json_error(post_action)
else
# We need to reload or otherwise we are showing the old values on the front end

View file

@ -15,7 +15,7 @@ class SessionController < ApplicationController
if @user.present?
# If the site requires user approval and the user is not approved yet
if SiteSetting.must_approve_users? and !@user.approved?
if SiteSetting.must_approve_users? && !@user.approved?
render :json => {error: I18n.t("login.not_approved")}
return
end

View file

@ -25,7 +25,7 @@ class TopicsController < ApplicationController
create_topic_view
anonymous_etag(@topic_view.topic) do
redirect_to_correct_topic and return if slugs_do_not_match
redirect_to_correct_topic && return if slugs_do_not_match
View.create_for(@topic_view.topic, request.remote_ip, current_user)
track_visit_to_topic
perform_show_response

View file

@ -156,7 +156,7 @@ class Users::OmniauthCallbacksController < ApplicationController
user = user_open_id.user
# If we have to approve users
if SiteSetting.must_approve_users? and !user.approved?
if SiteSetting.must_approve_users? && !user.approved?
@data = {awaiting_approval: true}
else
log_on_user(user)
@ -222,7 +222,7 @@ class Users::OmniauthCallbacksController < ApplicationController
user = User.find_by_email(email)
if user
if SiteSetting.must_approve_users? and !user.approved?
if SiteSetting.must_approve_users? && !user.approved?
@data = {awaiting_approval: true}
else
log_on_user(user)

View file

@ -89,7 +89,7 @@ class UsersController < ApplicationController
else
# Contact the Discourse Hub server
email_given = (params[:email].present? or current_user.present?)
email_given = (params[:email].present? || current_user.present?)
available_locally = User.username_available?(params[:username])
global_match = false
available_globally, suggestion_from_discourse_hub = begin
@ -101,9 +101,9 @@ class UsersController < ApplicationController
end
end
if available_globally and available_locally
if available_globally && available_locally
render json: {available: true, global_match: (global_match ? true : false)}
elsif available_locally and !available_globally
elsif available_locally && !available_globally
if email_given
# Nickname and email do not match what's registered on the discourse hub.
render json: {available: false, global_match: false, suggestion: suggestion_from_discourse_hub}
@ -113,7 +113,7 @@ class UsersController < ApplicationController
# Don't give a suggestion until we get the email and try to match it with on the discourse hub.
render json: {available: false}
end
elsif available_globally and !available_locally
elsif available_globally && !available_locally
# Already registered on this site with the matching nickname and email address. Why are you signing up again?
render json: {available: false, suggestion: User.suggest_username(params[:username])}
else
@ -128,7 +128,7 @@ class UsersController < ApplicationController
def create
if params[:password_confirmation] != honeypot_value or params[:challenge] != challenge_value.try(:reverse)
if params[:password_confirmation] != honeypot_value || params[:challenge] != challenge_value.try(:reverse)
# Don't give any indication that we caught you in the honeypot
return render(:json => {success: true, active: false, message: I18n.t("login.activate_email", email: params[:email]) })
end
@ -145,7 +145,7 @@ class UsersController < ApplicationController
end
user.password_required! unless auth
DiscourseHub.register_nickname( user.username, user.email ) if user.valid? and SiteSetting.call_discourse_hub?
DiscourseHub.register_nickname( user.username, user.email ) if user.valid? && SiteSetting.call_discourse_hub?
if user.save
@ -174,7 +174,7 @@ class UsersController < ApplicationController
TwitterUserInfo.create(:user_id => user.id, :screen_name => auth[:twitter_screen_name], :twitter_user_id => auth[:twitter_user_id])
end
if auth[:facebook].present? and FacebookUserInfo.find_by_facebook_user_id(auth[:facebook][:facebook_user_id]).nil?
if auth[:facebook].present? && FacebookUserInfo.find_by_facebook_user_id(auth[:facebook][:facebook_user_id]).nil?
FacebookUserInfo.create!(auth[:facebook].merge(user_id: user.id))
end
@ -232,11 +232,11 @@ class UsersController < ApplicationController
if @user.blank?
flash[:error] = I18n.t('password_reset.no_token')
else
if request.put? and params[:password].present?
if request.put? && params[:password].present?
@user.password = params[:password]
if @user.save
if SiteSetting.must_approve_users? and !@user.approved?
if SiteSetting.must_approve_users? && !@user.approved?
@requires_approval = true
flash[:success] = I18n.t('password_reset.success_unapproved')
else

View file

@ -25,7 +25,7 @@ module ApplicationHelper
end
def mini_profiler_enabled?
defined?(Rack::MiniProfiler) and admin?
defined?(Rack::MiniProfiler) && admin?
end
def admin?

View file

@ -49,7 +49,7 @@ class UserNotifications < ActionMailer::Base
@markdown_linker = MarkdownLinker.new(Discourse.base_url)
# Don't send email unless there is content in it
if @new_topics.present? or @notifications.present?
if @new_topics.present? || @notifications.present?
mail to: user.email,
subject: I18n.t('user_notifications.digest.subject_template',
:site_name => @site_name,

View file

@ -206,7 +206,7 @@ class Post < ActiveRecord::Base
parent_raw = parent_post.raw.sub(/\[quote.+\/quote\]/m, '')
if raw[parent_raw] or (parent_raw.size < SHORT_POST_CHARS)
if raw[parent_raw] || (parent_raw.size < SHORT_POST_CHARS)
return cooked.sub(/\<aside.+\<\/aside\>/m, '')
end

View file

@ -123,7 +123,7 @@ class PostAction < ActiveRecord::Base
end
before_create do
raise AlreadyFlagged if is_flag? and PostAction.where(user_id: user_id,
raise AlreadyFlagged if is_flag? && PostAction.where(user_id: user_id,
post_id: post_id,
post_action_type_id: PostActionType.flag_types.values).exists?
end

View file

@ -155,7 +155,7 @@ class SiteSetting < ActiveRecord::Base
client_setting(:educate_until_posts, 2)
def self.call_discourse_hub?
self.enforce_global_nicknames? and self.discourse_org_access_key.present?
self.enforce_global_nicknames? && self.discourse_org_access_key.present?
end
def self.topic_title_length

View file

@ -272,7 +272,7 @@ class Topic < ActiveRecord::Base
Topic.transaction do
old_category = category
if category_id.present? and category_id != cat.id
if category_id.present? && category_id != cat.id
Category.update_all 'topic_count = topic_count - 1', ['id = ?', category_id]
end
@ -444,7 +444,7 @@ class Topic < ActiveRecord::Base
end
end
posted = if topic_user.present? and current_user.present?
posted = if topic_user.present? && current_user.present?
current_user if topic_user.posted?
end

View file

@ -528,7 +528,7 @@ class User < ActiveRecord::Base
end
def password_validator
if (@raw_password and @raw_password.length < 6) || (@password_required && !@raw_password)
if (@raw_password && @raw_password.length < 6) || (@password_required && !@raw_password)
errors.add(:password, "must be 6 letters or longer")
end
end

View file

@ -153,10 +153,10 @@ class PostSerializer < ApplicationSerializer
can_act: scope.post_can_act?(object, sym, taken_actions: post_actions)}
# The following only applies if you're logged in
if action_summary[:can_act] and scope.current_user.present?
if action_summary[:can_act] && scope.current_user.present?
action_summary[:can_clear_flags] = scope.is_admin? && PostActionType.flag_types.values.include?(id)
if post_actions.present? and post_actions.has_key?(id)
if post_actions.present? && post_actions.has_key?(id)
action_summary[:acted] = true
action_summary[:can_undo] = scope.can_delete?(post_actions[id])
end
@ -188,7 +188,7 @@ class PostSerializer < ApplicationSerializer
def include_link_counts?
return true if @single_post_link_counts.present?
@topic_view.present? and @topic_view.link_counts.present? and @topic_view.link_counts[object.id].present?
@topic_view.present? && @topic_view.link_counts.present? && @topic_view.link_counts[object.id].present?
end
def include_read?
@ -196,11 +196,11 @@ class PostSerializer < ApplicationSerializer
end
def include_reply_to_user?
object.quoteless? and object.reply_to_user
object.quoteless? && object.reply_to_user
end
def include_bookmarked?
post_actions.present? and post_actions.keys.include?(PostActionType.types[:bookmark])
post_actions.present? && post_actions.keys.include?(PostActionType.types[:bookmark])
end
private

View file

@ -9,7 +9,7 @@ class TopicListSerializer < ApplicationSerializer
end
def include_more_topics_url?
object.more_topics_url.present? and (object.topics.size == SiteSetting.topics_per_page)
object.more_topics_url.present? && (object.topics.size == SiteSetting.topics_per_page)
end
end

View file

@ -174,19 +174,19 @@ class TopicViewSerializer < ApplicationSerializer
end
def include_participants?
object.initial_load? and object.posts_count.present?
object.initial_load? && object.posts_count.present?
end
def suggested_topics
object.suggested_topics.topics
end
def include_suggested_topics?
at_bottom and object.suggested_topics.present?
at_bottom && object.suggested_topics.present?
end
# Whether we're at the bottom of a topic (last page)
def at_bottom
posts.present? and (@highest_number_in_posts == object.highest_post_number)
posts.present? && (@highest_number_in_posts == object.highest_post_number)
end
def highest_post_number

View file

@ -6,12 +6,12 @@ if defined?(Rack::MiniProfiler)
# For our app, let's just show mini profiler always, polling is chatty so nuke that
Rack::MiniProfiler.config.pre_authorize_cb = lambda do |env|
(env['HTTP_USER_AGENT'] !~ /iPad|iPhone|Nexus 7/) and
(env['PATH_INFO'] !~ /^\/message-bus/) and
(env['PATH_INFO'] !~ /topics\/timings/) and
(env['PATH_INFO'] !~ /assets/) and
(env['PATH_INFO'] !~ /jasmine/) and
(env['PATH_INFO'] !~ /users\/.*\/avatar/) and
(env['HTTP_USER_AGENT'] !~ /iPad|iPhone|Nexus 7/) &&
(env['PATH_INFO'] !~ /^\/message-bus/) &&
(env['PATH_INFO'] !~ /topics\/timings/) &&
(env['PATH_INFO'] !~ /assets/) &&
(env['PATH_INFO'] !~ /jasmine/) &&
(env['PATH_INFO'] !~ /users\/.*\/avatar/) &&
(env['PATH_INFO'] !~ /srv\/status/)
end
@ -27,7 +27,7 @@ if defined?(Rack::MiniProfiler)
inst = Class.new
class << inst
def start(name,id,payload)
if Rack::MiniProfiler.current and name !~ /(process_action.action_controller)|(render_template.action_view)/
if Rack::MiniProfiler.current && name !~ /(process_action.action_controller)|(render_template.action_view)/
@prf ||= {}
@prf[id] ||= []
@prf[id] << Rack::MiniProfiler.start_step("#{payload[:serializer] if name =~ /serialize.serializer/} #{name}")
@ -35,7 +35,7 @@ if defined?(Rack::MiniProfiler)
end
def finish(name,id,payload)
if Rack::MiniProfiler.current and name !~ /(process_action.action_controller)|(render_template.action_view)/
if Rack::MiniProfiler.current && name !~ /(process_action.action_controller)|(render_template.action_view)/
t = @prf[id].pop
@prf.delete id unless t
Rack::MiniProfiler.finish_step t

View file

@ -2,7 +2,7 @@ require "#{Rails.root}/lib/discourse_redis"
$redis = DiscourseRedis.new
if Rails.env.development? and !ENV['DO_NOT_FLUSH_REDIS']
if Rails.env.development? && !ENV['DO_NOT_FLUSH_REDIS']
puts "Flushing redis (development mode)"
$redis.flushall
end

View file

@ -1,6 +1,6 @@
# Check that the app is configured correctly. Raise some helpful errors if something is wrong.
if Rails.env.production? and ['localhost', 'production.localhost'].include?(Discourse.current_hostname)
if Rails.env.production? && ['localhost', 'production.localhost'].include?(Discourse.current_hostname)
puts <<END
Discourse.current_hostname = '#{Discourse.current_hostname}'

View file

@ -6,7 +6,7 @@ class DiscourseIIFE < Sprockets::Processor
path = context.pathname.to_s
# Only discourse or admin paths
return data unless (path =~ /\/javascripts\/discourse/ or path =~ /\/javascripts\/admin/)
return data unless (path =~ /\/javascripts\/discourse/ || path =~ /\/javascripts\/admin/)
# Ugh, ignore translations
return data if (path =~ /\/translations/)

View file

@ -24,7 +24,7 @@ module Export
end
def write_schema_info(args)
raise SchemaArgumentsError unless args[:source].present? and args[:version].present?
raise SchemaArgumentsError unless args[:source].present? && args[:version].present?
@schema_data = {
schema: {
@ -50,7 +50,7 @@ module Export
# TODO: write to multiple files as needed.
# one file per table? multiple files per table?
end while rows and rows.size > 0
end while rows && rows.size > 0
@table_data[table_name][:rows].flatten!(1)
@table_data[table_name][:row_count] = @table_data[table_name][:rows].size

View file

@ -25,7 +25,7 @@ class ActiveRecord::Base
begin
yield
rescue ActiveRecord::StatementInvalid => e
if e.message =~ /deadlock detected/ and (retries.nil? || retries > 0)
if e.message =~ /deadlock detected/ && (retries.nil? || retries > 0)
retry_lock_error(retries ? retries - 1 : nil, &block)
else
raise e

View file

@ -345,7 +345,7 @@ class Guardian
when :like
return false if post.user == @user
when :vote then
return false if opts[:voted_in_topic] and post.topic.has_meta_data_boolean?(:single_vote)
return false if opts[:voted_in_topic] && post.topic.has_meta_data_boolean?(:single_vote)
end
return true

View file

@ -3,7 +3,7 @@ module ImageSizer
# Resize an image to the aspect ratio we want
def self.resize(width, height)
max_width = SiteSetting.max_image_width.to_f
return nil if width.blank? or height.blank?
return nil if width.blank? || height.blank?
w = width.to_f
h = height.to_f

View file

@ -19,7 +19,7 @@ module Jobs
opts = opts.with_indifferent_access
if opts.delete(:sync_exec)
if opts.has_key?(:current_site_id) and opts[:current_site_id] != RailsMultisite::ConnectionManagement.current_db
if opts.has_key?(:current_site_id) && opts[:current_site_id] != RailsMultisite::ConnectionManagement.current_db
raise ArgumentError.new("You can't connect to another database when executing a job synchronously.")
else
return execute(opts)

View file

@ -125,8 +125,8 @@ module Jobs
end
def set_schema_info(arg)
if arg[:source] and arg[:source].downcase == 'discourse'
if arg[:version] and arg[:version] <= Export.current_schema_version
if arg[:source] && arg[:source].downcase == 'discourse'
if arg[:version] && arg[:version] <= Export.current_schema_version
@export_schema_version = arg[:version]
if arg[:table_count] == ordered_models_for_import.size
true
@ -210,7 +210,7 @@ module Jobs
# The indexdef statements don't create the primary keys, so we need to find the primary key and do it ourselves.
pkey_index_def = @index_definitions[model.table_name].find { |ixdef| ixdef =~ / ([\S]{1,}_pkey) / }
if pkey_index_def and pkey_index_name = / ([\S]{1,}_pkey) /.match(pkey_index_def)[1]
if pkey_index_def && pkey_index_name = / ([\S]{1,}_pkey) /.match(pkey_index_def)[1]
model.exec_sql( "ALTER TABLE ONLY #{model.table_name} ADD PRIMARY KEY USING INDEX #{pkey_index_name}" )
end
@ -263,9 +263,9 @@ module Jobs
def send_notification
# Doesn't work. "WARNING: Can't mass-assign protected attributes: created_at"
# Still a problem with the activerecord schema_cache I think.
# if @user_info and @user_info[:user_id]
# if @user_info && @user_info[:user_id]
# user = User.where(id: @user_info[:user_id]).first
# if user and user.email == @user_info[:email]
# if user && user.email == @user_info[:email]
# SystemMessage.new(user).create('import_succeeded')
# end
# end

View file

@ -15,7 +15,7 @@ module Jobs
user = User.where(id: args[:user_id]).first
return unless user.present?
seen_recently = (user.last_seen_at.present? and user.last_seen_at > SiteSetting.email_time_window_mins.minutes.ago)
seen_recently = (user.last_seen_at.present? && user.last_seen_at > SiteSetting.email_time_window_mins.minutes.ago)
email_args = {}

View file

@ -26,7 +26,7 @@ module Oneboxer
@template = 'user'
when 'topics'
if route[:post_number].present? and route[:post_number].to_i > 1
if route[:post_number].present? && route[:post_number].to_i > 1
# Post Link
post = Post.where(topic_id: route[:topic_id], post_number: route[:post_number].to_i).first
Guardian.new.ensure_can_see!(post)

View file

@ -13,7 +13,7 @@ module Oneboxer
# A site is supposed to supply all the basic og attributes, but some don't (like deviant art)
# If it just has image and no title, embed it as an image.
return BaseOnebox.image_html(@opts['image'], nil, @url) if @opts['image'].present? and @opts['title'].blank?
return BaseOnebox.image_html(@opts['image'], nil, @url) if @opts['image'].present? && @opts['title'].blank?
@opts['title'] ||= @opts['description']
return nil if @opts['title'].blank?

View file

@ -41,7 +41,7 @@ module Oneboxer
unless paras.empty?
cnt = 0
while text.length < MAX_TEXT and cnt <= 3
while text.length < MAX_TEXT && cnt <= 3
text << " " unless cnt == 0
paragraph = paras[cnt].inner_text[0..MAX_TEXT]
paragraph.gsub!(/\[\d+\]/mi, "")

View file

@ -91,7 +91,7 @@ class PostRevisor
# If found, update its description
body = @post.cooked
matches = body.scan(/\<p\>(.*)\<\/p\>/)
if matches and matches[0] and matches[0][0]
if matches && matches[0] && matches[0][0]
new_description = matches[0][0]
new_description = nil if new_description == I18n.t("category.replace_paragraph")
category.update_column(:description, new_description)

View file

@ -47,7 +47,7 @@ class RateLimiter
rate_limiter = send(limiter_method)
return unless rate_limiter.present?
if @performed.present? and @performed[limiter_method]
if @performed.present? && @performed[limiter_method]
rate_limiter.rollback!
@performed[limiter_method] = false
end

View file

@ -40,7 +40,7 @@ class TextSentinel
return false if @text.blank? || @text.strip.blank?
# Entropy check if required
return false if @opts[:min_entropy].present? and (entropy < @opts[:min_entropy])
return false if @opts[:min_entropy].present? && (entropy < @opts[:min_entropy])
# We don't have a comprehensive list of symbols, but this will eliminate some noise
non_symbols = @text.gsub(TextSentinel.non_symbols_regexp, '').size
@ -48,10 +48,10 @@ class TextSentinel
# Don't allow super long strings without spaces
return false if @opts[:max_word_length] and @text =~ /\w{#{@opts[:max_word_length]},}(\s|$)/
return false if @opts[:max_word_length] && @text =~ /\w{#{@opts[:max_word_length]},}(\s|$)/
# We don't allow all upper case content in english
return false if (@text =~ /[A-Z]+/) and (@text == @text.upcase)
return false if (@text =~ /[A-Z]+/) && (@text == @text.upcase)
true
end

View file

@ -11,7 +11,7 @@ class TopicView
# Special case: If the topic is private and the user isn't logged in, ask them
# to log in!
if @topic.present? and @topic.private_message? and user.blank?
if @topic.present? && @topic.private_message? && user.blank?
raise Discourse::NotLoggedIn.new
end
@ -52,7 +52,7 @@ class TopicView
def next_page
last_post = @posts.last
if last_post.present? and (@topic.highest_post_number > last_post.post_number)
if last_post.present? && (@topic.highest_post_number > last_post.post_number)
(@posts[0].post_number / SiteSetting.posts_per_page) + 1
end
end

View file

@ -28,7 +28,7 @@ describe Jobs do
it "should enqueue with the correct database id when the current_site_id option is given" do
Sidekiq::Client.expects(:enqueue).with do |arg1, arg2|
arg2[:current_site_id] == 'test_db' and arg2[:sync_exec].nil?
arg2[:current_site_id] == 'test_db' && arg2[:sync_exec].nil?
end
Jobs.enqueue(:process_post, post_id: 1, current_site_id: 'test_db')
end