Skip to content

Commit

Permalink
add rubocop and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
classicalliu committed Sep 21, 2018
1 parent ce36476 commit 05a7a54
Show file tree
Hide file tree
Showing 52 changed files with 394 additions and 140 deletions.
2 changes: 2 additions & 0 deletions .pryrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# use awesome_print in console default
require "awesome_print"
Pry.config.print = proc { |output, value| Pry::Helpers::BaseHelpers.stagger_output("=> #{value.ai}", output) }
120 changes: 120 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
AllCops:
TargetRubyVersion: 2.5
Exclude:
- 'spec/**/*'
- 'db/**/*'
- 'app/views/**/*'
- 'config/**/*'
- 'bin/*'
- 'Rakefile'
- 'Gemfile'
- 'Gemfile.lock'
- 'node_modules/**/*'
- 'vendor/**/*'
- 'lib/blockchain_pb.rb'

Bundler/OrderedGems:
Enabled: false

Layout/AccessModifierIndentation:
EnforcedStyle: indent

Layout/EmptyLineAfterMagicComment:
Enabled: false

Layout/SpaceInsideHashLiteralBraces:
EnforcedStyle: space

Metrics/AbcSize:
Max: 100

Metrics/ClassLength:
CountComments: false
Max: 300

Metrics/CyclomaticComplexity:
Max: 25

Metrics/LineLength:
AllowURI: true
Enabled: false

Metrics/MethodLength:
CountComments: false
Max: 55

Metrics/ModuleLength:
CountComments: false
Max: 200

Metrics/ParameterLists:
Max: 5
CountKeywordArgs: true

Metrics/PerceivedComplexity:
Max: 20

Naming/MemoizedInstanceVariableName:
Enabled: false

Rails:
Enabled: true

Rails/HasAndBelongsToMany:
Enabled: false

Rails/SkipsModelValidations:
Enabled: false

Rails/HttpStatus:
Enabled: false

Rails/HasManyOrHasOneDependent:
Enabled: false

Style/CollectionMethods:
Enabled: true
PreferredMethods:
find_all: 'select'

Style/DoubleNegation:
Enabled: true

Style/FrozenStringLiteralComment:
Enabled: true

Style/GuardClause:
Enabled: false

Style/Lambda:
Enabled: false

Style/Documentation:
Enabled: false

Style/PercentLiteralDelimiters:
PreferredDelimiters:
'%i': '()'
'%w': '()'

Style/ClassAndModuleChildren:
Enabled: false

Naming/AccessorMethodName:
Enabled: false

Metrics/BlockLength:
CountComments: false
Max: 25
ExcludedMethods:
- refine
- included

Style/StringLiterals:
EnforcedStyle: double_quotes
SupportedStyles:
- single_quotes
- double_quotes
# If `true`, strings which span multiple lines using `\` for continuation must
# use the same type of quotes on each line.
ConsistentQuotesInMultiline: false
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ group :development, :test do
gem 'simplecov', require: false
gem 'yard', '~> 0.9.14'
gem 'yard-activesupport-concern'

# Ruby static code analyzer and code formatter
gem "rubocop", require: false
end

group :development do
Expand Down
18 changes: 18 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ GEM
archive-zip (0.11.0)
io-like (~> 0.3.0)
arel (9.0.0)
ast (2.4.0)
awesome_print (1.8.0)
bindex (0.5.0)
bitcoin-secp256k1 (0.4.0)
Expand Down Expand Up @@ -126,6 +127,7 @@ GEM
i18n (1.1.0)
concurrent-ruby (~> 1.0)
io-like (0.3.0)
jaro_winkler (1.5.1-x86_64-darwin-17)
jbuilder (2.7.0)
activesupport (>= 4.2.0)
multi_json (>= 1.2)
Expand Down Expand Up @@ -175,7 +177,11 @@ GEM
mini_portile2 (~> 2.3.0)
oj (3.6.10)
open4 (1.3.4)
parallel (1.12.1)
parser (2.5.1.2)
ast (~> 2.4.0)
pg (1.1.3)
powerpack (0.1.2)
pry (0.11.3)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
Expand Down Expand Up @@ -211,6 +217,7 @@ GEM
method_source
rake (>= 0.8.7)
thor (>= 0.19.0, < 2.0)
rainbow (3.0.0)
rake (12.3.1)
ransack (2.0.1)
actionpack (>= 5.0)
Expand All @@ -237,6 +244,15 @@ GEM
rspec-mocks (~> 3.8.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.0)
rubocop (0.59.1)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.5, != 2.5.1.1)
powerpack (~> 0.1)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.10.0)
ruby_dep (1.5.0)
rubyzip (1.2.2)
safe_yaml (1.0.4)
Expand Down Expand Up @@ -281,6 +297,7 @@ GEM
thread_safe (~> 0.1)
uglifier (4.1.19)
execjs (>= 0.3.0, < 3)
unicode-display_width (1.4.0)
url (0.3.2)
web-console (3.7.0)
actionview (>= 5.0)
Expand Down Expand Up @@ -336,6 +353,7 @@ DEPENDENCIES
rails (~> 5.2.0)
ransack (~> 2.0, >= 2.0.1)
rspec-rails (~> 3.7)
rubocop
sass-rails (~> 5.0)
selenium-webdriver
simplecov
Expand Down
2 changes: 2 additions & 0 deletions app/channels/application_cable/channel.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ApplicationCable
class Channel < ActionCable::Channel::Base
end
Expand Down
2 changes: 2 additions & 0 deletions app/channels/application_cable/connection.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ApplicationCable
class Connection < ActionCable::Connection::Base
end
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/api/blocks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Api::BlocksController < ApplicationController
# get blocks info list and paginate it.
#
Expand Down Expand Up @@ -54,6 +56,7 @@ def index
# @return [Integer]
def parse_hex(number)
return number.to_i(16) if number.to_s.downcase.start_with?("0x")

number
end
end
3 changes: 2 additions & 1 deletion app/controllers/api/erc20_transfers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Api::Erc20TransfersController < ApplicationController
# params:
# {
Expand Down Expand Up @@ -33,7 +35,6 @@ def index
end
transfers = Erc20Transfer.where(address: address).order(id: :desc).ransack(options).result


if params[:page].nil? && (!params[:offset].nil? || !params[:limit].nil?)
offset = params[:offset] || 0
limit = params[:limit] || 10
Expand Down
11 changes: 7 additions & 4 deletions app/controllers/api/statistics_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Api::StatisticsController < ApplicationController
BLOCK_COUNT = 100

Expand Down Expand Up @@ -52,9 +54,11 @@ def brief

block_count = [blocks.count, BLOCK_COUNT].min

return render json: {
result: {}
} if blocks.empty?
if blocks.empty?
return render json: {
result: {}
}
end

end_timestamp = blocks.first.timestamp
start_timestamp = blocks.last.timestamp
Expand All @@ -72,5 +76,4 @@ def brief
}
}
end

end
2 changes: 2 additions & 0 deletions app/controllers/api/status_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Api::StatusController < ApplicationController
# GET /api/status
def index
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/api/sync_errors_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Api::SyncErrorsController < ApplicationController
# params:
# {
Expand Down
6 changes: 4 additions & 2 deletions app/controllers/api/transactions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Api::TransactionsController < ApplicationController
# params:
# {
Expand Down Expand Up @@ -34,7 +36,7 @@ def index
total_count = transactions.total_count
end

decimal_value = params[:valueFormat] == 'decimal' ? true : false
decimal_value = params[:valueFormat] == "decimal"

render json: {
result: {
Expand Down Expand Up @@ -64,7 +66,7 @@ def show
}
end

decimal_value = params[:valueFormat] == 'decimal' ? true : false
decimal_value = params[:valueFormat] == "decimal"

render json: {
result: {
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ApplicationController < ActionController::API
rescue_from ActionController::RoutingError do |e|
render json: {
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/cita_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class CitaController < ApplicationController
include SplitRequestsConcern

Expand All @@ -8,5 +10,4 @@ def index
resp = find(params)
render json: resp
end

end
5 changes: 5 additions & 0 deletions app/controllers/concerns/local_infos_concern.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module LocalInfosConcern
extend ActiveSupport::Concern

Expand All @@ -11,6 +13,7 @@ def get_block_by_number(params)
block_number = HexUtils.to_decimal(block_number_hex)
block = Block.find_by(block_number: block_number)
return nil if block.nil?

# BlockSerializer.new(block).as_json
ActiveModelSerializers::SerializableResource.new(block, serializer: ::BlockSerializer, flag: flag)
end
Expand All @@ -23,6 +26,7 @@ def get_block_by_hash(params)
hash, flag = params
block = Block.find_by(cita_hash: hash)
return nil if block.nil?

ActiveModelSerializers::SerializableResource.new(block, serializer: ::BlockSerializer, flag: flag)
end

Expand All @@ -34,6 +38,7 @@ def get_transaction(params)
hash, = params
transaction = Transaction.find_by(cita_hash: hash)
return nil if transaction.nil?

# TransactionSerializer.new(transaction).as_json
ActiveModelSerializers::SerializableResource.new(transaction, serializer: ::TransactionSerializer)
end
Expand Down
Loading

0 comments on commit 05a7a54

Please sign in to comment.