Let's use Rubocop! (#1325)

* Add limited rubocop config and TODO config

* Remove trailing whitespaces and blanklines

* Add rubocop rake task; upd travis.yml
This commit is contained in:
Vladimir Dementyev 2017-06-04 23:21:05 +03:00 committed by Nate Berkopec
parent 4af4a006d1
commit 2cb2357d39
14 changed files with 188 additions and 10 deletions

88
.rubocop.yml Normal file
View File

@ -0,0 +1,88 @@
AllCops:
DisabledByDefault: true
TargetRubyVersion: 1.9.3
DisplayCopNames: true
StyleGuideCopsOnly: false
Exclude:
- 'tmp/**/*'
- 'gemfiles/vendor/**/*'
- 'vendor/**/*'
- 'Rakefile'
Layout/SpaceAfterColon:
Enabled: true
Layout/SpaceAroundKeyword:
Enabled: true
Layout/SpaceBeforeFirstArg:
Enabled: true
Layout/SpaceInsideParens:
Enabled: true
Layout/Tab:
Enabled: true
Layout/TrailingBlankLines:
Enabled: true
Layout/TrailingWhitespace:
Enabled: true
Lint/Debugger:
Enabled: true
Style/MethodDefParentheses:
Enabled: true
Style/MethodName:
Enabled: true
EnforcedStyle: snake_case
Exclude:
- 'test/**/**'
Style/TrailingCommaInArguments:
Enabled: true
Style/VariableName:
Enabled: true
Performance/Count:
Enabled: true
Performance/Detect:
Enabled: true
Performance/EndWith:
Enabled: true
Performance/FlatMap:
Enabled: true
Performance/HashEachMethods:
Enabled: true
Performance/RangeInclude:
Enabled: true
Performance/RedundantMerge:
Enabled: true
Performance/RedundantSortBy:
Enabled: true
Performance/ReverseEach:
Enabled: true
Performance/Sample:
Enabled: true
Performance/Size:
Enabled: true
Performance/StartWith:
Enabled: true
Performance/TimesMap:
Enabled: true

86
.rubocop_todo.yml Normal file
View File

@ -0,0 +1,86 @@
inherit_from: "./.rubocop.yml"
# 29 offenses
Layout/SpaceAroundOperators:
Enabled: true
# 21 offenses
Layout/SpaceInsideBlockBraces:
Enabled: true
# 16 offenses
Layout/SpaceAroundEqualsInParameterDefault:
Enabled: true
EnforcedStyle: no_space
# 15 offenses
Layout/SpaceBeforeBlockBraces:
Enabled: true
# 15 offenses
Layout/SpaceInsideHashLiteralBraces:
Enabled: true
EnforcedStyle: no_space
# 8 offenses
Layout/EmptyLines:
Enabled: true
# 4 offenses
Layout/EmptyLinesAroundClassBody:
Enabled: true
Exclude:
- 'test/**/*'
# 6 offenses
Layout/EmptyLinesAroundMethodBody:
Enabled: true
# 5 offenses
Layout/EmptyLinesAroundModuleBody:
Enabled: true
# 5 offenses
Layout/IndentationWidth:
Enabled: true
# 3 offenses
Layout/AccessModifierIndentation:
EnforcedStyle: indent
# 2 offenses
Style/WhileUntilModifier:
Enabled: true
# 1 offense
Style/TernaryParentheses:
Enabled: true
# >200 offenses for 80
# 58 offenses for 100
# 18 offenses for 120
Metrics/LineLength:
Max: 120
AllowHeredoc: true
AllowURI: true
URISchemes:
- http
- https
IgnoreCopDirectives: false
IgnoredPatterns: []
# 1 offense
Metrics/ParameterLists:
Max: 5
# 1 offense
Performance/RedundantMatch:
Enabled: true
# 1 offense
Performance/RedundantBlockCall:
Enabled: true
# 1 offense
Performance/StringReplacement:
Enabled: true

View File

@ -7,7 +7,7 @@ before_install:
# bundler installation needed for jruby-head
# https://github.com/travis-ci/travis-ci/issues/5861
- gem install bundler -v 1.11.2
script: "TESTOPTS=-v bundle exec rake test"
script: "TESTOPTS=-v bundle exec rake"
branches:
only: [master]
rvm:

View File

@ -12,3 +12,5 @@ gem "rack", "< 3.0"
gem "minitest", "~> 5.9"
gem "jruby-openssl", :platform => "jruby"
gem "rubocop", "~> 0.49.1"

View File

@ -2,6 +2,10 @@ require "bundler/setup"
require "hoe"
require "rake/extensiontask"
require "rake/javaextensiontask"
require "rubocop/rake_task"
# Add rubocop task
RuboCop::RakeTask.new
IS_JRUBY = defined?(RUBY_ENGINE) ? RUBY_ENGINE == "jruby" : false
@ -163,3 +167,5 @@ namespace :test do
task :all => [:test, "test:integration"]
end
end
task :default => [:rubocop, :test]

View File

@ -6,7 +6,7 @@
CA[:domainname] = domainname
CA[:CA_dir] = File.join Dir.pwd, "CA"
CA[:password] = 'puma'
CERTS << {
:type => 'server',
:hostname => 'puma'

View File

@ -10,3 +10,5 @@ gem "rack", "~> 1.6"
gem "minitest", '~> 5.9'
gem "jruby-openssl", :platform => "jruby"
gem "rubocop", "~> 0.49.1"

View File

@ -80,4 +80,3 @@ module Puma
end
end
end

View File

@ -32,4 +32,3 @@ Puma::Plugin.create do
end
end
end

View File

@ -11,4 +11,3 @@ on_worker_fork { 1 }
on_restart { 1 }
after_worker_boot { 1 }
lowlevel_error_handler { 1 }

View File

@ -16,4 +16,3 @@ if log =~ %r!GET / HTTP/1\.1!
else
exit 1
end

View File

@ -9,7 +9,7 @@ sleep 2
worker_index_within_number_of_workers = !File.file?("t3-worker-3-pid")
system "kill `cat t3-pid`"
system "kill `cat t3-pid`"
File.unlink "t3-pid" if File.file? "t3-pid"
File.unlink "t3-worker-0-pid" if File.file? "t3-worker-0-pid"
@ -22,4 +22,3 @@ if worker_pid_was_present and worker_index_within_number_of_workers
else
exit 1
end

View File

@ -179,4 +179,3 @@ class TestUserSuppliedOptionsIsNotPresent < Minitest::Test
end
end
end

View File

@ -31,7 +31,7 @@ st = "GET / HTTP/1.1\r\nHost: www.zedshaw.com\r\nContent-Type: text/plain\r\nCon
puts "length: #{content.length}"
threads = []
ARGV[1].to_i.times do
ARGV[1].to_i.times do
t = Thread.new do
size = 100
puts ">>>> #{size} sized chunks"