Skip to content

Commit

Permalink
Improve RuboCop (#279)
Browse files Browse the repository at this point in the history
* Improve RuboCop version lock (and its plugins)

With `NewCops: enable` there are new offenses for new minor RuboCop versions.

The same for plugins, at least some of them.

* Resolve new RuboCop RSpec offenses

* Add `rubocop-performance` plugin

Pretty standard.

And resolve the single issue.

* Fix `frozen_string_literal` offense in `bin/console` instead of ignoring

* Remove unnecessary RuboCop excluding
  • Loading branch information
AlexWayfer authored Jul 11, 2023
1 parent ae92a9c commit 721691b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 18 deletions.
8 changes: 1 addition & 7 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require:
- rubocop-rake
- rubocop-rspec
- rubocop-performance

AllCops:
NewCops: enable
Expand All @@ -10,10 +11,6 @@ AllCops:
Style/Documentation:
Enabled: false

Style/FrozenStringLiteralComment:
Exclude:
- bin/console

Metrics/BlockLength:
AllowedMethods:
- context
Expand All @@ -22,6 +19,3 @@ Metrics/BlockLength:

Layout/LineLength:
Max: 120
Exclude:
- telegram-bot-ruby.gemspec
- examples/*.rb
9 changes: 6 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ gem 'dotenv', '~> 2.8'
gem 'nokogiri', '~> 1.13'
gem 'pry'
gem 'rake', '~> 13.0'

gem 'rspec', '~> 3.4'
gem 'rubocop', '~> 1.27'
gem 'rubocop-rake'
gem 'rubocop-rspec', '~> 2.10'

gem 'rubocop', '~> 1.54.1'
gem 'rubocop-performance', '~> 1.18'
gem 'rubocop-rake', '~> 0.6.0'
gem 'rubocop-rspec', '~> 2.22.0'
4 changes: 3 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ task :dump_type_attributes do
# Fetch and parse docs
doc = Nokogiri::HTML(URI.open('https://core.telegram.org/bots/api').read)

next_type_element_names = %w[table h4]

result = types.to_h do |type|
# This is very hacky but working way to find table containing attributes for
# given type. Basic idea is to find heading with type and then iterate until
Expand All @@ -38,7 +40,7 @@ task :dump_type_attributes do
element = doc.at_xpath(%{//h4[text() = "#{type}"]})
loop do
element = element.next_element
break if %w[table h4].include?(element.name)
break if next_type_element_names.include?(element.name)
end

attributes = element.xpath('.//tbody//tr').map do |el|
Expand Down
3 changes: 3 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/usr/bin/env ruby

# frozen_string_literal: true

require 'bundler/setup'
require 'pry'

Expand Down
9 changes: 2 additions & 7 deletions lib/telegram/bot/types/compactable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@ module Bot
module Types
module Compactable
def to_compact_hash
attributes.dup.delete_if { |_, v| v.nil? }.to_h do |key, value|
value =
if value.respond_to?(:to_compact_hash)
value.to_compact_hash
else
value
end
attributes.dup.compact.to_h do |key, value|
value = value.to_compact_hash if value.respond_to?(:to_compact_hash)

[key, value]
end
Expand Down

0 comments on commit 721691b

Please sign in to comment.