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

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

From 9248ad19052459cea8ab58846e0df7b5e771f0b4 Mon Sep 17 00:00:00 2001
From: David Taylor <david@taylorhq.com>
Date: Tue, 4 Dec 2018 03:48:13 +0000
Subject: [PATCH] DEV: Enable `Style/SingleLineMethods` and `Style/Semicolon`
 in Rubocop (#6717)


diff --git a/.rubocop.yml b/.rubocop.yml
index e28a087..9f2254d 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -114,3 +114,10 @@ Layout/AlignHash:
 
 Bundler/OrderedGems:
   Enabled: false
+
+Style/SingleLineMethods:
+  Enabled: true
+
+Style/Semicolon:
+  Enabled: true
+  AllowAsExpressionSeparator: true
\ No newline at end of file
diff --git a/app/mailers/user_notifications.rb b/app/mailers/user_notifications.rb
index fec948e..2d35370 100644
--- a/app/mailers/user_notifications.rb
+++ b/app/mailers/user_notifications.rb
@@ -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"
diff --git a/app/models/backup_location_site_setting.rb b/app/models/backup_location_site_setting.rb
index aef3c89..4763c3b 100644
--- a/app/models/backup_location_site_setting.rb
+++ b/app/models/backup_location_site_setting.rb
@@ -1,6 +1,6 @@
 # frozen_string_literal: true
 
-require_dependency 'enum_site_setting';
+require_dependency 'enum_site_setting'
 
 class BackupLocationSiteSetting < EnumSiteSetting
   LOCAL ||= "local"
diff --git a/app/models/queued_post.rb b/app/models/queued_post.rb
index a4067f8..92cc688 100644
--- a/app/models/queued_post.rb
+++ b/app/models/queued_post.rb
@@ -1,6 +1,6 @@
 class QueuedPost < ActiveRecord::Base
 
-  class InvalidStateTransition < StandardError; end;
+  class InvalidStateTransition < StandardError; end
 
   belongs_to :user
   belongs_to :topic
diff --git a/db/migrate/20150818190757_create_embeddable_hosts.rb b/db/migrate/20150818190757_create_embeddable_hosts.rb
index c5ae2ac..fc52e7b 100644
--- a/db/migrate/20150818190757_create_embeddable_hosts.rb
+++ b/db/migrate/20150818190757_create_embeddable_hosts.rb
@@ -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'")
diff --git a/lib/autospec/qunit_runner.rb b/lib/autospec/qunit_runner.rb
index 6598207..91e3d39 100644
--- a/lib/autospec/qunit_runner.rb
+++ b/lib/autospec/qunit_runner.rb
@@ -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)?$})
diff --git a/lib/autospec/rspec_runner.rb b/lib/autospec/rspec_runner.rb
index e8848c6..64cb030 100644
--- a/lib/autospec/rspec_runner.rb
+++ b/lib/autospec/rspec_runner.rb
@@ -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")
diff --git a/lib/es6_module_transpiler/tilt/es6_module_transpiler_template.rb b/lib/es6_module_transpiler/tilt/es6_module_transpiler_template.rb
index 10802fe..f45884f 100644
--- a/lib/es6_module_transpiler/tilt/es6_module_transpiler_template.rb
+++ b/lib/es6_module_transpiler/tilt/es6_module_transpiler_template.rb
@@ -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
diff --git a/lib/guardian.rb b/lib/guardian.rb
index 0f8d568..f06ec7c 100644
--- a/lib/guardian.rb
+++ b/lib/guardian.rb
@@ -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
diff --git a/lib/html_to_markdown.rb b/lib/html_to_markdown.rb
index 3f362e6..a213611 100644
--- a/lib/html_to_markdown.rb
+++ b/lib/html_to_markdown.rb
@@ -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 = {})
diff --git a/lib/migration/safe_migrate.rb b/lib/migration/safe_migrate.rb
index d777f09..4ec48aa 100644
--- a/lib/migration/safe_migrate.rb
+++ b/lib/migration/safe_migrate.rb
@@ -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/
diff --git a/lib/stylesheet/compiler.rb b/lib/stylesheet/compiler.rb
index 5aff8df..8cba8e6 100644
--- a

GitHub

1 Like

Except for AnonymousUser change I am on board with this as being positive.

That said, I can live with this one slight uglification for the greater good so :+1:

1 Like