Skip to content

Commit

Permalink
Update rubopcop [WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
printercu committed Dec 30, 2023
1 parent 7bcb0ca commit 263873d
Show file tree
Hide file tree
Showing 78 changed files with 207 additions and 40 deletions.
23 changes: 17 additions & 6 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# Rubocop does not support 2.0
Gemspec/RequiredRubyVersion: {Enabled: false}
require: rubocop-rails

Rails: {Enabled: true}
AllCops:
TargetRubyVersion: 2.4
NewCops: enable
Exclude:
- gemfiles/*
- tmp/*

Layout/AlignParameters:
Gemspec/DevelopmentDependencies: {Enabled: false}

Layout/ParameterAlignment:
# Disable, till rubocop supports combination of styles.
# Use one of this styles where appropriate, keep it clean, compact and readable.
Enabled: false
Expand All @@ -19,15 +25,20 @@ Layout/AlignParameters:
# )
Layout/ClosingParenthesisIndentation: {Enabled: false}
Layout/DotPosition: {EnforcedStyle: trailing}
Layout/EmptyLineAfterGuardClause: {Enabled: false}
Layout/FirstParameterIndentation: {EnforcedStyle: consistent}
# Same as Layout/ClosingParenthesisIndentation
Layout/LineLength: {Max: 100}
Layout/MultilineMethodCallBraceLayout: {Enabled: false}
Layout/MultilineMethodCallIndentation: {EnforcedStyle: indented}
Layout/MultilineOperationIndentation: {EnforcedStyle: indented}
Layout/SpaceInsideHashLiteralBraces: {EnforcedStyle: no_space}

# Offences named scopes and `expect {}.to change {}`.
Lint/AmbiguousBlockAssociation: {Enabled: false}
Lint/EmptyBlock:
Exclude:
- spec/**/*

Naming/PredicateName: {Enabled: false}
Naming/VariableNumber: {EnforcedStyle: snake_case}
Expand All @@ -45,12 +56,12 @@ Style/ModuleFunction: {Enabled: false}
Style/NestedParenthesizedCalls: {Enabled: false}
Style/SignalException: {EnforcedStyle: only_raise}
Style/TrailingCommaInArguments: {Enabled: false}
Style/TrailingCommaInLiteral: {EnforcedStyleForMultiline: comma}
Style/TrailingCommaInArrayLiteral: {EnforcedStyleForMultiline: comma}
Style/TrailingCommaInHashLiteral: {EnforcedStyleForMultiline: comma}

Metrics/AbcSize: {Max: 21}
# Other metrics are just enough.
# This one offences all specs, routes and some initializers.
Metrics/BlockLength: {Enabled: false}
Metrics/LineLength: {Max: 100}
Metrics/MethodLength: {Max: 30}
Metrics/CyclomaticComplexity: {Max: 8}
2 changes: 2 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

appraise 'rails-71' do
gem 'actionpack', '~> 7.1.0'
gem 'railties', '~> 7.1.0'
Expand Down
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'
gemspec

Expand All @@ -14,7 +16,8 @@ group :development do
gem 'rspec-its', '~> 1.3.0'
gem 'rspec-rails', '~> 4.0.2'

gem 'rubocop', '~> 0.52.1'
gem 'rubocop', '~> 1.59.0'
gem 'rubocop-rails', '~> 2.23.1'

gem 'coveralls', '~> 0.8.23', require: false
end
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

Expand Down
1 change: 1 addition & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'bundler/setup'
require 'telegram/bot'
Expand Down
2 changes: 2 additions & 0 deletions bin/fetch-telegram-methods
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# Fetch list of methods from Telegram docs.
# Use it to update client.rb.
Expand Down
3 changes: 2 additions & 1 deletion bin/install_git_hooks
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

root = File.expand_path('../../', __FILE__)
root = File.expand_path('..', __dir__)
hooks_dir = "#{root}/bin/git-hooks"

`ls -1 #{hooks_dir}`.each_line.map(&:strip).each do |file|
Expand Down
2 changes: 2 additions & 0 deletions lib/tasks/telegram-bot.rake
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

namespace :telegram do
namespace :bot do
desc 'Run poller. It broadcasts Rails.logger to STDOUT in dev like `rails s` do. ' \
Expand Down
2 changes: 2 additions & 0 deletions lib/telegram/bot.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'telegram/bot/config_methods'

module Telegram
Expand Down
2 changes: 2 additions & 0 deletions lib/telegram/bot/async.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Telegram
module Bot
# Telegram clients can perform requests in async way with
Expand Down
4 changes: 3 additions & 1 deletion lib/telegram/bot/client.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'active_support/core_ext/hash/keys'
require 'httpclient'

Expand Down Expand Up @@ -41,7 +43,7 @@ def prepare_async_args(action, body = {})
end

def error_for_response(response)
result = JSON.parse(response.body) rescue nil # rubocop:disable RescueModifier
result = JSON.parse(response.body) rescue nil # rubocop:disable Style/RescueModifier
return Error.new(response.reason) unless result
message = result['description'] || '-'
# This errors are raised only for valid responses from Telegram
Expand Down
4 changes: 3 additions & 1 deletion lib/telegram/bot/client/api_helper.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# frozen_string_literal: true

require 'active_support/core_ext/string/inflections'

module Telegram
module Bot
class Client
module ApiHelper
METHODS_LIST_FILE = File.expand_path('../api_methods.txt', __FILE__)
METHODS_LIST_FILE = File.expand_path('api_methods.txt', __dir__)

class << self
def methods_list(file = METHODS_LIST_FILE)
Expand Down
2 changes: 2 additions & 0 deletions lib/telegram/bot/client/request_body_formatter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'json'

module Telegram
Expand Down
2 changes: 2 additions & 0 deletions lib/telegram/bot/client/typed_response.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'telegram/bot/client/api_helper'
require 'active_support/core_ext/string/inflections'

Expand Down
2 changes: 2 additions & 0 deletions lib/telegram/bot/client_stub.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Telegram
module Bot
# Stubbed client for tests. Saves all requests into #requests hash.
Expand Down
2 changes: 2 additions & 0 deletions lib/telegram/bot/config_methods.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'active_support/core_ext/hash/keys'
require 'active_support/core_ext/hash/indifferent_access'

Expand Down
2 changes: 2 additions & 0 deletions lib/telegram/bot/debug_client.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Telegram
module Bot
module DebugClient
Expand Down
2 changes: 2 additions & 0 deletions lib/telegram/bot/middleware.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'active_support/concern'
require 'active_support/core_ext/hash/indifferent_access'
require 'active_support/json'
Expand Down
2 changes: 2 additions & 0 deletions lib/telegram/bot/railtie.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'telegram/bot/routes_helper'

module Telegram
Expand Down
2 changes: 2 additions & 0 deletions lib/telegram/bot/routes_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'base64'
require 'openssl'

Expand Down
2 changes: 2 additions & 0 deletions lib/telegram/bot/rspec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Telegram
module Bot
module RSpec
Expand Down
2 changes: 2 additions & 0 deletions lib/telegram/bot/rspec/callback_query_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'telegram/bot/rspec'
require 'telegram/bot/rspec/message_helpers'

Expand Down
4 changes: 3 additions & 1 deletion lib/telegram/bot/rspec/client_matchers.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Telegram
module Bot
module RSpec
Expand Down Expand Up @@ -68,7 +70,7 @@ def initialize(bot, action, description: nil)
exactly(1)
end

def matches?(proc) # rubocop:disable AbcSize
def matches?(proc) # rubocop:disable Metrics/AbcSize
raise ArgumentError, 'matcher only supports block expectations' unless proc.is_a?(Proc)
original_requests_count = bot.requests[action].count
proc.call
Expand Down
2 changes: 2 additions & 0 deletions lib/telegram/bot/rspec/integration/poller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'telegram/bot/rspec/integration/shared'

RSpec.shared_context 'telegram/bot/integration/poller' do
Expand Down
2 changes: 2 additions & 0 deletions lib/telegram/bot/rspec/integration/rack.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'telegram/bot/rspec/integration/shared'
require 'rack/test'

Expand Down
2 changes: 2 additions & 0 deletions lib/telegram/bot/rspec/integration/rails.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'telegram/bot/rspec/integration/shared'

RSpec.shared_context 'telegram/bot/integration/rails', type: :request do
Expand Down
2 changes: 2 additions & 0 deletions lib/telegram/bot/rspec/integration/shared.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'active_support/json'
require 'telegram/bot'
require 'telegram/bot/rspec/message_helpers'
Expand Down
2 changes: 2 additions & 0 deletions lib/telegram/bot/rspec/message_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Shared helpers for testing message updates.
RSpec.shared_context 'telegram/bot/message_helpers' do
let(:default_message_options) { {from: from, chat: chat} }
Expand Down
4 changes: 3 additions & 1 deletion lib/telegram/bot/updates_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'abstract_controller'
require 'active_support/core_ext/string/inflections'
require 'active_support/callbacks'
Expand Down Expand Up @@ -47,7 +49,7 @@ module Bot
# ControllerClass.new(bot, from: telegram_user, chat: telegram_chat).
# process(:help, *args)
#
class UpdatesController < AbstractController::Base # rubocop:disable ClassLength
class UpdatesController < AbstractController::Base # rubocop:disable Metrics/ClassLength
abstract!

%w[
Expand Down
2 changes: 2 additions & 0 deletions lib/telegram/bot/updates_controller/callback_query_context.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Telegram
module Bot
class UpdatesController
Expand Down
4 changes: 3 additions & 1 deletion lib/telegram/bot/updates_controller/commands.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Telegram
module Bot
class UpdatesController
Expand Down Expand Up @@ -34,7 +36,7 @@ def action_for_command(cmd)
def action_for_message
cmd, args = Commands.command_from_text(payload['text'], bot_username)
return unless cmd
[[action_for_command(cmd), type: :command, command: cmd], args]
[[action_for_command(cmd), {type: :command, command: cmd}], args]
end

alias_method :action_for_channel_post, :action_for_message
Expand Down
2 changes: 2 additions & 0 deletions lib/telegram/bot/updates_controller/instrumentation.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Telegram
module Bot
class UpdatesController
Expand Down
2 changes: 2 additions & 0 deletions lib/telegram/bot/updates_controller/log_subscriber.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'active_support/log_subscriber'

module Telegram
Expand Down
4 changes: 3 additions & 1 deletion lib/telegram/bot/updates_controller/message_context.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Telegram
module Bot
class UpdatesController
Expand Down Expand Up @@ -52,7 +54,7 @@ def action_for_message
super || context && begin
args = payload['text'].try!(:split) || []
action = action_for_message_context(context)
[[action, type: :message_context, context: context], args]
[[action, {type: :message_context, context: context}], args]
end
end

Expand Down
6 changes: 4 additions & 2 deletions lib/telegram/bot/updates_controller/reply_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Telegram
module Bot
class UpdatesController
Expand Down Expand Up @@ -59,9 +61,9 @@ def answer_shipping_query(ok, params = {})
# Edit message from callback query.
def edit_message(type, params = {})
params =
if message_id = payload['inline_message_id'] # rubocop:disable AssignmentInCondition
if message_id = payload['inline_message_id'] # rubocop:disable Lint/AssignmentInCondition
params.merge(inline_message_id: message_id)
elsif message = payload['message'] # rubocop:disable AssignmentInCondition
elsif message = payload['message'] # rubocop:disable Lint/AssignmentInCondition
params.merge(chat_id: message['chat']['id'], message_id: message['message_id'])
else
raise 'Can not edit message without `inline_message_id` or `message`'
Expand Down
4 changes: 3 additions & 1 deletion lib/telegram/bot/updates_controller/rescue.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'active_support/rescuable'

module Telegram
Expand All @@ -11,7 +13,7 @@ module Rescue

def process_action(*)
super
rescue Exception => exception # rubocop:disable RescueException
rescue Exception => exception # rubocop:disable Lint/RescueException
rescue_with_handler(exception) || raise
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/telegram/bot/updates_controller/rspec_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'telegram/bot/updates_controller/testing'
require 'telegram/bot/rspec/message_helpers'
require 'telegram/bot/rspec/callback_query_helpers'
Expand Down
2 changes: 2 additions & 0 deletions lib/telegram/bot/updates_controller/session.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rack/session/abstract/id'
require 'active_support/cache'

Expand Down
2 changes: 2 additions & 0 deletions lib/telegram/bot/updates_controller/testing.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Telegram
module Bot
class UpdatesController
Expand Down
2 changes: 2 additions & 0 deletions lib/telegram/bot/updates_controller/translation.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Telegram
module Bot
class UpdatesController
Expand Down
2 changes: 2 additions & 0 deletions lib/telegram/bot/updates_controller/typed_update.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Telegram
module Bot
class UpdatesController
Expand Down
4 changes: 3 additions & 1 deletion lib/telegram/bot/updates_poller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# frozen_string_literal: true

module Telegram
module Bot
# Supposed to be used in development environments only.
class UpdatesPoller
class << self
@@instances = {} # rubocop:disable ClassVars
@@instances = {} # rubocop:disable Style/ClassVars

def instances
@@instances
Expand Down
Loading

0 comments on commit 263873d

Please sign in to comment.