DEV: Enable `Style/SingleLineMethods` and `Style/Semicolon` in Rubocop (#6717)

This commit is contained in:
David Taylor 2018-12-04 03:48:13 +00:00 committed by Guo Xiang Tan
parent 56948896ff
commit 9248ad1905
30 changed files with 171 additions and 72 deletions

View File

@ -114,3 +114,10 @@ Layout/AlignHash:
Bundler/OrderedGems:
Enabled: false
Style/SingleLineMethods:
Enabled: true
Style/Semicolon:
Enabled: true
AllowAsExpressionSeparator: true

View File

@ -575,7 +575,7 @@ class UserNotifications < ActionMailer::Base
if SiteSetting.private_email?
message = I18n.t('system_messages.contents_hidden')
else
message = email_post_markdown(post) + (reached_limit ? "\n\n#{I18n.t "user_notifications.reached_limit", count: SiteSetting.max_emails_per_day_per_user}" : "");
message = email_post_markdown(post) + (reached_limit ? "\n\n#{I18n.t "user_notifications.reached_limit", count: SiteSetting.max_emails_per_day_per_user}" : "")
end
first_footer_classes = "hilight"

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true
require_dependency 'enum_site_setting';
require_dependency 'enum_site_setting'
class BackupLocationSiteSetting < EnumSiteSetting
LOCAL ||= "local"

View File

@ -1,6 +1,6 @@
class QueuedPost < ActiveRecord::Base
class InvalidStateTransition < StandardError; end;
class InvalidStateTransition < StandardError; end
belongs_to :user
belongs_to :topic

View File

@ -6,7 +6,7 @@ class CreateEmbeddableHosts < ActiveRecord::Migration[4.2]
t.timestamps null: false
end
category_id = 0;
category_id = 0
category_row = execute("SELECT c.id FROM categories AS c
INNER JOIN site_settings AS s ON s.value = c.name
WHERE s.name = 'embed_category'")

View File

@ -5,8 +5,12 @@ module Autospec
class QunitRunner < BaseRunner
WATCHERS = {}
def self.watch(pattern, &blk); WATCHERS[pattern] = blk; end
def watchers; WATCHERS; end
def self.watch(pattern, &blk)
WATCHERS[pattern] = blk
end
def watchers
WATCHERS
end
# Discourse specific
watch(%r{^app/assets/javascripts/discourse/(.+)\.js.es6$}) { |m| "test/javascripts/#{m[1]}-test.js.es6" }
@ -14,8 +18,12 @@ module Autospec
watch(%r{^test/javascripts/.+\.js.es6$})
RELOADERS = Set.new
def self.reload(pattern); RELOADERS << pattern; end
def reloaders; RELOADERS; end
def self.reload(pattern)
RELOADERS << pattern
end
def reloaders
RELOADERS
end
# Discourse specific
reload(%r{^test/javascripts/fixtures/.+_fixtures\.js(\.es6)?$})

View File

@ -3,8 +3,12 @@ module Autospec
class RspecRunner < BaseRunner
WATCHERS = {}
def self.watch(pattern, &blk); WATCHERS[pattern] = blk; end
def watchers; WATCHERS; end
def self.watch(pattern, &blk)
WATCHERS[pattern] = blk
end
def watchers
WATCHERS
end
# Discourse specific
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/components/#{m[1]}_spec.rb" }
@ -30,8 +34,12 @@ module Autospec
watch(%r{^(plugins/.*)/lib/(.*)\.rb}) { |m| "#{m[1]}/spec/lib/#{m[2]}_spec.rb" }
RELOADERS = Set.new
def self.reload(pattern); RELOADERS << pattern; end
def reloaders; RELOADERS; end
def self.reload(pattern)
RELOADERS << pattern
end
def reloaders
RELOADERS
end
# we are using a simple runner at the moment, whole idea of using a reloader is no longer needed
watch("spec/rails_helper.rb")

View File

@ -28,7 +28,7 @@ module Tilt
ctx = MiniRacer::Context.new(timeout: 15000)
ctx.eval("var self = this; #{File.read("#{Rails.root}/vendor/assets/javascripts/babel.js")}")
ctx.eval(File.read(Ember::Source.bundled_path_for('ember-template-compiler.js')))
ctx.eval("module = {}; exports = {};");
ctx.eval("module = {}; exports = {};")
ctx.attach("rails.logger.info", proc { |err| Rails.logger.info(err.to_s) })
ctx.attach("rails.logger.error", proc { |err| Rails.logger.error(err.to_s) })
ctx.eval <<JS

View File

@ -19,17 +19,39 @@ class Guardian
include TagGuardian
class AnonymousUser
def blank?; true; end
def admin?; false; end
def staff?; false; end
def moderator?; false; end
def approved?; false; end
def staged?; false; end
def silenced?; false; end
def secure_category_ids; []; end
def topic_create_allowed_category_ids; []; end
def has_trust_level?(level); false; end
def email; nil; end
def blank?
true
end
def admin?
false
end
def staff?
false
end
def moderator?
false
end
def approved?
false
end
def staged?
false
end
def silenced?
false
end
def secure_category_ids
[]
end
def topic_create_allowed_category_ids
[]
end
def has_trust_level?(level)
false
end
def email
nil
end
end
attr_accessor :can_see_emails

View File

@ -3,7 +3,9 @@ require "nokogiri"
class HtmlToMarkdown
class Block < Struct.new(:name, :head, :body, :opened, :markdown)
def initialize(name, head = "", body = "", opened = false, markdown = ""); super; end
def initialize(name, head = "", body = "", opened = false, markdown = "")
super
end
end
def initialize(html, opts = {})

View File

@ -50,7 +50,9 @@ class Migration::SafeMigrate
super
rescue => e
if e.cause.is_a?(Discourse::InvalidMigration)
def e.cause; nil; end
def e.cause
nil
end
def e.backtrace
super.reject do |frame|
frame =~ /safe_migrate\.rb/ || frame =~ /schema_migration_details\.rb/

View File

@ -32,7 +32,7 @@ module Stylesheet
end
def self.compile(stylesheet, filename, options = {})
source_map_file = options[:source_map_file] || "#{filename.sub(".scss", "")}.css.map";
source_map_file = options[:source_map_file] || "#{filename.sub(".scss", "")}.css.map"
engine = SassC::Engine.new(stylesheet,
importer: Importer,

View File

@ -12,7 +12,7 @@ class AllowUserLocaleEnabledValidator
end
def error_message
I18n.t("site_settings.errors.user_locale_not_enabled");
I18n.t("site_settings.errors.user_locale_not_enabled")
end
end

View File

@ -183,14 +183,28 @@ class BulkImport::Base
@raw_connection.exec("SELECT setval('#{PostAction.sequence_name}', #{@last_post_action_id})") if @last_post_action_id > 0
end
def group_id_from_imported_id(id); @groups[id.to_s]; end
def user_id_from_imported_id(id); @users[id.to_s]; end
def category_id_from_imported_id(id); @categories[id.to_s]; end
def topic_id_from_imported_id(id); @topics[id.to_s]; end
def post_id_from_imported_id(id); @posts[id.to_s]; end
def group_id_from_imported_id(id)
@groups[id.to_s]
end
def user_id_from_imported_id(id)
@users[id.to_s]
end
def category_id_from_imported_id(id)
@categories[id.to_s]
end
def topic_id_from_imported_id(id)
@topics[id.to_s]
end
def post_id_from_imported_id(id)
@posts[id.to_s]
end
def post_number_from_imported_id(id); @post_number_by_post_id[post_id_from_imported_id(id)]; end
def topic_id_from_imported_post_id(id); @topic_id_by_post_id[post_id_from_imported_id(id)]; end
def post_number_from_imported_id(id)
@post_number_by_post_id[post_id_from_imported_id(id)]
end
def topic_id_from_imported_post_id(id)
@topic_id_by_post_id[post_id_from_imported_id(id)]
end
GROUP_COLUMNS ||= %i{
id name title bio_raw bio_cooked created_at updated_at
@ -250,7 +264,9 @@ class BulkImport::Base
topic_id tag_id created_at updated_at
}
def create_groups(rows, &block); create_records(rows, "group", GROUP_COLUMNS, &block); end
def create_groups(rows, &block)
create_records(rows, "group", GROUP_COLUMNS, &block)
end
def create_users(rows, &block)
@imported_usernames = {}
@ -273,16 +289,36 @@ class BulkImport::Base
end
end
def create_user_emails(rows, &block) create_records(rows, "user_email", USER_EMAIL_COLUMNS, &block); end
def create_user_stats(rows, &block) create_records(rows, "user_stat", USER_STAT_COLUMNS, &block); end
def create_user_profiles(rows, &block); create_records(rows, "user_profile", USER_PROFILE_COLUMNS, &block); end
def create_group_users(rows, &block); create_records(rows, "group_user", GROUP_USER_COLUMNS, &block); end
def create_categories(rows, &block); create_records(rows, "category", CATEGORY_COLUMNS, &block); end
def create_topics(rows, &block); create_records(rows, "topic", TOPIC_COLUMNS, &block); end
def create_posts(rows, &block); create_records(rows, "post", POST_COLUMNS, &block); end
def create_post_actions(rows, &block); create_records(rows, "post_action", POST_ACTION_COLUMNS, &block); end
def create_topic_allowed_users(rows, &block); create_records(rows, "topic_allowed_user", TOPIC_ALLOWED_USER_COLUMNS, &block); end
def create_topic_tags(rows, &block); create_records(rows, "topic_tag", TOPIC_TAG_COLUMNS, &block); end
def create_user_emails(rows, &block)
create_records(rows, "user_email", USER_EMAIL_COLUMNS, &block)
end
def create_user_stats(rows, &block)
create_records(rows, "user_stat", USER_STAT_COLUMNS, &block)
end
def create_user_profiles(rows, &block)
create_records(rows, "user_profile", USER_PROFILE_COLUMNS, &block)
end
def create_group_users(rows, &block)
create_records(rows, "group_user", GROUP_USER_COLUMNS, &block)
end
def create_categories(rows, &block)
create_records(rows, "category", CATEGORY_COLUMNS, &block)
end
def create_topics(rows, &block)
create_records(rows, "topic", TOPIC_COLUMNS, &block)
end
def create_posts(rows, &block)
create_records(rows, "post", POST_COLUMNS, &block)
end
def create_post_actions(rows, &block)
create_records(rows, "post_action", POST_ACTION_COLUMNS, &block)
end
def create_topic_allowed_users(rows, &block)
create_records(rows, "topic_allowed_user", TOPIC_ALLOWED_USER_COLUMNS, &block)
end
def create_topic_tags(rows, &block)
create_records(rows, "topic_tag", TOPIC_TAG_COLUMNS, &block)
end
def process_group(group)
@groups[group[:imported_id].to_s] = group[:id] = @last_group_id += 1
@ -339,7 +375,7 @@ class BulkImport::Base
end
def process_user_email(user_email)
user_email[:id] = @last_user_email_id += 1;
user_email[:id] = @last_user_email_id += 1
user_email[:user_id] = @users[user_email[:imported_user_id].to_s]
user_email[:primary] = true
user_email[:created_at] ||= NOW

View File

@ -1,7 +1,7 @@
ctx = MiniRacer::Context.new(timeout: 15000)
ctx.eval("var self = this; #{File.read("#{Rails.root}/vendor/assets/javascripts/babel.js")}")
ctx.eval(File.read(Ember::Source.bundled_path_for('ember-template-compiler.js')))
ctx.eval("module = {}; exports = {};");
ctx.eval("module = {}; exports = {};")
ctx.attach("rails.logger.info", proc { |err| puts(">> #{err.to_s}") })
ctx.attach("rails.logger.error", proc { |err| puts(">> #{err.to_s}") })
ctx.eval <<JS
@ -20,5 +20,5 @@ ctx.eval(js)
if ARGV[0].present?
source = File.read(ARGV[0])
js_source = ::JSON.generate(source, quirks_mode: true)
puts ctx.eval("exports.compile(#{js_source})");
puts ctx.eval("exports.compile(#{js_source})")
end

View File

@ -65,7 +65,7 @@ class ImportScripts::Bespoke < ImportScripts::Base
first = true
row = nil
current_row = "";
current_row = ""
double_quote_count = 0
File.open(filename).each_line do |line|

View File

@ -52,7 +52,7 @@ class ImportScripts::DrupalQA < ImportScripts::Drupal
GROUP BY n.nid, n.title, n.uid, n.created, f.body_value
LIMIT #{batch_size}
OFFSET #{offset}
", cache_rows: false);
", cache_rows: false)
break if results.size < 1

View File

@ -67,7 +67,7 @@ class ImportScripts::Jive < ImportScripts::Base
first = true
row = nil
current_row = "";
current_row = ""
double_quote_count = 0
File.open(filename).each_line do |line|

View File

@ -1019,7 +1019,7 @@ SQL
end
def html_for_attachments(user_id, files)
html = "";
html = ""
files.each do |file|
upload, filename = find_upload(user_id, file["attachment_id"], file["file_name"])

View File

@ -172,7 +172,7 @@ class ImportScripts::Nabble < ImportScripts::Base
txt.gsub! /\<quote author="(.*?)"\>/, '[quote="\1"]'
txt.gsub! /\<\/quote\>/, '[/quote]'
txt.gsub!(/\<raw\>(.*?)\<\/raw\>/m) do |match|
c = Regexp.last_match[1].indent(4);
c = Regexp.last_match[1].indent(4)
"\n#{c}\n"
end

View File

@ -53,6 +53,6 @@ module ImportScripts::PhpBB3
end
end
class UnsupportedVersionError < RuntimeError;
class UnsupportedVersionError < RuntimeError
end
end

View File

@ -19,7 +19,7 @@ HBS
ctx = MiniRacer::Context.new(timeout: 15000)
ctx.eval("var self = this; #{File.read("#{Rails.root}/vendor/assets/javascripts/babel.js")}")
ctx.eval(File.read(Ember::Source.bundled_path_for('ember-template-compiler.js')))
ctx.eval("module = {}; exports = {};");
ctx.eval("module = {}; exports = {};")
ctx.attach("rails.logger.info", proc { |err| puts(err.to_s) })
ctx.attach("rails.logger.error", proc { |err| puts(err.to_s) })
ctx.eval <<JS
@ -35,4 +35,4 @@ ctx.eval(source)
js_source = ::JSON.generate(template, quirks_mode: true)
puts ctx.eval("exports.compile(#{js_source})");
puts ctx.eval("exports.compile(#{js_source})")

View File

@ -3,7 +3,9 @@ require 'rails_helper'
describe Auth::ManagedAuthenticator do
let(:authenticator) {
Class.new(described_class) do
def name; "myauth" end
def name
"myauth"
end
end.new
}
@ -55,8 +57,12 @@ describe Auth::ManagedAuthenticator do
it 'does not work when disabled' do
authenticator = Class.new(described_class) do
def name; "myauth" end
def can_connect_existing_user?; false end
def name
"myauth"
end
def can_connect_existing_user?
false
end
end.new
result = authenticator.after_authenticate(hash, existing_account: user2)
expect(result.user.id).to eq(user1.id)
@ -81,8 +87,12 @@ describe Auth::ManagedAuthenticator do
it 'does not match if match_by_email is false' do
authenticator = Class.new(described_class) do
def name; "myauth" end
def match_by_email; false end
def name
"myauth"
end
def match_by_email
false
end
end.new
user = Fabricate(:user, email: "awesome@example.com")
result = authenticator.after_authenticate(hash)

View File

@ -1,4 +1,4 @@
require 'rails_helper';
require 'rails_helper'
require 'guardian'
require_dependency 'post_destroyer'

View File

@ -36,7 +36,9 @@ describe Plugin::Instance do
class TroutPlugin < Plugin::Instance
attr_accessor :enabled
def enabled?; @enabled; end
def enabled?
@enabled
end
end
before do

View File

@ -1118,13 +1118,13 @@ HTML
it "supports url bbcode" do
cooked = PrettyText.cook "[url]http://sam.com[/url]"
html = '<p><a href="http://sam.com" data-bbcode="true" rel="nofollow noopener">http://sam.com</a></p>';
html = '<p><a href="http://sam.com" data-bbcode="true" rel="nofollow noopener">http://sam.com</a></p>'
expect(cooked).to eq(html)
end
it "supports nesting tags in url" do
cooked = PrettyText.cook("[url=http://sam.com][b]I am sam[/b][/url]")
html = '<p><a href="http://sam.com" data-bbcode="true" rel="nofollow noopener"><span class="bbcode-b">I am sam</span></a></p>';
html = '<p><a href="http://sam.com" data-bbcode="true" rel="nofollow noopener"><span class="bbcode-b">I am sam</span></a></p>'
expect(cooked).to eq(html)
end

View File

@ -86,7 +86,9 @@ describe ContentSecurityPolicy do
it 'can be extended by plugins' do
plugin = Class.new(Plugin::Instance) do
attr_accessor :enabled
def enabled?; @enabled; end
def enabled?
@enabled
end
end.new(nil, "#{Rails.root}/spec/fixtures/plugins/csp_extension/plugin.rb")
plugin.activate!

View File

@ -240,7 +240,7 @@ describe TopicUser do
create_post(
archetype: Archetype.private_message,
target_usernames: target_user.username
);
)
end
let(:topic) { post.topic }

View File

@ -184,7 +184,7 @@ describe CategoriesController do
c3 = Fabricate(:category)
c4 = Fabricate(:category)
if c3.id < c2.id
tmp = c3; c2 = c3; c3 = tmp;
tmp = c3; c2 = c3; c3 = tmp
end
c1.position = 8
c2.position = 6

View File

@ -470,7 +470,7 @@ describe UsersController do
get "/u/admin-login/#{email_token.token}"
expect(response).not_to redirect_to('/')
expect(session[:current_user_id]).not_to eq(admin.id)
expect(response.body).to include(I18n.t('login.second_factor_description'));
expect(response.body).to include(I18n.t('login.second_factor_description'))
end
describe 'invalid 2 factor token' do
@ -483,8 +483,8 @@ describe UsersController do
}
expect(response.status).to eq(200)
expect(response.body).to include(I18n.t('login.second_factor_description'));
expect(response.body).to include(I18n.t('login.invalid_second_factor_code'));
expect(response.body).to include(I18n.t('login.second_factor_description'))
expect(response.body).to include(I18n.t('login.invalid_second_factor_code'))
end
end