diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 00000000..b10f351d --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,51 @@ +# inherit_from: .rubocop_todo.yml + +require: + - rubocop-rails + +AllCops: + NewCops: enable + DisplayCopNames: true + Exclude: + - 'vendor/**/*' + - 'node_modules/**/*' + - 'spec/**/*' + - 'db/schema.rb' + - 'db/**/*' + - 'config/**/*' + - 'Guardfile' + - 'bin/**/*' + - 'tmp/**/*' + +Style/Documentation: + Enabled: false + +Style/FrozenStringLiteralComment: + Enabled: false + +Style/StringLiterals: + EnforcedStyle: single_quotes + +Style/StringLiteralsInInterpolation: + EnforcedStyle: single_quotes + +Style/TrailingCommaInArrayLiteral: + EnforcedStyleForMultiline: comma + +Metrics/BlockLength: + Max: 52 + +Metrics/ClassLength: + Max: 500 + +Metrics/CyclomaticComplexity: + Max: 16 + +Metrics/MethodLength: + Max: 65 + +Metrics/PerceivedComplexity: + Max: 17 + +Metrics/ModuleLength: + Max: 160 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 32faeb5a..7cd3ede8 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class ApplicationController < ActionController::Base - if Rails.env == 'YOUR_ENVIRONMENT' + if Rails.env.YOUR_ENVIRONMENT? USERNAME = Rails.application.credentials.digest_auth[:username].freeze PASSWORD = Rails.application.credentials.digest_auth[:password].freeze diff --git a/app/lib/operate_spreadsheet.rb b/app/lib/operate_spreadsheet.rb index d9148812..795b2b41 100644 --- a/app/lib/operate_spreadsheet.rb +++ b/app/lib/operate_spreadsheet.rb @@ -7,7 +7,7 @@ def self.session client_secret: Rails.application.credentials.spreadsheet_api[:client_secret], scope: [ 'https://www.googleapis.com/auth/drive', - 'https://spreadsheets.google.com/feeds/' + 'https://spreadsheets.google.com/feeds/', ], refresh_token: Rails.application.credentials.spreadsheet_api[:refresh_token] ) @@ -31,7 +31,7 @@ def self.master_data is_retweet: 0 } tweeted_at_validation = { - tweeted_at: '2018-06-22 21:00:00'.in_time_zone('Tokyo')..'2018-06-24 09:59:59'.in_time_zone('Tokyo') + tweeted_at: ('2018-06-22 21:00:00'.in_time_zone('Tokyo'))..('2018-06-24 09:59:59'.in_time_zone('Tokyo')) } user_id_validation = { user_id: 28 @@ -72,7 +72,7 @@ def self.divided_sheets tweeted_at_index = 18 # R列 # TODO: whereの条件を分割する - tweets_ascending = Tweet.where(is_retweet: 0).where(tweeted_at: '2018-06-22 21:00:00'.in_time_zone('Tokyo')..'2018-06-24 09:00:00'.in_time_zone('Tokyo')).where.not(user_id: 28).order(tweeted_at: :asc) + tweets_ascending = Tweet.where(is_retweet: 0).where(tweeted_at: ('2018-06-22 21:00:00'.in_time_zone('Tokyo'))..('2018-06-24 09:00:00'.in_time_zone('Tokyo'))).where.not(user_id: 28).order(tweeted_at: :asc) # TODO: NOT DRY target_worksheets = [ @@ -95,7 +95,7 @@ def self.divided_sheets 'ツイ 17', 'ツイ 18', 'ツイ 19', - 'ツイ 20' + 'ツイ 20', ] # 100 ごとに分割 diff --git a/app/lib/twitter_api/search_tweet.rb b/app/lib/twitter_api/search_tweet.rb index 7df0a927..2b4d4104 100644 --- a/app/lib/twitter_api/search_tweet.rb +++ b/app/lib/twitter_api/search_tweet.rb @@ -20,10 +20,8 @@ def self.search_word_tweet_exists?(search_word:) # TODO: 汚い if SearchWord.where(word: search_word).first.nil? false - elsif SearchWord.where(word: search_word).first.tweets.empty? - false else - true + !SearchWord.where(word: search_word).first.tweets.empty? end end diff --git a/app/lib/twitter_api/upsert_objects/search_words_table.rb b/app/lib/twitter_api/upsert_objects/search_words_table.rb index 1813ef16..e7e0b237 100644 --- a/app/lib/twitter_api/upsert_objects/search_words_table.rb +++ b/app/lib/twitter_api/upsert_objects/search_words_table.rb @@ -11,8 +11,8 @@ def self.upsert(search_word:) word: search_word }, { - created_at: Time.now, - updated_at: Time.now + created_at: Time.zone.now, + updated_at: Time.zone.now } ) end diff --git a/app/lib/twitter_api/upserted_columns_hash/tweet_hash.rb b/app/lib/twitter_api/upserted_columns_hash/tweet_hash.rb index 67262c2f..67a0e623 100644 --- a/app/lib/twitter_api/upserted_columns_hash/tweet_hash.rb +++ b/app/lib/twitter_api/upserted_columns_hash/tweet_hash.rb @@ -40,8 +40,8 @@ def all_columns(tweet_object, search_word: nil) text: kill_nil(tweet_object.attrs[:full_text]), search_word_id: kill_nil(search_word_id), - created_at: Time.now, - updated_at: Time.now + created_at: Time.zone.now, + updated_at: Time.zone.now } end end diff --git a/app/lib/twitter_api/upserted_columns_hash/user_hash.rb b/app/lib/twitter_api/upserted_columns_hash/user_hash.rb index 5edb32fa..98ec9df2 100644 --- a/app/lib/twitter_api/upserted_columns_hash/user_hash.rb +++ b/app/lib/twitter_api/upserted_columns_hash/user_hash.rb @@ -47,8 +47,8 @@ def all_columns(user_object) connections: kill_nil(user_object.connections, default_value: 'NOTHING'), email: kill_nil(user_object.email, default_value: 'NOTHING'), - created_at: Time.now, - updated_at: Time.now + created_at: Time.zone.now, + updated_at: Time.zone.now } end end diff --git a/app/models/tweet.rb b/app/models/tweet.rb index 65100ee0..8fd7fe9f 100644 --- a/app/models/tweet.rb +++ b/app/models/tweet.rb @@ -16,7 +16,7 @@ class Tweet < ApplicationRecord } tweeted_at_validation = { - tweeted_at: '2018-06-22 21:00:00'.in_time_zone('Tokyo')..'2018-06-24 09:59:59'.in_time_zone('Tokyo') + tweeted_at: ('2018-06-22 21:00:00'.in_time_zone('Tokyo'))..('2018-06-24 09:59:59'.in_time_zone('Tokyo')) } user_id = User.find_by(screen_name: 'gensosenkyo').nil? ? 0 : User.find_by(screen_name: 'gensosenkyo').id @@ -30,7 +30,7 @@ class Tweet < ApplicationRecord # now_counting tweeted_at_validation_for_now_counting = { - tweeted_at: '2018-06-30 12:00:00'.in_time_zone('Tokyo')..'2018-07-01 23:59:59'.in_time_zone('Tokyo') + tweeted_at: ('2018-06-30 12:00:00'.in_time_zone('Tokyo'))..('2018-07-01 23:59:59'.in_time_zone('Tokyo')) } scope :now_counting_tweets_desc, lambda { diff --git a/app/models/user.rb b/app/models/user.rb index 88758416..e1e1ecdf 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -54,7 +54,7 @@ class User < ApplicationRecord def valid_condition_for_vote { is_retweet: 0, - tweeted_at: '2018-06-22 21:00:00'.in_time_zone('Tokyo')..'2018-06-24 09:59:59'.in_time_zone('Tokyo') + tweeted_at: ('2018-06-22 21:00:00'.in_time_zone('Tokyo'))..('2018-06-24 09:59:59'.in_time_zone('Tokyo')) } end