diff --git a/.rubocop.yml b/.rubocop.yml index ab27e3b3..dc25f913 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,8 +6,7 @@ require: - ./extras/prohibit_safe_navigation - ./extras/prohibit_form_for_and_form_tag -Rails: - Enabled: true + - rubocop-rails AllCops: Include: - '**/*.rb' @@ -43,7 +42,7 @@ Layout/EmptyLinesAroundExceptionHandlingKeywords: Enabled: false Layout/EndAlignment: EnforcedStyleAlignWith: variable -Layout/IndentHash: +Layout/IndentFirstHashElement: EnforcedStyle: consistent Layout/MultilineMethodCallBraceLayout: Enabled: false @@ -97,10 +96,6 @@ Naming/VariableName: Enabled: false # Performance -Performance/Casecmp: - Enabled: false -Performance/RedundantMatch: - Enabled: false # Rails Rails/Blank: @@ -115,6 +110,8 @@ Rails/Present: UnlessBlank: false Rails/SkipsModelValidations: Enabled: false +Rails/HelperInstanceVariable: + Enabled: false # Security diff --git a/Gemfile b/Gemfile index 1deb93a0..0122f35a 100644 --- a/Gemfile +++ b/Gemfile @@ -50,6 +50,7 @@ group :test, :development do gem "rspec-rails" gem "factory_bot_rails" gem "rubocop", require: false + gem "rubocop-rails", require: false gem "rubocop-rspec", require: false gem "faker" gem "byebug" diff --git a/Gemfile.lock b/Gemfile.lock index ee2f98b2..b2bb1164 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -100,7 +100,7 @@ GEM htmlentities (4.3.4) i18n (1.6.0) concurrent-ruby (~> 1.0) - jaro_winkler (1.5.1) + jaro_winkler (1.5.2) jquery-rails (4.3.3) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) @@ -128,10 +128,9 @@ GEM nokogiri (1.10.1) mini_portile2 (~> 2.4.0) oauth (0.5.4) - parallel (1.12.1) - parser (2.5.3.0) + parallel (1.17.0) + parser (2.6.3.0) ast (~> 2.4.0) - powerpack (0.1.2) public_suffix (3.0.3) rack (2.0.6) rack-test (1.1.0) @@ -189,19 +188,21 @@ GEM rspec-mocks (~> 3.8.0) rspec-support (~> 3.8.0) rspec-support (3.8.0) - rubocop (0.60.0) + rubocop (0.71.0) jaro_winkler (~> 1.5.1) parallel (~> 1.10) - parser (>= 2.5, != 2.5.1.1) - powerpack (~> 0.1) + parser (>= 2.6) rainbow (>= 2.2.2, < 4.0) ruby-progressbar (~> 1.7) - unicode-display_width (~> 1.4.0) - rubocop-rspec (1.30.1) + unicode-display_width (>= 1.4.0, < 1.7) + rubocop-rails (2.0.1) + rack (>= 1.1) + rubocop (>= 0.70.0) + rubocop-rspec (1.33.0) rubocop (>= 0.60.0) ruby-enum (0.7.2) i18n - ruby-progressbar (1.10.0) + ruby-progressbar (1.10.1) ruby_dep (1.5.0) ruumba (0.1.8) rubocop @@ -226,7 +227,7 @@ GEM thread_safe (~> 0.1) uglifier (4.1.20) execjs (>= 0.3.0, < 3) - unicode-display_width (1.4.0) + unicode-display_width (1.6.0) unicorn (5.4.1) kgio (~> 2.6) raindrops (~> 0.7) @@ -268,6 +269,7 @@ DEPENDENCIES rqrcode rspec-rails rubocop + rubocop-rails rubocop-rspec ruumba scenic diff --git a/app/models/comment.rb b/app/models/comment.rb index 33e2fd68..7df9f426 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -9,13 +9,13 @@ class Comment < ApplicationRecord belongs_to :parent_comment, :class_name => "Comment", :inverse_of => false, - :required => false + :optional => true has_one :moderation, :class_name => "Moderation", :inverse_of => :comment, :dependent => :destroy belongs_to :hat, - :required => false + :optional => true has_many :taggings, through: :story attr_accessor :current_vote, :previewing, :indent_level diff --git a/app/models/invitation.rb b/app/models/invitation.rb index 8281844a..39d8605f 100644 --- a/app/models/invitation.rb +++ b/app/models/invitation.rb @@ -1,6 +1,6 @@ class Invitation < ApplicationRecord belongs_to :user - belongs_to :new_user, class_name: 'User', inverse_of: nil, required: false + belongs_to :new_user, class_name: 'User', inverse_of: nil, optional: true scope :used, -> { where.not(:used_at => nil) } scope :unused, -> { where(:used_at => nil) } diff --git a/app/models/message.rb b/app/models/message.rb index 1e1716f5..fa3e9b14 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -8,7 +8,7 @@ class Message < ApplicationRecord :foreign_key => "author_user_id", :inverse_of => :sent_messages belongs_to :hat, - :required => false + :optional => true attribute :mod_note, :boolean attr_reader :recipient_username diff --git a/app/models/moderation.rb b/app/models/moderation.rb index b45a2cb9..f6801708 100644 --- a/app/models/moderation.rb +++ b/app/models/moderation.rb @@ -3,15 +3,15 @@ class Moderation < ApplicationRecord :class_name => "User", :foreign_key => "moderator_user_id", :inverse_of => :moderations, - :required => false + :optional => true belongs_to :comment, - :required => false + :optional => true belongs_to :story, - :required => false + :optional => true belongs_to :tag, - :required => false + :optional => true belongs_to :user, - :required => false + :optional => true scope :for, ->(user) { left_outer_joins(:story, :comment) .where(" diff --git a/app/models/story.rb b/app/models/story.rb index 13562985..c705b151 100644 --- a/app/models/story.rb +++ b/app/models/story.rb @@ -4,7 +4,7 @@ class Story < ApplicationRecord :class_name => "Story", :foreign_key => "merged_story_id", :inverse_of => :merged_stories, - :required => false + :optional => true has_many :merged_stories, :class_name => "Story", :foreign_key => "merged_story_id", diff --git a/app/models/user.rb b/app/models/user.rb index 81b0d75b..7dcd3010 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -22,15 +22,15 @@ class User < ApplicationRecord belongs_to :invited_by_user, :class_name => "User", :inverse_of => false, - :required => false + :optional => true belongs_to :banned_by_user, :class_name => "User", :inverse_of => false, - :required => false + :optional => true belongs_to :disabled_invite_by_user, :class_name => "User", :inverse_of => false, - :required => false + :optional => true has_many :invitations, :dependent => :destroy has_many :moderations, :inverse_of => :moderator, diff --git a/app/models/vote.rb b/app/models/vote.rb index 4f562544..915d6cce 100644 --- a/app/models/vote.rb +++ b/app/models/vote.rb @@ -1,7 +1,7 @@ class Vote < ApplicationRecord - belongs_to :user, required: false - belongs_to :story, required: false - belongs_to :comment, required: false + belongs_to :user, optional: true + belongs_to :story, optional: true + belongs_to :comment, optional: true COMMENT_REASONS = { "O" => "Off-topic", diff --git a/script/parse_inbound_mail b/script/parse_inbound_mail index 973492a1..243ccbab 100755 --- a/script/parse_inbound_mail +++ b/script/parse_inbound_mail @@ -24,22 +24,22 @@ if parser.been_here? exit elsif !parser.sending_user - STDERR.puts "no active user with mailing list token #{parser.user_token}" + warn "no active user with mailing list token #{parser.user_token}" # if this looks like a user token but invalid, generate a bounce to be # helpful. otherwise supress it to avoid talking back to spammers exit(parser.user_token ? EX_NOUSER : 0) elsif !parser.email - STDERR.puts "error parsing e-mail" + warn "error parsing e-mail" exit EX_UNAVAILABLE elsif !parser.parent - STDERR.puts "no valid comment or story being replied to" + warn "no valid comment or story being replied to" exit EX_NOUSER elsif !parser.body.present? - STDERR.puts "no valid text/plain body found" + warn "no valid text/plain body found" exit EX_UNAVAILABLE end @@ -58,6 +58,6 @@ end if c.save exit else - STDERR.puts c.errors.inspect + warn c.errors.inspect exit EX_UNAVAILABLE end diff --git a/script/sync_twitter_users b/script/sync_twitter_users index b70a50fc..37335d53 100755 --- a/script/sync_twitter_users +++ b/script/sync_twitter_users @@ -26,7 +26,7 @@ if their_users.empty? raise "Intemittent Twitter bug: they said the list is empty when it's not" end if their_users.count >= 5000 - STDERR.puts "need to implement paging for list members" + warn "need to implement paging for list members" end # fetch our active users that have a linked twitter account diff --git a/spec/controllers/tags_controller_spec.rb b/spec/controllers/tags_controller_spec.rb index 6dbe221a..15c1c351 100644 --- a/spec/controllers/tags_controller_spec.rb +++ b/spec/controllers/tags_controller_spec.rb @@ -28,7 +28,7 @@ describe TagsController do hotness_mod: 1.5, privileged: true, inactive: true, - }, } + } } tag = Tag.find_by(tag: 'mytag') expect(tag.description).to eq 'desc' expect(tag.is_media).to be true